Add initial draft of heterogeneous erase()

This commit is contained in:
LeonineKing1199
2021-12-02 15:59:12 -08:00
parent f252480bee
commit 33f84624ec
2 changed files with 45 additions and 0 deletions

View File

@ -18,6 +18,7 @@
#include <boost/functional/hash.hpp>
#include <boost/move/move.hpp>
#include <boost/type_traits/is_constructible.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/unordered/detail/map.hpp>
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@ -1382,6 +1383,20 @@ namespace boost {
iterator erase(const_iterator);
size_type erase(const key_type&);
iterator erase(const_iterator, const_iterator);
template <class Key>
typename boost::enable_if_c<
detail::is_transparent<Key, H>::value &&
detail::is_transparent<Key, P>::value &&
!boost::is_convertible<Key, iterator>::value &&
!boost::is_convertible<Key, const_iterator>::value,
size_type>::type
erase(BOOST_FWD_REF(Key) k)
{
return table_.erase_key_unique_impl(
this->key_eq(), boost::forward<Key>(k));
}
BOOST_UNORDERED_DEPRECATED("Use erase instead")
void quick_erase(const_iterator it) { erase(it); }
BOOST_UNORDERED_DEPRECATED("Use erase instead")

View File

@ -515,6 +515,36 @@ template <class UnorderedMap> void test_non_transparent_equal_range()
}
}
template <class UnorderedMap> void test_transparent_erase()
{
count_reset();
UnorderedMap map;
int num_erased = 0;
num_erased = map.erase(0);
BOOST_TEST(map.empty());
BOOST_TEST(num_erased == 0);
BOOST_TEST(key::count_ == 0);
map[key(0)] = 1337;
map[key(1)] = 1338;
map[key(2)] = 1339;
int const expected_key_count = 2 * map.size();
BOOST_TEST(key::count_ == expected_key_count);
num_erased = map.erase(0);
BOOST_TEST(num_erased == 1);
num_erased = map.erase(1337);
BOOST_TEST(num_erased == 0);
BOOST_TEST(key::count_ == expected_key_count);
}
UNORDERED_AUTO_TEST (unordered_map_transparent_count) {
{
typedef boost::unordered_map<key, int, transparent_hasher,