I have a Matrix class, and it would be really convenient to be able to initialize the matrix using an initialization list.
For example, the following would produce a 2x2 Matrix.
[source]Matrix M = { {1,2}, {3,4} };[/source]
It appears that a multidimensional initialization list can only be used on template types, because it relies on a subtype.
"as_compiler.cpp" around line 2540...
[source]void asCCompiler::CompileInitList
if( el->nodeType == snAssignment )
{
// Compile the assignment expression
CompileAssignment(el, &rctx);
}
else if( el->nodeType == snInitList )
{
int offset = AllocateVariable(var->dataType.GetSubType(), true)[/source]
I don't see any way to initialize my Matrix, which is registered as follows, with an initialization list.
[source]engine->RegisterObjectType("Matrix", 0, asOBJ_REF);[/source]
I saw the following source comment:
"as_compiler.cpp"
[source] // TODO: initlist: Should we have a special indexing operator for this? How can we support
// initialization lists with different types for different elements? Maybe
// by using the variable arguments the initialization can be done with one
// call, passing all the elements as arguments. The registered function can
// then traverse them however it wants.[/source]
Perhaps a nested initialization list could take advantage of a similar (or the same) solution. If some sort of generic, variable argument function could be called which passed in all the arguments at once, then a nested initialization list could appear as another variable argument list.
It is likely that you were already thinking of this, and I didn't check the entire forum to see if anybody else had expressed a desire for a similar feature. In any case, mark me down as wanting this feature