www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Partially applied template alias messes up template inferance

reply Jonathan Levi <catanscout gmail.com> writes:
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?
Oct 13 2020
parent reply Paul Backus <snarwin gmail.com> writes:
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.
Oct 13 2020
parent Jonathan Levi <catanscout gmail.com> writes:
On Wednesday, 14 October 2020 at 03:29:50 UTC, Paul Backus wrote:
 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.
Thanks, that is what I know. Bummer.
Oct 14 2020