Adding arity traits

This commit is contained in:
Guillaume Chatelet 2012-06-22 23:26:05 +02:00
parent cbd1e63026
commit 34e998889a

View file

@ -364,6 +364,29 @@ unittest
static assert(is(P_dglit[0] == int));
}
/**
Returns the number of arguments of function $(D func)
Example:
---
void foo(){}
static assert(arity!foo==0);
void bar(uint){}
static assert(arity!bar==1);
---
*/
template arity(alias func)
if (isCallable!func)
{
enum uint arity = (ParameterTypeTuple!func).length;
}
unittest {
void foo(){}
static assert(arity!foo==0);
void bar(uint){}
static assert(arity!bar==1);
}
/**
Returns a tuple consisting of the storage classes of the parameters of a