Return enum-templated struct based on runtime value
Tobias Pankrath
tobias at pankrath.net
Sun Apr 7 03:44:46 PDT 2013
On Saturday, 6 April 2013 at 20:35:54 UTC, Sebastian Graf wrote:
> 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...
The final switch isn't important here. You could use a normal
switch with a default block instead.
More information about the Digitalmars-d-learn
mailing list