From d39b1c143c5badfed3115ed42fe7ce3e1d078492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 28 Feb 2015 23:46:08 +0100 Subject: [PATCH] Add missing initializer list overload taking an additional allocator. --- include/boost/container/flat_map.hpp | 24 +++++++++++++++ include/boost/container/flat_set.hpp | 20 +++++++++--- include/boost/container/map.hpp | 46 ++++++++++++++++++++++++++-- include/boost/container/set.hpp | 18 +++++++++-- test/map_test.hpp | 36 +++------------------- test/propagate_allocator_test.hpp | 30 +++++++++++++++++- test/set_test.hpp | 4 +++ 7 files changed, 136 insertions(+), 42 deletions(-) diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index d251c35..ef0e1cb 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -271,6 +271,18 @@ class flat_map BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty flat_map using the specified + //! 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 last - first. + flat_map(std::initializer_list il, const allocator_type& a) + : m_flat_tree(true, il.begin(), il.end(), Compare(), container_detail::force(a)) + { + //A type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + //! Effects: Constructs an empty flat_map 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. @@ -1282,6 +1294,18 @@ class flat_multimap BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty flat_map using the specified + //! 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 last - first. + flat_multimap(std::initializer_list il, const allocator_type& a) + : m_flat_tree(false, il.begin(), il.end(), Compare(), container_detail::force(a)) + { + //A type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + //! Effects: Constructs an empty flat_multimap using the specified comparison object and //! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function //! is more efficient than the normal range creation for ordered ranges. diff --git a/include/boost/container/flat_set.hpp b/include/boost/container/flat_set.hpp index 4cf2e00..8f59279 100644 --- a/include/boost/container/flat_set.hpp +++ b/include/boost/container/flat_set.hpp @@ -180,9 +180,16 @@ class flat_set flat_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 container using the specified + //! 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(). + flat_set(std::initializer_list il, const allocator_type& a) + : base_t(true, il.begin(), il.end(), Compare(), a) + {} //! Effects: Constructs an empty container using the specified comparison object and //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function @@ -197,9 +204,7 @@ class flat_set flat_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 the container. @@ -946,6 +951,11 @@ class flat_multiset : base_t(false, il.begin(), il.end(), comp, a) {} + //! @copydoc ::boost::container::flat_set::flat_set(std::initializer_list, const allocator_type&) + flat_multiset(std::initializer_list il, const allocator_type& a) + : base_t(false, il.begin(), il.end(), Compare(), a) + {} + //! @copydoc ::boost::container::flat_set::flat_set(ordered_unique_range_t, std::initializer_list, const Compare& comp, const allocator_type&) flat_multiset(ordered_unique_range_t, std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index 7889517..4dc6096 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -143,8 +143,7 @@ class map //! and allocator. //! //! Complexity: Constant. - explicit map(const Compare& comp, - const allocator_type& a = allocator_type()) + explicit map(const Compare& comp, const allocator_type& a = allocator_type()) : base_t(comp, a) { //A type must be std::pair @@ -220,6 +219,28 @@ class map BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty map using the specified + //! 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 allocator_type& a) + : base_t(true, il.begin(), il.end(), Compare(), a) + { + //A type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + + //! 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. 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) @@ -1038,6 +1059,27 @@ class multimap BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty multimap using the specified + //! 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 allocator_type& a) + : base_t(false, il.begin(), il.end(), Compare(), a) + { + //A type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + + //! Effects: Constructs an empty set using the specified comparison object and + //! allocator, and inserts elements from the ordered 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. + //! + //! Complexity: Linear in N. + //! + //! Note: Non-standard extension. 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) diff --git a/include/boost/container/set.hpp b/include/boost/container/set.hpp index 06e909d..79fa1ae 100644 --- a/include/boost/container/set.hpp +++ b/include/boost/container/set.hpp @@ -177,6 +177,15 @@ class set : base_t(true, il.begin(), il.end(), comp, a) {} + //! Effects: Constructs an empty set using the specified + //! 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 allocator_type& a) + : base_t(true, il.begin(), il.end(), Compare(), 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. @@ -187,7 +196,8 @@ class set //! 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()) + 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 @@ -825,13 +835,17 @@ class multiset : base_t(false, il.begin(), il.end(), comp, a) {} + //! @copydoc ::boost::container::set::set(std::initializer_list, const allocator_type&) + multiset(std::initializer_list il, const allocator_type& a) + : base_t(false, il.begin(), il.end(), Compare(), 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)) diff --git a/test/map_test.hpp b/test/map_test.hpp index 4c87708..79504d9 100644 --- a/test/map_test.hpp +++ b/test/map_test.hpp @@ -663,39 +663,7 @@ int map_test() } 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, 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; -} -*/ template bool test_map_support_for_initialization_list_for() { @@ -713,6 +681,10 @@ bool test_map_support_for_initialization_list_for() if (sila != expected) return false; + MapType silca(il, typename MapType::key_compare(), typename MapType::allocator_type()); + if (silca != expected) + return false; + const MapType sil_ordered(ordered_unique_range, il); if (sil_ordered != expected) return false; diff --git a/test/propagate_allocator_test.hpp b/test/propagate_allocator_test.hpp index 6aacea2..aefda76 100644 --- a/test/propagate_allocator_test.hpp +++ b/test/propagate_allocator_test.hpp @@ -33,7 +33,9 @@ class alloc_propagate_wrapper typedef typename alloc_propagate_base ::template apply::type Base; - typedef typename Base::allocator_type allocator_type; + typedef typename Base::allocator_type allocator_type; + typedef typename Base::value_type value_type; + typedef typename Base::size_type size_type; alloc_propagate_wrapper() : Base() @@ -42,6 +44,32 @@ class alloc_propagate_wrapper explicit alloc_propagate_wrapper(const allocator_type &a) : Base(a) {} +/* + //sequence containers only + explicit alloc_propagate_wrapper(size_type n, const value_type &v, const allocator_type &a) + : Base(n, v, a) + {} + + alloc_propagate_wrapper(size_type n, const allocator_type &a) + : Base(n, a) + {}*/ + + template + alloc_propagate_wrapper(Iterator b, Iterator e, const allocator_type &a) + : Base(b, e, a) + {} + + #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + alloc_propagate_wrapper(std::initializer_list il, const allocator_type& a) + : Base(il, a) + {} +/* + //associative containers only + alloc_propagate_wrapper(std::initializer_list il, const Compare& comp, const allocator_type& a) + : Base(il, comp, a) + {}*/ + + #endif alloc_propagate_wrapper(const alloc_propagate_wrapper &x) : Base(x) diff --git a/test/set_test.hpp b/test/set_test.hpp index b8f043c..1ab8af5 100644 --- a/test/set_test.hpp +++ b/test/set_test.hpp @@ -722,6 +722,10 @@ bool test_set_methods_with_initializer_list_as_argument_for() if (sila != expected) return false; + SetType silca(il, typename SetType::key_compare(), typename SetType::allocator_type()); + if (silca != expected) + return false; + SetType sil_ordered(ordered_unique_range, ilu); if (sil_ordered != expectedu) return false;