On Sunday, 8 June 2025 at 18:44:15 UTC, mitgedanken wrote:
// Is this struct needed? An alternative please.
I want to specify through these ``struct``s that a routine ...
A. returns the type ``TRet``
B. how many arguments (and their type*) it needs
```d
template foo(T...){
enum len=T.length;
static if(T.length>0&& ! is(T[0]==void)){
alias first=T[0];
} else {
alias first=void;
}
}
unittest{
alias bar=foo!(int,13.37,true);
static assert(bar.len==3);
static assert(foo!().len==0);
static assert(is(bar.first==int));
}
```
crash course of templates ugly syntax:
1. templates can store groups of `thingz`
2. alias hold types, enums hold litterals(the exceptions to this
rule are complicated)
3. throw static in front of keywords and hope it works
4. T... is magic, learn all the syntax of AliasSeq
5. pragma(msg, and __traits are ugly but nessery
read the template book when you start running into major problems