Double face templates
bearophile
bearophileHUGS at lycos.com
Tue Sep 30 07:07:12 PDT 2008
BCS:
> you might be able to use a form like this
> template T(alias a)
> {
> static if(is(a))
> {
> // stuff
> }
> else
> alias T!(typeof(a)) T;
> // or 'mixin T!(typeof(a));'
> }
I think it doesn't work:
import std.stdio;
template ArrayType1(T: T[]) {
alias T ArrayType1;
}
template Foo(alias x) {
static if(is(x))
alias ArrayType1!(x) Foo;
else
alias ArrayType1!(typeof(x)) Foo;
}
void main() {
alias string[] Ts;
Ts s = ["aaaa", "bb"];
writefln(typeid( Foo!(s) ));
writefln(typeid( Foo!(Ts) ));
}
But it doesn't matter much, I'll keep using just the version of the templates that take a type...
Bye and thank you,
bearophile
More information about the Digitalmars-d-learn
mailing list