Partially applied template alias messes up template inferance
Paul Backus
snarwin at gmail.com
Wed Oct 14 03:29:50 UTC 2020
On Wednesday, 14 October 2020 at 02:37:25 UTC, Jonathan Levi
wrote:
> This gist gives a full example:
> https://gist.github.com/run-dlang/a28372ffaa05c3f2a4d852ca4b0a7bf5 (See the compiler error.)
>
> In essence:
> ```
> struct Vec(T, size_t size) {}
> alias Vec2(T) = Vec(T, size);
> void fun(T)(Vec2!T vec) {}
>
> void main() {
> // Error: template fun cannot deduce function from argument
> types !()(Vec!(float, 2LU))
> fun(Vec2!float());
> }
> ```
>
> The template function can be written without using the alias
> and everything works great:
> ```
> void fun(T)(Vec!(T,2) vec) {}
> ```
>
> Is this fixable in the language, or is it just not feasible?
This is a known limitation of template argument deduction:
https://issues.dlang.org/show_bug.cgi?id=1807
Attempts have been made to fix it in the past, but so far none
have succeeded. It's probably not feasible given the compiler's
current implementation of templates.
More information about the Digitalmars-d
mailing list