From e5569e5feafdc2ca4b7f33471c9073a9645cf670 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 15 Sep 2018 06:06:17 +0200 Subject: [PATCH] meta.trait.EnumMembers: Fix one-member enums Produce a tuple for an enum with only one member. --- source/tanya/meta/trait.d | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/source/tanya/meta/trait.d b/source/tanya/meta/trait.d index e4754b2..81b2127 100644 --- a/source/tanya/meta/trait.d +++ b/source/tanya/meta/trait.d @@ -1601,7 +1601,7 @@ if (is(T == class) || is(T == struct) || is(T == union)) } /// -pure nothrow @safe unittest +@nogc pure nothrow @safe unittest { static struct S { @@ -2613,14 +2613,23 @@ if (is(T == enum)) } else { - alias getEnumMembers = AliasSeq!(__traits(getMember, T, Args[0]), getEnumMembers!(Args[1 .. $])); + alias getEnumMembers = AliasSeq!(__traits(getMember, T, Args[0]), + getEnumMembers!(Args[1 .. $])); } } - alias EnumMembers = getEnumMembers!(__traits(allMembers, T)); + private alias allMembers = AliasSeq!(__traits(allMembers, T)); + static if (allMembers.length == 1) + { + alias EnumMembers = AliasSeq!(__traits(getMember, T, allMembers)); + } + else + { + alias EnumMembers = getEnumMembers!allMembers; + } } /// -pure nothrow @nogc @safe unittest +@nogc nothrow pure @safe unittest { enum E : int { @@ -2628,7 +2637,17 @@ pure nothrow @nogc @safe unittest two, three, } - static assert([E.one, E.two, E.three] == [ EnumMembers!E ]); + static assert([EnumMembers!E] == [E.one, E.two, E.three]); +} + +// Produces a tuple for an enum with only one member +@nogc nothrow pure @safe unittest +{ + enum E : int + { + one = 0, + } + static assert(EnumMembers!E == AliasSeq!0); } /**