generating switch case from compile time sequence of functions

Sjoerd Nijboer dlang at sjoerdnijboer.com
Mon Jul 15 08:14:51 UTC 2019


On Sunday, 14 July 2019 at 19:59:36 UTC, Adam D. Ruppe wrote:
> but I think even attempting this is overcomplicating.
>
>>         static foreach (name; FunctionNames)
>>         {
>>             name ~ " : " ~ name ~ "(); break;";
>>         }

I eventually went with

`switch (mixin(index))
{
     static foreach (index, name; FunctionNames)
     {
         mixin(index) ~ " : " ~ mixin(name) ~ "(); break;";
     }
     default:
         throw new Exception("Out of range.");
}`

I also ditched the idea of an enum for now, but I might add 
something simular in later for logging purposes.
Thank you for your help!



More information about the Digitalmars-d-learn mailing list