static switch statement
monkyyy
crazymonkyyy at gmail.com
Mon Jul 28 16:59:59 UTC 2025
On Monday, 28 July 2025 at 06:49:17 UTC, IchorDev wrote:
> The equivalent of `static if`, but for `switch` statements.
>
> Is there any reason why we don't already have this?
Id suggest reusing template specailization logic
```d
template foo(T...){
static switch(T){
case(int I,string S){
foo()=>iota(0,I).each!(()=>s.writeln);
}
case(S:int){
foo(int i)=>i.writeln;
}
case(S) if(isNumberic!S){
foo(S i)=>i.writeln("not int");
}}
unittest{
foo!(10,"foo");
foo!int(10);
foo(13.37);//inferred somehow
}
```
More information about the dip.ideas
mailing list