Min, max of enum

Profile Anaysis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 25 21:58:26 PST 2017


Since we do not have attributes for enums, I use _ in front of 
the names for meta values.

I need to get the non-meta values for the enum so I can iterate 
over it and use it properly.

enum myEnum
{
     _Meta1 = 0,
     A,B,C,
     _Meta3 = 43,
     D = 3,
}

The num, for all practical purposes does not contain _Meta1, 
and_Meta3. But in code I use to!myEnum(intI) and having the meta 
values complicate things(simple shifting may or may not work).

I also need to create array indexers based on myEnum that don't 
include the meta characters.

What I do a lot is convert integers in to fields of the enum.

If I do not include any Meta, then it is straight forward 
to!myEnum(i), but with them it is not, so doing things like

int[myEnum] x;

x[to!myEnum(i))] is difficult because the conversion will be 
invalid for meta. I'd have to do some work on i to get the 0-n 
representation to map properly in to the enum... basically 
avoiding the meta fields.

This would all be solved with attributes for enums, but that, I 
suppose is a pipe dream.

Any ideas how I can make this easy?






More information about the Digitalmars-d-learn mailing list