From f8ebfa472ad7350f4bd6f988c26c6d9960fa7584 Mon Sep 17 00:00:00 2001 From: Robert Matusewicz Date: Wed, 27 Aug 2014 14:46:25 +0200 Subject: [PATCH] Add std::initializer_list to the following containers: * deque * map * multimap * set * multiset * list * slist Tested on clant and g++ --- include/boost/container/deque.hpp | 61 +++++++++++++++++++++ include/boost/container/list.hpp | 61 +++++++++++++++++++++ include/boost/container/map.hpp | 88 +++++++++++++++++++++++++++++++ include/boost/container/set.hpp | 74 ++++++++++++++++++++++++++ include/boost/container/slist.hpp | 85 ++++++++++++++++++++++++++++- test/deque_test.cpp | 33 ++++++++++++ test/list_test.cpp | 32 +++++++++++ test/map_test.cpp | 39 ++++++++++++++ test/set_test.cpp | 35 ++++++++++++ test/slist_test.cpp | 45 ++++++++++++++++ 10 files changed, 552 insertions(+), 1 deletion(-) diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp index c91ed93..eefbede 100644 --- a/include/boost/container/deque.hpp +++ b/include/boost/container/deque.hpp @@ -42,6 +42,10 @@ #include #include +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif + namespace boost { namespace container { @@ -603,6 +607,21 @@ class deque : protected deque_base this->priv_range_initialize(first, last, ItCat()); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs a deque that will use a copy of allocator a + //! and inserts a copy of the range [il.begin(), il.end()) in the deque. + //! + //! Throws: If allocator_type's default constructor + //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws. + //! + //! Complexity: Linear to the range [il.begin(), il.end()). + deque(std::initializer_list il, const allocator_type& a = allocator_type()) + : Base(a) + { + this->priv_range_initialize(il.begin(), il.end(), std::input_iterator_tag()); + } +#endif + //! Effects: Copy constructs a deque. //! //! Postcondition: x == *this. @@ -741,6 +760,22 @@ class deque : protected deque_base return *this; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Makes *this contain the same elements as il. + //! + //! Postcondition: this->size() == il.size(). *this contains a copy + //! of each of x's elements. + //! + //! Throws: If memory allocation throws or T's copy constructor throws. + //! + //! Complexity: Linear to the number of elements in il. + deque& operator=(std::initializer_list il) + { + this->assign(il.begin(), il.end()); + return *this; + } +#endif + //! Effects: Assigns the n copies of val to *this. //! //! Throws: If memory allocation throws or T's copy constructor throws. @@ -802,6 +837,17 @@ class deque : protected deque_base } #endif +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Assigns the the range [il.begin(), il.end()) to *this. + //! + //! Throws: If memory allocation throws or + //! T's constructor from dereferencing std::initializer_list iterator throws. + //! + //! Complexity: Linear to il.size(). + void assign(std::initializer_list il) + { this->assign(il.begin(), il.end()); } +#endif + //! Effects: Returns a copy of the internal allocator. //! //! Throws: If allocator's copy constructor throws. @@ -1389,6 +1435,21 @@ class deque : protected deque_base return it; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Requires: pos must be a valid iterator of *this. + //! + //! Effects: Insert a copy of the [il.begin(), il.end()) range before pos. + //! + //! Returns: an iterator to the first inserted element or pos if il.begin() == il.end(). + //! + //! Throws: If memory allocation throws, T's constructor from a + //! dereferenced std::initializer_list throws or T's copy constructor throws. + //! + //! Complexity: Linear to std::distance [il.begin(), il.end()). + iterator insert(const_iterator pos, std::initializer_list il) + { return insert(pos, il.begin(), il.end()); } +#endif + #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) template iterator insert(const_iterator p, FwdIt first, FwdIt last diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index 0e6cb11..0c96fd6 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -38,6 +38,10 @@ #include #endif +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif + #include #include #include @@ -299,6 +303,21 @@ class list : AllocHolder(a) { this->insert(this->cbegin(), first, last); } + +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs a list that will use a copy of allocator a + //! and inserts a copy of the range [il.begin(), il.end()) in the list. + //! + //! Throws: If allocator_type's default constructor + //! throws or T's constructor taking a dereferenced + //! std::initializer_list iterator throws. + //! + //! Complexity: Linear to the range [il.begin(), il.end()). + list(std::initializer_list il, const Allocator &a = Allocator()) + : AllocHolder(a) + { this->insert(this->cbegin(), il.begin(), il.end()); } +#endif + //! Effects: Destroys the list. All stored values are destroyed //! and used memory is deallocated. //! @@ -370,6 +389,22 @@ class list return *this; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Makes *this contain the same elements as il. + //! + //! Postcondition: this->size() == il.size(). *this contains a copy + //! of each of x's elements. + //! + //! Throws: If memory allocation throws or T's copy constructor throws. + //! + //! Complexity: Linear to the number of elements in x. + list& operator=(std::initializer_list il) + { + assign(il.begin(), il.end()); + return *this; + } +#endif + //! Effects: Assigns the n copies of val to *this. //! //! Throws: If memory allocation throws or T's copy constructor throws. @@ -407,6 +442,17 @@ class list } } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Assigns the the range [il.begin(), il.end()) to *this. + //! + //! Throws: If memory allocation throws or + //! T's constructor from dereferencing std::initializer_list iterator throws. + //! + //! Complexity: Linear to n. + void assign(std::initializer_list il) + { assign(il.begin(), il.end()); } +#endif + //! Effects: Returns a copy of the internal allocator. //! //! Throws: If allocator's copy constructor throws. @@ -860,6 +906,21 @@ class list } #endif +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Requires: p must be a valid iterator of *this. + //! + //! Effects: Insert a copy of the [il.begin(), il.end()) range before p. + //! + //! Returns: an iterator to the first inserted element or p if if.begin() == il.end(). + //! + //! Throws: If memory allocation throws, T's constructor from a + //! dereferenced std::initializer_list iterator throws. + //! + //! Complexity: Linear to std::distance [il.begin(), il.end()). + iterator insert(const_iterator p, std::initializer_list il) + { return insert(p, il.begin(), il.end()); } +#endif + //! Effects: Removes the first element from the list. //! //! Throws: Nothing. diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index 58722db..c5f24c8 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -36,6 +36,10 @@ #include #include +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif + namespace boost { namespace container { @@ -180,6 +184,28 @@ class map BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs an empty map using the specified comparison object and + //! allocator, and inserts elements from the range [il.begin(), il.end()). + //! + //! Complexity: Linear in N if the range [first ,last ) is already sorted using + //! comp and otherwise N logN, where N is il.first() - il.end(). + map(std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) + : base_t(true, il.begin(), il.end(), comp, a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + + map(ordered_unique_range_t, std::initializer_list il, const Compare& comp = Compare(), + const allocator_type& a = allocator_type()) + : base_t(ordered_range, il.begin(), il.end(), comp, a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } +#endif + //! Effects: Copy constructs a map. //! //! Complexity: Linear in x.size(). @@ -243,6 +269,17 @@ class map BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value) { return static_cast(this->base_t::operator=(boost::move(static_cast(x)))); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Assign content of il to *this. + //! + map& operator=(std::initializer_list il) + { + this->clear(); + insert(il.begin(), il.end()); + return *this; + } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Returns a copy of the Allocator that @@ -551,6 +588,15 @@ class map void insert(InputIterator first, InputIterator last) { this->base_t::insert_unique(first, last); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: inserts each element from the range [il.begin(), il.end()) if and only + //! if there is no element with key equivalent to the key of that element. + //! + //! Complexity: At most N log(size()+N) (N is the distance from il.begin() to il.end()) + void insert(std::initializer_list il) + { this->base_t::insert_unique(il.begin(), il.end()); } +#endif + #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Inserts an object x of type T constructed with @@ -935,6 +981,29 @@ class multimap : base_t(ordered_range, first, last, comp, a) {} +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs an empty multimap using the specified comparison object and + //! allocator, and inserts elements from the range [il.begin(), il.end()). + //! + //! Complexity: Linear in N if the range [first ,last ) is already sorted using + //! comp and otherwise N logN, where N is il.first() - il.end(). + multimap(std::initializer_list il, const Compare& comp = Compare(), + const allocator_type& a = allocator_type()) + : base_t(false, il.begin(), il.end(), comp, a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + + multimap(ordered_range_t, std::initializer_list il, const Compare& comp = Compare(), + const allocator_type& a = allocator_type()) + : base_t(ordered_range, il.begin(), il.end(), comp, a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } +#endif + //! Effects: Copy constructs a multimap. //! //! Complexity: Linear in x.size(). @@ -991,6 +1060,17 @@ class multimap multimap& operator=(BOOST_RV_REF(multimap) x) { return static_cast(this->base_t::operator=(boost::move(static_cast(x)))); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Assign content of il to *this. + //! + multimap& operator=(std::initializer_list il) + { + this->clear(); + insert(il.begin(), il.end()); + return *this; + } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! @copydoc ::boost::container::set::get_allocator() @@ -1176,6 +1256,14 @@ class multimap void insert(InputIterator first, InputIterator last) { this->base_t::insert_equal(first, last); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: inserts each element from the range [il.begin(), il.end(). + //! + //! Complexity: At most N log(size()+N) (N is the distance from il.begin() to il.end()) + void insert(std::initializer_list il) + { this->base_t::insert_equal(il.begin(), il.end()); } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! @copydoc ::boost::container::set::erase(const_iterator) diff --git a/include/boost/container/set.hpp b/include/boost/container/set.hpp index edf69b6..41230a3 100644 --- a/include/boost/container/set.hpp +++ b/include/boost/container/set.hpp @@ -31,6 +31,9 @@ #ifndef BOOST_CONTAINER_PERFECT_FORWARDING #include #endif +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif namespace boost { namespace container { @@ -146,6 +149,31 @@ class set : base_t(ordered_range, first, last, comp, a) {} +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs an empty set using the specified comparison object and + //! allocator, and inserts elements from the range [il.begin(), il.end()). + //! + //! Complexity: Linear in N if the range [il.begin(), il.end()) is already sorted using + //! comp and otherwise N logN, where N is il.begin() - il.end(). + set(std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) + : base_t(true, il.begin(), il.end(), comp, a) + {} + + //! Effects: Constructs an empty set using the specified comparison object and + //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function + //! is more efficient than the normal range creation for ordered ranges. + //! + //! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be + //! unique values. + //! + //! Complexity: Linear in N. + //! + //! Note: Non-standard extension. + set(ordered_unique_range_t, std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) + : base_t(ordered_range, il.begin(), il.end(), comp, a) + {} +#endif + //! Effects: Copy constructs a set. //! //! Complexity: Linear in x.size(). @@ -195,6 +223,15 @@ class set BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value) { return static_cast(this->base_t::operator=(boost::move(static_cast(x)))); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + set& operator=(std::initializer_list il) + { + this->clear(); + insert(il.begin(), il.end()); + return *this; + } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Returns a copy of the Allocator that @@ -444,6 +481,15 @@ class set void insert(InputIterator first, InputIterator last) { this->base_t::insert_unique(first, last); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: inserts each element from the range [il.begin(),il.end()) if and only + //! if there is no element with key equivalent to the key of that element. + //! + //! Complexity: At most N log(size()+N) (N is the distance from il.begin() to il.end()) + void insert(std::initializer_list il) + { this->base_t::insert_unique(il.begin(), il.end()); } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Erases the element pointed to by p. @@ -745,6 +791,19 @@ class multiset : base_t(ordered_range, first, last, comp, a) {} +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! @copydoc ::boost::container::set::set(std::initializer_list, const Compare& comp, const allocator_type&) + multiset(std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) + : base_t(false, il.begin(), il.end(), comp, a) + {} + + //! @copydoc ::boost::container::set::set(ordered_unique_range_t, std::initializer_list, const Compare& comp, const allocator_type&) + multiset(ordered_unique_range_t, std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) + : base_t(ordered_range, il.begin(), il.end(), comp, a) + {} +#endif + + //! @copydoc ::boost::container::set::set(const set &) multiset(const multiset& x) : base_t(static_cast(x)) @@ -773,6 +832,15 @@ class multiset multiset& operator=(BOOST_RV_REF(multiset) x) { return static_cast(this->base_t::operator=(boost::move(static_cast(x)))); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! @copydoc ::boost::container::set::operator=(std::initializer_list) + multiset& operator=(std::initializer_list il) + { + this->clear(); + insert(il.begin(), il.end()); + return *this; + } +#endif #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! @copydoc ::boost::container::set::get_allocator() @@ -924,6 +992,12 @@ class multiset void insert(InputIterator first, InputIterator last) { this->base_t::insert_equal(first, last); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! @copydoc ::boost::container::set::insert(std::initializer_list) + void insert(std::initializer_list il) + { this->base_t::insert_unique(il.begin(), il.end()); } +#endif + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! @copydoc ::boost::container::set::erase(const_iterator) diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index dac44ad..6611b75 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -45,6 +45,11 @@ #include #include +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif + + namespace boost { namespace container { @@ -272,7 +277,20 @@ class slist : AllocHolder(a) { this->insert_after(this->cbefore_begin(), first, last); } - //! Effects: Copy constructs a list. +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Constructs a list that will use a copy of allocator a + //! and inserts a copy of the range [il.begin(), il.end()) in the list. + //! + //! Throws: If allocator_type's default constructor + //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws. + //! + //! Complexity: Linear to the range [il.begin(), il.end()). + slist(std::initializer_list il, const allocator_type& a = allocator_type()) + : AllocHolder(a) + { this->insert_after(this->cbefore_begin(), il.begin(), il.end()); } +#endif + + //! Effects: Copy constructs a list. //! //! Postcondition: x == *this. //! @@ -391,6 +409,21 @@ class slist return *this; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Makes *this contain the same elements as in il. + //! + //! Postcondition: this->size() == il.size(). *this contains a copy + //! of each of il's elements. + //! + //! Throws: If allocator_traits_type::propagate_on_container_move_assignment + //! is false and (allocation throws or value_type's move constructor throws) + slist& operator=(std::initializer_list il) + { + assign(il.begin(), il.end()); + return *this; + } +#endif + //! Effects: Assigns the n copies of val to *this. //! //! Throws: If memory allocation throws or T's copy constructor throws. @@ -432,6 +465,19 @@ class slist this->erase_after(prev, end_n); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Effects: Assigns the range [il.begin(), il.end()) to *this. + //! + //! Throws: If memory allocation throws or + //! T's constructor from dereferencing std::initializer_list iterator throws. + //! + //! Complexity: Linear to range [il.begin(), il.end()). + + void assign(std::initializer_list il) + { + assign(il.begin(), il.end()); + } +#endif //! Effects: Returns a copy of the internal allocator. //! //! Throws: If allocator's copy constructor throws. @@ -817,6 +863,25 @@ class slist return ret_it; } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Requires: prev_p must be a valid iterator of *this. + //! + //! Effects: Inserts the range pointed by [il.begin(), il.end()) after prev_p. + //! + //! Returns: an iterator to the last inserted element or prev_p if il.begin() == il.end(). + //! + //! Throws: If memory allocation throws, T's constructor from a + //! dereferenced std::initializer_list iterator throws. + //! + //! Complexity: Linear to the number of elements inserted. + //! + //! Note: Does not affect the validity of iterators and references of + //! previous values. + iterator insert_after(const_iterator prev_p, std::initializer_list il) + { + return insert_after(prev_p, il.begin(), il.end()); + } +#endif #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) template iterator insert_after(const_iterator prev, FwdIt first, FwdIt last @@ -1313,6 +1378,24 @@ class slist return ++iterator(prev.get()); } +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + //! Requires: p must be a valid iterator of *this. + //! + //! Effects: Insert a copy of the [il.begin(), il.end()) range before p. + //! + //! Returns: an iterator to the first inserted element or p if il.begin() == il.end(). + //! + //! Throws: If memory allocation throws, T's constructor from a + //! dereferenced std::initializer_list iterator throws. + //! + //! Complexity: Linear to the range [il.begin(), il.end()) plus + //! linear to the elements before p. + iterator insert(const_iterator p, std::initializer_list il) + { + return insert(p, il.begin(), il.end()); + } +#endif + //! Requires: p must be a valid iterator of *this. //! //! Effects: Erases the element at p p. diff --git a/test/deque_test.cpp b/test/deque_test.cpp index 71527f3..029826a 100644 --- a/test/deque_test.cpp +++ b/test/deque_test.cpp @@ -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 il = {1, 10, 11}; + const deque expectedDeque(il.begin(), il.end()); + + const deque testConstructor = il; + if(testConstructor != expectedDeque) + return false; + + deque testAssignmentOperator = {11, 12, 23}; + testAssignmentOperator = il; + if(testConstructor != expectedDeque) + return false; + + deque testAssignmentMethod = {11, 12, 23}; + testAssignmentMethod.assign(il); + if(testConstructor != expectedDeque) + return false; + + deque 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 //////////////////////////////////// diff --git a/test/list_test.cpp b/test/list_test.cpp index 578fac2..61990b9 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -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 il = {1, 10}; + const list expectedList(il.begin(), il.end()); + + const list testConstructor = il; + if(testConstructor != expectedList) + return false; + + list testAssignOperator = {10, 11}; + testAssignOperator = il; + if(testAssignOperator != expectedList) + return false; + + list testAssignMethod = {99}; + testAssignMethod = il; + if(testAssignMethod != expectedList) + return false; + + list 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()) return 1; + if(!test_support_for_initializer_list()) + return 1; + return 0; } diff --git a/test/map_test.cpp b/test/map_test.cpp index fc9363f..856944e 100644 --- a/test/map_test.cpp +++ b/test/map_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "print_container.hpp" #include "movable_int.hpp" @@ -345,6 +346,38 @@ int test_map_variants() return 0; } +template +bool test_support_for_initialization_list_for() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + const std::initializer_list> 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()) return 1; + if(!test_support_for_initialization_list_for >()) + return 1; + + if(!test_support_for_initialization_list_for >()) + return 1; + //////////////////////////////////// // Test optimize_size option //////////////////////////////////// diff --git a/test/set_test.cpp b/test/set_test.cpp index 3cd58ad..279d77d 100644 --- a/test/set_test.cpp +++ b/test/set_test.cpp @@ -314,7 +314,36 @@ int test_set_variants() return 0; } +template +bool test_support_for_initialization_list_for() +{ +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + std::initializer_list 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()) return 1; + if(!test_support_for_initialization_list_for >()) + return 1; + + if(!test_support_for_initialization_list_for >()) + return 1; + //////////////////////////////////// // Test optimize_size option //////////////////////////////////// diff --git a/test/slist_test.cpp b/test/slist_test.cpp index dbcf78b..9af79a6 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -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 il = {5, 10, 15}; + const slist expected_list(il.begin(), il.end()); + { + slist sl = il; + if(sl != expected_list) + return false; + } + + { + slist sl = {1, 2}; + sl = il; + if(sl != expected_list) + return false; + } + + { + slist sl = {4, 5}; + sl.assign(il); + if(sl != expected_list) + return false; + } + + { + slist sl = {15}; + sl.insert(sl.cbegin(), {5, 10}); + if(sl != expected_list) + return false; + } + + { + slist 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()) return 1; + + if(!test_support_for_initializer_list()) + return 1; } #include