Add transparent insert() overloads to unordered_[flat]_set

This commit is contained in:
Christian Mazakas
2022-12-13 12:33:07 -08:00
parent 7572de875c
commit 7d77f1d478
3 changed files with 57 additions and 4 deletions

View File

@ -1477,7 +1477,22 @@ namespace boost {
}
#endif
}
template <typename T, typename Alloc, typename Key>
inline typename boost::allocator_pointer<Alloc>::type
construct_node_from_key(T*, Alloc& alloc, BOOST_FWD_REF(Key) k)
{
return construct_node(alloc, boost::forward<Key>(k));
}
template <typename T, typename V, typename Alloc, typename Key>
inline typename boost::allocator_pointer<Alloc>::type
construct_node_from_key(
std::pair<T const, V>*, Alloc& alloc, BOOST_FWD_REF(Key) k)
{
return construct_node_pair(alloc, boost::forward<Key>(k));
}
} // namespace func
}
}
}
@ -2640,8 +2655,10 @@ namespace boost {
} else {
node_allocator_type alloc = node_alloc();
node_tmp tmp(
detail::func::construct_node_pair(alloc, boost::forward<Key>(k)),
value_type* dispatch = BOOST_NULLPTR;
node_tmp tmp(detail::func::construct_node_from_key(
dispatch, alloc, boost::forward<Key>(k)),
alloc);
if (size_ + 1 > max_load_) {
@ -2660,7 +2677,7 @@ namespace boost {
template <typename Key>
iterator try_emplace_hint_unique(c_iterator hint, BOOST_FWD_REF(Key) k)
{
if (hint.p && this->key_eq()(hint->first, k)) {
if (hint.p && this->key_eq()(extractor::extract(*hint), k)) {
return iterator(hint.p, hint.itb);
} else {
return try_emplace_unique(k).first;

View File

@ -231,6 +231,15 @@ namespace boost {
return table_.insert(std::move(value));
}
template <class K>
BOOST_FORCEINLINE typename std::enable_if<
detail::transparent_non_iterable<K, unordered_flat_set>::value,
std::pair<iterator, bool> >::type
insert(K&& k)
{
return table_.try_emplace(std::forward<K>(k));
}
BOOST_FORCEINLINE iterator insert(const_iterator, value_type const& value)
{
return table_.insert(value).first;
@ -241,6 +250,15 @@ namespace boost {
return table_.insert(std::move(value)).first;
}
template <class K>
BOOST_FORCEINLINE typename std::enable_if<
detail::transparent_non_iterable<K, unordered_flat_set>::value,
iterator>::type
insert(const_iterator, K&& k)
{
return table_.try_emplace(std::forward<K>(k)).first;
}
template <class InputIterator>
void insert(InputIterator first, InputIterator last)
{

View File

@ -390,6 +390,15 @@ namespace boost {
return this->emplace(boost::move(x));
}
template <class Key>
typename boost::enable_if_c<
detail::transparent_non_iterable<Key, unordered_set>::value,
std::pair<iterator, bool> >::type
insert(BOOST_FWD_REF(Key) k)
{
return table_.try_emplace_unique(boost::forward<Key>(k));
}
iterator insert(const_iterator hint, value_type const& x)
{
return this->emplace_hint(hint, x);
@ -400,6 +409,15 @@ namespace boost {
return this->emplace_hint(hint, boost::move(x));
}
template <class Key>
typename boost::enable_if_c<
detail::transparent_non_iterable<Key, unordered_set>::value,
iterator>::type
insert(const_iterator hint, BOOST_FWD_REF(Key) k)
{
return table_.try_emplace_hint_unique(hint, boost::forward<Key>(k));
}
template <class InputIt> void insert(InputIt, InputIt);
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)