mirror of
https://github.com/dlang/phobos.git
synced 2025-05-06 19:16:13 +03:00
Adding arity traits
This commit is contained in:
parent
cbd1e63026
commit
34e998889a
1 changed files with 23 additions and 0 deletions
23
std/traits.d
23
std/traits.d
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue