From d179658a0816fe97646fc8026366c44e1c207624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 5 Nov 2025 15:04:50 +0100 Subject: [PATCH] Add small test to set/flat_map for transparent erase --- include/boost/container/flat_set.hpp | 13 +++++++++++++ test/flat_set_test.cpp | 10 ++++++++++ test/set_test.cpp | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/boost/container/flat_set.hpp b/include/boost/container/flat_set.hpp index 91d15e0..672f3a2 100644 --- a/include/boost/container/flat_set.hpp +++ b/include/boost/container/flat_set.hpp @@ -801,6 +801,15 @@ class flat_set //! linear to the elements with bigger keys. iterator erase(const_iterator first, const_iterator last); + //! Requires: This overload is available only if + //! key_compare::is_transparent exists. + //! + //! Effects: If present, erases the element in the container with key equivalent to x. + //! + //! Returns: Returns the number of erased elements. + template + size_type erase(K && k); + //! Effects: Swaps the contents of *this and x. //! //! Throws: Nothing. @@ -1736,6 +1745,10 @@ class flat_multiset //! @copydoc ::boost::container::flat_set::erase(const_iterator,const_iterator) iterator erase(const_iterator first, const_iterator last); + //! @copydoc ::boost::container::flat_set::erase(K&&) + template + size_type erase(K && k); + //! @copydoc ::boost::container::flat_set::swap void swap(flat_multiset& x) BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value diff --git a/test/flat_set_test.cpp b/test/flat_set_test.cpp index 36612c9..2aea2cb 100644 --- a/test/flat_set_test.cpp +++ b/test/flat_set_test.cpp @@ -580,6 +580,16 @@ bool test_heterogeneous_lookups() if(*cmset1.equal_range(find_me).second != 3) return false; + //erase + if (set1.erase(find_me) != 1) + return false; + if (set1.erase(find_me) != 0) + return false; + if (mset1.erase(find_me) != 2) + return false; + if (mset1.erase(find_me) != 0) + return false; + return true; } diff --git a/test/set_test.cpp b/test/set_test.cpp index 35c1d0e..a7be5ae 100644 --- a/test/set_test.cpp +++ b/test/set_test.cpp @@ -437,6 +437,16 @@ bool test_heterogeneous_lookups() if(*cmset1.equal_range(find_me).second != 3) return false; + //erase + if (set1.erase(find_me) != 1) + return false; + if (set1.erase(find_me) != 0) + return false; + if (mset1.erase(find_me) != 2) + return false; + if (mset1.erase(find_me) != 0) + return false; + return true; }