Compile-time reflection and templates

Jean-Louis Leroy jl at
Wed Sep 27 21:18:54 UTC 2017

On Wednesday, 27 September 2017 at 20:04:42 UTC, jmh530 wrote:
> On Wednesday, 27 September 2017 at 19:47:32 UTC, Jean-Louis 
> Leroy wrote:
>> I'd like to go further: find the template arguments and the 
>> function arguments and return types. Looking at __traits and 
>> std.traits, it doesn't seem feasible, but maybe I overlooked 
>> something?
> You can use TemplateArgsOf
> to get the template arguments.
> For the stuff below, I think you can't just use foo, it has to 
> be a specific foo!T.
> You can test if it's a function
> You can get the Parameter and Return types
> You can get the names of parameters

I am aware of these but TemplateArgsOf takes a template 
*instantiation* and returns the arguments. I want to reflect the 

Here what I am trying to achieve (for openmethods). Given:

   Matrix!T times(T, virtual!(Matrix!T));

...inject, at compile time (in 'mixin(registerMethods)'), the 
following code:

   Matrix!T times(T)(T s, Matrix!T m) {
     return Method!("times", "deallocator", Matrix!T, T, 
virtual!(Matrix!T)).dispatcher(s, m);

   Method!("times", "deallocator", Matrix!T, T, 
virtual!(Matrix!T)) times(T)(MethodTag, T s, Matrix!T m);

More information about the Digitalmars-d mailing list