mirror of
https://github.com/boostorg/unordered.git
synced 2025-09-27 08:10:56 +02:00
Add missing init_type overloads for insert(hint)
This commit is contained in:
@@ -231,12 +231,14 @@ namespace boost {
|
||||
return table_.insert(std::move(value));
|
||||
}
|
||||
|
||||
iterator insert(const_iterator, value_type const& value)
|
||||
template <class Ty>
|
||||
auto insert(const_iterator, Ty&& value)
|
||||
-> decltype(table_.insert(std::forward<Ty>(value)).first)
|
||||
{
|
||||
return table_.insert(value).first;
|
||||
return table_.insert(std::forward<Ty>(value)).first;
|
||||
}
|
||||
|
||||
iterator insert(const_iterator, value_type&& value)
|
||||
iterator insert(const_iterator, init_type&& value)
|
||||
{
|
||||
return table_.insert(std::move(value)).first;
|
||||
}
|
||||
|
@@ -164,9 +164,76 @@ static void test_insert_tracking()
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 7u + 2u * map.size());
|
||||
}
|
||||
|
||||
static void test_insert_hint_tracking()
|
||||
{
|
||||
raii_tracker::reset_counts();
|
||||
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 0u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 0u);
|
||||
|
||||
boost::unordered_flat_map<raii_tracker, raii_tracker,
|
||||
std::hash<raii_tracker> >
|
||||
map;
|
||||
|
||||
{
|
||||
std::pair<raii_tracker, raii_tracker> value{1, 2};
|
||||
|
||||
map.insert(map.begin(), value);
|
||||
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 2u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 0u);
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<raii_tracker, raii_tracker> value{2, 3};
|
||||
|
||||
map.insert(std::move(value));
|
||||
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 2u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 2u);
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<raii_tracker const, raii_tracker> value{3, 4};
|
||||
|
||||
map.insert(map.begin(), value);
|
||||
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 4u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 2u);
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<raii_tracker const, raii_tracker> value{4, 5};
|
||||
|
||||
map.insert(map.begin(), std::move(value));
|
||||
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 5u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 3u);
|
||||
}
|
||||
|
||||
{
|
||||
map.insert(map.begin(), std::make_pair(5, 6));
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 5u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 5u);
|
||||
}
|
||||
|
||||
{
|
||||
map.insert(map.begin(), {6, 7});
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 5u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 7u);
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ(map.size(), 6u);
|
||||
|
||||
map.rehash(1024);
|
||||
BOOST_TEST_EQ(raii_tracker::copy_constructs, 5u);
|
||||
BOOST_TEST_EQ(raii_tracker::move_constructs, 7u + 2u * map.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_move_only();
|
||||
test_insert_tracking();
|
||||
test_insert_hint_tracking();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user