forked from boostorg/container
Add std::initializer_list to the following containers:
* deque * map * multimap * set * multiset * list * slist Tested on clant and g++
This commit is contained in:
1 parent
d517cb9f1b
commit
f8ebfa472a
10 files changed
+552
-1
No files matched your search
@@ -341,6 +341,36 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initialization_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {1, 10, 11};
|
||||
const deque<int> expectedDeque(il.begin(), il.end());
|
||||
|
||||
const deque<int> testConstructor = il;
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testAssignmentOperator = {11, 12, 23};
|
||||
testAssignmentOperator = il;
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testAssignmentMethod = {11, 12, 23};
|
||||
testAssignmentMethod.assign(il);
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testInsertMethod = {11};
|
||||
testInsertMethod.insert(testInsertMethod.cbegin(), {12, 23});
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -396,6 +426,9 @@ int main ()
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_support_for_initialization_list())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Emplace testing
|
||||
////////////////////////////////////
|
||||
|
||||
@@ -115,6 +115,35 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initializer_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {1, 10};
|
||||
const list<int> expectedList(il.begin(), il.end());
|
||||
|
||||
const list<int> testConstructor = il;
|
||||
if(testConstructor != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testAssignOperator = {10, 11};
|
||||
testAssignOperator = il;
|
||||
if(testAssignOperator != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testAssignMethod = {99};
|
||||
testAssignMethod = il;
|
||||
if(testAssignMethod != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testInsertMethod;
|
||||
testInsertMethod.insert(testInsertMethod.cbegin(), il);
|
||||
if(testInsertMethod != testInsertMethod)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -166,6 +195,9 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<list>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initializer_list())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <boost/container/allocator.hpp>
|
||||
#include <boost/container/node_allocator.hpp>
|
||||
#include <boost/container/adaptive_pool.hpp>
|
||||
#include <utility>
|
||||
|
||||
#include "print_container.hpp"
|
||||
#include "movable_int.hpp"
|
||||
@@ -345,6 +346,38 @@ int test_map_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename MapType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<const int, int>> il
|
||||
= {std::make_pair(1, 2), std::make_pair(3, 4)};
|
||||
const MapType expected(il.begin(), il.end());
|
||||
{
|
||||
const MapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
const MapType sil_ordered(ordered_unique_range_t{}, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
MapType sil_assign = {std::make_pair(99, 100)};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
MapType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
//Recursive container instantiation
|
||||
@@ -421,6 +454,12 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<map_propagate_test_wrapper>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<map<int, int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multimap<int, int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Test optimize_size option
|
||||
////////////////////////////////////
|
||||
|
||||
@@ -314,7 +314,36 @@ int test_set_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename SetType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
std::initializer_list<int> il = {1, 2, 3, 4, 5};
|
||||
SetType expected(il.begin(), il.end());
|
||||
{
|
||||
SetType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_ordered(ordered_unique_range_t{}, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_assign = {99, 100, 101, 102, 103, 104, 105};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
SetType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
//Recursive container instantiation
|
||||
@@ -391,6 +420,12 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<set_propagate_test_wrapper>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<set<int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multiset<int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Test optimize_size option
|
||||
////////////////////////////////////
|
||||
|
||||
@@ -101,6 +101,48 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initializer_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {5, 10, 15};
|
||||
const slist<int> expected_list(il.begin(), il.end());
|
||||
{
|
||||
slist<int> sl = il;
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {1, 2};
|
||||
sl = il;
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {4, 5};
|
||||
sl.assign(il);
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {15};
|
||||
sl.insert(sl.cbegin(), {5, 10});
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {5};
|
||||
sl.insert_after(sl.cbegin(), {10, 15});
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -159,6 +201,9 @@ int main ()
|
||||
////////////////////////////////////
|
||||
if(!boost::container::test::test_propagate_allocator<slist>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initializer_list())
|
||||
return 1;
|
||||
}
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
Reference in new issue
Block a user