Re: enum-indexed arrays

2014-09-20 Thread Nordlöw
On Saturday, 20 September 2014 at 22:13:30 UTC, Baz wrote: Not true, because you can use std.traits.EnumMembers to prepare an enum member rank lookup table, so that values have even not be consecutive. You're correct. Even better not having that limitation :) there is an example here: http:

Re: enum-indexed arrays

2014-09-20 Thread Baz via Digitalmars-d-learn
On Saturday, 20 September 2014 at 22:00:24 UTC, bearophile wrote: Nordlöw: should be Enumerator start = Enumerator.min This also requires the enum to have adjacent values (in general enums can skip values). Bye, bearophile Not true, because you can use std.traits.EnumMembers to prepa

Re: enum-indexed arrays

2014-09-20 Thread bearophile via Digitalmars-d-learn
Nordlöw: should be Enumerator start = Enumerator.min This also requires the enum to have adjacent values (in general enums can skip values). Bye, bearophile

Re: enum-indexed arrays

2014-09-20 Thread Nordlöw
On Saturday, 20 September 2014 at 21:05:12 UTC, Nordlöw wrote: On Saturday, 20 September 2014 at 20:43:28 UTC, bearophile wrote: In D currently that "int[I]" is an associative array with I index and int values. So in another post I have suggested another syntax. Couldn't we simply add an opti

Re: enum-indexed arrays

2014-09-20 Thread Nordlöw
On Saturday, 20 September 2014 at 20:43:28 UTC, bearophile wrote: In D currently that "int[I]" is an associative array with I index and int values. So in another post I have suggested another syntax. Couldn't we simply add an optimization pass that CT-introspects the enumerators of an enum-in

Re: enum-indexed arrays

2014-09-20 Thread bearophile via Digitalmars-d-learn
Nordlöw: Have anybody thought about adding safe enum-based indexing to builtin arrays? Ada has this. I'd like this. I'd like even more: a general way to have optionally strongly typed array indexes. enum I { a=3,b=4,c=5 } int[I] x = [3,4,5]; In D currently that "int[I]" is an as

enum-indexed arrays

2014-09-20 Thread Nordlöw
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); as