On Wednesday, 20 June 2018 at 09:52:04 UTC, Per Nordlöw wrote:
My suggestion for nothrow @nogc string-to-enum conversion with default value


T toDefaulted(T)(scope const(char)[] value,
                 T defaultValue) @safe pure nothrow @nogc
if (is(T == enum))
{
    switch (value)
    {
        static foreach (index, member; __traits(allMembers, T))
        {
        case member:
            return cast(T)(index);
        }

Oops, this doesn't work for enums with "holes". How do I most easily fix that?

Reply via email to