Implement insert_or_assign.

This commit is contained in:
Daniel James
2017-02-27 03:59:02 +00:00
parent 8fa93cc55b
commit 958d206bb6
4 changed files with 193 additions and 1 deletions

View File

@@ -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
//