"toString(enum.value)" How?
Ingo Oeser
ioe-news at rameria.de
Tue Jul 10 11:33:57 PDT 2007
Jarrett Billingsley wrote:
> Furthermore, EnumValue.stringof would have to give a string
> representation of the actual enum value, rather than a string of the type
> as it does now
That behavior would be perfect! This is also much better that min/max,
since enums can contain holes. Enums are just a set of valid symbols
with defined ordering within a scope.
> (I think .stringof is still not 100% finished anyway..). With those two
> abilities, generating some kind of lookup table at compile-time would be
> very easy indeed.
And is very much needed. Just look how often that kind of stuff is
implemented! Maybe we can have the best of both worlds and just
get a string[enum foo] from any named enum, where we can iterate
either through the keys or through the values.
> But of course as Jason pointed out, one issue is with flag enums.
They are nothing else but additional values for me.
Consider:
enum Foo {
bar = 1,
baz = 2,
boo = 4,
all = bar | baz | boo,
}
Foo.all is just an additional valid value. The way it is composed is
nothing else but an implementation detail, which can change.
> I'd even go so far as to say that the
> use of an enum as a simple list of constants and the use of an enum as a
> list of flags is divergent enough to warrant a new language construct
> i.e. "flags
Yes, that is a completely new semantic, which is called "set" :-)
Ok, that is actually a "set of enum values" which might be an interesting
specialisation for the set template :-)
We don't have that semantic now. But we have enums and they miss a useful
method. That is my point.
Maybe I should forward that thread to the "D"
newsgroup?
Best Regards
Ingo Oeser
More information about the Digitalmars-d-learn
mailing list