Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -4129,50 +4129,10 @@ int[] abc = cast(int[]) [ EnumMembers!E ];
template EnumMembers(E)
if (is(E == enum))
{
import std.meta : AliasSeq;
// Supply the specified identifier to an constant value.
template WithIdentifier(string ident)
{
static if (ident == "Symbolize")
{
template Symbolize(alias value)
{
enum Symbolize = value;
}
}
else
{
mixin("template Symbolize(alias "~ ident ~")"
~"{"
~"alias Symbolize = "~ ident ~";"
~"}");
}
}

template EnumSpecificMembers(names...)
{
static if (names.length == 1)
{
alias EnumSpecificMembers = AliasSeq!(WithIdentifier!(names[0])
.Symbolize!(__traits(getMember, E, names[0])));
}
else static if (names.length > 0)
{
alias EnumSpecificMembers =
AliasSeq!(
WithIdentifier!(names[0])
.Symbolize!(__traits(getMember, E, names[0])),
EnumSpecificMembers!(names[1 .. $/2]),
EnumSpecificMembers!(names[$/2..$])
);
}
else
{
alias EnumSpecificMembers = AliasSeq!();
}
}
import std.meta : Map = staticMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you keep the alias Map instead of using the staticMap directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to start a trend. :)

More seriously: std.meta has a lot of weird naming inconsistencies—compare staticMap, Filter, and templateOr, for example. I think smoothing out these inconsistencies with renamed imports makes code easier to read, and would like to see the practice catch on in Phobos. With local imports, the potential for confusion is low, since one only has to scroll a few lines to see where the alias is defined.

Copy link
Contributor

@nordlow nordlow Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good point. I guess an alias is lightweight enough to serve this purpose. ;)

Thanks. Keep up the awesome work.


alias EnumMembers = EnumSpecificMembers!(__traits(allMembers, E));
alias getEnumMember(string name) = __traits(getMember, E, name);
alias EnumMembers = Map!(getEnumMember, __traits(allMembers, E));
}

/// Create an array of enumerated values
Expand Down