Templated function as associative array property
biozic
dransic at free.fr
Sun Mar 7 16:11:25 PST 2010
This problem might have been raised before, but I can't why this doesn't
compile (except the last line), while a non-template version of the same
code works well. Is this a bug?
---
module test;
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
graph.add_edge!(string)("A", "B"); // Error
add_edge(graph, "A", "B"); // Error
add_edge!(string)(graph, "A", "B"); // OK
}
---
DMD 2.040, Mac OS X
Thanks,
Nicolas
More information about the Digitalmars-d-learn
mailing list