isNumeric

Detect whether T is a built-in numeric type (integral or floating point).

template isNumeric (
T
) {
static if(!__traits(isArithmetic, T))
enum isNumeric;
static if(!(!__traits(isArithmetic, T)))
static if(__traits(isFloating, T))
enum isNumeric;
static if(!(!__traits(isArithmetic, T)))
static if(!(__traits(isFloating, T)))
static if(is(T U == enum))
enum isNumeric;
static if(!(!__traits(isArithmetic, T)))
static if(!(__traits(isFloating, T)))
static if(!(is(T U == enum)))
enum isNumeric;
}

Examples

static assert(
    isNumeric!byte &&
    isNumeric!short &&
    isNumeric!int &&
    isNumeric!long &&
    isNumeric!float &&
    isNumeric!double &&
    isNumeric!real &&
    isNumeric!(const(real)) &&
    isNumeric!(immutable(real))
);

static assert(
    !isNumeric!void &&
    !isNumeric!bool &&
    !isNumeric!char &&
    !isNumeric!wchar &&
    !isNumeric!dchar
);

// types which act as numeric values do not pass
struct S
{
    int val;
    alias val this;
}

static assert(!isNumeric!S);

Meta