* Implemented merge operations for associative containers.

* Update tree-based containers to changes done in Intrusive internal utilities in order to fix Trac 12432.
This commit is contained in:
Ion Gaztañaga
2016-09-03 00:03:42 +02:00
parent 0617d0e538
commit f540b83ccd
13 changed files with 722 additions and 172 deletions
-2
View File
@@ -62,7 +62,6 @@ namespace container_detail {
//Instantiate base class as previous instantiations don't instantiate inherited members
template class flat_tree
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, identity<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, test::simple_allocator<test::movable_and_copyable_int>
@@ -70,7 +69,6 @@ template class flat_tree
template class flat_tree
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, identity<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, allocator<test::movable_and_copyable_int>
+44 -9
View File
@@ -23,6 +23,8 @@
using namespace boost::container;
typedef std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> pair_t;
namespace boost {
namespace container {
@@ -33,34 +35,59 @@ template class map
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, std::less<test::movable_and_copyable_int>
, test::simple_allocator
< std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
, test::simple_allocator< pair_t >
>;
template class map
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, std::less<test::movable_and_copyable_int>
, std::allocator
< std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
, std::allocator< pair_t >
>;
template class map
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, std::less<test::movable_and_copyable_int>
, adaptive_pool
< std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
, adaptive_pool< pair_t >
>;
template class multimap
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, std::less<test::movable_and_copyable_int>
, std::allocator
< std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
, std::allocator< pair_t >
>;
namespace container_detail {
//Instantiate base class as previous instantiations don't instantiate inherited members
template class tree
< pair_t
, select1st<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, test::simple_allocator<pair_t>
, tree_assoc_defaults
>;
template class tree
< pair_t
, select1st<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, std::allocator<pair_t>
, tree_assoc_defaults
>;
template class tree
< pair_t
, select1st<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, adaptive_pool<pair_t>
, tree_assoc_defaults
>;
} //container_detail {
}} //boost::container
class recursive_map
@@ -334,6 +361,13 @@ struct alloc_propagate_base<boost_container_multimap>
};
};
void test_merge_from_different_comparison()
{
map<int, int> map1;
map<int, int, std::greater<int> > map2;
map1.merge(map2);
}
}}} //namespace boost::container::test
int main ()
@@ -357,7 +391,6 @@ int main ()
//Test std::pair value type as tree has workarounds to make old std::pair
//implementations movable that can break things
{
typedef std::pair<int,int> pair_t;
boost::container::map<pair_t, pair_t> s;
std::pair<const pair_t,pair_t> p;
s.insert(p);
@@ -447,6 +480,8 @@ int main ()
if(!node_type_test())
return 1;
test::test_merge_from_different_comparison();
////////////////////////////////////
// Test optimize_size option
////////////////////////////////////
+192 -90
View File
@@ -68,7 +68,7 @@ int map_test_copyable(boost::container::container_detail::true_type)
typedef container_detail::pair<IntType, IntType> IntPairType;
typedef typename MyStdMap::value_type StdPairType;
const int max = 50;
const int MaxElem = 50;
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>();
::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>();
@@ -86,7 +86,7 @@ int map_test_copyable(boost::container::container_detail::true_type)
boostmultimap.insert(boostmultimap.begin(), boostmultimap.end());
int i;
for(i = 0; i < max; ++i){
for(i = 0; i < MaxElem; ++i){
{
IntType i1(i), i2(i);
IntPairType intpair1(boost::move(i1), boost::move(i2));
@@ -138,7 +138,7 @@ int map_test()
typedef typename MyBoostMap::key_type IntType;
typedef container_detail::pair<IntType, IntType> IntPairType;
typedef typename MyStdMap::value_type StdPairType;
const int max = 50;
const int MaxElem = 50;
typedef typename MyStdMap::value_type StdValueType;
typedef typename MyStdMap::key_type StdKeyType;
typedef typename MyStdMap::mapped_type StdMappedType;
@@ -146,20 +146,20 @@ int map_test()
//Test construction from a range
{
IntPairType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
StdValueType aux_vect2[50];
for(int i = 0; i < 50; ++i){
StdValueType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2));
}
IntPairType aux_vect3[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
@@ -167,33 +167,33 @@ int map_test()
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>
( boost::make_move_iterator(&aux_vect[0])
, boost::make_move_iterator(&aux_vect[0] + 50), typename MyBoostMap::key_compare());
, boost::make_move_iterator(&aux_vect[0] + MaxElem), typename MyBoostMap::key_compare());
::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>
(&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
( boost::make_move_iterator(&aux_vect3[0])
, boost::make_move_iterator(&aux_vect3[0] + 50), typename MyBoostMap::key_compare());
, boost::make_move_iterator(&aux_vect3[0] + MaxElem), typename MyBoostMap::key_compare());
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
(&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
}
{
IntPairType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
StdValueType aux_vect2[50];
for(int i = 0; i < 50; ++i){
StdValueType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2));
}
IntPairType aux_vect3[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
@@ -201,16 +201,16 @@ int map_test()
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>
( boost::make_move_iterator(&aux_vect[0])
, boost::make_move_iterator(&aux_vect[0] + 50), typename MyBoostMap::allocator_type());
, boost::make_move_iterator(&aux_vect[0] + MaxElem), typename MyBoostMap::allocator_type());
::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>
(&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
( boost::make_move_iterator(&aux_vect3[0])
, boost::make_move_iterator(&aux_vect3[0] + 50), typename MyBoostMap::allocator_type());
, boost::make_move_iterator(&aux_vect3[0] + MaxElem), typename MyBoostMap::allocator_type());
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
(&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
}
@@ -225,8 +225,8 @@ int map_test()
{
//This is really nasty, but we have no other simple choice
IntPairType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
@@ -235,13 +235,13 @@ int map_test()
typedef typename MyStdMap::value_type StdValueType;
typedef typename MyStdMap::key_type StdKeyType;
typedef typename MyStdMap::mapped_type StdMappedType;
StdValueType aux_vect2[50];
for(int i = 0; i < 50; ++i){
StdValueType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2));
}
IntPairType aux_vect3[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i/2);
IntType i2(i/2);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
@@ -249,14 +249,14 @@ int map_test()
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap2 = ::boost::movelib::make_unique<MyBoostMap>
( boost::make_move_iterator(&aux_vect[0])
, boost::make_move_iterator(&aux_vect[0] + 50));
, boost::make_move_iterator(&aux_vect[0] + MaxElem));
::boost::movelib::unique_ptr<MyStdMap> const pstdmap2 = ::boost::movelib::make_unique<MyStdMap>
(&aux_vect2[0], &aux_vect2[0] + 50);
(&aux_vect2[0], &aux_vect2[0] + MaxElem);
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap2 = ::boost::movelib::make_unique<MyBoostMultiMap>
( boost::make_move_iterator(&aux_vect3[0])
, boost::make_move_iterator(&aux_vect3[0] + 50));
, boost::make_move_iterator(&aux_vect3[0] + MaxElem));
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap2 = ::boost::movelib::make_unique<MyStdMultiMap>
(&aux_vect2[0], &aux_vect2[0] + 50);
(&aux_vect2[0], &aux_vect2[0] + MaxElem);
MyBoostMap &boostmap2 = *pboostmap2;
MyStdMap &stdmap2 = *pstdmap2;
MyBoostMultiMap &boostmultimap2 = *pboostmultimap2;
@@ -267,17 +267,17 @@ int map_test()
//ordered range insertion
//This is really nasty, but we have no other simple choice
for(int i = 0; i < 50; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
for(int i = 0; i < 50; ++i){
for(int i = 0; i < MaxElem; ++i){
new(&aux_vect2[i])StdValueType(StdKeyType(i), StdMappedType(i));
}
for(int i = 0; i < 50; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
@@ -301,14 +301,14 @@ int map_test()
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap3 = ::boost::movelib::make_unique<MyBoostMap>
( boost::make_move_iterator(&aux_vect[0])
, boost::make_move_iterator(&aux_vect[0] + 50));
, boost::make_move_iterator(&aux_vect[0] + MaxElem));
::boost::movelib::unique_ptr<MyStdMap> const pstdmap3 = ::boost::movelib::make_unique<MyStdMap>
(&aux_vect2[0], &aux_vect2[0] + 50);
(&aux_vect2[0], &aux_vect2[0] + MaxElem);
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap3 = ::boost::movelib::make_unique<MyBoostMultiMap>
( boost::make_move_iterator(&aux_vect3[0])
, boost::make_move_iterator(&aux_vect3[0] + 50));
, boost::make_move_iterator(&aux_vect3[0] + MaxElem));
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap3 = ::boost::movelib::make_unique<MyStdMultiMap>
(&aux_vect2[0], &aux_vect2[0] + 50);
(&aux_vect2[0], &aux_vect2[0] + MaxElem);
MyBoostMap &boostmap3 = *pboostmap3;
MyStdMap &stdmap3 = *pstdmap3;
MyBoostMultiMap &boostmultimap3 = *pboostmultimap3;
@@ -344,20 +344,20 @@ int map_test()
}
{
//This is really nasty, but we have no other simple choice
IntPairType aux_vect[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
boostmap.insert(boost::move(aux_vect[i]));
stdmap.insert(StdPairType(i, i));
boostmultimap.insert(boost::move(aux_vect3[i]));
@@ -405,22 +405,22 @@ int map_test()
//Initialize values
{
//This is really nasty, but we have no other simple choice
IntPairType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50));
boostmultimap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + 50));
for(std::size_t i = 0; i != 50; ++i){
boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmultimap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
for(int i = 0; i != MaxElem; ++i){
StdPairType stdpairtype(-1, -1);
stdmap.insert(stdpairtype);
stdmultimap.insert(stdpairtype);
@@ -439,40 +439,40 @@ int map_test()
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
}
{
IntPairType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect4[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect4[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect4[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect5[50];
for(int i = 0; i < 50; ++i){
IntPairType aux_vect5[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(-1);
IntType i2(-1);
new(&aux_vect5[i])IntPairType(boost::move(i1), boost::move(i2));
}
boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50));
boostmap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + 50));
boostmultimap.insert(boost::make_move_iterator(&aux_vect4[0]), boost::make_move_iterator(aux_vect4 + 50));
boostmultimap.insert(boost::make_move_iterator(&aux_vect5[0]), boost::make_move_iterator(aux_vect5 + 50));
boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
boostmultimap.insert(boost::make_move_iterator(&aux_vect4[0]), boost::make_move_iterator(aux_vect4 + MaxElem));
boostmultimap.insert(boost::make_move_iterator(&aux_vect5[0]), boost::make_move_iterator(aux_vect5 + MaxElem));
for(std::size_t i = 0; i != 50; ++i){
for(int i = 0; i != MaxElem; ++i){
StdPairType stdpairtype(-1, -1);
stdmap.insert(stdpairtype);
stdmultimap.insert(stdpairtype);
@@ -492,20 +492,20 @@ int map_test()
{
//This is really nasty, but we have no other simple choice
IntPairType aux_vect[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
boostmap.insert(boost::move(aux_vect[i]));
stdmap.insert(StdPairType(i, i));
boostmultimap.insert(boost::move(aux_vect3[i]));
@@ -515,7 +515,7 @@ int map_test()
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntPairType intpair;
{
IntType i1(i);
@@ -629,7 +629,7 @@ int map_test()
}
//Compare count with std containers
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType k(i);
if(boostmap.count(k) != stdmap.count(i)){
return -1;
@@ -673,14 +673,14 @@ int map_test()
stdmap.clear();
stdmultimap.clear();
IntPairType aux_vect[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
boostmap[boost::move(aux_vect[i].first)] = boost::move(aux_vect[i].second);
stdmap[i] = i;
}
@@ -695,21 +695,21 @@ int map_test()
stdmap.clear();
stdmultimap.clear();
IntPairType aux_vect[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect2[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(max-i);
IntType i2(MaxElem-i);
new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2));
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
boostmap.insert_or_assign(boost::move(aux_vect[i].first), boost::move(aux_vect[i].second));
stdmap[i] = i;
}
@@ -717,9 +717,9 @@ int map_test()
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
boostmap.insert_or_assign(boost::move(aux_vect2[i].first), boost::move(aux_vect2[i].second));
stdmap[i] = max-i;
stdmap[i] = MaxElem-i;
}
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
@@ -732,22 +732,22 @@ int map_test()
stdmap.clear();
stdmultimap.clear();
IntPairType aux_vect[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect2[max];
for(int i = 0; i < max; ++i){
IntPairType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(max-i);
IntType i2(MaxElem-i);
new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2));
}
typedef typename MyBoostMap::iterator iterator;
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
iterator it;
if(i&1){
std::pair<typename MyBoostMap::iterator, bool> ret =
@@ -769,7 +769,7 @@ int map_test()
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
iterator it;
iterator itex = boostmap.find(aux_vect2[i].first);
if(itex == boostmap.end())
@@ -795,6 +795,108 @@ int map_test()
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
}
{ //merge
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap2 = ::boost::movelib::make_unique<MyBoostMap>();
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap2 = ::boost::movelib::make_unique<MyBoostMultiMap>();
MyBoostMap &boostmap2 = *pboostmap2;
MyBoostMultiMap &boostmultimap2 = *pboostmultimap2;
boostmap.clear();
boostmap2.clear();
boostmultimap.clear();
boostmultimap2.clear();
stdmap.clear();
stdmultimap.clear();
{
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(MaxElem/2+i);
IntType i2(MaxElem-i);
new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(MaxElem*2/2+i);
IntType i2(MaxElem*2+i);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmap2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
boostmultimap2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
}
for(int i = 0; i < MaxElem; ++i){
stdmap.insert(StdPairType(i, i));
}
for(int i = 0; i < MaxElem; ++i){
stdmap.insert(StdPairType(MaxElem/2+i, MaxElem-i));
}
boostmap.merge(boost::move(boostmap2));
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
for(int i = 0; i < MaxElem; ++i){
stdmap.insert(StdPairType(MaxElem*2/2+i, MaxElem*2+i));
}
boostmap.merge(boost::move(boostmultimap2));
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
boostmap.clear();
boostmap2.clear();
boostmultimap.clear();
boostmultimap2.clear();
stdmap.clear();
stdmultimap.clear();
{
IntPairType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(i);
IntType i2(i);
new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(MaxElem/2+i);
IntType i2(MaxElem-i);
new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2));
}
IntPairType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
IntType i1(MaxElem*2/2+i);
IntType i2(MaxElem*2+i);
new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
}
boostmultimap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmultimap2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
boostmap2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
}
for(int i = 0; i < MaxElem; ++i){
stdmultimap.insert(StdPairType(i, i));
}
for(int i = 0; i < MaxElem; ++i){
stdmultimap.insert(StdPairType(MaxElem/2+i, MaxElem-i));
}
boostmultimap.merge(boost::move(boostmultimap2));
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
for(int i = 0; i < MaxElem; ++i){
stdmultimap.insert(StdPairType(MaxElem*2/2+i, MaxElem*2+i));
}
boostmultimap.merge(boost::move(boostmap2));
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
}
if(map_test_copyable<MyBoostMap, MyStdMap, MyBoostMultiMap, MyStdMultiMap>
(container_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){
return 1;
+9 -3
View File
@@ -58,7 +58,6 @@ namespace container_detail {
//Instantiate base class as previous instantiations don't instantiate inherited members
template class tree
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, identity<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, test::simple_allocator<test::movable_and_copyable_int>
@@ -67,7 +66,6 @@ template class tree
template class tree
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, identity<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, std::allocator<test::movable_and_copyable_int>
@@ -76,7 +74,6 @@ template class tree
template class tree
< test::movable_and_copyable_int
, test::movable_and_copyable_int
, identity<test::movable_and_copyable_int>
, std::less<test::movable_and_copyable_int>
, adaptive_pool<test::movable_and_copyable_int>
@@ -354,6 +351,13 @@ int test_set_variants()
return 0;
}
void test_merge_from_different_comparison()
{
set<int> set1;
set<int, std::greater<int> > set2;
set1.merge(set2);
}
int main ()
{
@@ -381,6 +385,8 @@ int main ()
s.emplace(p);
}
test_merge_from_different_comparison();
////////////////////////////////////
// Testing allocator implementations
////////////////////////////////////
+97 -7
View File
@@ -46,6 +46,8 @@ template<class MyBoostSet
int set_test_copyable(boost::container::container_detail::false_type)
{ return 0; }
const int MaxElem = 50;
template<class MyBoostSet
,class MyStdSet
,class MyBoostMultiSet
@@ -53,7 +55,6 @@ template<class MyBoostSet
int set_test_copyable(boost::container::container_detail::true_type)
{
typedef typename MyBoostSet::value_type IntType;
const int max = 50;
::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>();
::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>();
@@ -71,7 +72,7 @@ int set_test_copyable(boost::container::container_detail::true_type)
boostset.insert(boostset.begin(), boostset.end());
boostmultiset.insert(boostmultiset.begin(), boostmultiset.end());
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType move_me(i);
boostset.insert(boost::move(move_me));
stdset.insert(i);
@@ -134,7 +135,6 @@ template<class MyBoostSet
int set_test ()
{
typedef typename MyBoostSet::value_type IntType;
const int max = 50;
::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>();
::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>();
@@ -293,7 +293,7 @@ int set_test ()
}
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType move_me(i);
boostset.insert(boost::move(move_me));
stdset.insert(i);
@@ -474,7 +474,7 @@ int set_test ()
}
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType move_me(i);
boostset.insert(boost::move(move_me));
stdset.insert(i);
@@ -492,7 +492,7 @@ int set_test ()
return 1;
}
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
{
IntType move_me(i);
boostset.insert(boostset.begin(), boost::move(move_me));
@@ -579,7 +579,7 @@ int set_test ()
}
//Compare count with std containers
for(int i = 0; i < max; ++i){
for(int i = 0; i < MaxElem; ++i){
IntType count_me(i);
if(boostset.count(count_me) != stdset.count(i)){
return -1;
@@ -703,6 +703,96 @@ int set_test ()
}
}
{ //merge
::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>();
::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>();
MyBoostSet &boostset2 = *pboostset2;
MyBoostMultiSet &boostmultiset2 = *pboostmultiset2;
boostset.clear();
boostset2.clear();
boostmultiset.clear();
boostmultiset2.clear();
stdset.clear();
stdmultiset.clear();
{
IntType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect[i] = i;
}
IntType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect2[i] = MaxElem/2+i;
}
IntType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect3[i] = MaxElem*2/2+i;
}
boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
boostmultiset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
}
for(int i = 0; i < MaxElem; ++i){
stdset.insert(i);
}
for(int i = 0; i < MaxElem; ++i){
stdset.insert(MaxElem/2+i);
}
boostset.merge(boost::move(boostset2));
if(!CheckEqualContainers(boostset, stdset)) return 1;
for(int i = 0; i < MaxElem; ++i){
stdset.insert(MaxElem*2/2+i);
}
boostset.merge(boost::move(boostmultiset2));
if(!CheckEqualContainers(boostset, stdset)) return 1;
boostset.clear();
boostset2.clear();
boostmultiset.clear();
boostmultiset2.clear();
stdset.clear();
stdmultiset.clear();
{
IntType aux_vect[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect[i] = i;
}
IntType aux_vect2[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect2[i] = MaxElem/2+i;
}
IntType aux_vect3[MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect3[i] = MaxElem*2/2+i;
}
boostmultiset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmultiset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
boostset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
}
for(int i = 0; i < MaxElem; ++i){
stdmultiset.insert(i);
}
for(int i = 0; i < MaxElem; ++i){
stdmultiset.insert(MaxElem/2+i);
}
boostmultiset.merge(boost::move(boostmultiset2));
if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
for(int i = 0; i < MaxElem; ++i){
stdmultiset.insert(MaxElem*2/2+i);
}
boostmultiset.merge(boost::move(boostset2));
if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
}
if(set_test_copyable<MyBoostSet, MyStdSet, MyBoostMultiSet, MyStdMultiSet>
(container_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){
return 1;