Iterate over symbols in tupleof without instance
Artur Skawina
art.08.09 at gmail.com
Tue Apr 15 04:25:02 PDT 2014
On 04/15/14 12:45, Dicebot wrote:
> 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.
void iterate(T)()
{
foreach (index, member; typeof(T.tupleof))
{
pragma(msg, __traits(identifier, T.tupleof[index]));
}
}
artur
More information about the Digitalmars-d-learn
mailing list