isIntegral

Detect whether T is a built-in integral type. Integral types are byte, ubyte, short, ushort, int, uint, long, ulong, cent, ucent, and enums with an integral type as its base type.

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

Parameters

T

type to test

Return Value

true if T is an integral type Note: this is not the same as __traits(isIntegral)

Examples

static assert(
    isIntegral!byte &&
    isIntegral!short &&
    isIntegral!int &&
    isIntegral!long &&
    isIntegral!(const(long)) &&
    isIntegral!(immutable(long))
);

static assert(
    !isIntegral!bool &&
    !isIntegral!char &&
    !isIntegral!double
);

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

static assert(!isIntegral!S);

Meta