Unique Enum Members

Mark Isaacson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 5 07:17:27 PDT 2016


On Thursday, 5 May 2016 at 12:54:08 UTC, Nordlöw wrote:
> Is there a way to calculate unique enum members without using 
> sort, such as *not* done in my current implementation:
>
> auto uniqueEnumMembers(T)()
> {
>     import std.traits: EnumMembers;
>     import std.algorithm: sort, uniq;
>     return [EnumMembers!T].sort().uniq;
> }
>
> Preferrably both at compile-time and run-time.

Sure, if you can hash the underlying type this should do the 
trick in linear time: 
http://melpon.org/wandbox/permlink/Rvq60fv7jOIPuhXz


More information about the Digitalmars-d-learn mailing list