Sort enum values, please
BCS
none at anon.com
Wed Nov 25 12:44:34 PST 2009
Hello Tomek,
> Quick one: could the compiler enforce that enum values in order of
> appearance are sorted?
>
> It could neatly guarantee no surprises with case ranges, like this
> one:
>
> enum Weird { One=1, Two=4, Three=3 }
>
> Now, case Weird.One: .. case Weird.Three: won't match Weird.Two.
>
My current programming project (in C++ as a result of the CS class it's for)
has a rather common enum where this would be a bother as it has several identifiers
for the same values. Having to sort them would make working with them a pain.
> I'd agree that you don't see enums like Weird often. Then again, why
> rely on a coding convention? This guarantee looks cheap to implement.
>
> Any reason against?
>
> Tomek
>
More information about the Digitalmars-d
mailing list