Return enum-templated struct based on runtime value

Sebastian Graf Sebastiangraf at t-online.de
Sat Apr 6 13:35:52 PDT 2013


On Saturday, 6 April 2013 at 15:38:55 UTC, Tobias Pankrath wrote:
>>
>> Is there however some way to generate that switch with cases 
>> for each enum member in a template, so that each case calls 
>> <some-passed-template-func>(Machine)() instantiated with the 
>> appropriate enum member? I know you could do it with string 
>> mixins, but that be a hassle to implement...
>>
>> Eventually, I want my code to look like
>>
>>    void func(Machine machine)() { ... }
>>    switchOnEachEnumMember!func(machine);
>
> http://dpaste.dzfl.pl/ce8366a7
>
> The foreach is unrolled at compile time.
Perfect! So that's a final switch...


More information about the Digitalmars-d-learn mailing list