May 06 [Issue 24540] Add order/index to enum member to return its position | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24540 --- Comment #1 from apham <apz28@hotmail.com> --- The value is also needed to be known at compile time static assert(Foo.one.order == 0); static assert(Foo.two.order == 1); -- |
May 06 [Issue 24540] Add order/index to enum member to return its position | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24540 Nick Treleaven <nick@geany.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nick@geany.org --- Comment #2 from Nick Treleaven <nick@geany.org> --- (In reply to apham from comment #0) > void set(Foo e) > { > v |= 1 << e.order; > } > > bool isSet(Foo e) > { > return (v & (1 << e.order)) != 0; > } It's not possible to take a runtime enum value and produce its index in an enum without some runtime overhead. Another issue is that `e.order` is already valid code, meaning call `order(e)`. -- |
Copyright © 1999-2021 by the D Language Foundation