From d9341ec394ef97bd1b36f05b5e6be6ec538e480c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 22 Jun 2019 11:41:05 +0200 Subject: [PATCH] Fix "count" with heterogeneous lookups in flat_map and flat_set --- include/boost/container/flat_map.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index a3bcf47..f1d5ed2 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -1343,9 +1343,7 @@ class flat_map //! //! Complexity: log(size())+count(k) BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const - //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); } + { return static_cast(m_flat_tree.find(x) != m_flat_tree.end()); } //! Requires: This overload is available only if //! key_compare::is_transparent exists. @@ -1355,7 +1353,9 @@ class flat_map //! Complexity: log(size())+count(k) template BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const - { return static_cast(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); } //! Returns: Returns true if there is an element with key //! equivalent to key in the container, otherwise false.