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

Reply via email to