| |
| Posted by Jean-Louis Leroy | PermalinkReply |
|
Jean-Louis Leroy
| This works:
module test;
void foo(T)(T a, T b) {}
void foo(T)(char a, T b) {}
template InstantiateTemplateAt(alias Module, string name, int index, T...) {
alias Template = __traits(getOverloads, test, name, true)[index];
alias InstantiateTemplateAt = Template!(T);
}
pragma(msg, typeof(InstantiateTemplateAt!(test, "foo", 1, int)));
// pure nothrow @nogc @safe void(char a, int b)
class Matrix(T) {}
Matrix!T times(T)(Matrix!T a, T b);
// Matrix!T times(T)(T a, Matrix!T b); // <-- second 'times' overload
pragma(msg, typeof(InstantiateTemplateAt!(test, "times", 0, int)));
// Matrix!int(Matrix!int a, int b)
But if I uncomment the second 'times' function template, I get an error:
templateoverloads.d(8): Error: template `test.times` matches more than one template declaration:
templateoverloads.d(16): `times(T)(Matrix!T a, T b)`
and
templateoverloads.d(17): `times(T)(T a, Matrix!T b)`
templateoverloads.d(19): Error: template instance `test.InstantiateTemplateAt!(test, "times", 0, int)` error instantiating
_error_
I may be missing the obvious...or it's a compiler bug???
(not sure if this belongs to the Learn section either)
|