Imperative Templates

monkyyy crazymonkyyy at gmail.com
Wed May 8 14:56:37 UTC 2024


Allow saner escape hatches for state-ful templates, instead of 
compiler ~~bugs~~ fun unintended features with generally horrible 
proforence, syntax and limitations

---

`__COUNTER__` a special token that increases by 1 each time its 
called

```
unittest{
    __COUNTER__.writeln;//0
    __COUNTER__.writeln;//1
}
unittest{
    __COUNTER__.writeln;//2
}
```

this is already possible with mixin and mix files

---

`__traits(oldarguments)` returns the previous template arguments

```
template foo(T...){
   alias bar=__traits(oldarguments);
}
alias a=foo!int;//bar=()
alias b=foo!bool;//bar=(int)
alias c=foo!(float,double);//bar=(int,bool)
alias d=foo!();//bar=(int,bool,float,double)
```

this is already possible with my favorite compiler bug, but with 
n^2 complexity


More information about the dip.ideas mailing list