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

2021-11-25 Thread Alexey via Digitalmars-d-learn

On Friday, 26 November 2021 at 00:41:34 UTC, Elronnd wrote:

you are right. thanks


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

2021-11-25 Thread Elronnd via Digitalmars-d-learn

static if (...) {
} else static if (...) {
} else {
static assert(0);
}


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

2021-11-25 Thread Alexey via Digitalmars-d-learn

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...
}
```


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

2021-11-25 Thread Alexey via Digitalmars-d-learn
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.