A module comprehensive template-specialization

Matthias Walter xammy at xammy.homelinux.net
Sun Jun 27 09:51:35 PDT 2010


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


More information about the Digitalmars-d-learn mailing list