Skip to content

Commit

Permalink
Merge pull request #50 from serge-sans-paille/fix/enum-class-keys
Browse files Browse the repository at this point in the history
Fix/enum class keys
  • Loading branch information
serge-sans-paille authored Jul 9, 2018
2 parents d0a9d3f + 1e1b029 commit 325449a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/frozen/bits/elsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
namespace frozen {

template <class T> struct elsa {
static_assert(std::is_integral<T>::value,
static_assert(std::is_integral<T>::value || std::is_enum<T>::value,
"only supports integral types, specialize for other types");

constexpr std::size_t operator()(T const &value, std::size_t seed) const {
std::size_t key = seed ^ value;
std::size_t key = seed ^ static_cast<std::size_t>(value);
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
key = key ^ (key >> 24);
key = (key + (key << 3)) + (key << 8); // key * 265
Expand Down
9 changes: 9 additions & 0 deletions tests/test_unordered_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ TEST_CASE("frozen::unordered_set<int> <> std::unordered_set",

}

TEST_CASE("frozen::unordered_set with enum keys", "[unordered_set]") {
enum class some_enum {
A,B,C
};
constexpr frozen::unordered_set<some_enum, 2> frozen_set = { some_enum::A, some_enum::B };
REQUIRE(frozen_set.count(some_enum::A) == 1);
REQUIRE(frozen_set.count(some_enum::C) == 0);
}

TEST_CASE("frozen::unordered_set <> frozen::make_unordered_set", "[unordered_set]") {
constexpr frozen::unordered_set<int, 129> frozen_set = { INIT_SEQ };
constexpr auto frozen_set2 = frozen::make_unordered_set<int>({INIT_SEQ});
Expand Down

0 comments on commit 325449a

Please sign in to comment.