Thread overview
[Issue 24540] Add order/index to enum member to return its position
May 06, 2024
apham
May 06, 2024
Nick Treleaven
May 06, 2024
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, 2024
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)`.

--
December 13
https://issues.dlang.org/show_bug.cgi?id=24540

--- Comment #3 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18239

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--