RFC to: my need for 'static switch' and CT 'static variables'

Alexey animuspexus at protonmail.com
Thu Nov 25 22:00:15 UTC 2021


for example, I have the code (code in sample generates different 
types of Properties dependingly on struct's mode value):
```D
struct PropSetting
{
     string mode;
     string type;
     string var_name;
     string title_name;
     string default_value;
}

mixin template mixin_install_multiple_properties(PropSetting[] 
settings)
{
     import std.format;

     static foreach (v; settings)
     {
         static if (v.mode == "gs_w_d")
         {
             mixin(
                 q{
                     private {
                         mixin Property_%1$s!(%2$s, "%3$s", %5$s);
                     }

                     mixin Property_forwarding!(%2$s, %3$s, 
"%4$s");

                 }.format(
                     v.mode,
                     v.type,
                     v.var_name,
                     v.title_name,
                     v.default_value,
                     )
                 );
         }

         static if (v.mode == "gsu" || v.mode == "gs" || v.mode == 
"gsun")
         {
             mixin(
                 q{
                     private {
                         mixin Property_%1$s!(%2$s, "%3$s");
                     }

                     mixin Property_forwarding!(%2$s, %3$s, 
"%4$s");

                 }.format(
                     v.mode,
                     v.type,
                     v.var_name,
                     v.title_name,
                     )
                 );
         }

     }
}
```
currently it works kind of ok. but what it's missing is check on 
what none of [static if]s have worked. Ideally, I would want an 
static 'switch here', so I could make `static assert(false)` in 
it. and/or I'd like some sort of [compile time variable] to 
change it if  [static if]s have worked and check such [compile 
time variable] later.



More information about the Digitalmars-d-learn mailing list