Skip to content

Commit

Permalink
Merge pull request #9 from elbeno/fix-cx-multimap
Browse files Browse the repository at this point in the history
🐛 Fix cx_multimap erase
  • Loading branch information
elbeno authored Sep 13, 2023
2 parents 68de4cc + 5e68eec commit 9cf1f58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/stdx/cx_multimap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class cx_multimap {
constexpr auto erase(key_type const &k, mapped_type const &v) -> size_type {
if (storage.contains(k)) {
auto &s = storage.get(k);
auto const r = s.remove(v);
auto const r = s.erase(v);
if (s.empty()) {
storage.remove(k);
storage.erase(k);
}
return r;
}
Expand Down
15 changes: 15 additions & 0 deletions test/cx_multimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ TEST_CASE("put multiple values", "[cx_multimap]") {
CHECK(not t.contains(60, 0));
}

TEST_CASE("erase values", "[cx_multimap]") {
stdx::cx_multimap<int, int, 64> t;

t.put(60, 1);
t.put(60, 2);
t.put(60, 3);

t.erase(60, 2);
CHECK(t.size() == 1);
CHECK(not t.contains(60, 2));

t.erase(60);
CHECK(t.empty());
}

TEST_CASE("constexpr populated map", "[cx_multimap]") {
constexpr auto m = [] {
stdx::cx_multimap<int, int, 64> t;
Expand Down

0 comments on commit 9cf1f58

Please sign in to comment.