Fixes #241: flat_map should support same interface as std::map

This commit is contained in:
Ion Gaztañaga committed 2024-06-28 14:04:00 +02:00
1 parent 6f10e52887
commit df03ffc8ec
8 files changed
+142 -3

No files matched your search

+34 -3
View File
@@ -1127,9 +1127,6 @@ class flat_tree
return ret;
}
inline iterator erase(const_iterator position)
{ return this->m_data.m_seq.erase(position); }
size_type erase(const key_type& k)
{
std::pair<iterator,iterator > itp = this->equal_range(k);
@@ -1149,6 +1146,40 @@ class flat_tree
return ret;
}
template <class K>
inline typename dtl::enable_if_c<
dtl::is_transparent<key_compare>::value && //transparent
!dtl::is_convertible<K, iterator>::value && //not convertible to iterator
!dtl::is_convertible<K, const_iterator>::value //not convertible to const_iterator
, size_type>::type
erase(const K& k)
{
std::pair<iterator, iterator > itp = this->equal_range(k);
size_type ret = static_cast<size_type>(itp.second - itp.first);
if (ret) {
this->m_data.m_seq.erase(itp.first, itp.second);
}
return ret;
}
template <class K>
inline typename dtl::enable_if_c<
dtl::is_transparent<key_compare>::value && //transparent
!dtl::is_convertible<K, iterator>::value && //not convertible to iterator
!dtl::is_convertible<K, const_iterator>::value //not convertible to const_iterator
, size_type>::type
erase_unique(const K& k)
{
const_iterator i = static_cast<const flat_tree&>(*this).find(k);
size_type ret = static_cast<size_type>(i != this->cend());
if (ret)
this->erase(i);
return ret;
}
inline iterator erase(const_iterator position)
{ return this->m_data.m_seq.erase(position); }
inline iterator erase(const_iterator first, const_iterator last)
{ return this->m_data.m_seq.erase(first, last); }
@@ -536,6 +536,19 @@ struct node_alloc_holder
return this->icont().erase_and_dispose(k, chain_holder.get_chain_builder());
}
template<class Key, class KeyCompare>
inline size_type erase_key(const Key& k, KeyCompare cmp, version_1)
{
return this->icont().erase_and_dispose(k, cmp, Destroyer(this->node_alloc()));
}
template<class Key, class KeyCompare>
inline size_type erase_key(const Key& k, KeyCompare cmp, version_2)
{
allocator_multialloc_chain_node_deallocator<NodeAlloc> chain_holder(this->node_alloc());
return this->icont().erase_and_dispose(k, cmp, chain_holder.get_chain_builder());
}
protected:
struct cloner
{
+25
View File
@@ -1142,6 +1142,31 @@ class tree
return ret;
}
template <class K>
inline typename dtl::enable_if_c<
dtl::is_transparent<key_compare>::value && //transparent
!dtl::is_convertible<K, iterator>::value && //not convertible to iterator
!dtl::is_convertible<K, const_iterator>::value //not convertible to const_iterator
, size_type>::type
erase(const K& k)
{ return AllocHolder::erase_key(k, KeyNodeCompare(key_comp()), alloc_version()); }
template <class K>
inline typename dtl::enable_if_c<
dtl::is_transparent<key_compare>::value && //transparent
!dtl::is_convertible<K, iterator>::value && //not convertible to iterator
!dtl::is_convertible<K, const_iterator>::value //not convertible to const_iterator
, size_type>::type
erase_unique(const K& k)
{
iterator i = this->find(k);
size_type ret = static_cast<size_type>(i != this->end());
if (ret)
this->erase(i);
return ret;
}
iterator erase(const_iterator first, const_iterator last)
{
BOOST_ASSERT(first == last || (first != this->cend() && (priv_is_linked)(first)));