Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@101: // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/container for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: #ifndef BOOST_CONTAINER_FLAT_MAP_HPP Chris@16: #define BOOST_CONTAINER_FLAT_MAP_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@101: // container Chris@101: #include Chris@101: #include Chris@101: #include //new_allocator Chris@101: #include Chris@101: // container/detail Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include //equal() Chris@101: // move Chris@101: #include Chris@101: #include Chris@101: // move/detail Chris@101: #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@101: #include Chris@101: #endif Chris@101: #include Chris@101: // intrusive Chris@101: #include //pair Chris@101: #include //less, equal Chris@101: //others Chris@101: #include Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: #include Chris@101: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace container { Chris@16: Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: namespace container_detail{ Chris@16: Chris@16: template Chris@16: static D &force(const S &s) Chris@16: { return *const_cast((reinterpret_cast(&s))); } Chris@16: Chris@16: template Chris@16: static D force_copy(S s) Chris@16: { Chris@16: D *vp = reinterpret_cast(&s); Chris@16: return D(*vp); Chris@16: } Chris@16: Chris@16: } //namespace container_detail{ Chris@16: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: //! A flat_map is a kind of associative container that supports unique keys (contains at Chris@16: //! most one of each key value) and provides for fast retrieval of values of another Chris@16: //! type T based on the keys. The flat_map class supports random-access iterators. Chris@16: //! Chris@16: //! A flat_map satisfies all of the requirements of a container and of a reversible Chris@16: //! container and of an associative container. A flat_map also provides Chris@16: //! most operations described for unique keys. For a Chris@16: //! flat_map the key_type is Key and the value_type is std::pair Chris@16: //! (unlike std::map which value_type is std::pair<const Key, T>). Chris@16: //! Chris@16: //! Compare is the ordering function for Keys (e.g. std::less). Chris@16: //! Chris@16: //! Allocator is the allocator to allocate the value_types Chris@16: //! (e.g. allocator< std::pair >). Chris@16: //! Chris@16: //! flat_map is similar to std::map but it's implemented like an ordered vector. Chris@16: //! This means that inserting a new element into a flat_map invalidates Chris@16: //! previous iterators and references Chris@16: //! Chris@16: //! Erasing an element invalidates iterators and references Chris@16: //! pointing to elements that come after (their keys are bigger) the erased element. Chris@16: //! Chris@16: //! This container provides random-access iterators. Chris@101: //! Chris@101: //! \tparam Key is the key_type of the map Chris@101: //! \tparam Value is the mapped_type Chris@101: //! \tparam Compare is the ordering function for Keys (e.g. std::less). Chris@101: //! \tparam Allocator is the allocator to allocate the value_types Chris@101: //! (e.g. allocator< std::pair > ). Chris@16: #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@101: template , class Allocator = new_allocator< std::pair< Key, T> > > Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class flat_map Chris@16: { Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: private: Chris@16: BOOST_COPYABLE_AND_MOVABLE(flat_map) Chris@16: //This is the tree that we should store if pair was movable Chris@16: typedef container_detail::flat_tree, Chris@16: container_detail::select1st< std::pair >, Chris@16: Compare, Chris@16: Allocator> tree_t; Chris@16: Chris@16: //This is the real tree stored here. It's based on a movable pair Chris@16: typedef container_detail::flat_tree, Chris@16: container_detail::select1st >, Chris@16: Compare, Chris@16: typename allocator_traits::template portable_rebind_alloc Chris@16: >::type> impl_tree_t; Chris@16: impl_tree_t m_flat_tree; // flat tree representing flat_map Chris@16: Chris@16: typedef typename impl_tree_t::value_type impl_value_type; Chris@16: typedef typename impl_tree_t::const_iterator impl_const_iterator; Chris@101: typedef typename impl_tree_t::iterator impl_iterator; Chris@16: typedef typename impl_tree_t::allocator_type impl_allocator_type; Chris@16: typedef container_detail::flat_tree_value_compare Chris@16: < Compare Chris@16: , container_detail::select1st< std::pair > Chris@16: , std::pair > value_compare_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::iterator iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::const_iterator const_iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::reverse_iterator reverse_iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::const_reverse_iterator const_reverse_iterator_impl; Chris@101: public: Chris@101: typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type; Chris@101: private: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: public: Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // types Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: typedef Key key_type; Chris@16: typedef T mapped_type; Chris@16: typedef std::pair value_type; Chris@101: typedef ::boost::container::allocator_traits allocator_traits_type; Chris@16: typedef typename boost::container::allocator_traits::pointer pointer; Chris@16: typedef typename boost::container::allocator_traits::const_pointer const_pointer; Chris@16: typedef typename boost::container::allocator_traits::reference reference; Chris@16: typedef typename boost::container::allocator_traits::const_reference const_reference; Chris@16: typedef typename boost::container::allocator_traits::size_type size_type; Chris@16: typedef typename boost::container::allocator_traits::difference_type difference_type; Chris@16: typedef Allocator allocator_type; Chris@16: typedef BOOST_CONTAINER_IMPDEF(Allocator) stored_allocator_type; Chris@16: typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare; Chris@16: typedef Compare key_compare; Chris@16: typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type; Chris@16: Chris@16: public: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // construct/copy/destroy Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Default constructs an empty flat_map. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: flat_map() Chris@101: : m_flat_tree() Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_map using the specified Chris@16: //! comparison object and allocator. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: explicit flat_map(const Compare& comp, const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_map using the specified allocator. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: explicit flat_map(const allocator_type& a) Chris@16: : m_flat_tree(container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_map using the specified comparison object and Chris@16: //! allocator, and inserts elements from the range [first ,last ). Chris@16: //! Chris@16: //! Complexity: Linear in N if the range [first ,last ) is already sorted using Chris@16: //! comp and otherwise N logN, where N is last - first. Chris@16: template Chris@16: flat_map(InputIterator first, InputIterator last, const Compare& comp = Compare(), Chris@16: const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(true, first, last, comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_map using the specified Chris@101: //! allocator, and inserts elements from the range [first ,last ). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [first ,last ) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: template Chris@101: flat_map(InputIterator first, InputIterator last, const allocator_type& a) Chris@101: : m_flat_tree(true, first, last, Compare(), container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_map using the specified comparison object and Chris@16: //! allocator, and inserts elements from the ordered unique range [first ,last). This function Chris@16: //! is more efficient than the normal range creation for ordered ranges. Chris@16: //! Chris@16: //! Requires: [first ,last) must be ordered according to the predicate and must be Chris@16: //! unique values. Chris@16: //! Chris@16: //! Complexity: Linear in N. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@16: template Chris@16: flat_map( ordered_unique_range_t, InputIterator first, InputIterator last Chris@16: , const Compare& comp = Compare(), const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(ordered_range, first, last, comp, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: Constructs an empty flat_map using the specified comparison object and Chris@101: //! allocator, and inserts elements from the range [il.begin() ,il.end()). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [il.begin(), il.end()) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: flat_map(std::initializer_list il, const Compare& comp = Compare(), Chris@101: const allocator_type& a = allocator_type()) Chris@101: : m_flat_tree(true, il.begin(), il.end(), comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_map using the specified Chris@101: //! allocator, and inserts elements from the range [il.begin() ,il.end()). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [il.begin(), il.end()) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: flat_map(std::initializer_list il, const allocator_type& a) Chris@101: : m_flat_tree(true, il.begin(), il.end(), Compare(), container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_map using the specified comparison object and Chris@101: //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function Chris@101: //! is more efficient than the normal range creation for ordered ranges. Chris@101: //! Chris@101: //! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be Chris@101: //! unique values. Chris@101: //! Chris@101: //! Complexity: Linear in N. Chris@101: //! Chris@101: //! Note: Non-standard extension. Chris@101: flat_map(ordered_unique_range_t, std::initializer_list il, const Compare& comp = Compare(), Chris@101: const allocator_type& a = allocator_type()) Chris@101: : m_flat_tree(ordered_range, il.begin(), il.end(), comp, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: #endif Chris@16: Chris@16: //! Effects: Copy constructs a flat_map. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_map(const flat_map& x) Chris@101: : m_flat_tree(x.m_flat_tree) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Move constructs a flat_map. Chris@16: //! Constructs *this using x's resources. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Postcondition: x is emptied. Chris@16: flat_map(BOOST_RV_REF(flat_map) x) Chris@16: : m_flat_tree(boost::move(x.m_flat_tree)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Copy constructs a flat_map using the specified allocator. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_map(const flat_map& x, const allocator_type &a) Chris@16: : m_flat_tree(x.m_flat_tree, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Move constructs a flat_map using the specified allocator. Chris@16: //! Constructs *this using x's resources. Chris@16: //! Chris@16: //! Complexity: Constant if x.get_allocator() == a, linear otherwise. Chris@16: flat_map(BOOST_RV_REF(flat_map) x, const allocator_type &a) Chris@16: : m_flat_tree(boost::move(x.m_flat_tree), a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Makes *this a copy of x. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_map& operator=(BOOST_COPY_ASSIGN_REF(flat_map) x) Chris@16: { m_flat_tree = x.m_flat_tree; return *this; } Chris@16: Chris@16: //! Effects: Move constructs a flat_map. Chris@16: //! Constructs *this using x's resources. Chris@16: //! Chris@101: //! Throws: If allocator_traits_type::propagate_on_container_move_assignment Chris@101: //! is false and (allocation throws or value_type's move constructor throws) Chris@16: //! Chris@101: //! Complexity: Constant if allocator_traits_type:: Chris@101: //! propagate_on_container_move_assignment is true or Chris@101: //! this->get>allocator() == x.get_allocator(). Linear otherwise. Chris@101: flat_map& operator=(BOOST_RV_REF(flat_map) x) Chris@101: BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value Chris@101: && boost::container::container_detail::is_nothrow_move_assignable::value ) Chris@101: { m_flat_tree = boost::move(x.m_flat_tree); return *this; } Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: Assign elements from il to *this Chris@101: flat_map& operator=(std::initializer_list il) Chris@101: { Chris@101: this->clear(); Chris@101: this->insert(il.begin(), il.end()); Chris@101: return *this; Chris@101: } Chris@101: #endif Chris@101: Chris@101: //! Effects: Returns a copy of the allocator that Chris@16: //! was passed to the object's constructor. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.get_allocator()); } Chris@16: Chris@16: //! Effects: Returns a reference to the internal allocator. Chris@16: //! Chris@16: //! Throws: Nothing Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@101: stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force(m_flat_tree.get_stored_allocator()); } Chris@16: Chris@16: //! Effects: Returns a reference to the internal allocator. Chris@16: //! Chris@16: //! Throws: Nothing Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@101: const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force(m_flat_tree.get_stored_allocator()); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // iterators Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns an iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: iterator begin() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.begin()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.begin()); } Chris@16: Chris@16: //! Effects: Returns an iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: iterator end() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.end()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.end()); } Chris@16: Chris@16: //! Effects: Returns a reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rbegin()); } Chris@16: Chris@16: //! Effects: Returns a reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rend()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rend()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.cbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.cend()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.crbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.crend()); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // capacity Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns true if the container contains no elements. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: bool empty() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.empty(); } Chris@16: Chris@16: //! Effects: Returns the number of the elements contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type size() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.size(); } Chris@16: Chris@16: //! Effects: Returns the largest possible size of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.max_size(); } Chris@16: Chris@16: //! Effects: Number of elements for which memory has been allocated. Chris@16: //! capacity() is always greater than or equal to size(). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.capacity(); } Chris@16: Chris@16: //! Effects: If n is less than or equal to capacity(), this call has no Chris@16: //! effect. Otherwise, it is a request for allocation of additional memory. Chris@16: //! If the request is successful, then capacity() is greater than or equal to Chris@16: //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. Chris@16: //! Chris@16: //! Throws: If memory allocation allocation throws or T's copy constructor throws. Chris@16: //! Chris@16: //! Note: If capacity() is less than "cnt", iterators and references to Chris@16: //! to values might be invalidated. Chris@101: void reserve(size_type cnt) Chris@16: { m_flat_tree.reserve(cnt); } Chris@16: Chris@16: //! Effects: Tries to deallocate the excess of memory created Chris@16: // with previous allocations. The size of the vector is unchanged Chris@16: //! Chris@16: //! Throws: If memory allocation throws, or T's copy constructor throws. Chris@16: //! Chris@16: //! Complexity: Linear to size(). Chris@16: void shrink_to_fit() Chris@16: { m_flat_tree.shrink_to_fit(); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // element access Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: //! Effects: If there is no key equivalent to x in the flat_map, inserts Chris@16: //! value_type(x, T()) into the flat_map. Chris@16: //! Chris@101: //! Returns: A reference to the mapped_type corresponding to x in *this. Chris@16: //! Chris@16: //! Complexity: Logarithmic. Chris@16: mapped_type &operator[](const key_type& k); Chris@16: Chris@16: //! Effects: If there is no key equivalent to x in the flat_map, inserts Chris@16: //! value_type(move(x), T()) into the flat_map (the key is move-constructed) Chris@16: //! Chris@101: //! Returns: A reference to the mapped_type corresponding to x in *this. Chris@16: //! Chris@16: //! Complexity: Logarithmic. Chris@16: mapped_type &operator[](key_type &&k) ; Chris@16: Chris@16: #else Chris@16: BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript) Chris@16: #endif Chris@16: Chris@101: //! @copydoc ::boost::container::flat_set::nth(size_type) Chris@101: iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return container_detail::force_copy(m_flat_tree.nth(n)); } Chris@101: Chris@101: //! @copydoc ::boost::container::flat_set::nth(size_type) const Chris@101: const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return container_detail::force_copy(m_flat_tree.nth(n)); } Chris@101: Chris@101: //! @copydoc ::boost::container::flat_set::index_of(iterator) Chris@101: size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return m_flat_tree.index_of(container_detail::force_copy(p)); } Chris@101: Chris@101: //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const Chris@101: size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return m_flat_tree.index_of(container_detail::force_copy(p)); } Chris@101: Chris@101: //! Returns: A reference to the element whose key is equivalent to x. Chris@16: //! Chris@16: //! Throws: An exception object of type out_of_range if no such element is present. Chris@16: //! Chris@16: //! Complexity: logarithmic. Chris@16: T& at(const key_type& k) Chris@16: { Chris@16: iterator i = this->find(k); Chris@16: if(i == this->end()){ Chris@16: throw_out_of_range("flat_map::at key not found"); Chris@16: } Chris@16: return i->second; Chris@16: } Chris@16: Chris@101: //! Returns: A reference to the element whose key is equivalent to x. Chris@16: //! Chris@16: //! Throws: An exception object of type out_of_range if no such element is present. Chris@16: //! Chris@16: //! Complexity: logarithmic. Chris@16: const T& at(const key_type& k) const Chris@16: { Chris@16: const_iterator i = this->find(k); Chris@16: if(i == this->end()){ Chris@16: throw_out_of_range("flat_map::at key not found"); Chris@16: } Chris@16: return i->second; Chris@16: } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // modifiers Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: Chris@16: //! Effects: Inserts an object x of type T constructed with Chris@16: //! std::forward(args)... if and only if there is no element in the container Chris@16: //! with key equivalent to the key of x. Chris@16: //! Chris@16: //! Returns: The bool component of the returned pair is true if and only Chris@16: //! if the insertion takes place, and the iterator component of the pair Chris@16: //! points to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@101: std::pair emplace(BOOST_FWD_REF(Args)... args) Chris@16: { return container_detail::force_copy< std::pair >(m_flat_tree.emplace_unique(boost::forward(args)...)); } Chris@16: Chris@16: //! Effects: Inserts an object of type T constructed with Chris@16: //! std::forward(args)... in the container if and only if there is Chris@16: //! no element in the container with key equivalent to the key of x. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant if x is inserted Chris@16: //! right before p) plus insertion linear to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@101: iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) Chris@16: { Chris@16: return container_detail::force_copy Chris@16: (m_flat_tree.emplace_hint_unique( container_detail::force_copy(hint) Chris@16: , boost::forward(args)...)); Chris@16: } Chris@16: Chris@101: #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@101: #define BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE(N) \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: std::pair emplace(BOOST_MOVE_UREF##N)\ Chris@101: {\ Chris@101: return container_detail::force_copy< std::pair >\ Chris@101: (m_flat_tree.emplace_unique(BOOST_MOVE_FWD##N));\ Chris@101: }\ Chris@101: \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ Chris@101: {\ Chris@101: return container_detail::force_copy(m_flat_tree.emplace_hint_unique\ Chris@101: (container_detail::force_copy(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\ Chris@101: }\ Chris@101: // Chris@101: BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE) Chris@101: #undef BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE Chris@16: Chris@101: #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@16: //! Effects: Inserts x if and only if there is no element in the container Chris@16: //! with key equivalent to the key of x. Chris@16: //! Chris@16: //! Returns: The bool component of the returned pair is true if and only Chris@16: //! if the insertion takes place, and the iterator component of the pair Chris@16: //! points to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: std::pair insert(const value_type& x) Chris@101: { return container_detail::force_copy >( Chris@16: m_flat_tree.insert_unique(container_detail::force(x))); } Chris@16: Chris@16: //! Effects: Inserts a new value_type move constructed from the pair if and Chris@16: //! only if there is no element in the container with key equivalent to the key of x. Chris@16: //! Chris@16: //! Returns: The bool component of the returned pair is true if and only Chris@16: //! if the insertion takes place, and the iterator component of the pair Chris@16: //! points to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: std::pair insert(BOOST_RV_REF(value_type) x) Chris@16: { return container_detail::force_copy >( Chris@16: m_flat_tree.insert_unique(boost::move(container_detail::force(x)))); } Chris@16: Chris@16: //! Effects: Inserts a new value_type move constructed from the pair if and Chris@16: //! only if there is no element in the container with key equivalent to the key of x. Chris@16: //! Chris@16: //! Returns: The bool component of the returned pair is true if and only Chris@16: //! if the insertion takes place, and the iterator component of the pair Chris@16: //! points to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: std::pair insert(BOOST_RV_REF(movable_value_type) x) Chris@16: { Chris@16: return container_detail::force_copy > Chris@16: (m_flat_tree.insert_unique(boost::move(x))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts a copy of x in the container if and only if there is Chris@16: //! no element in the container with key equivalent to the key of x. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant if x is inserted Chris@16: //! right before p) plus insertion linear to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, const value_type& x) Chris@16: { Chris@16: return container_detail::force_copy( Chris@101: m_flat_tree.insert_unique( container_detail::force_copy(p) Chris@16: , container_detail::force(x))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts an element move constructed from x in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant if x is inserted Chris@16: //! right before p) plus insertion linear to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, BOOST_RV_REF(value_type) x) Chris@16: { Chris@16: return container_detail::force_copy Chris@101: (m_flat_tree.insert_unique( container_detail::force_copy(p) Chris@16: , boost::move(container_detail::force(x)))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts an element move constructed from x in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant if x is inserted Chris@16: //! right before p) plus insertion linear to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x) Chris@16: { Chris@16: return container_detail::force_copy( Chris@101: m_flat_tree.insert_unique(container_detail::force_copy(p), boost::move(x))); Chris@16: } Chris@16: Chris@16: //! Requires: first, last are not iterators into *this. Chris@16: //! Chris@16: //! Effects: inserts each element from the range [first,last) if and only Chris@16: //! if there is no element with key equivalent to the key of that element. Chris@16: //! Chris@16: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@16: //! search time plus N*size() insertion time. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@16: void insert(InputIterator first, InputIterator last) Chris@16: { m_flat_tree.insert_unique(first, last); } Chris@16: Chris@16: //! Requires: first, last are not iterators into *this. Chris@16: //! Chris@16: //! Requires: [first ,last) must be ordered according to the predicate and must be Chris@16: //! unique values. Chris@16: //! Chris@16: //! Effects: inserts each element from the range [first,last) if and only Chris@16: //! if there is no element with key equivalent to the key of that element. This Chris@16: //! function is more efficient than the normal range creation for ordered ranges. Chris@16: //! Chris@16: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@16: //! search time plus N*size() insertion time. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@16: template Chris@16: void insert(ordered_unique_range_t, InputIterator first, InputIterator last) Chris@16: { m_flat_tree.insert_unique(ordered_unique_range, first, last); } Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: inserts each element from the range [il.begin(), il.end()) if and only Chris@101: //! if there is no element with key equivalent to the key of that element. Chris@101: //! Chris@101: //! Complexity: At most N log(size()+N) (N is the distance from il.first() to il.end()) Chris@101: //! search time plus N*size() insertion time. Chris@101: //! Chris@101: //! Note: If an element is inserted it might invalidate elements. Chris@101: void insert(std::initializer_list il) Chris@101: { m_flat_tree.insert_unique(il.begin(), il.end()); } Chris@101: Chris@101: //! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be Chris@101: //! unique values. Chris@101: //! Chris@101: //! Effects: inserts each element from the range [il.begin(), il.end()) if and only Chris@101: //! if there is no element with key equivalent to the key of that element. This Chris@101: //! function is more efficient than the normal range creation for ordered ranges. Chris@101: //! Chris@101: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@101: //! search time plus N*size() insertion time. Chris@101: //! Chris@101: //! Note: If an element is inserted it might invalidate elements. Chris@101: //! Chris@101: //! Note: Non-standard extension. Chris@101: void insert(ordered_unique_range_t, std::initializer_list il) Chris@101: { m_flat_tree.insert_unique(ordered_unique_range, il.begin(), il.end()); } Chris@101: #endif Chris@101: Chris@101: //! Effects: Erases the element pointed to by p. Chris@16: //! Chris@16: //! Returns: Returns an iterator pointing to the element immediately Chris@16: //! following q prior to the element being erased. If no such element exists, Chris@16: //! returns end(). Chris@16: //! Chris@101: //! Complexity: Linear to the elements with keys bigger than p Chris@16: //! Chris@16: //! Note: Invalidates elements with keys Chris@16: //! not less than the erased element. Chris@101: iterator erase(const_iterator p) Chris@16: { Chris@16: return container_detail::force_copy Chris@101: (m_flat_tree.erase(container_detail::force_copy(p))); Chris@16: } Chris@16: Chris@16: //! Effects: Erases all elements in the container with key equivalent to x. Chris@16: //! Chris@16: //! Returns: Returns the number of erased elements. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus erasure time Chris@16: //! linear to the elements with bigger keys. Chris@16: size_type erase(const key_type& x) Chris@16: { return m_flat_tree.erase(x); } Chris@16: Chris@16: //! Effects: Erases all the elements in the range [first, last). Chris@16: //! Chris@16: //! Returns: Returns last. Chris@16: //! Chris@16: //! Complexity: size()*N where N is the distance from first to last. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus erasure time Chris@16: //! linear to the elements with bigger keys. Chris@16: iterator erase(const_iterator first, const_iterator last) Chris@16: { Chris@16: return container_detail::force_copy( Chris@16: m_flat_tree.erase( container_detail::force_copy(first) Chris@16: , container_detail::force_copy(last))); Chris@16: } Chris@16: Chris@16: //! Effects: Swaps the contents of *this and x. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: void swap(flat_map& x) Chris@101: BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value Chris@101: && boost::container::container_detail::is_nothrow_swappable::value ) Chris@16: { m_flat_tree.swap(x.m_flat_tree); } Chris@16: Chris@16: //! Effects: erase(a.begin(),a.end()). Chris@16: //! Chris@16: //! Postcondition: size() == 0. Chris@16: //! Chris@16: //! Complexity: linear in size(). Chris@101: void clear() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { m_flat_tree.clear(); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // observers Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns the comparison object out Chris@16: //! of which a was constructed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: key_compare key_comp() const Chris@16: { return container_detail::force_copy(m_flat_tree.key_comp()); } Chris@16: Chris@16: //! Effects: Returns an object of value_compare constructed out Chris@16: //! of the comparison object. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: value_compare value_comp() const Chris@16: { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // map operations Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Returns: An iterator pointing to an element with the key Chris@16: //! equivalent to x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic. Chris@16: iterator find(const key_type& x) Chris@16: { return container_detail::force_copy(m_flat_tree.find(x)); } Chris@16: Chris@101: //! Returns: A const_iterator pointing to an element with the key Chris@16: //! equivalent to x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic.s Chris@16: const_iterator find(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.find(x)); } Chris@16: Chris@16: //! Returns: The number of elements with key equivalent to x. Chris@16: //! Chris@16: //! Complexity: log(size())+count(k) Chris@16: size_type count(const key_type& x) const Chris@16: { return static_cast(m_flat_tree.find(x) != m_flat_tree.end()); } Chris@16: Chris@16: //! Returns: An iterator pointing to the first element with key not less Chris@16: //! than k, or a.end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: iterator lower_bound(const key_type& x) Chris@16: { return container_detail::force_copy(m_flat_tree.lower_bound(x)); } Chris@16: Chris@101: //! Returns: A const iterator pointing to the first element with key not Chris@16: //! less than k, or a.end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: const_iterator lower_bound(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.lower_bound(x)); } Chris@16: Chris@16: //! Returns: An iterator pointing to the first element with key not less Chris@16: //! than x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: iterator upper_bound(const key_type& x) Chris@16: { return container_detail::force_copy(m_flat_tree.upper_bound(x)); } Chris@16: Chris@101: //! Returns: A const iterator pointing to the first element with key not Chris@16: //! less than x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: const_iterator upper_bound(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.upper_bound(x)); } Chris@16: Chris@16: //! Effects: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: std::pair equal_range(const key_type& x) Chris@101: { return container_detail::force_copy >(m_flat_tree.lower_bound_range(x)); } Chris@16: Chris@16: //! Effects: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: std::pair equal_range(const key_type& x) const Chris@101: { return container_detail::force_copy >(m_flat_tree.lower_bound_range(x)); } Chris@16: Chris@101: //! Effects: Returns true if x and y are equal Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator==(const flat_map& x, const flat_map& y) Chris@101: { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } Chris@16: Chris@101: //! Effects: Returns true if x and y are unequal Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator!=(const flat_map& x, const flat_map& y) Chris@101: { return !(x == y); } Chris@101: Chris@101: //! Effects: Returns true if x is less than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator<(const flat_map& x, const flat_map& y) Chris@101: { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } Chris@101: Chris@101: //! Effects: Returns true if x is greater than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator>(const flat_map& x, const flat_map& y) Chris@101: { return y < x; } Chris@101: Chris@101: //! Effects: Returns true if x is equal or less than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator<=(const flat_map& x, const flat_map& y) Chris@101: { return !(y < x); } Chris@101: Chris@101: //! Effects: Returns true if x is equal or greater than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator>=(const flat_map& x, const flat_map& y) Chris@101: { return !(x < y); } Chris@101: Chris@101: //! Effects: x.swap(y) Chris@101: //! Chris@101: //! Complexity: Constant. Chris@101: friend void swap(flat_map& x, flat_map& y) Chris@101: { x.swap(y); } Chris@101: Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: private: Chris@16: mapped_type &priv_subscript(const key_type& k) Chris@16: { Chris@16: iterator i = lower_bound(k); Chris@16: // i->first is greater than or equivalent to k. Chris@16: if (i == end() || key_comp()(k, (*i).first)){ Chris@16: container_detail::value_init m; Chris@16: i = insert(i, impl_value_type(k, ::boost::move(m.m_t))); Chris@16: } Chris@16: return (*i).second; Chris@16: } Chris@16: mapped_type &priv_subscript(BOOST_RV_REF(key_type) mk) Chris@16: { Chris@16: key_type &k = mk; Chris@16: iterator i = lower_bound(k); Chris@16: // i->first is greater than or equivalent to k. Chris@16: if (i == end() || key_comp()(k, (*i).first)){ Chris@16: container_detail::value_init m; Chris@16: i = insert(i, impl_value_type(boost::move(k), ::boost::move(m.m_t))); Chris@16: } Chris@16: return (*i).second; Chris@16: } Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: }; Chris@16: Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: } //namespace container { Chris@16: Chris@16: //!has_trivial_destructor_after_move<> == true_type Chris@16: //!specialization for optimizations Chris@101: template Chris@101: struct has_trivial_destructor_after_move > Chris@16: { Chris@101: typedef typename ::boost::container::allocator_traits::pointer pointer; Chris@101: static const bool value = ::boost::has_trivial_destructor_after_move::value && Chris@101: ::boost::has_trivial_destructor_after_move::value && Chris@101: ::boost::has_trivial_destructor_after_move::value; Chris@16: }; Chris@16: Chris@16: namespace container { Chris@16: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: //! A flat_multimap is a kind of associative container that supports equivalent keys Chris@16: //! (possibly containing multiple copies of the same key value) and provides for Chris@16: //! fast retrieval of values of another type T based on the keys. The flat_multimap Chris@16: //! class supports random-access iterators. Chris@16: //! Chris@16: //! A flat_multimap satisfies all of the requirements of a container and of a reversible Chris@16: //! container and of an associative container. For a Chris@16: //! flat_multimap the key_type is Key and the value_type is std::pair Chris@16: //! (unlike std::multimap which value_type is std::pair<const Key, T>). Chris@16: //! Chris@16: //! Compare is the ordering function for Keys (e.g. std::less). Chris@16: //! Chris@16: //! Allocator is the allocator to allocate the value_types Chris@16: //! (e.g. allocator< std::pair >). Chris@16: //! Chris@16: //! flat_multimap is similar to std::multimap but it's implemented like an ordered vector. Chris@16: //! This means that inserting a new element into a flat_map invalidates Chris@16: //! previous iterators and references Chris@16: //! Chris@16: //! Erasing an element invalidates iterators and references Chris@16: //! pointing to elements that come after (their keys are bigger) the erased element. Chris@16: //! Chris@16: //! This container provides random-access iterators. Chris@101: //! Chris@101: //! \tparam Key is the key_type of the map Chris@101: //! \tparam Value is the mapped_type Chris@101: //! \tparam Compare is the ordering function for Keys (e.g. std::less). Chris@101: //! \tparam Allocator is the allocator to allocate the value_types Chris@101: //! (e.g. allocator< std::pair > ). Chris@16: #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@101: template , class Allocator = new_allocator< std::pair< Key, T> > > Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class flat_multimap Chris@16: { Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: private: Chris@16: BOOST_COPYABLE_AND_MOVABLE(flat_multimap) Chris@16: typedef container_detail::flat_tree, Chris@16: container_detail::select1st< std::pair >, Chris@16: Compare, Chris@16: Allocator> tree_t; Chris@16: //This is the real tree stored here. It's based on a movable pair Chris@16: typedef container_detail::flat_tree, Chris@16: container_detail::select1st >, Chris@16: Compare, Chris@16: typename allocator_traits::template portable_rebind_alloc Chris@16: >::type> impl_tree_t; Chris@16: impl_tree_t m_flat_tree; // flat tree representing flat_map Chris@16: Chris@16: typedef typename impl_tree_t::value_type impl_value_type; Chris@16: typedef typename impl_tree_t::const_iterator impl_const_iterator; Chris@101: typedef typename impl_tree_t::iterator impl_iterator; Chris@16: typedef typename impl_tree_t::allocator_type impl_allocator_type; Chris@16: typedef container_detail::flat_tree_value_compare Chris@16: < Compare Chris@16: , container_detail::select1st< std::pair > Chris@16: , std::pair > value_compare_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::iterator iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::const_iterator const_iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::reverse_iterator reverse_iterator_impl; Chris@16: typedef typename container_detail::get_flat_tree_iterators Chris@16: ::pointer>::const_reverse_iterator const_reverse_iterator_impl; Chris@101: public: Chris@101: typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type; Chris@101: private: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: public: Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // types Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: typedef Key key_type; Chris@16: typedef T mapped_type; Chris@16: typedef std::pair value_type; Chris@101: typedef ::boost::container::allocator_traits allocator_traits_type; Chris@16: typedef typename boost::container::allocator_traits::pointer pointer; Chris@16: typedef typename boost::container::allocator_traits::const_pointer const_pointer; Chris@16: typedef typename boost::container::allocator_traits::reference reference; Chris@16: typedef typename boost::container::allocator_traits::const_reference const_reference; Chris@16: typedef typename boost::container::allocator_traits::size_type size_type; Chris@16: typedef typename boost::container::allocator_traits::difference_type difference_type; Chris@16: typedef Allocator allocator_type; Chris@16: typedef BOOST_CONTAINER_IMPDEF(Allocator) stored_allocator_type; Chris@16: typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare; Chris@16: typedef Compare key_compare; Chris@16: typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(reverse_iterator_impl) reverse_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(const_reverse_iterator_impl) const_reverse_iterator; Chris@16: typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type; Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // construct/copy/destroy Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Default constructs an empty flat_map. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: flat_multimap() Chris@101: : m_flat_tree() Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_multimap using the specified comparison Chris@16: //! object and allocator. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: explicit flat_multimap(const Compare& comp, Chris@16: const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_multimap using the specified allocator. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: explicit flat_multimap(const allocator_type& a) Chris@16: : m_flat_tree(container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_multimap using the specified comparison object Chris@16: //! and allocator, and inserts elements from the range [first ,last ). Chris@16: //! Chris@16: //! Complexity: Linear in N if the range [first ,last ) is already sorted using Chris@16: //! comp and otherwise N logN, where N is last - first. Chris@16: template Chris@16: flat_multimap(InputIterator first, InputIterator last, Chris@16: const Compare& comp = Compare(), Chris@16: const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(false, first, last, comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_multimap using the specified Chris@101: //! allocator, and inserts elements from the range [first ,last ). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [first ,last ) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: template Chris@101: flat_multimap(InputIterator first, InputIterator last, const allocator_type& a) Chris@101: : m_flat_tree(false, first, last, Compare(), container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Constructs an empty flat_multimap using the specified comparison object and Chris@16: //! allocator, and inserts elements from the ordered range [first ,last). This function Chris@16: //! is more efficient than the normal range creation for ordered ranges. Chris@16: //! Chris@16: //! Requires: [first ,last) must be ordered according to the predicate. Chris@16: //! Chris@16: //! Complexity: Linear in N. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@16: template Chris@16: flat_multimap(ordered_range_t, InputIterator first, InputIterator last, Chris@16: const Compare& comp = Compare(), Chris@16: const allocator_type& a = allocator_type()) Chris@16: : m_flat_tree(ordered_range, first, last, comp, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: Constructs an empty flat_map using the specified comparison object and Chris@101: //! allocator, and inserts elements from the range [il.begin(), il.end()). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [il.begin(), il.end()) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: flat_multimap(std::initializer_list il, const Compare& comp = Compare(), const allocator_type& a = allocator_type()) Chris@101: : m_flat_tree(false, il.begin(), il.end(), comp, container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_map using the specified Chris@101: //! allocator, and inserts elements from the range [il.begin(), il.end()). Chris@101: //! Chris@101: //! Complexity: Linear in N if the range [il.begin(), il.end()) is already sorted using Chris@101: //! comp and otherwise N logN, where N is last - first. Chris@101: flat_multimap(std::initializer_list il, const allocator_type& a) Chris@101: : m_flat_tree(false, il.begin(), il.end(), Compare(), container_detail::force(a)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: Chris@101: //! Effects: Constructs an empty flat_multimap using the specified comparison object and Chris@101: //! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function Chris@101: //! is more efficient than the normal range creation for ordered ranges. Chris@101: //! Chris@101: //! Requires: [il.begin(), il.end()) must be ordered according to the predicate. Chris@101: //! Chris@101: //! Complexity: Linear in N. Chris@101: //! Chris@101: //! Note: Non-standard extension. Chris@101: flat_multimap(ordered_range_t, std::initializer_list il, const Compare& comp = Compare(), Chris@101: const allocator_type& a = allocator_type()) Chris@101: : m_flat_tree(ordered_range, il.begin(), il.end(), comp, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@101: #endif Chris@16: Chris@16: //! Effects: Copy constructs a flat_multimap. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_multimap(const flat_multimap& x) Chris@101: : m_flat_tree(x.m_flat_tree) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Move constructs a flat_multimap. Constructs *this using x's resources. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Postcondition: x is emptied. Chris@16: flat_multimap(BOOST_RV_REF(flat_multimap) x) Chris@16: : m_flat_tree(boost::move(x.m_flat_tree)) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Copy constructs a flat_multimap using the specified allocator. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_multimap(const flat_multimap& x, const allocator_type &a) Chris@16: : m_flat_tree(x.m_flat_tree, a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Move constructs a flat_multimap using the specified allocator. Chris@16: //! Constructs *this using x's resources. Chris@16: //! Chris@16: //! Complexity: Constant if a == x.get_allocator(), linear otherwise. Chris@16: flat_multimap(BOOST_RV_REF(flat_multimap) x, const allocator_type &a) Chris@16: : m_flat_tree(boost::move(x.m_flat_tree), a) Chris@101: { Chris@101: //A type must be std::pair Chris@101: BOOST_STATIC_ASSERT((container_detail::is_same, typename Allocator::value_type>::value)); Chris@101: } Chris@16: Chris@16: //! Effects: Makes *this a copy of x. Chris@16: //! Chris@16: //! Complexity: Linear in x.size(). Chris@16: flat_multimap& operator=(BOOST_COPY_ASSIGN_REF(flat_multimap) x) Chris@16: { m_flat_tree = x.m_flat_tree; return *this; } Chris@16: Chris@16: //! Effects: this->swap(x.get()). Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: flat_multimap& operator=(BOOST_RV_REF(flat_multimap) x) Chris@101: BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value Chris@101: && boost::container::container_detail::is_nothrow_move_assignable::value ) Chris@101: { m_flat_tree = boost::move(x.m_flat_tree); return *this; } Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: Assign content of il to *this Chris@101: //! Chris@101: //! Complexity: Linear in il.size(). Chris@101: flat_multimap& operator=(std::initializer_list il) Chris@101: { Chris@101: this->clear(); Chris@101: this->insert(il.begin(), il.end()); Chris@101: return *this; Chris@101: } Chris@101: #endif Chris@101: Chris@101: //! Effects: Returns a copy of the allocator that Chris@16: //! was passed to the object's constructor. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.get_allocator()); } Chris@16: Chris@16: //! Effects: Returns a reference to the internal allocator. Chris@16: //! Chris@16: //! Throws: Nothing Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@101: stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force(m_flat_tree.get_stored_allocator()); } Chris@16: Chris@16: //! Effects: Returns a reference to the internal allocator. Chris@16: //! Chris@16: //! Throws: Nothing Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@101: const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force(m_flat_tree.get_stored_allocator()); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // iterators Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns an iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: iterator begin() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.begin()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.begin()); } Chris@16: Chris@16: //! Effects: Returns an iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: iterator end() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.end()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.end()); } Chris@16: Chris@16: //! Effects: Returns a reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rbegin()); } Chris@16: Chris@16: //! Effects: Returns a reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rend()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.rend()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the first element contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.cbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_iterator to the end of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.cend()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the beginning Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.crbegin()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the end Chris@16: //! of the reversed container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return container_detail::force_copy(m_flat_tree.crend()); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // capacity Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns true if the container contains no elements. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: bool empty() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.empty(); } Chris@16: Chris@16: //! Effects: Returns the number of the elements contained in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type size() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.size(); } Chris@16: Chris@16: //! Effects: Returns the largest possible size of the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.max_size(); } Chris@16: Chris@16: //! Effects: Number of elements for which memory has been allocated. Chris@16: //! capacity() is always greater than or equal to size(). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@101: size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { return m_flat_tree.capacity(); } Chris@16: Chris@16: //! Effects: If n is less than or equal to capacity(), this call has no Chris@16: //! effect. Otherwise, it is a request for allocation of additional memory. Chris@16: //! If the request is successful, then capacity() is greater than or equal to Chris@16: //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged. Chris@16: //! Chris@16: //! Throws: If memory allocation allocation throws or T's copy constructor throws. Chris@16: //! Chris@16: //! Note: If capacity() is less than "cnt", iterators and references to Chris@16: //! to values might be invalidated. Chris@101: void reserve(size_type cnt) Chris@16: { m_flat_tree.reserve(cnt); } Chris@16: Chris@16: //! Effects: Tries to deallocate the excess of memory created Chris@16: // with previous allocations. The size of the vector is unchanged Chris@16: //! Chris@16: //! Throws: If memory allocation throws, or T's copy constructor throws. Chris@16: //! Chris@16: //! Complexity: Linear to size(). Chris@16: void shrink_to_fit() Chris@16: { m_flat_tree.shrink_to_fit(); } Chris@16: Chris@101: //! @copydoc ::boost::container::flat_set::nth(size_type) Chris@101: iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return container_detail::force_copy(m_flat_tree.nth(n)); } Chris@16: Chris@101: //! @copydoc ::boost::container::flat_set::nth(size_type) const Chris@101: const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return container_detail::force_copy(m_flat_tree.nth(n)); } Chris@101: Chris@101: //! @copydoc ::boost::container::flat_set::index_of(iterator) Chris@101: size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return m_flat_tree.index_of(container_detail::force_copy(p)); } Chris@101: Chris@101: //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const Chris@101: size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW Chris@101: { return m_flat_tree.index_of(container_detail::force_copy(p)); } Chris@101: Chris@101: #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) Chris@16: Chris@16: //! Effects: Inserts an object of type T constructed with Chris@16: //! std::forward(args)... and returns the iterator pointing to the Chris@16: //! newly inserted element. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@101: iterator emplace(BOOST_FWD_REF(Args)... args) Chris@16: { return container_detail::force_copy(m_flat_tree.emplace_equal(boost::forward(args)...)); } Chris@16: Chris@16: //! Effects: Inserts an object of type T constructed with Chris@16: //! std::forward(args)... in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant time if the value Chris@16: //! is to be inserted before p) plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@101: iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args) Chris@16: { Chris@16: return container_detail::force_copy(m_flat_tree.emplace_hint_equal Chris@16: (container_detail::force_copy(hint), boost::forward(args)...)); Chris@16: } Chris@16: Chris@101: #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@101: #define BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE(N) \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: iterator emplace(BOOST_MOVE_UREF##N)\ Chris@101: { return container_detail::force_copy(m_flat_tree.emplace_equal(BOOST_MOVE_FWD##N)); }\ Chris@101: \ Chris@101: BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ Chris@101: iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ Chris@101: {\ Chris@101: return container_detail::force_copy(m_flat_tree.emplace_hint_equal\ Chris@101: (container_detail::force_copy(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\ Chris@101: }\ Chris@101: // Chris@101: BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE) Chris@101: #undef BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE Chris@16: Chris@101: #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@16: //! Effects: Inserts x and returns the iterator pointing to the Chris@16: //! newly inserted element. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: iterator insert(const value_type& x) Chris@16: { Chris@16: return container_detail::force_copy( Chris@16: m_flat_tree.insert_equal(container_detail::force(x))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts a new value move-constructed from x and returns Chris@16: //! the iterator pointing to the newly inserted element. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: iterator insert(BOOST_RV_REF(value_type) x) Chris@16: { return container_detail::force_copy(m_flat_tree.insert_equal(boost::move(x))); } Chris@16: Chris@16: //! Effects: Inserts a new value move-constructed from x and returns Chris@16: //! the iterator pointing to the newly inserted element. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: iterator insert(BOOST_RV_REF(impl_value_type) x) Chris@16: { return container_detail::force_copy(m_flat_tree.insert_equal(boost::move(x))); } Chris@16: Chris@16: //! Effects: Inserts a copy of x in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant time if the value Chris@16: //! is to be inserted before p) plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, const value_type& x) Chris@16: { Chris@16: return container_detail::force_copy Chris@101: (m_flat_tree.insert_equal( container_detail::force_copy(p) Chris@16: , container_detail::force(x))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts a value move constructed from x in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant time if the value Chris@16: //! is to be inserted before p) plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, BOOST_RV_REF(value_type) x) Chris@16: { Chris@16: return container_detail::force_copy Chris@101: (m_flat_tree.insert_equal(container_detail::force_copy(p) Chris@16: , boost::move(x))); Chris@16: } Chris@16: Chris@16: //! Effects: Inserts a value move constructed from x in the container. Chris@16: //! p is a hint pointing to where the insert should start to search. Chris@16: //! Chris@16: //! Returns: An iterator pointing to the element with key equivalent Chris@16: //! to the key of x. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time (constant time if the value Chris@16: //! is to be inserted before p) plus linear insertion Chris@16: //! to the elements with bigger keys than x. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@101: iterator insert(const_iterator p, BOOST_RV_REF(impl_value_type) x) Chris@16: { Chris@16: return container_detail::force_copy( Chris@101: m_flat_tree.insert_equal(container_detail::force_copy(p), boost::move(x))); Chris@16: } Chris@16: Chris@16: //! Requires: first, last are not iterators into *this. Chris@16: //! Chris@16: //! Effects: inserts each element from the range [first,last) . Chris@16: //! Chris@16: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@16: //! search time plus N*size() insertion time. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: template Chris@16: void insert(InputIterator first, InputIterator last) Chris@16: { m_flat_tree.insert_equal(first, last); } Chris@16: Chris@16: //! Requires: first, last are not iterators into *this. Chris@16: //! Chris@16: //! Requires: [first ,last) must be ordered according to the predicate. Chris@16: //! Chris@16: //! Effects: inserts each element from the range [first,last) if and only Chris@16: //! if there is no element with key equivalent to the key of that element. This Chris@16: //! function is more efficient than the normal range creation for ordered ranges. Chris@16: //! Chris@16: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@16: //! search time plus N*size() insertion time. Chris@16: //! Chris@16: //! Note: If an element is inserted it might invalidate elements. Chris@16: //! Chris@16: //! Note: Non-standard extension. Chris@16: template Chris@16: void insert(ordered_range_t, InputIterator first, InputIterator last) Chris@16: { m_flat_tree.insert_equal(ordered_range, first, last); } Chris@16: Chris@101: #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) Chris@101: //! Effects: inserts each element from the range [il.begin(), il.end()) . Chris@101: //! Chris@101: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@101: //! search time plus N*size() insertion time. Chris@101: //! Chris@101: //! Note: If an element is inserted it might invalidate elements. Chris@101: void insert(std::initializer_list il) Chris@101: { m_flat_tree.insert_equal(il.begin(), il.end()); } Chris@101: Chris@101: //! Requires: [il.begin(), il.end()) must be ordered according to the predicate. Chris@101: //! Chris@101: //! Effects: inserts each element from the range [il.begin(), il.end()) if and only Chris@101: //! if there is no element with key equivalent to the key of that element. This Chris@101: //! function is more efficient than the normal range creation for ordered ranges. Chris@101: //! Chris@101: //! Complexity: At most N log(size()+N) (N is the distance from first to last) Chris@101: //! search time plus N*size() insertion time. Chris@101: //! Chris@101: //! Note: If an element is inserted it might invalidate elements. Chris@101: //! Chris@101: //! Note: Non-standard extension. Chris@101: void insert(ordered_range_t, std::initializer_list il) Chris@101: { m_flat_tree.insert_equal(ordered_range, il.begin(), il.end()); } Chris@101: #endif Chris@101: Chris@101: //! Effects: Erases the element pointed to by p. Chris@16: //! Chris@16: //! Returns: Returns an iterator pointing to the element immediately Chris@16: //! following q prior to the element being erased. If no such element exists, Chris@16: //! returns end(). Chris@16: //! Chris@101: //! Complexity: Linear to the elements with keys bigger than p Chris@16: //! Chris@16: //! Note: Invalidates elements with keys Chris@16: //! not less than the erased element. Chris@101: iterator erase(const_iterator p) Chris@16: { Chris@16: return container_detail::force_copy( Chris@101: m_flat_tree.erase(container_detail::force_copy(p))); Chris@16: } Chris@16: Chris@16: //! Effects: Erases all elements in the container with key equivalent to x. Chris@16: //! Chris@16: //! Returns: Returns the number of erased elements. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus erasure time Chris@16: //! linear to the elements with bigger keys. Chris@16: size_type erase(const key_type& x) Chris@16: { return m_flat_tree.erase(x); } Chris@16: Chris@16: //! Effects: Erases all the elements in the range [first, last). Chris@16: //! Chris@16: //! Returns: Returns last. Chris@16: //! Chris@16: //! Complexity: size()*N where N is the distance from first to last. Chris@16: //! Chris@16: //! Complexity: Logarithmic search time plus erasure time Chris@16: //! linear to the elements with bigger keys. Chris@16: iterator erase(const_iterator first, const_iterator last) Chris@16: { Chris@16: return container_detail::force_copy Chris@16: (m_flat_tree.erase( container_detail::force_copy(first) Chris@16: , container_detail::force_copy(last))); Chris@16: } Chris@16: Chris@16: //! Effects: Swaps the contents of *this and x. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: void swap(flat_multimap& x) Chris@101: BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value Chris@101: && boost::container::container_detail::is_nothrow_swappable::value ) Chris@16: { m_flat_tree.swap(x.m_flat_tree); } Chris@16: Chris@16: //! Effects: erase(a.begin(),a.end()). Chris@16: //! Chris@16: //! Postcondition: size() == 0. Chris@16: //! Chris@16: //! Complexity: linear in size(). Chris@101: void clear() BOOST_NOEXCEPT_OR_NOTHROW Chris@16: { m_flat_tree.clear(); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // observers Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Effects: Returns the comparison object out Chris@16: //! of which a was constructed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: key_compare key_comp() const Chris@16: { return container_detail::force_copy(m_flat_tree.key_comp()); } Chris@16: Chris@16: //! Effects: Returns an object of value_compare constructed out Chris@16: //! of the comparison object. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: value_compare value_comp() const Chris@16: { return value_compare(container_detail::force_copy(m_flat_tree.key_comp())); } Chris@16: Chris@16: ////////////////////////////////////////////// Chris@16: // Chris@16: // map operations Chris@16: // Chris@16: ////////////////////////////////////////////// Chris@16: Chris@16: //! Returns: An iterator pointing to an element with the key Chris@16: //! equivalent to x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic. Chris@16: iterator find(const key_type& x) Chris@16: { return container_detail::force_copy(m_flat_tree.find(x)); } Chris@16: Chris@16: //! Returns: An const_iterator pointing to an element with the key Chris@16: //! equivalent to x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic. Chris@16: const_iterator find(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.find(x)); } Chris@16: Chris@16: //! Returns: The number of elements with key equivalent to x. Chris@16: //! Chris@16: //! Complexity: log(size())+count(k) Chris@16: size_type count(const key_type& x) const Chris@16: { return m_flat_tree.count(x); } Chris@16: Chris@16: //! Returns: An iterator pointing to the first element with key not less Chris@16: //! than k, or a.end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: iterator lower_bound(const key_type& x) Chris@16: { return container_detail::force_copy(m_flat_tree.lower_bound(x)); } Chris@16: Chris@101: //! Returns: A const iterator pointing to the first element with key Chris@16: //! not less than k, or a.end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: const_iterator lower_bound(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.lower_bound(x)); } Chris@16: Chris@16: //! Returns: An iterator pointing to the first element with key not less Chris@16: //! than x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: iterator upper_bound(const key_type& x) Chris@16: {return container_detail::force_copy(m_flat_tree.upper_bound(x)); } Chris@16: Chris@101: //! Returns: A const iterator pointing to the first element with key Chris@16: //! not less than x, or end() if such an element is not found. Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: const_iterator upper_bound(const key_type& x) const Chris@16: { return container_detail::force_copy(m_flat_tree.upper_bound(x)); } Chris@16: Chris@16: //! Effects: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: std::pair equal_range(const key_type& x) Chris@16: { return container_detail::force_copy >(m_flat_tree.equal_range(x)); } Chris@16: Chris@16: //! Effects: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)). Chris@16: //! Chris@16: //! Complexity: Logarithmic Chris@16: std::pair equal_range(const key_type& x) const Chris@16: { return container_detail::force_copy >(m_flat_tree.equal_range(x)); } Chris@16: Chris@101: //! Effects: Returns true if x and y are equal Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator==(const flat_multimap& x, const flat_multimap& y) Chris@101: { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } Chris@16: Chris@101: //! Effects: Returns true if x and y are unequal Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator!=(const flat_multimap& x, const flat_multimap& y) Chris@101: { return !(x == y); } Chris@16: Chris@101: //! Effects: Returns true if x is less than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator<(const flat_multimap& x, const flat_multimap& y) Chris@101: { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } Chris@16: Chris@101: //! Effects: Returns true if x is greater than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator>(const flat_multimap& x, const flat_multimap& y) Chris@16: { return y < x; } Chris@16: Chris@101: //! Effects: Returns true if x is equal or less than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator<=(const flat_multimap& x, const flat_multimap& y) Chris@16: { return !(y < x); } Chris@16: Chris@101: //! Effects: Returns true if x is equal or greater than y Chris@101: //! Chris@101: //! Complexity: Linear to the number of elements in the container. Chris@101: friend bool operator>=(const flat_multimap& x, const flat_multimap& y) Chris@16: { return !(x < y); } Chris@16: Chris@101: //! Effects: x.swap(y) Chris@101: //! Chris@101: //! Complexity: Constant. Chris@101: friend void swap(flat_multimap& x, flat_multimap& y) Chris@16: { x.swap(y); } Chris@101: }; Chris@16: Chris@16: }} Chris@16: Chris@101: #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: //!has_trivial_destructor_after_move<> == true_type Chris@16: //!specialization for optimizations Chris@101: template Chris@101: struct has_trivial_destructor_after_move< boost::container::flat_multimap > Chris@16: { Chris@101: typedef typename ::boost::container::allocator_traits::pointer pointer; Chris@101: static const bool value = ::boost::has_trivial_destructor_after_move::value && Chris@101: ::boost::has_trivial_destructor_after_move::value && Chris@101: ::boost::has_trivial_destructor_after_move::value; Chris@16: }; Chris@16: Chris@16: } //namespace boost { Chris@16: Chris@101: #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED Chris@16: Chris@16: #include Chris@16: Chris@101: #endif // BOOST_CONTAINER_FLAT_MAP_HPP