From 48acf451b8e303e8b52269d7288f9a778584165a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 8 Sep 2024 01:51:16 +0200 Subject: [PATCH] Fix incorrect invariant check for iterators. We don't have a proper comparator for them, we need to wait until they are inserted in the sequence before checking invariants. --- include/boost/container/detail/flat_tree.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 98bd702..73f990e 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -199,7 +200,8 @@ inline void flat_tree_merge_equal //has_merge_unique == false { if(first != last) { typedef typename SequenceContainer::iterator iterator; - iterator const it = dest.insert( dest.end(), first, last ); + iterator const it = dest.insert( dest.end(), first, last); + BOOST_ASSERT((is_sorted)(it, dest.end(), comp)); dtl::bool_::value> contiguous_tag; (flat_tree_container_inplace_merge)(dest, it, comp, contiguous_tag); } @@ -227,7 +229,9 @@ inline void flat_tree_merge_unique //has_merge_unique == false typedef typename SequenceContainer::difference_type difference_type; size_type const old_sz = dest.size(); - iterator const first_new = dest.insert(dest.cend(), first, last ); + iterator const first_new = dest.insert(dest.cend(), first, last); + //We can't assert "is_sorted_and_unique" because the sequence can come from a multiset + BOOST_ASSERT((is_sorted)(first_new, dest.end(), comp)); iterator e = boost::movelib::inplace_set_unique_difference(first_new, dest.end(), dest.begin(), first_new, comp); dest.erase(e, dest.end()); dtl::bool_::value> contiguous_tag; @@ -954,7 +958,6 @@ class flat_tree template void insert_equal(ordered_range_t, InIt first, InIt last) { - BOOST_ASSERT((is_sorted)(first, last, this->priv_value_comp())); const bool value = boost::container::dtl:: has_member_function_callable_with_merge_unique::value; (flat_tree_merge_equal)(this->m_data.m_seq, first, last, this->priv_value_comp(), dtl::bool_()); @@ -963,7 +966,6 @@ class flat_tree template void insert_unique(ordered_unique_range_t, InIt first, InIt last) { - BOOST_ASSERT((is_sorted_and_unique)(this->m_data.m_seq.cbegin(), this->m_data.m_seq.cend(), this->priv_value_comp())); const bool value = boost::container::dtl:: has_member_function_callable_with_merge_unique::value; (flat_tree_merge_unique)(this->m_data.m_seq, first, last, this->priv_value_comp(), dtl::bool_());