isVariantN - is expression doesn't match
Piotr Szturmaj
bncrbme at jadamspam.pl
Wed Mar 23 01:08:16 PDT 2011
I wrote simple template to test VariantN type (and thus Algebraic and
Variant).
template isVariantN(T)
{
static if (is(T X == VariantN!(N, Types), uint N, Types...))
enum isVariantN = true;
else
enum isVariantN = false;
}
but testing against Variant yields false:
static assert(isVariantN!(Variant)); // fail
Variant is declared as an alias to VariantN:
alias VariantN!(maxSize!(creal, char[], void delegate())) Variant;
which is equivalent to VariantN!(20u) on 32 bit DMD 2.052:
static assert(is(Variant == VariantN!(20u))); // pass
Strange thing is when I set maxSize other than 20u then isVariantN
yields true:
static assert(isVariantN!(VariantN!(21u))); // pass
static assert(isVariantN!(VariantN!(20))); // pass, 20 as int
static assert(isVariantN!(VariantN!(20u))); // fail, same as Variant
If I add at least one type then it passes even for 20u maxSize.
static assert(isVariantN!(VariantN!(21u, int))); // pass
static assert(isVariantN!(VariantN!(20, int))); // pass, 20 as int
static assert(isVariantN!(VariantN!(20u, int))); // pass
What is going on here?
I also have question regarding integral type aliases such as size_t. For
example I can't use size_t in is expression:
template isVariantN(T)
{
static if (is(T X == VariantN!(N, Types), size_t N, Types...))
enum isVariantN = true;
else
enum isVariantN = false;
}
Error: undefined identifier size_t
TIA
More information about the Digitalmars-d-learn
mailing list