* Implemented C++20 contains() for associative containers as specified in P0458R2.

* Fixed serious bug in heterogeneous lookup functions (is_transparent was broken).
This commit is contained in:
Ion Gaztañaga
2018-08-13 15:36:00 +02:00
parent 1ad64316a4
commit 139db663a3
16 changed files with 220 additions and 16 deletions
@@ -1201,6 +1201,15 @@ class flat_tree
return n;
}
BOOST_CONTAINER_FORCEINLINE bool contains(const key_type& x) const
{ return this->find(x) != this->cend(); }
template<typename K>
BOOST_CONTAINER_FORCEINLINE
typename dtl::enable_if_transparent<key_compare, K, bool>::type
contains(const K& x) const
{ return this->find(x) != this->cend(); }
template<class C2>
BOOST_CONTAINER_FORCEINLINE void merge_unique(flat_tree<Value, KeyOfValue, C2, AllocatorOrContainer>& source)
{
+12 -3
View File
@@ -76,19 +76,28 @@ struct select1st
{ return const_cast<type&>(x.first); }
};
template<typename T>
struct void_t { typedef void type; };
template <class T, class=void>
struct is_transparent
struct is_transparent_base
{
static const bool value = false;
};
template <class T>
struct is_transparent<T, typename T::is_transparent>
struct is_transparent_base<T, typename void_t<typename T::is_transparent>::type>
{
static const bool value = true;
};
template <typename C, typename K, typename R>
template <class T>
struct is_transparent
: is_transparent_base<T>
{};
template <typename C, class /*Dummy*/, typename R>
struct enable_if_transparent
: boost::move_detail::enable_if_c<dtl::is_transparent<C>::value, R>
{};
+9
View File
@@ -1297,6 +1297,15 @@ class tree
count(const K& k) const
{ return size_type(this->icont().count(k, KeyNodeCompare(key_comp()))); }
BOOST_CONTAINER_FORCEINLINE bool contains(const key_type& x) const
{ return this->find(x) != this->cend(); }
template<typename K>
BOOST_CONTAINER_FORCEINLINE
typename dtl::enable_if_transparent<key_compare, K, bool>::type
contains(const K& x) const
{ return this->find(x) != this->cend(); }
BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const key_type& k)
{ return iterator(this->icont().lower_bound(k, KeyNodeCompare(key_comp()))); }
+36
View File
@@ -1340,6 +1340,24 @@ class flat_map
BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
{ return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const
{ return m_flat_tree.find(x) != m_flat_tree.end(); }
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const
{ return m_flat_tree.find(x) != m_flat_tree.end(); }
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
@@ -2631,6 +2649,24 @@ class flat_multimap
BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
{ return m_flat_tree.count(x); }
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const
{ return m_flat_tree.find(x) != m_flat_tree.end(); }
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const
{ return m_flat_tree.find(x) != m_flat_tree.end(); }
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
+24
View File
@@ -912,6 +912,23 @@ class flat_set
{ return static_cast<size_type>(this->tree_t::find(x) != this->tree_t::cend()); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const;
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
@@ -1685,6 +1702,13 @@ class flat_multiset
//! @copydoc ::boost::container::flat_set::count(const key_type& ) const
size_type count(const key_type& x) const;
//! @copydoc ::boost::container::flat_set::contains(const key_type& ) const
bool contains(const key_type& x) const;
//! @copydoc ::boost::container::flat_set::contains(const K& ) const
template<typename K>
bool contains(const K& x) const;
//! @copydoc ::boost::container::flat_set::lower_bound(const key_type& )
iterator lower_bound(const key_type& x);
+32
View File
@@ -1119,6 +1119,22 @@ class map
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const;
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
@@ -2017,6 +2033,22 @@ class multimap
template<typename K>
size_type count(const K& x) const;
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const;
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
+23 -6
View File
@@ -772,14 +772,24 @@ class set
BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
{ return static_cast<size_type>(this->find(x) != this->cend()); }
//! <b>Returns</b>: The number of elements with key equivalent to x.
//!
//! <b>Complexity</b>: log(size())+count(k)
BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x)
{ return static_cast<size_type>(this->base_t::find(x) != this->base_t::end()); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
bool contains(const key_type& x) const;
//! <b>Requires</b>: This overload is available only if
//! key_compare::is_transparent exists.
//!
//! <b>Returns</b>: Returns true if there is an element with key
//! equivalent to key in the container, otherwise false.
//!
//! <b>Complexity</b>: log(size()).
template<typename K>
bool contains(const K& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
@@ -1461,6 +1471,13 @@ class multiset
template<typename K>
size_type count(const K& x) const;
//! @copydoc ::boost::container::set::contains(const key_type& ) const
bool contains(const key_type& x) const;
//! @copydoc ::boost::container::set::contains(const K& ) const
template<typename K>
bool contains(const K& x) const;
//! @copydoc ::boost::container::set::lower_bound(const key_type& )
iterator lower_bound(const key_type& x);