Review all associative containers and implement a different constructor overload to avoid any unnecessary copy construction of the predicate or the allocator.

This commit is contained in:
Ion Gaztañaga committed 2017-05-16 16:29:49 +02:00
1 parent 40451e4bf7
commit ec91367383
14 files changed
+1694 -914

No files matched your search

+12 -12
View File
@@ -143,8 +143,6 @@ bool test_expected_container(const Container &ec, const std::pair<EmplaceInt, Em
return true;
}
static EmplaceInt expected [10];
typedef std::pair<EmplaceInt, EmplaceInt> EmplaceIntPair;
static boost::container::container_detail::aligned_storage<sizeof(EmplaceIntPair)*10>::type pair_storage;
@@ -166,6 +164,7 @@ bool test_emplace_back(container_detail::true_)
{
std::cout << "Starting test_emplace_back." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
{
new(&expected [0]) EmplaceInt();
@@ -218,7 +217,7 @@ bool test_emplace_front(container_detail::true_)
{
std::cout << "Starting test_emplace_front." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
{
new(&expected [0]) EmplaceInt(1, 2, 3, 4, 5);
new(&expected [1]) EmplaceInt(1, 2, 3, 4);
@@ -270,7 +269,7 @@ bool test_emplace_before(container_detail::true_)
{
std::cout << "Starting test_emplace_before." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
{
new(&expected [0]) EmplaceInt();
new(&expected [1]) EmplaceInt(1);
@@ -382,6 +381,7 @@ bool test_emplace_after(container_detail::true_)
{
std::cout << "Starting test_emplace_after." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
{
new(&expected [0]) EmplaceInt();
new(&expected [1]) EmplaceInt(1);
@@ -467,7 +467,7 @@ bool test_emplace_assoc(container_detail::true_)
{
std::cout << "Starting test_emplace_assoc." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
new(&expected [0]) EmplaceInt();
new(&expected [1]) EmplaceInt(1);
new(&expected [2]) EmplaceInt(1, 2);
@@ -514,7 +514,7 @@ bool test_emplace_hint(container_detail::true_)
{
std::cout << "Starting test_emplace_hint." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
static EmplaceInt expected [10];
new(&expected [0]) EmplaceInt();
new(&expected [1]) EmplaceInt(1);
new(&expected [2]) EmplaceInt(1, 2);
@@ -565,11 +565,11 @@ bool test_emplace_assoc_pair(container_detail::true_)
std::cout << "Starting test_emplace_assoc_pair." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
new(&expected_pair[0].first) EmplaceInt();
new(&expected_pair[0].first) EmplaceInt();
new(&expected_pair[0].second) EmplaceInt();
new(&expected_pair[1].first) EmplaceInt(1);
new(&expected_pair[1].first) EmplaceInt(1);
new(&expected_pair[1].second) EmplaceInt(1);
new(&expected_pair[2].first) EmplaceInt(2);
new(&expected_pair[2].first) EmplaceInt(2);
new(&expected_pair[2].second) EmplaceInt(2);
{
Container c;
@@ -603,11 +603,11 @@ bool test_emplace_hint_pair(container_detail::true_)
std::cout << "Starting test_emplace_hint_pair." << std::endl << " Class: "
<< typeid(Container).name() << std::endl;
new(&expected_pair[0].first) EmplaceInt();
new(&expected_pair[0].first) EmplaceInt();
new(&expected_pair[0].second) EmplaceInt();
new(&expected_pair[1].first) EmplaceInt(1);
new(&expected_pair[1].first) EmplaceInt(1);
new(&expected_pair[1].second) EmplaceInt(1);
new(&expected_pair[2].first) EmplaceInt(2);
new(&expected_pair[2].first) EmplaceInt(2);
new(&expected_pair[2].second) EmplaceInt(2);
{
Container c;
+3
View File
@@ -502,6 +502,9 @@ int main()
return 1;
}
if (!boost::container::test::instantiate_constructors<flat_map<int, int>, flat_multimap<int, int> >())
return 1;
////////////////////////////////////
// Testing allocator implementations
////////////////////////////////////
+3
View File
@@ -608,6 +608,9 @@ int main()
return 1;
}
if (!boost::container::test::instantiate_constructors<flat_set<int>, flat_multiset<int> >())
return 1;
////////////////////////////////////
// Testing allocator implementations
////////////////////////////////////
+8 -5
View File
@@ -432,6 +432,9 @@ int main ()
if(!node_type_test())
return 1;
if (!boost::container::test::instantiate_constructors<map<int, int>, multimap<int, int> >())
return 1;
test::test_merge_from_different_comparison();
////////////////////////////////////
@@ -440,22 +443,22 @@ int main ()
//
// map
//
typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int const*, int*> >
typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
, tree_assoc_options< optimize_size<false>, tree_type<red_black_tree> >::type > rbmap_size_optimized_no;
typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int const*, int*> >
typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
, tree_assoc_options< optimize_size<true>, tree_type<avl_tree> >::type > avlmap_size_optimized_yes;
//
// multimap
//
typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int const*, int*> >
typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
, tree_assoc_options< optimize_size<true>, tree_type<red_black_tree> >::type > rbmmap_size_optimized_yes;
typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int const*, int*> >
typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
, tree_assoc_options< optimize_size<false>, tree_type<avl_tree> >::type > avlmmap_size_optimized_no;
BOOST_STATIC_ASSERT(sizeof(rbmmap_size_optimized_yes) < sizeof(rbmap_size_optimized_no));
BOOST_STATIC_ASSERT(sizeof(avlmap_size_optimized_yes) < sizeof(avlmmap_size_optimized_no));
return 0;
}
+82
View File
@@ -945,6 +945,88 @@ bool test_map_support_for_initialization_list_for()
return true;
}
template<typename MapType, typename MultimapType>
bool instantiate_constructors()
{
{
typedef typename MapType::value_type value_type;
typename MapType::key_compare comp;
typename MapType::allocator_type a;
typename MapType::value_type value;
{
MapType s0;
MapType s1(comp);
MapType s2(a);
MapType s3(comp, a);
}
{
MapType s0(&value, &value);
MapType s1(&value, &value ,comp);
MapType s2(&value, &value ,a);
MapType s3(&value, &value ,comp, a);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
std::initializer_list<value_type> il;
MapType s0(il);
MapType s1(il, comp);
MapType s2(il, a);
MapType s3(il, comp, a);
}
{
std::initializer_list<value_type> il;
MapType s0(ordered_unique_range, il);
MapType s1(ordered_unique_range, il, comp);
MapType s3(ordered_unique_range, il, comp, a);
}
#endif
{
MapType s0(ordered_unique_range, &value, &value);
MapType s1(ordered_unique_range, &value, &value ,comp);
MapType s2(ordered_unique_range, &value, &value ,comp, a);
}
}
{
typedef typename MultimapType::value_type value_type;
typename MultimapType::key_compare comp;
typename MultimapType::allocator_type a;
typename MultimapType::value_type value;
{
MultimapType s0;
MultimapType s1(comp);
MultimapType s2(a);
MultimapType s3(comp, a);
}
{
MultimapType s0(&value, &value);
MultimapType s1(&value, &value ,comp);
MultimapType s2(&value, &value ,a);
MultimapType s3(&value, &value ,comp, a);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
std::initializer_list<value_type> il;
MultimapType s0(il);
MultimapType s1(il, comp);
MultimapType s2(il, a);
MultimapType s3(il, comp, a);
}
{
std::initializer_list<value_type> il;
MultimapType s0(ordered_range, il);
MultimapType s1(ordered_range, il, comp);
MultimapType s3(ordered_range, il, comp, a);
}
#endif
{
MultimapType s0(ordered_range, &value, &value);
MultimapType s1(ordered_range, &value, &value ,comp);
MultimapType s2(ordered_range, &value, &value ,comp, a);
}
}
return true;
}
} //namespace test{
} //namespace container {
+3 -1
View File
@@ -318,7 +318,6 @@ void test_merge_from_different_comparison()
set1.merge(set2);
}
int main ()
{
//Recursive container instantiation
@@ -345,6 +344,9 @@ int main ()
s.emplace(p);
}
if (!boost::container::test::instantiate_constructors<set<int>, multiset<int> >())
return 1;
test_merge_from_different_comparison();
////////////////////////////////////
+93 -12
View File
@@ -162,14 +162,14 @@ int set_test ()
IntType move_me(i/2);
aux_vect3[i] = boost::move(move_me);
}
::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>
::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>
(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::key_compare());
::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostset, *pstdset)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>
::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>
(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::key_compare());
::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostmultiset, *pstdmultiset)) return 1;
::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1;
}
{ //Set(beg, end, alloc)
IntType aux_vect[50];
@@ -186,14 +186,14 @@ int set_test ()
IntType move_me(i/2);
aux_vect3[i] = boost::move(move_me);
}
::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>
::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>
(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::allocator_type());
::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostset, *pstdset)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>
::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1;
::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>
(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::allocator_type());
::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostmultiset, *pstdmultiset)) return 1;
::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1;
}
{
IntType aux_vect[50];
@@ -842,6 +842,87 @@ bool test_set_methods_with_initializer_list_as_argument_for()
return true;
}
template<typename SetType, typename MultisetType>
bool instantiate_constructors()
{
{
typedef typename SetType::value_type value_type;
typename SetType::key_compare comp;
typename SetType::allocator_type a;
typename SetType::value_type value;
{
SetType s0;
SetType s1(comp);
SetType s2(a);
SetType s3(comp, a);
}
{
SetType s0(&value, &value);
SetType s1(&value, &value ,comp);
SetType s2(&value, &value ,a);
SetType s3(&value, &value ,comp, a);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
SetType s0({ 0 });
SetType s1({ 0 },comp);
SetType s2({ 0 },a);
SetType s3({ 0 },comp, a);
}
{
std::initializer_list<value_type> il{0};
SetType s0(ordered_unique_range, il);
SetType s1(ordered_unique_range, il,comp);
SetType s3(ordered_unique_range, il,comp, a);
}
#endif
{
SetType s0(ordered_unique_range, &value, &value);
SetType s1(ordered_unique_range, &value, &value ,comp);
SetType s2(ordered_unique_range, &value, &value ,comp, a);
}
}
{
typename MultisetType::key_compare comp;
typename MultisetType::allocator_type a;
typename MultisetType::value_type value;
{
MultisetType s0;
MultisetType s1(comp);
MultisetType s2(a);
MultisetType s3(comp, a);
}
{
MultisetType s0(&value, &value);
MultisetType s1(&value, &value ,comp);
MultisetType s2(&value, &value ,a);
MultisetType s3(&value, &value ,comp, a);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
MultisetType s0({ 0 });
MultisetType s1({ 0 },comp);
MultisetType s2({ 0 },a);
MultisetType s3({ 0 },comp, a);
}
{
typedef typename MultisetType::value_type value_type;
std::initializer_list<value_type>il{0};
MultisetType s0(ordered_range, il);
MultisetType s1(ordered_range, il,comp);
MultisetType s3(ordered_range, il,comp, a);
}
#endif
{
MultisetType s0(ordered_range, &value, &value);
MultisetType s1(ordered_range, &value, &value ,comp);
MultisetType s2(ordered_range, &value, &value ,comp, a);
}
}
return true;
}
} //namespace test{
} //namespace container {
} //namespace boost{