D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3904 - Infer function type from an alias in a template
Summary: Infer function type from an alias in a template
Status: RESOLVED DUPLICATE of issue 1807
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-08 15:27 UTC by bearophile_hugs
Modified: 2020-12-24 02:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-03-08 15:27:19 UTC
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 Steven Schveighoffer 2010-03-09 04:15:46 UTC

*** This issue has been marked as a duplicate of issue 1807 ***