How to assert a function signature in D2.008?
Janice Caron
caron800 at googlemail.com
Tue Dec 4 04:48:12 PST 2007
This used to compile under D2.007
struct A
{
void f() {}
static assert(is(typeof(f)==void function()));
}
It doesn't under D2.008. The only way I've found to make it compile
under D2.008 is to change it to
struct A
{
void f() {}
static assert(is(typeof(f)==function));
}
which means I am no longer able to check the function signature. So,
the question is, /how/ do I check the function signature in D2.008? I
know I could use ReturnType! and ParameterTypeTuple!, but that would
be so tedious for functions with more complex signatures. For example:
struct A
{
int f(int,char,float,int) {}
static assert(is(typeof(f)==function));
static assert(is(ReturnType!(f) == int));
static assert(ParameterTypeTuple!(f).length == 4);
static assert(is(ParameterTypeTuple!(f)[0] == int));
static assert(is(ParameterTypeTuple!(f)[1] == char));
static assert(is(ParameterTypeTuple!(f)[2] == float));
static assert(is(ParameterTypeTuple!(f)[3] == int));
}
Is this really the "right" way to do things now? The old (D2.007) way
let me make that check in a single line.
More information about the Digitalmars-d
mailing list