mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 11:27:15 +02:00
Update insert(Iterator, Iterator) overloads to use emplace internally instead of insert()'ing
This commit is contained in:
@ -1256,7 +1256,14 @@ public:
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BOOST_FORCEINLINE std::pair<iterator,bool> emplace(Args&&... args)
|
BOOST_FORCEINLINE std::pair<iterator,bool> emplace(Args&&... args)
|
||||||
{
|
{
|
||||||
return emplace_impl(init_type(std::forward<Args>(args)...));
|
using emplace_type = typename std::conditional<
|
||||||
|
std::is_constructible<
|
||||||
|
init_type, Args...
|
||||||
|
>::value,
|
||||||
|
init_type,
|
||||||
|
value_type
|
||||||
|
>::type;
|
||||||
|
return emplace_impl(emplace_type(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key,typename... Args>
|
template<typename Key,typename... Args>
|
||||||
|
@ -242,7 +242,7 @@ namespace boost {
|
|||||||
void insert(InputIterator first, InputIterator last)
|
void insert(InputIterator first, InputIterator last)
|
||||||
{
|
{
|
||||||
for (auto pos = first; pos != last; ++pos) {
|
for (auto pos = first; pos != last; ++pos) {
|
||||||
table_.insert(*pos);
|
table_.emplace(*pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ namespace boost {
|
|||||||
void insert(InputIterator first, InputIterator last)
|
void insert(InputIterator first, InputIterator last)
|
||||||
{
|
{
|
||||||
for (auto pos = first; pos != last; ++pos) {
|
for (auto pos = first; pos != last; ++pos) {
|
||||||
table_.insert(*pos);
|
table_.emplace(*pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "../helpers/input_iterator.hpp"
|
#include "../helpers/input_iterator.hpp"
|
||||||
#include "../helpers/helpers.hpp"
|
#include "../helpers/helpers.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace insert_tests {
|
namespace insert_tests {
|
||||||
|
|
||||||
test::seed_t initialize_seed(243432);
|
test::seed_t initialize_seed(243432);
|
||||||
@ -674,6 +676,23 @@ namespace insert_tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class X> void set_tests(X*, test::random_generator)
|
||||||
|
{
|
||||||
|
// prove that our insert(iterator, iterator) implementation honors
|
||||||
|
// Cpp17EmplaceConstructible
|
||||||
|
//
|
||||||
|
|
||||||
|
X x;
|
||||||
|
std::vector<int> v;
|
||||||
|
v.reserve(1000);
|
||||||
|
for (unsigned i = 0; i < 1000; ++i) {
|
||||||
|
v.push_back(static_cast<int>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
x.insert(v.begin(), v.end());
|
||||||
|
BOOST_TEST_EQ(x.size(), 1000u);
|
||||||
|
}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
void try_emplace_tests(X*, test::random_generator generator)
|
void try_emplace_tests(X*, test::random_generator generator)
|
||||||
{
|
{
|
||||||
@ -909,6 +928,9 @@ namespace insert_tests {
|
|||||||
|
|
||||||
UNORDERED_TEST(map_insert_range_test2,
|
UNORDERED_TEST(map_insert_range_test2,
|
||||||
((test_map))((default_generator)(generate_collisions)(limited_range)))
|
((test_map))((default_generator)(generate_collisions)(limited_range)))
|
||||||
|
|
||||||
|
UNORDERED_TEST(
|
||||||
|
set_tests, ((test_set_std_alloc)(test_set))((default_generator)))
|
||||||
#else
|
#else
|
||||||
boost::unordered_set<test::movable, test::hash, test::equal_to,
|
boost::unordered_set<test::movable, test::hash, test::equal_to,
|
||||||
std::allocator<test::movable> >* test_set_std_alloc;
|
std::allocator<test::movable> >* test_set_std_alloc;
|
||||||
@ -965,6 +987,9 @@ namespace insert_tests {
|
|||||||
UNORDERED_TEST(map_insert_range_test2,
|
UNORDERED_TEST(map_insert_range_test2,
|
||||||
((test_multimap_std_alloc)(test_map)(test_multimap))(
|
((test_multimap_std_alloc)(test_map)(test_multimap))(
|
||||||
(default_generator)(generate_collisions)(limited_range)))
|
(default_generator)(generate_collisions)(limited_range)))
|
||||||
|
|
||||||
|
UNORDERED_TEST(
|
||||||
|
set_tests, ((test_set_std_alloc)(test_set)(test_multiset))((default_generator)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||||
|
Reference in New Issue
Block a user