Fix "count" with heterogeneous lookups in flat_map and flat_set

This commit is contained in:
Ion Gaztañaga
2019-06-22 10:26:36 +02:00
parent b383c0809a
commit 0c95d4846f
6 changed files with 27 additions and 5 deletions
+1 -1
View File
@@ -1605,7 +1605,7 @@ class flat_tree
const Compare &key_cmp = this->m_data.get_comp();
KeyOfValue key_extract;
RanIt lb(this->priv_lower_bound(first, last, k)), ub(lb);
if(lb != last && static_cast<difference_type>(!key_cmp(k, key_extract(*lb)))){
if(lb != last && !key_cmp(k, key_extract(*lb))){
++ub;
}
return std::pair<RanIt, RanIt>(lb, ub);
+7 -1
View File
@@ -1343,7 +1343,9 @@ class flat_map
//!
//! <b>Complexity</b>: log(size())+count(k)
BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
{ return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
//Don't use find() != end optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return m_flat_tree.count(x); }
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
@@ -1465,6 +1467,8 @@ class flat_map
//! <b>Complexity</b>: Logarithmic.
template<class K>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const K& x)
//Don't use lower_bound_range optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
//! <b>Requires</b>: This overload is available only if
@@ -1475,6 +1479,8 @@ class flat_map
//! <b>Complexity</b>: Logarithmic.
template<class K>
BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const K& x) const
//Don't use lower_bound_range optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
//! <b>Effects</b>: Extracts the internal sequence container.
+7 -1
View File
@@ -925,7 +925,9 @@ class flat_set
//! <b>Complexity</b>: log(size())+count(k)
template<typename K>
BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
{ return static_cast<size_type>(this->tree_t::find(x) != this->tree_t::cend()); }
//Don't use find() != end optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return this->tree_t::count(x); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
@@ -1031,6 +1033,8 @@ class flat_set
//! <b>Complexity</b>: Logarithmic
template<typename K>
std::pair<iterator,iterator> equal_range(const K& x)
//Don't use lower_bound_range optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return this->tree_t::equal_range(x); }
//! <b>Requires</b>: This overload is available only if
@@ -1041,6 +1045,8 @@ class flat_set
//! <b>Complexity</b>: Logarithmic
template<typename K>
std::pair<const_iterator,const_iterator> equal_range(const K& x) const
//Don't use lower_bound_range optimization here as transparent comparators with key K might
//return a different range than key_type (which can only return a single element range)
{ return this->tree_t::equal_range(x); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)