diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index 27f1074..24ee997 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -127,48 +127,54 @@ class flat_map typedef typename impl_tree_t::const_reverse_iterator impl_const_reverse_iterator; typedef typename impl_tree_t::allocator_type impl_allocator_type; typedef allocator_traits allocator_traits_type; - - + typedef container_detail::flat_tree_value_compare + < Pred + , container_detail::select1st< std::pair > + , std::pair > value_compare_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::iterator iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::const_iterator const_iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::reverse_iterator reverse_iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::const_reverse_iterator const_reverse_iterator_impl; /// @endcond public: - // typedefs: - typedef Key key_type; - typedef T mapped_type; - typedef typename std::pair value_type; - typedef typename allocator_traits_type::pointer pointer; - typedef typename allocator_traits_type::const_pointer const_pointer; - typedef typename allocator_traits_type::reference reference; - typedef typename allocator_traits_type::const_reference const_reference; - typedef typename impl_tree_t::size_type size_type; - typedef typename impl_tree_t::difference_type difference_type; - - typedef container_detail::flat_tree_value_compare - < Pred - , container_detail::select1st< std::pair > - , std::pair > value_compare; - typedef Pred key_compare; - typedef typename container_detail:: - get_flat_tree_iterators::iterator iterator; - typedef typename container_detail:: - get_flat_tree_iterators::const_iterator const_iterator; - typedef typename container_detail:: - get_flat_tree_iterators - ::reverse_iterator reverse_iterator; - typedef typename container_detail:: - get_flat_tree_iterators - ::const_reverse_iterator const_reverse_iterator; - typedef A allocator_type; - - //!Standard extension - typedef A stored_allocator_type; - - //!Standard extension for C++03 compilers with non-movable std::pair - typedef impl_value_type movable_value_type; + ////////////////////////////////////////////// + // + // types + // + ////////////////////////////////////////////// + typedef Key key_type; + typedef T mapped_type; + typedef typename std::pair value_type; + typedef typename boost::container::allocator_traits::pointer pointer; + typedef typename boost::container::allocator_traits::const_pointer const_pointer; + typedef typename boost::container::allocator_traits::reference reference; + typedef typename boost::container::allocator_traits::const_reference const_reference; + typedef typename boost::container::allocator_traits::size_type size_type; + typedef typename boost::container::allocator_traits::difference_type difference_type; + typedef A allocator_type; + typedef BOOST_CONTAINER_IMPDEF(A) stored_allocator_type; + typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare; + typedef Pred key_compare; + typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; + typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; + typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type; public: + ////////////////////////////////////////////// + // + // construct/copy/destroy + // + ////////////////////////////////////////////// + //! Effects: Default constructs an empty flat_map. //! //! Complexity: Constant. @@ -255,20 +261,6 @@ class flat_map flat_map& operator=(BOOST_RV_REF(flat_map) mx) { m_flat_tree = boost::move(mx.m_flat_tree); return *this; } - //! Effects: Returns the comparison object out - //! of which a was constructed. - //! - //! Complexity: Constant. - key_compare key_comp() const - { return container_detail::force_copy(m_flat_tree.key_comp()); } - - //! Effects: Returns an object of value_compare constructed out - //! of the comparison object. - //! - //! Complexity: Constant. - value_compare value_comp() const - { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } - //! Effects: Returns a copy of the Allocator that //! was passed to the object's constructor. //! @@ -276,11 +268,31 @@ class flat_map allocator_type get_allocator() const { return container_detail::force_copy(m_flat_tree.get_allocator()); } + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() + { return container_detail::force(m_flat_tree.get_stored_allocator()); } + + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. const stored_allocator_type &get_stored_allocator() const { return container_detail::force(m_flat_tree.get_stored_allocator()); } - stored_allocator_type &get_stored_allocator() - { return container_detail::force(m_flat_tree.get_stored_allocator()); } + ////////////////////////////////////////////// + // + // iterators + // + ////////////////////////////////////////////// //! Effects: Returns an iterator to the first element contained in the container. //! @@ -384,6 +396,12 @@ class flat_map const_reverse_iterator crend() const { return container_detail::force_copy(m_flat_tree.crend()); } + ////////////////////////////////////////////// + // + // capacity + // + ////////////////////////////////////////////// + //! Effects: Returns true if the container contains no elements. //! //! Throws: Nothing. @@ -408,6 +426,42 @@ class flat_map size_type max_size() const { return m_flat_tree.max_size(); } + //! Effects: Number of elements for which memory has been allocated. + //! capacity() is always greater than or equal to size(). + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + size_type capacity() const + { return m_flat_tree.capacity(); } + + //! Effects: If n is less than or equal to capacity(), this call has no + //! effect. Otherwise, it is a request for allocation of additional memory. + //! If the request is successful, then capacity() is greater than or equal to + //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. + //! + //! Throws: If memory allocation allocation throws or T's copy constructor throws. + //! + //! Note: If capacity() is less than "count", iterators and references to + //! to values might be invalidated. + void reserve(size_type count) + { m_flat_tree.reserve(count); } + + //! Effects: Tries to deallocate the excess of memory created + // with previous allocations. The size of the vector is unchanged + //! + //! Throws: If memory allocation throws, or T's copy constructor throws. + //! + //! Complexity: Linear to size(). + void shrink_to_fit() + { m_flat_tree.shrink_to_fit(); } + + ////////////////////////////////////////////// + // + // element access + // + ////////////////////////////////////////////// + #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: If there is no key equivalent to x in the flat_map, inserts //! value_type(x, T()) into the flat_map. @@ -430,7 +484,9 @@ class flat_map #endif //! Returns: A reference to the element whose key is equivalent to x. + //! //! Throws: An exception object of type out_of_range if no such element is present. + //! //! Complexity: logarithmic. T& at(const key_type& k) { @@ -442,7 +498,9 @@ class flat_map } //! Returns: A reference to the element whose key is equivalent to x. + //! //! Throws: An exception object of type out_of_range if no such element is present. + //! //! Complexity: logarithmic. const T& at(const key_type& k) const { @@ -453,13 +511,69 @@ class flat_map return i->second; } - //! Effects: Swaps the contents of *this and x. + ////////////////////////////////////////////// + // + // modifiers + // + ////////////////////////////////////////////// + + #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) + + //! Effects: Inserts an object x of type T constructed with + //! std::forward(args)... if and only if there is no element in the container + //! with key equivalent to the key of x. //! - //! Throws: Nothing. + //! Returns: The bool component of the returned pair is true if and only + //! if the insertion takes place, and the iterator component of the pair + //! points to the element with key equivalent to the key of x. //! - //! Complexity: Constant. - void swap(flat_map& x) - { m_flat_tree.swap(x.m_flat_tree); } + //! Complexity: Logarithmic search time plus linear insertion + //! to the elements with bigger keys than x. + //! + //! Note: If an element is inserted it might invalidate elements. + template + std::pair emplace(Args&&... args) + { return container_detail::force_copy< std::pair >(m_flat_tree.emplace_unique(boost::forward(args)...)); } + + //! Effects: Inserts an object of type T constructed with + //! std::forward(args)... in the container if and only if there is + //! no element in the container with key equivalent to the key of x. + //! p is a hint pointing to where the insert should start to search. + //! + //! Returns: An iterator pointing to the element with key equivalent + //! to the key of x. + //! + //! Complexity: Logarithmic search time (constant if x is inserted + //! right before p) plus insertion linear to the elements with bigger keys than x. + //! + //! Note: If an element is inserted it might invalidate elements. + template + iterator emplace_hint(const_iterator hint, Args&&... args) + { + return container_detail::force_copy + (m_flat_tree.emplace_hint_unique( container_detail::force_copy(hint) + , boost::forward(args)...)); + } + + #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING + + #define BOOST_PP_LOCAL_MACRO(n) \ + BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ + std::pair emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ + { return container_detail::force_copy< std::pair > \ + (m_flat_tree.emplace_unique(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ + \ + BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ + iterator emplace_hint(const_iterator hint \ + BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ + { return container_detail::force_copy(m_flat_tree.emplace_hint_unique \ + (container_detail::force_copy(hint) \ + BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ + //! + #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) + #include BOOST_PP_LOCAL_ITERATE() + + #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING //! Effects: Inserts x if and only if there is no element in the container //! with key equivalent to the key of x. @@ -587,64 +701,6 @@ class flat_map void insert(ordered_unique_range_t, InputIterator first, InputIterator last) { m_flat_tree.insert_unique(ordered_unique_range, first, last); } - #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) - - //! Effects: Inserts an object x of type T constructed with - //! std::forward(args)... if and only if there is no element in the container - //! with key equivalent to the key of x. - //! - //! Returns: The bool component of the returned pair is true if and only - //! if the insertion takes place, and the iterator component of the pair - //! points to the element with key equivalent to the key of x. - //! - //! Complexity: Logarithmic search time plus linear insertion - //! to the elements with bigger keys than x. - //! - //! Note: If an element is inserted it might invalidate elements. - template - std::pair emplace(Args&&... args) - { return container_detail::force_copy< std::pair >(m_flat_tree.emplace_unique(boost::forward(args)...)); } - - //! Effects: Inserts an object of type T constructed with - //! std::forward(args)... in the container if and only if there is - //! no element in the container with key equivalent to the key of x. - //! p is a hint pointing to where the insert should start to search. - //! - //! Returns: An iterator pointing to the element with key equivalent - //! to the key of x. - //! - //! Complexity: Logarithmic search time (constant if x is inserted - //! right before p) plus insertion linear to the elements with bigger keys than x. - //! - //! Note: If an element is inserted it might invalidate elements. - template - iterator emplace_hint(const_iterator hint, Args&&... args) - { - return container_detail::force_copy - (m_flat_tree.emplace_hint_unique( container_detail::force_copy(hint) - , boost::forward(args)...)); - } - - #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING - - #define BOOST_PP_LOCAL_MACRO(n) \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - std::pair emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { return container_detail::force_copy< std::pair > \ - (m_flat_tree.emplace_unique(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ - \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - iterator emplace_hint(const_iterator hint \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { return container_detail::force_copy(m_flat_tree.emplace_hint_unique \ - (container_detail::force_copy(hint) \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ - //! - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() - - #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING - //! Effects: Erases the element pointed to by position. //! //! Returns: Returns an iterator pointing to the element immediately @@ -685,6 +741,14 @@ class flat_map , container_detail::force_copy(last))); } + //! Effects: Swaps the contents of *this and x. + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + void swap(flat_map& x) + { m_flat_tree.swap(x.m_flat_tree); } + //! Effects: erase(a.begin(),a.end()). //! //! Postcondition: size() == 0. @@ -693,14 +757,31 @@ class flat_map void clear() { m_flat_tree.clear(); } - //! Effects: Tries to deallocate the excess of memory created - // with previous allocations. The size of the vector is unchanged + ////////////////////////////////////////////// + // + // observers + // + ////////////////////////////////////////////// + + //! Effects: Returns the comparison object out + //! of which a was constructed. //! - //! Throws: If memory allocation throws, or T's copy constructor throws. + //! Complexity: Constant. + key_compare key_comp() const + { return container_detail::force_copy(m_flat_tree.key_comp()); } + + //! Effects: Returns an object of value_compare constructed out + //! of the comparison object. //! - //! Complexity: Linear to size(). - void shrink_to_fit() - { m_flat_tree.shrink_to_fit(); } + //! Complexity: Constant. + value_compare value_comp() const + { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } + + ////////////////////////////////////////////// + // + // map operations + // + ////////////////////////////////////////////// //! Returns: An iterator pointing to an element with the key //! equivalent to x, or end() if such an element is not found. @@ -762,27 +843,6 @@ class flat_map std::pair equal_range(const key_type& x) const { return container_detail::force_copy >(m_flat_tree.equal_range(x)); } - //! Effects: Number of elements for which memory has been allocated. - //! capacity() is always greater than or equal to size(). - //! - //! Throws: Nothing. - //! - //! Complexity: Constant. - size_type capacity() const - { return m_flat_tree.capacity(); } - - //! Effects: If n is less than or equal to capacity(), this call has no - //! effect. Otherwise, it is a request for allocation of additional memory. - //! If the request is successful, then capacity() is greater than or equal to - //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. - //! - //! Throws: If memory allocation allocation throws or T's copy constructor throws. - //! - //! Note: If capacity() is less than "count", iterators and references to - //! to values might be invalidated. - void reserve(size_type count) - { m_flat_tree.reserve(count); } - /// @cond template friend bool operator== (const flat_map&, @@ -928,42 +988,51 @@ class flat_multimap typedef typename impl_tree_t::const_reverse_iterator impl_const_reverse_iterator; typedef typename impl_tree_t::allocator_type impl_allocator_type; typedef allocator_traits allocator_traits_type; - + typedef container_detail::flat_tree_value_compare + < Pred + , container_detail::select1st< std::pair > + , std::pair > value_compare_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::iterator iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::const_iterator const_iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::reverse_iterator reverse_iterator_impl; + typedef typename container_detail::get_flat_tree_iterators + ::pointer>::const_reverse_iterator const_reverse_iterator_impl; /// @endcond public: - // typedefs: - typedef Key key_type; - typedef T mapped_type; - typedef Pred key_compare; - typedef typename std::pair value_type; - typedef typename allocator_traits_type::pointer pointer; - typedef typename allocator_traits_type::const_pointer const_pointer; - typedef typename allocator_traits_type::reference reference; - typedef typename allocator_traits_type::const_reference const_reference; - typedef typename impl_tree_t::size_type size_type; - typedef typename impl_tree_t::difference_type difference_type; - typedef container_detail::flat_tree_value_compare - < Pred - , container_detail::select1st< std::pair > - , std::pair > value_compare; + ////////////////////////////////////////////// + // + // types + // + ////////////////////////////////////////////// + typedef Key key_type; + typedef T mapped_type; + typedef typename std::pair value_type; + typedef typename boost::container::allocator_traits::pointer pointer; + typedef typename boost::container::allocator_traits::const_pointer const_pointer; + typedef typename boost::container::allocator_traits::reference reference; + typedef typename boost::container::allocator_traits::const_reference const_reference; + typedef typename boost::container::allocator_traits::size_type size_type; + typedef typename boost::container::allocator_traits::difference_type difference_type; + typedef A allocator_type; + typedef BOOST_CONTAINER_IMPDEF(A) stored_allocator_type; + typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare; + typedef Pred key_compare; + typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; + typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; + typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator; + typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type; - typedef typename container_detail:: - get_flat_tree_iterators::iterator iterator; - typedef typename container_detail:: - get_flat_tree_iterators::const_iterator const_iterator; - typedef typename container_detail:: - get_flat_tree_iterators - ::reverse_iterator reverse_iterator; - typedef typename container_detail:: - get_flat_tree_iterators - ::const_reverse_iterator const_reverse_iterator; - typedef A allocator_type; - //Non-standard extension - typedef A stored_allocator_type; - //!Standard extension for C++03 compilers with non-movable std::pair - typedef impl_value_type movable_value_type; + ////////////////////////////////////////////// + // + // construct/copy/destroy + // + ////////////////////////////////////////////// //! Effects: Default constructs an empty flat_map. //! @@ -1020,7 +1089,7 @@ class flat_multimap //! Postcondition: x is emptied. flat_multimap(BOOST_RV_REF(flat_multimap) x) : m_flat_tree(boost::move(x.m_flat_tree)) - { } + {} //! Effects: Copy constructs a flat_multimap using the specified allocator. //! @@ -1049,20 +1118,6 @@ class flat_multimap flat_multimap& operator=(BOOST_RV_REF(flat_multimap) mx) { m_flat_tree = boost::move(mx.m_flat_tree); return *this; } - //! Effects: Returns the comparison object out - //! of which a was constructed. - //! - //! Complexity: Constant. - key_compare key_comp() const - { return container_detail::force_copy(m_flat_tree.key_comp()); } - - //! Effects: Returns an object of value_compare constructed out - //! of the comparison object. - //! - //! Complexity: Constant. - value_compare value_comp() const - { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } - //! Effects: Returns a copy of the Allocator that //! was passed to the object's constructor. //! @@ -1070,11 +1125,31 @@ class flat_multimap allocator_type get_allocator() const { return container_detail::force_copy(m_flat_tree.get_allocator()); } + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() + { return container_detail::force(m_flat_tree.get_stored_allocator()); } + + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. const stored_allocator_type &get_stored_allocator() const { return container_detail::force(m_flat_tree.get_stored_allocator()); } - stored_allocator_type &get_stored_allocator() - { return container_detail::force(m_flat_tree.get_stored_allocator()); } + ////////////////////////////////////////////// + // + // iterators + // + ////////////////////////////////////////////// //! Effects: Returns an iterator to the first element contained in the container. //! @@ -1178,6 +1253,12 @@ class flat_multimap const_reverse_iterator crend() const { return container_detail::force_copy(m_flat_tree.crend()); } + ////////////////////////////////////////////// + // + // capacity + // + ////////////////////////////////////////////// + //! Effects: Returns true if the container contains no elements. //! //! Throws: Nothing. @@ -1202,13 +1283,94 @@ class flat_multimap size_type max_size() const { return m_flat_tree.max_size(); } - //! Effects: Swaps the contents of *this and x. + //! Effects: Number of elements for which memory has been allocated. + //! capacity() is always greater than or equal to size(). //! //! Throws: Nothing. //! //! Complexity: Constant. - void swap(flat_multimap& x) - { m_flat_tree.swap(x.m_flat_tree); } + size_type capacity() const + { return m_flat_tree.capacity(); } + + //! Effects: If n is less than or equal to capacity(), this call has no + //! effect. Otherwise, it is a request for allocation of additional memory. + //! If the request is successful, then capacity() is greater than or equal to + //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. + //! + //! Throws: If memory allocation allocation throws or T's copy constructor throws. + //! + //! Note: If capacity() is less than "count", iterators and references to + //! to values might be invalidated. + void reserve(size_type count) + { m_flat_tree.reserve(count); } + + //! Effects: Tries to deallocate the excess of memory created + // with previous allocations. The size of the vector is unchanged + //! + //! Throws: If memory allocation throws, or T's copy constructor throws. + //! + //! Complexity: Linear to size(). + void shrink_to_fit() + { m_flat_tree.shrink_to_fit(); } + + ////////////////////////////////////////////// + // + // modifiers + // + ////////////////////////////////////////////// + + #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) + + //! Effects: Inserts an object of type T constructed with + //! std::forward(args)... and returns the iterator pointing to the + //! newly inserted element. + //! + //! Complexity: Logarithmic search time plus linear insertion + //! to the elements with bigger keys than x. + //! + //! Note: If an element is inserted it might invalidate elements. + template + iterator emplace(Args&&... args) + { return container_detail::force_copy(m_flat_tree.emplace_equal(boost::forward(args)...)); } + + //! Effects: Inserts an object of type T constructed with + //! std::forward(args)... in the container. + //! p is a hint pointing to where the insert should start to search. + //! + //! Returns: An iterator pointing to the element with key equivalent + //! to the key of x. + //! + //! Complexity: Logarithmic search time (constant time if the value + //! is to be inserted before p) plus linear insertion + //! to the elements with bigger keys than x. + //! + //! Note: If an element is inserted it might invalidate elements. + template + iterator emplace_hint(const_iterator hint, Args&&... args) + { + return container_detail::force_copy(m_flat_tree.emplace_hint_equal + (container_detail::force_copy(hint), boost::forward(args)...)); + } + + #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING + + #define BOOST_PP_LOCAL_MACRO(n) \ + BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ + iterator emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ + { return container_detail::force_copy(m_flat_tree.emplace_equal \ + (BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ + \ + BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ + iterator emplace_hint(const_iterator hint \ + BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ + { return container_detail::force_copy(m_flat_tree.emplace_hint_equal \ + (container_detail::force_copy(hint) \ + BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ + //! + #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) + #include BOOST_PP_LOCAL_ITERATE() + + #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING //! Effects: Inserts x and returns the iterator pointing to the //! newly inserted element. @@ -1324,59 +1486,6 @@ class flat_multimap void insert(ordered_range_t, InputIterator first, InputIterator last) { m_flat_tree.insert_equal(ordered_range, first, last); } - #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) - - //! Effects: Inserts an object of type T constructed with - //! std::forward(args)... and returns the iterator pointing to the - //! newly inserted element. - //! - //! Complexity: Logarithmic search time plus linear insertion - //! to the elements with bigger keys than x. - //! - //! Note: If an element is inserted it might invalidate elements. - template - iterator emplace(Args&&... args) - { return container_detail::force_copy(m_flat_tree.emplace_equal(boost::forward(args)...)); } - - //! Effects: Inserts an object of type T constructed with - //! std::forward(args)... in the container. - //! p is a hint pointing to where the insert should start to search. - //! - //! Returns: An iterator pointing to the element with key equivalent - //! to the key of x. - //! - //! Complexity: Logarithmic search time (constant time if the value - //! is to be inserted before p) plus linear insertion - //! to the elements with bigger keys than x. - //! - //! Note: If an element is inserted it might invalidate elements. - template - iterator emplace_hint(const_iterator hint, Args&&... args) - { - return container_detail::force_copy(m_flat_tree.emplace_hint_equal - (container_detail::force_copy(hint), boost::forward(args)...)); - } - - #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING - - #define BOOST_PP_LOCAL_MACRO(n) \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - iterator emplace(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { return container_detail::force_copy(m_flat_tree.emplace_equal \ - (BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ - \ - BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ - iterator emplace_hint(const_iterator hint \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ - { return container_detail::force_copy(m_flat_tree.emplace_hint_equal \ - (container_detail::force_copy(hint) \ - BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); } \ - //! - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() - - #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING - //! Effects: Erases the element pointed to by position. //! //! Returns: Returns an iterator pointing to the element immediately @@ -1417,6 +1526,14 @@ class flat_multimap , container_detail::force_copy(last))); } + //! Effects: Swaps the contents of *this and x. + //! + //! Throws: Nothing. + //! + //! Complexity: Constant. + void swap(flat_multimap& x) + { m_flat_tree.swap(x.m_flat_tree); } + //! Effects: erase(a.begin(),a.end()). //! //! Postcondition: size() == 0. @@ -1425,14 +1542,31 @@ class flat_multimap void clear() { m_flat_tree.clear(); } - //! Effects: Tries to deallocate the excess of memory created - // with previous allocations. The size of the vector is unchanged + ////////////////////////////////////////////// + // + // observers + // + ////////////////////////////////////////////// + + //! Effects: Returns the comparison object out + //! of which a was constructed. //! - //! Throws: If memory allocation throws, or T's copy constructor throws. + //! Complexity: Constant. + key_compare key_comp() const + { return container_detail::force_copy(m_flat_tree.key_comp()); } + + //! Effects: Returns an object of value_compare constructed out + //! of the comparison object. //! - //! Complexity: Linear to size(). - void shrink_to_fit() - { m_flat_tree.shrink_to_fit(); } + //! Complexity: Constant. + value_compare value_comp() const + { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } + + ////////////////////////////////////////////// + // + // map operations + // + ////////////////////////////////////////////// //! Returns: An iterator pointing to an element with the key //! equivalent to x, or end() if such an element is not found. @@ -1459,7 +1593,7 @@ class flat_multimap //! //! Complexity: Logarithmic iterator lower_bound(const key_type& x) - {return container_detail::force_copy(m_flat_tree.lower_bound(x)); } + { return container_detail::force_copy(m_flat_tree.lower_bound(x)); } //! Returns: A const iterator pointing to the first element with key //! not less than k, or a.end() if such an element is not found. @@ -1495,27 +1629,6 @@ class flat_multimap equal_range(const key_type& x) const { return container_detail::force_copy >(m_flat_tree.equal_range(x)); } - //! Effects: Number of elements for which memory has been allocated. - //! capacity() is always greater than or equal to size(). - //! - //! Throws: Nothing. - //! - //! Complexity: Constant. - size_type capacity() const - { return m_flat_tree.capacity(); } - - //! Effects: If n is less than or equal to capacity(), this call has no - //! effect. Otherwise, it is a request for allocation of additional memory. - //! If the request is successful, then capacity() is greater than or equal to - //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. - //! - //! Throws: If memory allocation allocation throws or T's copy constructor throws. - //! - //! Note: If capacity() is less than "count", iterators and references to - //! to values might be invalidated. - void reserve(size_type count) - { m_flat_tree.reserve(count); } - /// @cond template friend bool operator== (const flat_multimap& x, diff --git a/include/boost/container/flat_set.hpp b/include/boost/container/flat_set.hpp index 513d487..6af6827 100644 --- a/include/boost/container/flat_set.hpp +++ b/include/boost/container/flat_set.hpp @@ -209,10 +209,24 @@ class flat_set allocator_type get_allocator() const { return m_flat_tree.get_allocator(); } - const stored_allocator_type &get_stored_allocator() const + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return m_flat_tree.get_stored_allocator(); } - stored_allocator_type &get_stored_allocator() + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return m_flat_tree.get_stored_allocator(); } //! Effects: Returns an iterator to the first element contained in the container. @@ -860,10 +874,24 @@ class flat_multiset allocator_type get_allocator() const { return m_flat_tree.get_allocator(); } - const stored_allocator_type &get_stored_allocator() const + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return m_flat_tree.get_stored_allocator(); } - stored_allocator_type &get_stored_allocator() + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return m_flat_tree.get_stored_allocator(); } //! Effects: Returns an iterator to the first element contained in the container. diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index 8f196d1..1433fb1 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -506,20 +506,24 @@ class list allocator_type get_allocator() const { return allocator_type(this->node_alloc()); } - //! Effects: Returns a copy of the internal allocator. + //! Effects: Returns a reference to the internal allocator. //! - //! Throws: If allocator's copy constructor throws. + //! Throws: Nothing //! //! Complexity: Constant. - const stored_allocator_type &get_stored_allocator() const + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return this->node_alloc(); } - //! Effects: Returns a copy of the internal allocator. + //! Effects: Returns a reference to the internal allocator. //! - //! Throws: If allocator's copy constructor throws. + //! Throws: Nothing //! //! Complexity: Constant. - stored_allocator_type &get_stored_allocator() + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return this->node_alloc(); } ////////////////////////////////////////////// diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index d31122c..3cff41b 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -256,10 +256,24 @@ class map allocator_type get_allocator() const { return m_tree.get_allocator(); } - const stored_allocator_type &get_stored_allocator() const + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return m_tree.get_stored_allocator(); } - stored_allocator_type &get_stored_allocator() + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return m_tree.get_stored_allocator(); } //! Effects: Returns an iterator to the first element contained in the container. @@ -998,10 +1012,24 @@ class multimap allocator_type get_allocator() const { return m_tree.get_allocator(); } - const stored_allocator_type &get_stored_allocator() const + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return m_tree.get_stored_allocator(); } - stored_allocator_type &get_stored_allocator() + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return m_tree.get_stored_allocator(); } //! Effects: Returns an iterator to the first element contained in the container. diff --git a/include/boost/container/set.hpp b/include/boost/container/set.hpp index 44a854c..87473a4 100644 --- a/include/boost/container/set.hpp +++ b/include/boost/container/set.hpp @@ -199,9 +199,23 @@ class set allocator_type get_allocator() const { return m_tree.get_allocator(); } + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. const stored_allocator_type &get_stored_allocator() const { return m_tree.get_stored_allocator(); } + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. stored_allocator_type &get_stored_allocator() { return m_tree.get_stored_allocator(); } @@ -788,10 +802,24 @@ class multiset allocator_type get_allocator() const { return m_tree.get_allocator(); } - const stored_allocator_type &get_stored_allocator() const + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return m_tree.get_stored_allocator(); } - stored_allocator_type &get_stored_allocator() + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const { return m_tree.get_stored_allocator(); } //! Effects: Returns an iterator to the first element contained in the container. diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index c5ca7fa..2af3c39 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -519,12 +519,14 @@ class slist allocator_type get_allocator() const { return allocator_type(this->node_alloc()); } - //! Effects: Returns a copy of the internal allocator. + //! Effects: Returns a reference to the internal allocator. //! - //! Throws: If allocator's copy constructor throws. + //! Throws: Nothing //! //! Complexity: Constant. - const stored_allocator_type &get_stored_allocator() const + //! + //! Note: Non-standard extension. + stored_allocator_type &get_stored_allocator() { return this->node_alloc(); } //! Effects: Returns a reference to the internal allocator. @@ -534,7 +536,7 @@ class slist //! Complexity: Constant. //! //! Note: Non-standard extension. - stored_allocator_type &get_stored_allocator() + const stored_allocator_type &get_stored_allocator() const { return this->node_alloc(); } ////////////////////////////////////////////// diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 4af2ae2..42caee0 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -932,7 +932,7 @@ class basic_string //! Complexity: Constant. //! //! Note: Non-standard extension. - const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT + stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT { return this->alloc(); } //! Effects: Returns a reference to the internal allocator. @@ -942,7 +942,7 @@ class basic_string //! Complexity: Constant. //! //! Note: Non-standard extension. - stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT + const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT { return this->alloc(); } //! Effects: Returns the number of the elements contained in the vector.