Bug 5793 – Types can't be inferred from template argument types

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-03-28T14:40:00Z
Last change time
2015-05-19T00:42:52Z
Assigned to
nobody
Creator
magnus

Comments

Comment #0 by magnus — 2011-03-28T14:40:38Z
The following program fails for me (DMD 2.052): import std.array, std.container; template func(T) { alias void function(T) func; } void G(uint x) { } void f(T)(func!T g) { // Won't work, except with (*) // void f(T)(void function(T) g) { } void main() { f(&G); // f!uint(&G); // (*) } With the explicit "void function(T) g" in the argument specification, it works. Or, if f!uint is specified explicitly. The problem seems to be inferring the type T "through" the template func().
Comment #1 by dlang-bugzilla — 2015-05-19T00:41:15Z
I don't think D can or ever will reverse-match types to template instantiations (finding which parameters for a template will result in a given result), because D templates can be arbitrarily complicated.
Comment #2 by dlang-bugzilla — 2015-05-19T00:42:52Z
Simplified example: /////////// test.d ////////// template Identity(T) { alias Identity = T; } void fun(T)(Identity!T value) { } void main() { fun(5); } /////////////////////////////