www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - static switch statement

reply IchorDev <zxinsworld gmail.com> writes:
The equivalent of `static if`, but for `switch` statements.

Is there any reason why we don't already have this?
Jul 27
parent monkyyy <crazymonkyyy gmail.com> writes:
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 } ```
Jul 28