Implement transparent insert_or_assign()

This commit is contained in:
Christian Mazakas
2022-11-15 09:53:18 -08:00
parent 01d508b6af
commit 0a879c1063
2 changed files with 46 additions and 2 deletions

View File

@ -289,14 +289,26 @@ namespace boost {
template <class M>
std::pair<iterator, bool> insert_or_assign(key_type&& key, M&& obj)
{
auto ibp =
table_.try_emplace(std::move(key), std::forward<M>(obj));
auto ibp = table_.try_emplace(std::move(key), std::forward<M>(obj));
if (ibp.second) {
return ibp;
}
ibp.first->second = std::forward<M>(obj);
return ibp;
}
template <class K, class M>
typename std::enable_if<
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
std::pair<iterator, bool> >::type
insert_or_assign(K&& k, M&& obj)
{
auto ibp = table_.try_emplace(std::forward<K>(k), std::forward<M>(obj));
if (ibp.second) {
return ibp;
}
ibp.first->second = std::forward<M>(obj);
return ibp;
}
template <class M>
@ -312,6 +324,16 @@ namespace boost {
.first;
}
template <class K, class M>
typename std::enable_if<
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
iterator>::type
insert_or_assign(const_iterator, K&& k, M&& obj)
{
return this->insert_or_assign(std::forward<K>(k), std::forward<M>(obj))
.first;
}
template <class... Args>
BOOST_FORCEINLINE std::pair<iterator, bool> emplace(Args&&... args)
{

View File

@ -801,6 +801,16 @@ namespace boost {
boost::move(k), boost::forward<M>(obj));
}
template <class Key, class M>
typename boost::enable_if_c<
detail::are_transparent<Key, hasher, key_equal>::value,
std::pair<iterator, bool> >::type
insert_or_assign(BOOST_FWD_REF(Key) k, BOOST_FWD_REF(M) obj)
{
return table_.insert_or_assign_unique(
boost::forward<Key>(k), boost::forward<M>(obj));
}
template <class M>
iterator insert_or_assign(
const_iterator, key_type const& k, BOOST_FWD_REF(M) obj)
@ -817,6 +827,18 @@ namespace boost {
.first;
}
template <class Key, class M>
typename boost::enable_if_c<
detail::are_transparent<Key, hasher, key_equal>::value, iterator>::type
insert_or_assign(
const_iterator, BOOST_FWD_REF(Key) k, BOOST_FWD_REF(M) obj)
{
return table_
.insert_or_assign_unique(
boost::forward<Key>(k), boost::forward<M>(obj))
.first;
}
iterator erase(iterator);
iterator erase(const_iterator);
size_type erase(const key_type&);