Skip to content

Commit

Permalink
Merge pull request #524 from denis-sh/improve-variadicFunctionStyle-a…
Browse files Browse the repository at this point in the history
…nd-isIterable

Small improvements not changing the functionality
  • Loading branch information
9rnsr committed Apr 15, 2012
2 parents 022808f + 0f9ecb9 commit dd26e99
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions std/traits.d
Expand Up @@ -757,24 +757,19 @@ template variadicFunctionStyle(func...)
{
alias Unqual!(FunctionTypeOf!func) Func;

Variadic determineVariadicity()
{
// TypeFuncion --> CallConvention FuncAttrs Arguments ArgClose Type
immutable callconv = functionLinkage!Func;
immutable mfunc = mangledName!Func;
immutable mtype = mangledName!(ReturnType!Func);
debug assert(mfunc[$ - mtype.length .. $] == mtype, mfunc ~ "|" ~ mtype);

immutable argclose = mfunc[$ - mtype.length - 1];
final switch (argclose)
{
case 'X': return Variadic.typesafe;
case 'Y': return (callconv == "C") ? Variadic.c : Variadic.d;
case 'Z': return Variadic.no;
}
}
// TypeFuncion --> CallConvention FuncAttrs Arguments ArgClose Type
enum callconv = functionLinkage!Func;
enum mfunc = mangledName!Func;
enum mtype = mangledName!(ReturnType!Func);
static assert(mfunc[$ - mtype.length .. $] == mtype, mfunc ~ "|" ~ mtype);

enum argclose = mfunc[$ - mtype.length - 1];
static assert(argclose >= 'X' && argclose <= 'Z');

enum Variadic variadicFunctionStyle = determineVariadicity();
enum Variadic variadicFunctionStyle =
argclose == 'X' ? Variadic.typesafe :
argclose == 'Y' ? (callconv == "C") ? Variadic.c : Variadic.d :
Variadic.no; // 'Z'
}

unittest
Expand Down Expand Up @@ -3465,14 +3460,7 @@ unittest
*/
template isIterable(T)
{
static if (is(typeof({ foreach(elem; T.init) {} })))
{
enum bool isIterable = true;
}
else
{
enum bool isIterable = false;
}
enum isIterable = is(typeof({ foreach(elem; T.init) {} }));
}

unittest
Expand Down

0 comments on commit dd26e99

Please sign in to comment.