forked from boostorg/container
Fixes #118 ("Non-unique inplace_set_difference used in in flat_tree_merge_unique and iterator invalidation in insert_unique")
This commit is contained in:
@@ -1247,6 +1247,7 @@ use [*Boost.Container]? There are several reasons for that:
|
||||
* [@https://github.com/boostorg/container/pull/110 GitHub #110: ['"Avoid gcc 9 deprecated copy warnings in new_allocator.hpp"]].
|
||||
* [@https://github.com/boostorg/container/issues/112 GitHub #112: ['"vector::resize() compilation error with msvc-10..12: data is not a member of boost::detail::aligned_storage"]].
|
||||
* [@https://github.com/boostorg/container/issues/117 GitHub #117: ['"flat_map/map::insert_or_assign with hint has wrong return types"]].
|
||||
* [@https://github.com/boostorg/container/issues/118 GitHub #118: ['"Non-unique inplace_set_difference used in in flat_tree_merge_unique and iterator invalidation in insert_unique"]].
|
||||
|
||||
[endsect]
|
||||
|
||||
|
@@ -205,7 +205,7 @@ BOOST_CONTAINER_FORCEINLINE void flat_tree_merge_unique //has_merge_unique == f
|
||||
|
||||
size_type const old_sz = dest.size();
|
||||
iterator const first_new = dest.insert(dest.cend(), first, last );
|
||||
iterator e = boost::movelib::inplace_set_difference(first_new, dest.end(), dest.begin(), first_new, 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_<is_contiguous_container<SequenceContainer>::value> contiguous_tag;
|
||||
(flat_tree_container_inplace_merge)(dest, dest.begin()+old_sz, comp, contiguous_tag);
|
||||
@@ -883,11 +883,15 @@ class flat_tree
|
||||
//Step 3: only left unique values from the back not already present in the original range
|
||||
typename container_type::iterator const e = boost::movelib::inplace_set_unique_difference
|
||||
(it, seq.end(), seq.begin(), it, val_cmp);
|
||||
seq.erase(e, seq.cend());
|
||||
|
||||
seq.erase(e, seq.cend());
|
||||
//it might be invalidated by erasing [e, seq.end) if e == it
|
||||
if (it != e)
|
||||
{
|
||||
//Step 4: merge both ranges
|
||||
(flat_tree_container_inplace_merge)(seq, it, this->priv_value_comp(), contiguous_tag);
|
||||
}
|
||||
}
|
||||
|
||||
template <class InIt>
|
||||
void insert_equal(InIt first, InIt last)
|
||||
|
104
test/flat_map_adaptor_test.cpp
Normal file
104
test/flat_map_adaptor_test.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2004-2019. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/container for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/container/static_vector.hpp>
|
||||
#include <boost/container/stable_vector.hpp>
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/container/deque.hpp>
|
||||
|
||||
#include <boost/container/detail/container_or_allocator_rebind.hpp>
|
||||
|
||||
#include "map_test.hpp"
|
||||
#include <map>
|
||||
|
||||
using namespace boost::container;
|
||||
|
||||
template<class VoidAllocatorOrContainer>
|
||||
struct GetMapContainer
|
||||
{
|
||||
template<class ValueType>
|
||||
struct apply
|
||||
{
|
||||
typedef std::pair<ValueType, ValueType> type_t;
|
||||
typedef flat_map< ValueType
|
||||
, ValueType
|
||||
, std::less<ValueType>
|
||||
, typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, type_t>::type
|
||||
> map_type;
|
||||
|
||||
typedef flat_multimap< ValueType
|
||||
, ValueType
|
||||
, std::less<ValueType>
|
||||
, typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, type_t>::type
|
||||
> multimap_type;
|
||||
};
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::container::test;
|
||||
|
||||
////////////////////////////////////
|
||||
// Testing sequence container implementations
|
||||
////////////////////////////////////
|
||||
{
|
||||
typedef std::map<int, int> MyStdMap;
|
||||
typedef std::multimap<int, int> MyStdMultiMap;
|
||||
|
||||
if (0 != test::map_test
|
||||
< GetMapContainer<vector<std::pair<int, int> > >::apply<int>::map_type
|
||||
, MyStdMap
|
||||
, GetMapContainer<vector<std::pair<int, int> > >::apply<int>::multimap_type
|
||||
, MyStdMultiMap>()) {
|
||||
std::cout << "Error in map_test<vector<std::pair<int, int> > >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::map_test
|
||||
< GetMapContainer<small_vector<std::pair<int, int>, 7> >::apply<int>::map_type
|
||||
, MyStdMap
|
||||
, GetMapContainer<small_vector<std::pair<int, int>, 7> >::apply<int>::multimap_type
|
||||
, MyStdMultiMap>()) {
|
||||
std::cout << "Error in map_test<small_vector<std::pair<int, int>, 7> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::map_test
|
||||
< GetMapContainer<static_vector<std::pair<int, int>, MaxElem * 10> >::apply<int>::map_type
|
||||
, MyStdMap
|
||||
, GetMapContainer<static_vector<std::pair<int, int>, MaxElem * 10> >::apply<int>::multimap_type
|
||||
, MyStdMultiMap>()) {
|
||||
std::cout << "Error in map_test<static_vector<std::pair<int, int>, MaxElem * 10> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::map_test
|
||||
< GetMapContainer<stable_vector<std::pair<int, int> > >::apply<int>::map_type
|
||||
, MyStdMap
|
||||
, GetMapContainer<stable_vector<std::pair<int, int> > >::apply<int>::multimap_type
|
||||
, MyStdMultiMap>()) {
|
||||
std::cout << "Error in map_test<stable_vector<std::pair<int, int> > >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (0 != test::map_test
|
||||
< GetMapContainer<deque<std::pair<int, int> > >::apply<int>::map_type
|
||||
, MyStdMap
|
||||
, GetMapContainer<deque<std::pair<int, int> > >::apply<int>::multimap_type
|
||||
, MyStdMultiMap>()) {
|
||||
std::cout << "Error in map_test<deque<std::pair<int, int> > >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
101
test/flat_set_adaptor_test.cpp
Normal file
101
test/flat_set_adaptor_test.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2004-2019. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/container for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/container/static_vector.hpp>
|
||||
#include <boost/container/stable_vector.hpp>
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/container/deque.hpp>
|
||||
|
||||
#include <boost/container/detail/container_or_allocator_rebind.hpp>
|
||||
|
||||
#include "set_test.hpp"
|
||||
#include <set>
|
||||
|
||||
using namespace boost::container;
|
||||
|
||||
template<class VoidAllocatorOrContainer>
|
||||
struct GetSetContainer
|
||||
{
|
||||
template<class ValueType>
|
||||
struct apply
|
||||
{
|
||||
typedef flat_set < ValueType
|
||||
, std::less<ValueType>
|
||||
, typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, ValueType>::type
|
||||
> set_type;
|
||||
|
||||
typedef flat_multiset < ValueType
|
||||
, std::less<ValueType>
|
||||
, typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, ValueType>::type
|
||||
> multiset_type;
|
||||
};
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::container::test;
|
||||
|
||||
////////////////////////////////////
|
||||
// Testing sequence container implementations
|
||||
////////////////////////////////////
|
||||
{
|
||||
typedef std::set<int> MyStdSet;
|
||||
typedef std::multiset<int> MyStdMultiSet;
|
||||
|
||||
if (0 != test::set_test
|
||||
< GetSetContainer<vector<int> >::apply<int>::set_type
|
||||
, MyStdSet
|
||||
, GetSetContainer<vector<int> >::apply<int>::multiset_type
|
||||
, MyStdMultiSet>()) {
|
||||
std::cout << "Error in set_test<vector<int> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::set_test
|
||||
< GetSetContainer<small_vector<int, 7> >::apply<int>::set_type
|
||||
, MyStdSet
|
||||
, GetSetContainer<small_vector<int, 7> >::apply<int>::multiset_type
|
||||
, MyStdMultiSet>()) {
|
||||
std::cout << "Error in set_test<small_vector<int, 7> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::set_test
|
||||
< GetSetContainer<static_vector<int, MaxElem * 10> >::apply<int>::set_type
|
||||
, MyStdSet
|
||||
, GetSetContainer<static_vector<int, MaxElem * 10> >::apply<int>::multiset_type
|
||||
, MyStdMultiSet>()) {
|
||||
std::cout << "Error in set_test<static_vector<int, MaxElem * 10> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != test::set_test
|
||||
< GetSetContainer<stable_vector<int> >::apply<int>::set_type
|
||||
, MyStdSet
|
||||
, GetSetContainer<stable_vector<int> >::apply<int>::multiset_type
|
||||
, MyStdMultiSet>()) {
|
||||
std::cout << "Error in set_test<stable_vector<int> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (0 != test::set_test
|
||||
< GetSetContainer<deque<int> >::apply<int>::set_type
|
||||
, MyStdSet
|
||||
, GetSetContainer<deque<int> >::apply<int>::multiset_type
|
||||
, MyStdMultiSet>()) {
|
||||
std::cout << "Error in set_test<deque<int> >" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -14,6 +14,7 @@
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
#include "check_equal_containers.hpp"
|
||||
#include "print_container.hpp"
|
||||
#include "movable_int.hpp"
|
||||
#include <boost/container/detail/pair.hpp>
|
||||
#include <boost/move/iterator.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
#include "check_equal_containers.hpp"
|
||||
#include "print_container.hpp"
|
||||
#include "movable_int.hpp"
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/move/iterator.hpp>
|
||||
#include <boost/move/make_unique.hpp>
|
||||
|
Reference in New Issue
Block a user