biozic: > 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?
I don't know why your code doesn't work, someone more expert than me can answer you. Maybe it's a bug. In the meantime this works: template Graph(T) { alias T[][T] Graph; } void add_edge(G, T)(ref G graph, T source, T target) if (is(G == Graph!T)) { graph[source] ~= target; // this is a slow operation } void main() { Graph!(string) graph; graph.add_edge("A", "B"); } Bye, bearophile