A module comprehensive template-specialization

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Mon Jun 28 00:49:30 PDT 2010


On Sun, 27 Jun 2010 18:51:35 +0200, Matthias Walter 
<xammy at xammy.homelinux.net> wrote:
> 
> Hi list,
> 
> I tried to write a traits class comparable to iterator_traits in C++ STL
> or graph_traits in Boost Graph Library in D 2.0, but failed to do so via
> template specialization which is put into different modules. Putting
> everything into one module interferes with extensibility. I tried the
> following:
> 
> == Module a ==
> | module a;
> |
> | template Base (T)
> | {
> |   alias T Base;
> | }
> 
> == Module b ==
> | module b;
> |
> | import a;
> |
> | template Base(T: T*)
> | {
> |   alias Base !(T) Base;
> | }
> 
> == Main module ==
> |
> |  import a, b;
> |
> | int main(char[][] args)
> | {
> |   alias Base !(int*) foo;
> |
> |   return 0;
> | }
> 
> The error message is:
> "bug.d(8): Error: template instance ambiguous template declaration
> b.Base(T : T*) and a.Base(T)"
> 
> Can I handle this in another way (like making the template a conditional
> one)?
> 
> best regards
> Matthias Walter

I believe this is intended behavior, as it prevents template hijacking 
and the like. Using alias to import the two templates into the same 
scope might help, though I'm not sure exactly how it should be done.

On another note, though, have you looked at __traits() and std.traits?


More information about the Digitalmars-d-learn mailing list