Tuple enumeration without integers or strings

Paul paultjeadriaanse at gmail.com
Sat Jan 2 00:57:48 UTC 2021


It seems w.to!string works in conjunction with Wind.N.stringof, 
though I wonder about the efficiency/wastefulness of this method.
Sadly this also leads to very funny behavior when some of the 
enums have the same value, as to!string(Enum) will yield the name 
of the first of these enums having the same values.

> alias Thing = Tuple!(int, int);
> enum Enum {
>     A = Thing(0, 1),
>     B = Thing(0, 2),
>     C = Thing(0, 2)
> }
> void main(){
>     Enum.C.to!string.writeln;
> }

For example, the code above will print 'B' (I'm slightly curious 
how & why std.conv uses the Enum name when converting to string, 
instead of using the value, especially since I didn't see this 
pitfall coming partly due to this)

So this neither seems a satisfiable solution to me :/


More information about the Digitalmars-d-learn mailing list