[Issue 24540] Add order/index to enum member to return its position

2024-05-06 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24540

Nick Treleaven  changed:

   What|Removed |Added

 CC||n...@geany.org

--- Comment #2 from Nick Treleaven  ---
(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)`.

--


[Issue 24540] Add order/index to enum member to return its position

2024-05-06 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=24540

--- Comment #1 from apham  ---
The value is also needed to be known at compile time

static assert(Foo.one.order == 0);
static assert(Foo.two.order == 1);

--