On Sunday, 3 January 2021 at 01:15:56 UTC, Paul wrote:
On Saturday, 2 January 2021 at 21:48:04 UTC, Paul Backus wrote:
Yes, but this will be true of any approach you choose. If two enum members have exactly the same value, there is no way to distinguish between them, either at compile time or at runtime.

Oh I see, thanks!
A bit of a bummer as I guess that means you're pretty much required to use an additional seperate structure like an array or map/associative array, the latter making the use of an enum instead of string names slightly pointless in this scenario, thank you nontheless 😅.

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);
}

Reply via email to