digitalmars.D.learn - Unique Enum Members
- =?UTF-8?B?Tm9yZGzDtnc=?= (9/9) May 05 2016 Is there a way to calculate unique enum members without using
- Mark Isaacson (4/13) May 05 2016 Sure, if you can hash the underlying type this should do the
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.
May 05 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
May 05 2016