Compile time mapping
Bastiaan Veelo
Bastiaan at Veelo.net
Sun May 12 18:03:50 UTC 2019
On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote:
> On Saturday, 11 May 2019 at 15:48:44 UTC, Bogdan wrote:
>> What would be the most straight-forward way of mapping the
>> members of an enum to the members of another enum (one-to-one
>> mapping) at compile time?
>
> If I understand your question correctly, you have two enums of
> equal length, and you want to convert members across enums
> according to their position, right? You can do that with a
> little bit of template programming and static foreach. The
> following works irrespective of underlying value and type, the
> only requirement is that there are no duplicate values:
>
> https://run.dlang.io/is/dNssel
There was an error in the error reporting. That should teach me
to never copy+paste if you can static foreach :-) This one is
better:
https://run.dlang.io/is/TVl9db
More information about the Digitalmars-d-learn
mailing list