On Wednesday, 25 December 2024 at 18:25:57 UTC, sfp wrote:

What is a template map? I'd be interested in seeing this pattern and whether it's worth it to try to salvage std.sumtype.


```d
import std;
struct Ball(int i){}
struct Box(int i){}
struct CsgDiff(int i){}
alias dimlist(int dim)=AliasSeq!(Ball!dim,Box!dim,CsgDiff!dim);
alias dimedsumtype(int dim)=SumType!(dimlist!dim);
alias genfunction(T)=(T t)=>t.writeln;
void doSomething(int dim)(dimedsumtype!dim st){
    st.match!(
        staticMap!(genfunction,dimlist!dim)
    );
}
unittest{
    dimedsumtype!1 foo;
    foo.doSomething!1;
}
```

You will need to read the template book to even begin to understand, I had to work around what seems to me to be a compiler bug to get it to compile, and the number of people who can help you drop to like 5

https://github.com/PhilippeSigaud/D-templates-tutorial

Reply via email to