mirror of
https://github.com/boostorg/unordered.git
synced 2025-11-01 16:21:37 +01:00
Implement insert_or_assign.
This commit is contained in:
@@ -3704,6 +3704,27 @@ struct table_impl : boost::unordered::detail::table<Types>
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Key, typename M>
|
||||
emplace_return insert_or_assign_impl(
|
||||
BOOST_FWD_REF(Key) k, BOOST_FWD_REF(M) obj)
|
||||
{
|
||||
std::size_t key_hash = this->hash(k);
|
||||
node_pointer pos = this->find_node(key_hash, k);
|
||||
|
||||
if (pos) {
|
||||
pos->value().second = boost::forward<M>(obj);
|
||||
return emplace_return(iterator(pos), false);
|
||||
} else {
|
||||
return emplace_return(
|
||||
iterator(this->resize_and_add_node(
|
||||
boost::unordered::detail::func::construct_node_pair(
|
||||
this->node_alloc(), boost::forward<Key>(k),
|
||||
boost::forward<M>(obj)),
|
||||
key_hash)),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Insert range methods
|
||||
//
|
||||
|
||||
@@ -342,6 +342,37 @@ template <class K, class T, class H, class P, class A> class unordered_map
|
||||
return this->emplace_hint(hint, boost::move(x));
|
||||
}
|
||||
|
||||
template <class M>
|
||||
std::pair<iterator, bool> insert_or_assign(
|
||||
key_type const& k, BOOST_FWD_REF(M) obj)
|
||||
{
|
||||
return table_.insert_or_assign_impl(k, boost::forward<M>(obj));
|
||||
}
|
||||
|
||||
template <class M>
|
||||
iterator insert_or_assign(
|
||||
const_iterator, key_type const& k, BOOST_FWD_REF(M) obj)
|
||||
{
|
||||
return table_.insert_or_assign_impl(k, boost::forward<M>(obj)).first;
|
||||
}
|
||||
|
||||
template <class M>
|
||||
std::pair<iterator, bool> insert_or_assign(
|
||||
BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
|
||||
{
|
||||
return table_.insert_or_assign_impl(
|
||||
boost::move(k), boost::forward<M>(obj));
|
||||
}
|
||||
|
||||
template <class M>
|
||||
iterator insert_or_assign(
|
||||
const_iterator, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
|
||||
{
|
||||
return table_
|
||||
.insert_or_assign_impl(boost::move(k), boost::forward<M>(obj))
|
||||
.first;
|
||||
}
|
||||
|
||||
template <class InputIt> void insert(InputIt, InputIt);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
|
||||
Reference in New Issue
Block a user