Re: Unique Enum Members
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
Unique Enum Members
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.