www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - RFC to: my need for 'static switch' and CT 'static variables'

reply Alexey <animuspexus protonmail.com> writes:
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.
Nov 25 2021
next sibling parent Alexey <animuspexus protonmail.com> writes:
On Thursday, 25 November 2021 at 22:00:15 UTC, Alexey wrote:
 I would want an static 'switch here',
I mean something like ```D static switch (v.mode) { default: static assert(false, "v.mode" is invalid) case "gs_w_d": // etc... } ```
Nov 25 2021
prev sibling parent reply Elronnd <elronnd elronnd.net> writes:
static if (...) {
} else static if (...) {
} else {
	static assert(0);
}
Nov 25 2021
parent Alexey <animuspexus protonmail.com> writes:
On Friday, 26 November 2021 at 00:41:34 UTC, Elronnd wrote:

you are right. thanks
Nov 25 2021