Re: Is there a way to get a template’s parameters and constraints?
Steven Schveighoffer
schveiguy at gmail.com
Fri Jan 20 17:24:07 UTC 2023
On 1/20/23 12:15 PM, Quirin Schroll wrote:
> 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.
No, there is no way to introspect anything about a template's details
until its instantiated.
-Steve
More information about the Digitalmars-d-learn
mailing list