On 06/28/2010 05:32 AM, Simen kjaeraas wrote: > Matthias Walter <[email protected]> wrote: > >> Can I handle this in another way (like making the template a conditional >> one)? > > Template constraints[1] sounds like what you want. > > Basically, you want the following: > > == Module a == > | module a; > | > | template Base (T) if (!is(T t : t*)) > | { > | alias T Base; > | } > > == Module b == > | module b; > | > | import a; > | > | template Base(T) if (is(T t : t*)) > | { > | alias Base !(T) Base; > | } > > == Main module == > | > | import a, b; > | > | int main(char[][] args) > | { > | alias Base !(int*) foo; > | > | return 0; > | } > > Not tested, ymmv. > > [1]: http://digitalmars.com/d/2.0/template.html#Constraint >
The problem with constraints arises when I want to make an existing class (who's code I cannot modify) match a Concept, in which case I would just add another template specialization for this class. Here I would have to add further conditions to the template constraints, which would also mean to modify a library. A prominent example for Boost Graph Library is the LEDA graph class, which can be enabled to be used by BGL by more or less just specializing the graph_traits template. Any further ideas?
