Is there a way to get a template’s parameters and constraints?

Quirin Schroll qs.il.paperinik at gmail.com
Fri Jan 20 17:15:31 UTC 2023


Is there a trait (or a combination of traits) that gives me the 
constraints of a template?

Example:
```D
void f(T1 : long, T2 : const(char)[])(T x) { }
template constraintsOf(alias templ) { /*Magic here*/ }
alias constraints = constraintsOf!f; // tuple(long, const(char)[])
```

At the moment, I care about constraints that are types. I don’t 
care about value or alias constraints (e.g. `opBinary(string op : 
"+")(..)` or `f(alias x : something)()`, but if it works for 
types, it should probably work for other constraints as well.

For what I want, `constraintsOf` may expect every template 
parameter to be a type and to have a constraint.


More information about the Digitalmars-d-learn mailing list