is expression on templated types
Simen Kjaeraas
simen.kjaras at gmail.com
Sat Jun 25 07:32:32 PDT 2011
On Sat, 25 Jun 2011 15:57:03 +0200, simendsjo <simen.endsjo at pandavre.com>
wrote:
> I have a templated struct, and I'd like to check if a given type is this
> struct. I have no idea how I should write the is expression..
>
> struct S(int C, int R, T) {
> T[C][R] data;
> }
> template isS(T) {
> enum isS = is(T : S); // How can I see if T is a kind of S no
> matter what values S is parameterized on?
> }
> unittest {
> static assert(isS!(S!(1,1,float)));
> static assert(!isS!(float[1][1]));
> }
template isS(T) {
static if ( is( T t == S!(C,R,U), int C, int R, U ) ) {
enum isS = true;
} else {
enum isS = false;
}
}
This works, but I thought the following had been added. Apparently not:
template isS(T) {
static if ( is( T t == S!U, U... ) ) {
enum isS = true;
} else {
enum isS = false;
}
}
As for the weird way to write this, it is caused by some variants of the
isExpression not being available outside static if.
--
Simen
More information about the Digitalmars-d-learn
mailing list