bearophile schrieb:
A way to tell them apart is the presence of the EnumTag, if it's present, then 
the enum is a new type:

enum V1 = 10;
enum { V2 = 20 }
enum Foo { V3 }
void main() {
    assert(V1 == 10);    // OK
    assert(V2 == 20);    // OK
    assert(Foo.V3 == 0); // ERROR, type mismatch
}

Bye,
bearophile

I sometimes find it convenient to just treat those values as integers, e.g. when reading/writing them with a stream (to a file, to some other process with SocketStream, ...).
Like
---
int x;
stream.read(x); // btw: this often sucks - why not x = stream.readInt()?
if(x == MyEnum.DIE)
        return 0;
else if(x == MyEnum.CALLFOO)
        foo(x);
---
or something like that (switch() might be better, but whatever).

Also treating named and unnamed enums differently seems inconsistent to me.

Cheers,
- Daniel

Reply via email to