From b1503a139e687f83ce90af96acaf6d4b6c3bdd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 29 Jul 2013 21:32:23 +0000 Subject: [PATCH] Fixes #8892. [SVN r85167] --- include/boost/container/detail/flat_tree.hpp | 15 ++++-- .../container/detail/node_alloc_holder.hpp | 21 +++++---- include/boost/container/detail/tree.hpp | 47 +++++++++++-------- include/boost/container/flat_map.hpp | 20 +++++++- include/boost/container/flat_set.hpp | 21 ++++++++- include/boost/container/map.hpp | 24 +++++++++- include/boost/container/set.hpp | 14 ++++++ 7 files changed, 124 insertions(+), 38 deletions(-) diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 90f0352..2330d5b 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -115,7 +115,7 @@ class flat_tree : value_compare(), m_vect() {} - Data(const Data &d) + explicit Data(const Data &d) : value_compare(static_cast(d)), m_vect(d.m_vect) {} @@ -131,15 +131,18 @@ class flat_tree : value_compare(boost::move(static_cast(d))), m_vect(boost::move(d.m_vect), a) {} - Data(const Compare &comp) + explicit Data(const Compare &comp) : value_compare(comp), m_vect() {} - Data(const Compare &comp, - const allocator_t &alloc) + Data(const Compare &comp, const allocator_t &alloc) : value_compare(comp), m_vect(alloc) {} + explicit Data(const allocator_t &alloc) + : value_compare(), m_vect(alloc) + {} + Data& operator=(BOOST_COPY_ASSIGN_REF(Data) d) { this->value_compare::operator=(d); @@ -203,6 +206,10 @@ class flat_tree : m_data(comp, a) { } + explicit flat_tree(const allocator_type& a) + : m_data(a) + { } + flat_tree(const flat_tree& x) : m_data(x.m_data) { } diff --git a/include/boost/container/detail/node_alloc_holder.hpp b/include/boost/container/detail/node_alloc_holder.hpp index 5a94a68..4a5052a 100644 --- a/include/boost/container/detail/node_alloc_holder.hpp +++ b/include/boost/container/detail/node_alloc_holder.hpp @@ -53,10 +53,14 @@ struct node_compare typedef typename ValueCompare::value_type value_type; typedef typename ValueCompare::key_of_value key_of_value; - node_compare(const ValueCompare &pred) + explicit node_compare(const ValueCompare &pred) : ValueCompare(pred) {} + node_compare() + : ValueCompare() + {} + ValueCompare &value_comp() { return static_cast(*this); } @@ -67,11 +71,10 @@ struct node_compare { return ValueCompare::operator()(a.get_data(), b.get_data()); } }; -template +template struct node_alloc_holder { typedef allocator_traits allocator_traits_type; - typedef node_alloc_holder self_t; typedef typename allocator_traits_type::value_type value_type; typedef typename ICont::value_type Node; typedef typename allocator_traits_type::template @@ -116,20 +119,20 @@ struct node_alloc_holder { this->icont().swap(x.icont()); } //Constructors for associative containers - explicit node_alloc_holder(const ValAlloc &a, const Pred &c) + explicit node_alloc_holder(const ValAlloc &a, const ValPred &c) : members_(a, c) {} - explicit node_alloc_holder(const node_alloc_holder &x, const Pred &c) + explicit node_alloc_holder(const node_alloc_holder &x, const ValPred &c) : members_(NodeAllocTraits::select_on_container_copy_construction(x.node_alloc()), c) {} - explicit node_alloc_holder(const Pred &c) + explicit node_alloc_holder(const ValPred &c) : members_(c) {} //helpers for move assignments - explicit node_alloc_holder(BOOST_RV_REF(node_alloc_holder) x, const Pred &c) + explicit node_alloc_holder(BOOST_RV_REF(node_alloc_holder) x, const ValPred &c) : members_(boost::move(x.node_alloc()), c) { this->icont().swap(x.icont()); } @@ -345,12 +348,12 @@ struct node_alloc_holder {} template - members_holder(BOOST_FWD_REF(ConvertibleToAlloc) c2alloc, const Pred &c) + members_holder(BOOST_FWD_REF(ConvertibleToAlloc) c2alloc, const ValPred &c) : NodeAlloc(boost::forward(c2alloc)) , m_icont(typename ICont::value_compare(c)) {} - explicit members_holder(const Pred &c) + explicit members_holder(const ValPred &c) : NodeAlloc() , m_icont(typename ICont::value_compare(c)) {} diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index 9cb3c9f..138595e 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -50,8 +50,12 @@ struct tree_value_compare typedef KeyOfValue key_of_value; typedef Key key_type; - tree_value_compare(const key_compare &kcomp) - : key_compare(kcomp) + explicit tree_value_compare(const key_compare &kcomp) + : KeyCompare(kcomp) + {} + + tree_value_compare() + : KeyCompare() {} const key_compare &key_comp() const @@ -212,15 +216,15 @@ class rbtree , typename container_detail::intrusive_rbtree_type >::type - , KeyCompare + , tree_value_compare > { + typedef tree_value_compare + ValComp; typedef typename container_detail::intrusive_rbtree_type - < A, tree_value_compare - - >::type Icont; + < A, ValComp>::type Icont; typedef container_detail::node_alloc_holder - AllocHolder; + AllocHolder; typedef typename AllocHolder::NodePtr NodePtr; typedef rbtree < Key, Value, KeyOfValue , KeyCompare, A> ThisType; @@ -318,8 +322,7 @@ class rbtree typedef Value value_type; typedef A allocator_type; typedef KeyCompare key_compare; - typedef tree_value_compare< Key, Value - , KeyCompare, KeyOfValue> value_compare; + typedef ValComp value_compare; typedef typename boost::container:: allocator_traits::pointer pointer; typedef typename boost::container:: @@ -471,11 +474,15 @@ class rbtree typedef std::reverse_iterator const_reverse_iterator; rbtree() - : AllocHolder(key_compare()) + : AllocHolder(ValComp(key_compare())) {} - rbtree(const key_compare& comp, const allocator_type& a = allocator_type()) - : AllocHolder(a, comp) + explicit rbtree(const key_compare& comp, const allocator_type& a = allocator_type()) + : AllocHolder(a, ValComp(comp)) + {} + + explicit rbtree(const allocator_type& a) + : AllocHolder(a) {} template @@ -488,7 +495,7 @@ class rbtree >::type * = 0 #endif ) - : AllocHolder(a, comp) + : AllocHolder(a, value_compare(comp)) { if(unique_insertion){ this->insert_unique(first, last); @@ -508,7 +515,7 @@ class rbtree >::type * = 0 #endif ) - : AllocHolder(a, comp) + : AllocHolder(a, value_compare(comp)) { if(unique_insertion){ this->insert_unique(first, last); @@ -530,7 +537,7 @@ class rbtree >::type * = 0 #endif ) - : AllocHolder(a, comp) + : AllocHolder(a, value_compare(comp)) { this->insert_equal(first, last); } @@ -545,7 +552,7 @@ class rbtree >::type * = 0 #endif ) - : AllocHolder(a, comp) + : AllocHolder(a, value_compare(comp)) { //Optimized allocation and construction this->allocate_many_and_construct @@ -553,25 +560,25 @@ class rbtree } rbtree(const rbtree& x) - : AllocHolder(x, x.key_comp()) + : AllocHolder(x, x.value_comp()) { this->icont().clone_from (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); } rbtree(BOOST_RV_REF(rbtree) x) - : AllocHolder(::boost::move(static_cast(x)), x.key_comp()) + : AllocHolder(::boost::move(static_cast(x)), x.value_comp()) {} rbtree(const rbtree& x, const allocator_type &a) - : AllocHolder(a, x.key_comp()) + : AllocHolder(a, x.value_comp()) { this->icont().clone_from (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); } rbtree(BOOST_RV_REF(rbtree) x, const allocator_type &a) - : AllocHolder(a, x.key_comp()) + : AllocHolder(a, x.value_comp()) { if(this->node_alloc() == x.node_alloc()){ this->icont().swap(x.icont()); diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index 8bb372f..ac48e6d 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -173,7 +173,15 @@ class flat_map //! //! Complexity: Constant. explicit flat_map(const Compare& comp, const allocator_type& a = allocator_type()) - : m_flat_tree(comp, container_detail::force(a)) {} + : m_flat_tree(comp, container_detail::force(a)) + {} + + //! Effects: Constructs an empty flat_map using the specified allocator. + //! + //! Complexity: Constant. + explicit flat_map(const allocator_type& a) + : m_flat_tree(container_detail::force(a)) + {} //! Effects: Constructs an empty flat_map using the specified comparison object and //! allocator, and inserts elements from the range [first ,last ). @@ -1024,7 +1032,15 @@ class flat_multimap //! Complexity: Constant. explicit flat_multimap(const Compare& comp, const allocator_type& a = allocator_type()) - : m_flat_tree(comp, container_detail::force(a)) { } + : m_flat_tree(comp, container_detail::force(a)) + {} + + //! Effects: Constructs an empty flat_multimap using the specified allocator. + //! + //! Complexity: Constant. + explicit flat_multimap(const allocator_type& a) + : m_flat_tree(container_detail::force(a)) + {} //! Effects: Constructs an empty flat_multimap using the specified comparison object //! and allocator, and inserts elements from the range [first ,last ). diff --git a/include/boost/container/flat_set.hpp b/include/boost/container/flat_set.hpp index 82bdea8..7acee1c 100644 --- a/include/boost/container/flat_set.hpp +++ b/include/boost/container/flat_set.hpp @@ -121,6 +121,13 @@ class flat_set : m_flat_tree(comp, a) {} + //! Effects: Constructs an empty flat_set using the specified allocator. + //! + //! Complexity: Constant. + explicit flat_set(const allocator_type& a) + : m_flat_tree(a) + {} + //! Effects: Constructs an empty set using the specified comparison object and //! allocator, and inserts elements from the range [first ,last ). //! @@ -810,9 +817,21 @@ class flat_multiset : m_flat_tree() {} + //! Effects: Constructs an empty flat_multiset using the specified + //! comparison object and allocator. + //! + //! Complexity: Constant. explicit flat_multiset(const Compare& comp, const allocator_type& a = allocator_type()) - : m_flat_tree(comp, a) {} + : m_flat_tree(comp, a) + {} + + //! Effects: Constructs an empty flat_multiset using the specified allocator. + //! + //! Complexity: Constant. + explicit flat_multiset(const allocator_type& a) + : m_flat_tree(a) + {} template flat_multiset(InputIterator first, InputIterator last, diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index b1faf49..e6ca865 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -138,6 +138,16 @@ class map BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty map using the specified allocator. + //! + //! Complexity: Constant. + explicit map(const allocator_type& a) + : m_tree(a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + //! Effects: Constructs an empty map using the specified comparison object and //! allocator, and inserts elements from the range [first ,last ). //! @@ -918,8 +928,7 @@ class multimap BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } - //! Effects: Constructs an empty multimap using the specified comparison - //! object and allocator. + //! Effects: Constructs an empty multimap using the specified allocator. //! //! Complexity: Constant. explicit multimap(const Compare& comp, const allocator_type& a = allocator_type()) @@ -929,6 +938,17 @@ class multimap BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); } + //! Effects: Constructs an empty multimap using the specified comparison + //! object and allocator. + //! + //! Complexity: Constant. + explicit multimap(const allocator_type& a) + : m_tree(a) + { + //Allocator type must be std::pair + BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); + } + //! Effects: Constructs an empty multimap using the specified comparison object //! and allocator, and inserts elements from the range [first ,last ). //! diff --git a/include/boost/container/set.hpp b/include/boost/container/set.hpp index 0b49376..7808859 100644 --- a/include/boost/container/set.hpp +++ b/include/boost/container/set.hpp @@ -113,6 +113,13 @@ class set : m_tree(comp, a) {} + //! Effects: Constructs an empty set using the specified allocator object. + //! + //! Complexity: Constant. + explicit set(const allocator_type& a) + : m_tree(a) + {} + //! Effects: Constructs an empty set using the specified comparison object and //! allocator, and inserts elements from the range [first ,last ). //! @@ -737,6 +744,13 @@ class multiset : m_tree(comp, a) {} + //! Effects: Constructs an empty multiset using the specified allocator. + //! + //! Complexity: Constant. + explicit multiset(const allocator_type& a) + : m_tree(a) + {} + //! Effects: Constructs an empty multiset using the specified comparison object //! and allocator, and inserts elements from the range [first ,last ). //!