A module comprehensive template-specialization
Simen kjaeraas
simen.kjaras at gmail.com
Sun Jun 27 20:32:01 PDT 2010
Matthias Walter <xammy at xammy.homelinux.net> 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
--
Simen
More information about the Digitalmars-d-learn
mailing list