diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index 366f073..3a21ea9 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -1465,7 +1465,7 @@ class flat_map //! Complexity: Logarithmic. template BOOST_CONTAINER_FORCEINLINE std::pair equal_range(const K& x) - { return dtl::force_copy >(m_flat_tree.lower_bound_range(x)); } + { return dtl::force_copy >(m_flat_tree.equal_range(x)); } //! Requires: This overload is available only if //! key_compare::is_transparent exists. @@ -1475,7 +1475,7 @@ class flat_map //! Complexity: Logarithmic. template BOOST_CONTAINER_FORCEINLINE std::pair equal_range(const K& x) const - { return dtl::force_copy >(m_flat_tree.lower_bound_range(x)); } + { return dtl::force_copy >(m_flat_tree.equal_range(x)); } //! Effects: Extracts the internal sequence container. //! diff --git a/include/boost/container/flat_set.hpp b/include/boost/container/flat_set.hpp index 5dae0f9..2b69e1a 100644 --- a/include/boost/container/flat_set.hpp +++ b/include/boost/container/flat_set.hpp @@ -1031,7 +1031,7 @@ class flat_set //! Complexity: Logarithmic template std::pair equal_range(const K& x) - { return this->tree_t::lower_bound_range(x); } + { return this->tree_t::equal_range(x); } //! Requires: This overload is available only if //! key_compare::is_transparent exists. @@ -1041,7 +1041,7 @@ class flat_set //! Complexity: Logarithmic template std::pair equal_range(const K& x) const - { return this->tree_t::lower_bound_range(x); } + { return this->tree_t::equal_range(x); } #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) diff --git a/test/flat_map_test.cpp b/test/flat_map_test.cpp index 9595775..d01598b 100644 --- a/test/flat_map_test.cpp +++ b/test/flat_map_test.cpp @@ -25,6 +25,7 @@ #include "../../intrusive/test/iterator_test.hpp" #include +#include using namespace boost::container; @@ -560,6 +561,37 @@ bool test_heterogeneous_lookups() return true; } +// An ordered sequence of std:pair is also ordered by std::pair::first. +struct with_lookup_by_first +{ + typedef void is_transparent; + inline bool operator()(std::pair a, std::pair b) const + { + return a < b; + } + inline bool operator()(std::pair a, int first) const + { + return a.first < first; + } + inline bool operator()(int first, std::pair b) const + { + return first < b.first; + } +}; + +bool test_heterogeneous_lookup_by_partial_key() +{ + typedef flat_map,int, with_lookup_by_first> map_t; + + map_t map1; + map1[std::pair(0, 1)] = 3; + map1[std::pair(0, 2)] = 3; + + std::pair const first_0_range = map1.equal_range(0); + + return 2 == first_0_range.second - first_0_range.first; +} + }}} //namespace boost::container::test int main() @@ -620,6 +652,9 @@ int main() if (!test_heterogeneous_lookups()) return 1; + if (!test_heterogeneous_lookup_by_partial_key()) + return 1; + //////////////////////////////////// // Testing allocator implementations //////////////////////////////////// diff --git a/test/flat_set_test.cpp b/test/flat_set_test.cpp index 0ffb839..693305f 100644 --- a/test/flat_set_test.cpp +++ b/test/flat_set_test.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -576,6 +577,37 @@ bool test_heterogeneous_lookups() return true; } +// An ordered sequence of std:pair is also ordered by std::pair::first. +struct with_lookup_by_first +{ + typedef void is_transparent; + inline bool operator()(std::pair a, std::pair b) const + { + return a < b; + } + inline bool operator()(std::pair a, int first) const + { + return a.first < first; + } + inline bool operator()(int first, std::pair b) const + { + return first < b.first; + } +}; + +bool test_heterogeneous_lookup_by_partial_key() +{ + typedef flat_set, with_lookup_by_first> set_t; + + set_t set1; + set1.insert(std::pair(0, 1)); + set1.insert(std::pair(0, 2)); + + std::pair const first_0_range = set1.equal_range(0); + + return 2 == first_0_range.second - first_0_range.first; +} + }}} template @@ -717,6 +749,10 @@ int main() return 1; } + if(!test_heterogeneous_lookup_by_partial_key()){ + return 1; + } + //////////////////////////////////// // Testing allocator implementations ////////////////////////////////////