Bug 3904 – Infer function type from an alias in a template

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-03-08T15:27:19Z
Last change time
2020-12-24T02:31:10Z
Assigned to
No Owner
Creator
bearophile_hugs
See also
https://issues.dlang.org/show_bug.cgi?id=1807

Comments

Comment #0 by bearophile_hugs — 2010-03-08T15:27:19Z
I think the compiler can infer the type here: template Type(T) { alias T Type; } void bar(T)(Type!T t) {} void main() { int b = 1; bar!int(b); // OK bar(b); // template test.bar(T) does not match any function template declaration } Problem found by Nicolas / biozic: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=19054 The original code was: template Graph(T) { alias T[][T] Graph; } void add_edge(T)(ref Graph!(T) graph, T source, T target) { graph[source] ~= target; } void main() { Graph!(string) graph; graph.add_edge("A", "B"); // Error }
Comment #1 by schveiguy — 2010-03-09T04:15:46Z
*** This issue has been marked as a duplicate of issue 1807 ***