From 81d78dbefa3ba6fce1a68e3e5f8a0d4f7b257d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 2 Feb 2019 00:25:09 +0100 Subject: [PATCH] Fixed GitHub #98: ("flat_map: insert_or_assign does not work with hint") --- doc/container.qbk | 1 + include/boost/container/flat_map.hpp | 4 ++-- test/flat_map_test.cpp | 26 +++++++++++++++++++++----- test/map_test.cpp | 26 +++++++++++++++++++++----- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index 976bd10..8650ff6 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1248,6 +1248,7 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs: * [@https://github.com/boostorg/container/pull/96 GitHub #96: ['"Workaround: Intel compilers do not offer CTAD yet"]]. * [@https://github.com/boostorg/container/issues/97 GitHub #97: ['"buffer overflow in boost::container::flat_map on FreeBSD"]]. + * [@https://github.com/boostorg/container/issues/98 GitHub #98: ['"flat_map: insert_or_assign does not work with hint"]]. * [@https://github.com/boostorg/container/issues/100 GitHub #100: ['"Compile error on Green Hills: container_detail::flat_tree has no member insert"]]. [endsect] diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index b55a6ca..283ab33 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -788,7 +788,7 @@ class flat_map //! Complexity: Logarithmic in the size of the container in general, but amortized constant if //! the new element is inserted just before hint. template - BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj) + BOOST_CONTAINER_FORCEINLINE std::pair insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj) { return dtl::force_copy< std::pair > (this->m_flat_tree.insert_or_assign @@ -812,7 +812,7 @@ class flat_map //! Complexity: Logarithmic in the size of the container in general, but amortized constant if //! the new element is inserted just before hint. template - BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj) + BOOST_CONTAINER_FORCEINLINE std::pair insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj) { return dtl::force_copy< std::pair > (this->m_flat_tree.insert_or_assign diff --git a/test/flat_map_test.cpp b/test/flat_map_test.cpp index f1cc06b..9497ee2 100644 --- a/test/flat_map_test.cpp +++ b/test/flat_map_test.cpp @@ -464,11 +464,27 @@ bool test_heterogeneous_lookups() const map_t &cmap1 = map1; const mmap_t &cmmap1 = mmap1; - map1.insert_or_assign(1, 'a'); - map1.insert_or_assign(1, 'b'); - map1.insert_or_assign(2, 'c'); - map1.insert_or_assign(2, 'd'); - map1.insert_or_assign(3, 'e'); + if(!map1.insert_or_assign(1, 'a').second) + return false; + if( map1.insert_or_assign(1, 'b').second) + return false; + if(!map1.insert_or_assign(2, 'c').second) + return false; + if( map1.insert_or_assign(2, 'd').second) + return false; + if(!map1.insert_or_assign(3, 'e').second) + return false; + + if(map1.insert_or_assign(1, 'a').second) + return false; + if(map1.insert_or_assign(1, 'b').second) + return false; + if(map1.insert_or_assign(2, 'c').second) + return false; + if(map1.insert_or_assign(2, 'd').second) + return false; + if(map1.insert_or_assign(3, 'e').second) + return false; mmap1.insert(value_type(1, 'a')); mmap1.insert(value_type(1, 'b')); diff --git a/test/map_test.cpp b/test/map_test.cpp index 90998f0..b73f569 100644 --- a/test/map_test.cpp +++ b/test/map_test.cpp @@ -260,11 +260,27 @@ bool test_heterogeneous_lookups() const map_t &cmap1 = map1; const mmap_t &cmmap1 = mmap1; - map1.insert_or_assign(1, 'a'); - map1.insert_or_assign(1, 'b'); - map1.insert_or_assign(2, 'c'); - map1.insert_or_assign(2, 'd'); - map1.insert_or_assign(3, 'e'); + if(!map1.insert_or_assign(1, 'a').second) + return false; + if( map1.insert_or_assign(1, 'b').second) + return false; + if(!map1.insert_or_assign(2, 'c').second) + return false; + if( map1.insert_or_assign(2, 'd').second) + return false; + if(!map1.insert_or_assign(3, 'e').second) + return false; + + if(map1.insert_or_assign(1, 'a').second) + return false; + if(map1.insert_or_assign(1, 'b').second) + return false; + if(map1.insert_or_assign(2, 'c').second) + return false; + if(map1.insert_or_assign(2, 'd').second) + return false; + if(map1.insert_or_assign(3, 'e').second) + return false; mmap1.insert(value_type(1, 'a')); mmap1.insert(value_type(1, 'b'));