enum

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Apr 9 10:06:01 PDT 2014


On 4/8/14, 3:06 PM, H. S. Teoh wrote:
> On Tue, Apr 08, 2014 at 09:46:51PM +0000, Meta wrote:
>> On Tuesday, 8 April 2014 at 19:09:55 UTC, Andrei Alexandrescu wrote:
> [...]
>>> 3. What is the priority of improving enums in the larger picture of
>>> other things we must do?
>>
>> Enums could stand to be improved, but finishing the implementation of
>> the language should take precedent.
>
> Yes! There are much bigger fish to fry than enums right now. Let's not
> lose sight of the forest for the trees.

I'm glad to see this trend! :o)

There are a couple of simple functions we can add to improve the enum 
experience incrementally (E is an enumerated type):

E succ(E value);
E succ(E value, E overflow) nothrow;
E pred(E value);
E pred(E value, E overflow) nothrow;

They'd return the successor/predecessor of value in the enumerated type, 
assuming it's ordered and has increment. Probably should only work for 
integral enums. It would prefer real ordering to lexical ordering, or 
would refuse to work with enums that are inconsistent.


Andrei



More information about the Digitalmars-d mailing list