toString

Convenience wrapper around Enum.toString that infers the type of the enum to instantiate it with from the passed enum member.

Limitations: Does not work with enums whose members' values cannot be used in a switch statement. This includes enums with members that share values with other members, as well as enums of values that are non-string arrays or other complex types.

@safe
toString
(
E
)
(
const E value
)
if (
is(E == enum)
)

Parameters

value E

Enum member whose string name we want.

Return Value

Type: auto

The string name of the passed enum member.

Examples

enum E { a, b, c }

static assert(E.a.toString() == "a");
static assert(E.b.toString() == "b");
static assert(E.c.toString() == "c");

See Also