digitalmars.D - Weird template error message
- NaN (34/34) May 15 2020 Stripped down example...
- Paul Backus (3/16) May 15 2020 This line is the problem. Template argument deduction does not
- NaN (3/25) May 15 2020 Ah OK thanks. Not the most helpful error message from the
Stripped down example... module test; import std.traits; auto offsetBy(T,F)(T path, F x, F y) { alias PathFloat = TemplateArgsOf!T[0]; struct Offseter(Q) { Q path; PathFloat x; PathFloat y; } return Offseter(path, cast(PathFloat) x, cast(PathFloat) y); } void Foo() { struct Path(T) { T a; } Path!float p; offsetBy(p, 1, 1); } ----> <source>(18): Error: struct `test.offsetBy!(Path!float, int).offsetBy.Offseter` cannot deduce function from argument types `!()(Path!float, float, float)`, candidates are: <source>(11): `test.offsetBy!(Path!float, int).offsetBy.Offseter(Q)` <source>(25): Error: template instance `test.offsetBy!(Path!float, int)` error instantiating Compiler returned: 1 (ldc 1.17) If you look at the template parameters in the error message you'll see "offsetBy!(Path!float, int)" which is clearly wrong... is it a compiler bug, or just a crappy error message?
May 15 2020
On Friday, 15 May 2020 at 21:40:20 UTC, NaN wrote:Stripped down example... module test; import std.traits; auto offsetBy(T,F)(T path, F x, F y) { alias PathFloat = TemplateArgsOf!T[0]; struct Offseter(Q) { Q path; PathFloat x; PathFloat y; } return Offseter(path, cast(PathFloat) x, cast(PathFloat) y);This line is the problem. Template argument deduction does not work for constructors; you have to write `Offsetter!T(...)`.
May 15 2020
On Friday, 15 May 2020 at 21:55:16 UTC, Paul Backus wrote:On Friday, 15 May 2020 at 21:40:20 UTC, NaN wrote:Ah OK thanks. Not the most helpful error message from the compiler lol.Stripped down example... module test; import std.traits; auto offsetBy(T,F)(T path, F x, F y) { alias PathFloat = TemplateArgsOf!T[0]; struct Offseter(Q) { Q path; PathFloat x; PathFloat y; } return Offseter(path, cast(PathFloat) x, cast(PathFloat) y);This line is the problem. Template argument deduction does not work for constructors; you have to write `Offsetter!T(...)`.
May 15 2020