isAggregateType

Detect whether type T is an aggregate type.

template isAggregateType (
T
) {
static if(is(T == enum))
enum isAggregateType;
static if(!(is(T == enum)))
enum isAggregateType;
}

Examples

class C {}
union U {}
struct S {}
interface I {}

static assert( isAggregateType!C);
static assert( isAggregateType!U);
static assert( isAggregateType!S);
static assert( isAggregateType!I);
static assert(!isAggregateType!void);
static assert(!isAggregateType!string);
static assert(!isAggregateType!(int[]));
static assert(!isAggregateType!(C[string]));
static assert(!isAggregateType!(void delegate(int)));

enum ES : S { a = S.init }
enum EC : C { a = C.init }
enum EI : I { a = I.init }
enum EU : U { a = U.init }

static assert( isAggregateType!ES);
static assert( isAggregateType!EC);
static assert( isAggregateType!EI);
static assert( isAggregateType!EU);

Meta