enum-indexed arrays
"Nordlöw" via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 20 13:37:34 PDT 2014
Have anybody thought about adding safe enum-based indexing to
builtin arrays? Ada has this.
IMHO I believe this could be implemented either in the compiler,
druntime or phobos.
Example
enum I { a=3,b=4,c=5 }
int[I] x = [3,4,5];
assert(x[I.a] == 3);
assert(x[I.b] == 4);
assert(x[I.c] == 5);
Iteration through
foreach (i, e; x) {}
where
i is of type I
and
e is of type int
More information about the Digitalmars-d-learn
mailing list