mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 19:07:15 +02:00
Add transparent tests for unordered_map's try_emplace()
This commit is contained in:
@ -1478,6 +1478,83 @@ template <class UnorderedMap> void test_map_non_transparent_extract()
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class UnorderedMap> void test_map_transparent_try_emplace()
|
||||
{
|
||||
count_reset();
|
||||
|
||||
typedef typename UnorderedMap::iterator iterator;
|
||||
|
||||
UnorderedMap map;
|
||||
|
||||
map.insert(std::make_pair(0, 1337));
|
||||
map.insert(std::make_pair(1, 1338));
|
||||
map.insert(std::make_pair(2, 1339));
|
||||
map.insert(std::make_pair(0, 1340));
|
||||
map.insert(std::make_pair(0, 1341));
|
||||
map.insert(std::make_pair(0, 1342));
|
||||
|
||||
int key_count = key::count_;
|
||||
|
||||
std::pair<iterator, bool> r = map.try_emplace(0, 7331);
|
||||
BOOST_TEST(r.first == map.find(0));
|
||||
BOOST_TEST_NOT(r.second);
|
||||
BOOST_TEST_EQ(key::count_, key_count);
|
||||
|
||||
r = map.try_emplace(4, 7331);
|
||||
BOOST_TEST(r.first == map.find(4));
|
||||
BOOST_TEST(r.second);
|
||||
BOOST_TEST_EQ(key::count_, key_count + 1);
|
||||
|
||||
key_count = key::count_;
|
||||
|
||||
iterator p = map.try_emplace(map.cbegin(), 0, 7331);
|
||||
BOOST_TEST(p == map.find(0));
|
||||
BOOST_TEST_EQ(key::count_, key_count);
|
||||
|
||||
p = map.try_emplace(map.begin(), 5, 7331);
|
||||
BOOST_TEST(p == map.find(5));
|
||||
BOOST_TEST_EQ(key::count_, key_count + 1);
|
||||
}
|
||||
|
||||
template <class UnorderedMap> void test_map_non_transparent_try_emplace()
|
||||
{
|
||||
count_reset();
|
||||
|
||||
typedef typename UnorderedMap::iterator iterator;
|
||||
|
||||
UnorderedMap map;
|
||||
|
||||
map.insert(std::make_pair(0, 1337));
|
||||
map.insert(std::make_pair(1, 1338));
|
||||
map.insert(std::make_pair(2, 1339));
|
||||
map.insert(std::make_pair(0, 1340));
|
||||
map.insert(std::make_pair(0, 1341));
|
||||
map.insert(std::make_pair(0, 1342));
|
||||
|
||||
int key_count = key::count_;
|
||||
|
||||
std::pair<iterator, bool> r = map.try_emplace(0, 7331);
|
||||
BOOST_TEST_EQ(key::count_, key_count + 1);
|
||||
BOOST_TEST(r.first == map.find(0));
|
||||
BOOST_TEST_NOT(r.second);
|
||||
|
||||
key_count = key::count_;
|
||||
r = map.try_emplace(4, 7331);
|
||||
BOOST_TEST_EQ(key::count_, key_count + 2);
|
||||
BOOST_TEST(r.first == map.find(4));
|
||||
BOOST_TEST(r.second);
|
||||
|
||||
key_count = key::count_;
|
||||
iterator p = map.try_emplace(map.cbegin(), 0, 7331);
|
||||
BOOST_TEST_EQ(key::count_, key_count + 1);
|
||||
BOOST_TEST(p == map.find(0));
|
||||
|
||||
key_count = key::count_;
|
||||
p = map.try_emplace(map.begin(), 5, 7331);
|
||||
BOOST_TEST_EQ(key::count_, key_count + 2);
|
||||
BOOST_TEST(p == map.find(5));
|
||||
}
|
||||
|
||||
#ifndef BOOST_UNORDERED_FOA_TESTS
|
||||
transparent_unordered_set::node_type set_extract_overload_compile_test()
|
||||
{
|
||||
@ -1646,6 +1723,7 @@ void test_unordered_map()
|
||||
test_map_transparent_equal_range<unordered_map>();
|
||||
test_map_transparent_erase<unordered_map>();
|
||||
test_map_transparent_extract<unordered_map>();
|
||||
test_map_transparent_try_emplace<unordered_map>();
|
||||
}
|
||||
|
||||
{
|
||||
@ -1658,6 +1736,7 @@ void test_unordered_map()
|
||||
test_map_non_transparent_equal_range<unordered_map>();
|
||||
test_map_non_transparent_erase<unordered_map>();
|
||||
test_map_non_transparent_extract<unordered_map>();
|
||||
test_map_non_transparent_try_emplace<unordered_map>();
|
||||
}
|
||||
|
||||
{
|
||||
@ -1671,6 +1750,7 @@ void test_unordered_map()
|
||||
test_map_non_transparent_equal_range<unordered_map>();
|
||||
test_map_non_transparent_erase<unordered_map>();
|
||||
test_map_non_transparent_extract<unordered_map>();
|
||||
test_map_non_transparent_try_emplace<unordered_map>();
|
||||
}
|
||||
|
||||
{
|
||||
@ -1684,6 +1764,7 @@ void test_unordered_map()
|
||||
test_map_non_transparent_equal_range<unordered_map>();
|
||||
test_map_non_transparent_erase<unordered_map>();
|
||||
test_map_non_transparent_extract<unordered_map>();
|
||||
test_map_non_transparent_try_emplace<unordered_map>();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user