diff --git a/std/traits.d b/std/traits.d index e840da9ce..8664efa3f 100644 --- a/std/traits.d +++ b/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