The OpenD Programming Language

unsafeEnumFromIndex

@trusted pure nothrow @nogc
T
unsafeEnumFromIndex
(
T
)
(
size_t index
)
if (
is(T == enum)
)

Parameters

index size_t

enum index std.traits.EnumMembers!T

Return Value

Type: T

A enum value that corresponds to the index. Note: The function doesn't check that index is less then EnumMembers!T.length.

Examples

enum Linear
{
    one = 1,
    two = 2
}

static assert(is(typeof(unsafeEnumFromIndex!Linear(0)) == Linear));
assert(unsafeEnumFromIndex!Linear(0) == Linear.one);
assert(unsafeEnumFromIndex!Linear(1) == Linear.two);

enum Mixed
{
    one = 1,
    oneAgain = 1,
    two = 2
}

assert(unsafeEnumFromIndex!Mixed(0) == Mixed.one);
assert(unsafeEnumFromIndex!Mixed(1) == Mixed.one);
assert(unsafeEnumFromIndex!Mixed(2) == Mixed.two);

Meta