maxSize

Gives the sizeof the largest type given.

template maxSize (
Ts...
) {
enum maxSize;
}

Examples

struct Cat { int a, b, c; }

align(1) struct S
{
    long l;
    ubyte b;
}

align(1) struct T
{
    ubyte b;
    long l;
}

static assert(maxSize!(int, long) == 8);
static assert(maxSize!(bool, byte) == 1);
static assert(maxSize!(bool, Cat) == 12);
static assert(maxSize!(char) == 1);
static assert(maxSize!(char, short, ubyte) == 2);
static assert(maxSize!(char, long, ubyte) == 8);
import std.algorithm.comparison : max;
static assert(maxSize!(long, S) == max(long.sizeof, S.sizeof));
static assert(maxSize!(S, T) == max(S.sizeof, T.sizeof));
static assert(maxSize!(int, ubyte[7]) == 7);
static assert(maxSize!(int, ubyte[3]) == 4);
static assert(maxSize!(int, int, ubyte[3]) == 4);
static assert(maxSize!(void, int, ubyte[3]) == 4);
static assert(maxSize!(void) == 1);

See Also

Meta