Skip to content

Commit

Permalink
Fix set erase function (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ry-DS authored Nov 12, 2023
1 parent 3c92e90 commit cd5fd2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/magic_enum/magic_enum_containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ class set {

constexpr size_type erase(const key_type& key) noexcept {
typename container_type::reference ref = a[key];
bool res = ref;
bool res = static_cast<bool>(ref);
if (res) {
--s;
}
Expand Down
6 changes: 6 additions & 0 deletions test/test_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ TEST_CASE("containers_set") {
REQUIRE_FALSE(color_set.empty());
REQUIRE(color_set.size() == 3);
REQUIRE(magic_enum::enum_count<Color>() == color_set.size());
color_set.erase(Color::RED);
color_set.erase(Color::GREEN);
REQUIRE(magic_enum::enum_count<Color>() - 2 == color_set.size());
REQUIRE(color_set.count(Color::RED) == 0);
REQUIRE_FALSE(color_set.contains(Color::GREEN));
REQUIRE(color_set.contains(Color::BLUE));

auto color_set_compare = magic_enum::containers::set<Color>();
color_set_compare.insert(Color::BLUE);
Expand Down

0 comments on commit cd5fd2c

Please sign in to comment.