Enum.toString

The inverse of fromString, this function takes an enum member value and returns its string identifier.

It lowers to a big switch of the enum members. It is faster than std.conv.to and generates less template bloat.

Taken from: https://forum.dlang.org/post/bfnwstkafhfgihavtzsz@forum.dlang.org written by Stephan Koch (https://github.com/UplinkCoder). Used with permission.

template Enum(E)
@safe pure nothrow
string
toString
()
if (
is(E == enum)
)

Parameters

value E

Enum member whose string name we want.

Return Value

Type: string

The string name of the passed enum member.

Examples

enum SomeEnum { one, two, three };

string foo = Enum!SomeEnum.toString(one);
assert(foo == "one");

Meta