"toString(enum.value)" How?

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Jul 10 13:45:46 PDT 2007


"Ingo Oeser" <ioe-news at rameria.de> wrote in message 
news:f70i4s$2o0d$1 at digitalmars.com...
>
> Doing it with tuples is only slightly useful, since there
> can be gaps in enums.
>

Not if the tuple was a tuple of aliases to the enum members.

For example, something like this:

enum X
{
    A, B, C = 6
}

alias X.A _A;
alias X.B _B;
alias X.C _C;

template Tuple(T...) { alias T Tuple; }

alias Tuple!(_A, _B, _C) XTupleof;

..

foreach(val; XTupleof)
    writefln(val);

this shows "0 1 6".

This of course is just the manual implementation of what the compiler could 
do for us.  Basically it'd become

foreach(val; X.tupleof)
    writefln(val);

and the tuple would be aliases to each value.  Then you could do .stringof 
on val and get the name.  And from there, it's a very short jump to 
generating the actual table.

Or, as you said, if the compiler could just give us a .namesof or something 
like that, we wouldn't have to do anything at all ;) 




More information about the Digitalmars-d-learn mailing list