Iterate over symbols in tupleof without instance
Dicebot
public at dicebot.lv
Tue Apr 15 03:45:06 PDT 2014
On Tuesday, 15 April 2014 at 08:18:31 UTC, Benjamin Thaut wrote:
> void iterate(T)()
> {
>
> foreach(size_t i, m; T.tupleof)
> // error message: "Need this to access <member name here>"
> {
> // do something with m
> }
> }
>
> Kind Regards
> Benjamin Thaut
Is this acceptable?
void iterate(T)()
{
foreach (index, member; T.init.tupleof)
{
pragma(msg, __traits(identifier, T.tupleof[index]));
}
}
struct A
{
int a, b, c;
}
void main()
{
iterate!A();
}
Reason why you can't naively iterate over T.tupleof is that
current tuple foreach tries to look like normal foreach and thus
iteration parameters can't be types. If
http://wiki.dlang.org/DIP57 is ever to be implemented, this will
be fixed.
More information about the Digitalmars-d-learn
mailing list