From 84e26ba759fbc2f700d892d2e3dbfac9f87f308c Mon Sep 17 00:00:00 2001 From: Ryan Samarakoon Date: Sun, 12 Nov 2023 13:52:29 +1100 Subject: [PATCH] Fix set erase function --- include/magic_enum/magic_enum_containers.hpp | 2 +- test/test_containers.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/magic_enum/magic_enum_containers.hpp b/include/magic_enum/magic_enum_containers.hpp index e2a873773..ccf0f0ed3 100644 --- a/include/magic_enum/magic_enum_containers.hpp +++ b/include/magic_enum/magic_enum_containers.hpp @@ -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(ref); if (res) { --s; } diff --git a/test/test_containers.cpp b/test/test_containers.cpp index 30d1e7390..1250bdaed 100644 --- a/test/test_containers.cpp +++ b/test/test_containers.cpp @@ -270,6 +270,12 @@ TEST_CASE("containers_set") { REQUIRE_FALSE(color_set.empty()); REQUIRE(color_set.size() == 3); REQUIRE(magic_enum::enum_count() == color_set.size()); + color_set.erase(Color::RED); + color_set.erase(Color::GREEN); + REQUIRE(magic_enum::enum_count() - 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_set_compare.insert(Color::BLUE);