Iterate over symbols in tupleof without instance
monarch_dodra
monarchdodra at gmail.com
Tue Apr 15 04:32:21 PDT 2014
On Tuesday, 15 April 2014 at 08:18:31 UTC, Benjamin Thaut wrote:
> I would like to iterate over T.tupleof at compiletime without
> having a instance of the given type.
*What* exactly are you trying to do? You could iterate over the
tupleof *types* instead if you want? Would that work for you?
foreach(i, SubT; FieldTypeTuple!T)
{
...
}
You get your static loop, your indexes, and types. And if you
need to operate on the subtypes, you can always use `SubT a =
SubT.init;`
Also, as a general rule, it is "recommended" to not use tupleof
directly, but rather:
T myData;
foreach(i, SubT; FieldTypeTuple!T)
{
alias subData = myData.tupleof[i];
}
This is because FieldTypeTuple will strip the "context pointer
field", which you generally don't care about.
More information about the Digitalmars-d-learn
mailing list