Tuple enumeration without integers or strings
Paul
paultjeadriaanse at gmail.com
Sun Jan 3 02:41:12 UTC 2021
On Sunday, 3 January 2021 at 02:17:43 UTC, frame wrote:
> Besides the problem with equal values, what's wrong with that:
>
> alias Thing = Tuple!(int, int);
> enum Wind {
> A = Thing(0, 1),
> B = Thing(0, 2),
> C = Thing(0, 2)
> }
>
> void some_function(Wind w) {
> switch (w.hashOf) {
> case Wind.B.hashOf:
> break;
>
> default:
> assert(0);
> }
> }
>
> void main() {
> some_function(Wind.B);
> writefln("%d%d", Wind.C.expand);
> }
I haven't used hashOf before, though assuming no equal values,
which I generally wouldn't do, I take it this is reliable? I
haven't tried it before, and I dont know how to effectively
compare it to using 'switch(w.to!string)' & 'case
Wind.B.stringof' (regarding speed/reliability).
More information about the Digitalmars-d-learn
mailing list