1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_MAP_HPP
11 #define BOOST_CONTAINER_MAP_HPP
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
21 #include <boost/container/detail/config_begin.hpp>
22 #include <boost/container/detail/workaround.hpp>
25 #include <boost/container/container_fwd.hpp>
26 #include <boost/container/new_allocator.hpp> //new_allocator
27 #include <boost/container/throw_exception.hpp>
29 #include <boost/container/detail/mpl.hpp>
30 #include <boost/container/detail/tree.hpp>
31 #include <boost/container/detail/type_traits.hpp>
32 #include <boost/container/detail/value_init.hpp>
33 #include <boost/container/detail/pair.hpp>
34 #include <boost/container/detail/pair_key_mapped_of_value.hpp>
37 #include <boost/move/traits.hpp>
38 #include <boost/move/utility_core.hpp>
40 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
41 #include <boost/move/detail/fwd_macros.hpp>
43 #include <boost/move/detail/move_helpers.hpp>
45 #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
46 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
48 #include <boost/static_assert.hpp>
49 #include <boost/core/no_exceptions_support.hpp>
51 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
52 #include <initializer_list>
58 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
60 //! A map is a kind of associative container that supports unique keys (contains at
61 //! most one of each key value) and provides for fast retrieval of values of another
62 //! type T based on the keys. The map class supports bidirectional iterators.
64 //! A map satisfies all of the requirements of a container and of a reversible
65 //! container and of an associative container. The <code>value_type</code> stored
66 //! by this container is the value_type is std::pair<const Key, T>.
68 //! \tparam Key is the key_type of the map
69 //! \tparam T is the <code>mapped_type</code>
70 //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
71 //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
72 //! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
73 //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
74 template < class Key, class T, class Compare = std::less<Key>
75 , class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults >
77 template <class Key, class T, class Compare, class Allocator, class Options>
81 : public container_detail::tree
82 < std::pair<const Key, T>
83 , container_detail::select1st<Key>
84 , Compare, Allocator, Options>
87 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
89 BOOST_COPYABLE_AND_MOVABLE(map)
91 typedef container_detail::select1st<Key> select_1st_t;
92 typedef std::pair<const Key, T> value_type_impl;
93 typedef container_detail::tree
94 <value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
95 typedef container_detail::pair <Key, T> movable_value_type_impl;
96 typedef typename base_t::value_compare value_compare_impl;
97 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
100 //////////////////////////////////////////////
104 //////////////////////////////////////////////
106 typedef Key key_type;
107 typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
108 typedef T mapped_type;
109 typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
110 typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
111 typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
112 typedef typename boost::container::allocator_traits<Allocator>::reference reference;
113 typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
114 typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
115 typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
116 typedef Allocator allocator_type;
117 typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
118 typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
119 typedef Compare key_compare;
120 typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
121 typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
122 typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
123 typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
124 typedef std::pair<key_type, mapped_type> nonconst_value_type;
125 typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
126 typedef BOOST_CONTAINER_IMPDEF(node_handle<
127 typename base_t::stored_allocator_type
128 BOOST_MOVE_I pair_key_mapped_of_value
129 <key_type BOOST_MOVE_I mapped_type> >) node_type;
130 typedef BOOST_CONTAINER_IMPDEF
131 (insert_return_type_base<iterator BOOST_MOVE_I node_type>) insert_return_type;
133 //allocator_type::value_type type must be std::pair<CONST Key, T>
134 BOOST_STATIC_ASSERT((container_detail::is_same<typename allocator_type::value_type, std::pair<const Key, T> >::value));
136 //////////////////////////////////////////////
138 // construct/copy/destroy
140 //////////////////////////////////////////////
142 //! <b>Effects</b>: Default constructs an empty map.
144 //! <b>Complexity</b>: Constant.
145 BOOST_CONTAINER_FORCEINLINE
146 map() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value &&
147 container_detail::is_nothrow_default_constructible<Compare>::value)
151 //! <b>Effects</b>: Constructs an empty map using the specified comparison object
154 //! <b>Complexity</b>: Constant.
155 BOOST_CONTAINER_FORCEINLINE map(const Compare& comp, const allocator_type& a)
159 //! <b>Effects</b>: Constructs an empty map using the specified comparison object.
161 //! <b>Complexity</b>: Constant.
162 BOOST_CONTAINER_FORCEINLINE explicit map(const Compare& comp)
166 //! <b>Effects</b>: Constructs an empty map using the specified allocator.
168 //! <b>Complexity</b>: Constant.
169 BOOST_CONTAINER_FORCEINLINE explicit map(const allocator_type& a)
173 //! <b>Effects</b>: Constructs an empty map and
174 //! inserts elements from the range [first ,last ).
176 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
177 //! the predicate and otherwise N logN, where N is last - first.
178 template <class InputIterator>
179 BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last)
180 : base_t(true, first, last)
183 //! <b>Effects</b>: Constructs an empty map using the specified
184 //! allocator, and inserts elements from the range [first ,last ).
186 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
187 //! the predicate and otherwise N logN, where N is last - first.
188 template <class InputIterator>
189 BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const allocator_type& a)
190 : base_t(true, first, last, Compare(), a)
193 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
194 //! inserts elements from the range [first ,last ).
196 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
197 //! the predicate and otherwise N logN, where N is last - first.
198 template <class InputIterator>
199 BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp)
200 : base_t(true, first, last, comp)
203 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
204 //! allocator, and inserts elements from the range [first ,last ).
206 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
207 //! the predicate and otherwise N logN, where N is last - first.
208 template <class InputIterator>
209 BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
210 : base_t(true, first, last, comp, a)
213 //! <b>Effects</b>: Constructs an empty map and
214 //! inserts elements from the ordered unique range [first ,last). This function
215 //! is more efficient than the normal range creation for ordered ranges.
217 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
220 //! <b>Complexity</b>: Linear in N.
222 //! <b>Note</b>: Non-standard extension.
223 template <class InputIterator>
224 BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last)
225 : base_t(ordered_range, first, last)
228 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
229 //! inserts elements from the ordered unique range [first ,last). This function
230 //! is more efficient than the normal range creation for ordered ranges.
232 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
235 //! <b>Complexity</b>: Linear in N.
237 //! <b>Note</b>: Non-standard extension.
238 template <class InputIterator>
239 BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
240 : base_t(ordered_range, first, last, comp)
243 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
244 //! allocator, and inserts elements from the ordered unique range [first ,last). This function
245 //! is more efficient than the normal range creation for ordered ranges.
247 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
250 //! <b>Complexity</b>: Linear in N.
252 //! <b>Note</b>: Non-standard extension.
253 template <class InputIterator>
254 BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last
255 , const Compare& comp, const allocator_type& a)
256 : base_t(ordered_range, first, last, comp, a)
259 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
260 //! <b>Effects</b>: Constructs an empty map and
261 //! inserts elements from the range [il.begin(), il.end()).
263 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted according
264 //! to the predicate and otherwise N logN, where N is il.first() - il.end().
265 BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il)
266 : base_t(true, il.begin(), il.end())
269 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
270 //! inserts elements from the range [il.begin(), il.end()).
272 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
273 //! the predicate and otherwise N logN, where N is il.first() - il.end().
274 BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const Compare& comp)
275 : base_t(true, il.begin(), il.end(), comp)
278 //! <b>Effects</b>: Constructs an empty map using the specified
279 //! allocator, and inserts elements from the range [il.begin(), il.end()).
281 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
282 //! the predicate and otherwise N logN, where N is il.first() - il.end().
283 BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const allocator_type& a)
284 : base_t(true, il.begin(), il.end(), Compare(), a)
287 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
288 //! allocator, and inserts elements from the range [il.begin(), il.end()).
290 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
291 //! the predicate and otherwise N logN, where N is il.first() - il.end().
292 BOOST_CONTAINER_FORCEINLINE map(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
293 : base_t(true, il.begin(), il.end(), comp, a)
296 //! <b>Effects</b>: Constructs an empty map and inserts elements from the ordered unique range [il.begin(), il.end()).
297 //! This function is more efficient than the normal range creation for ordered ranges.
299 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
302 //! <b>Complexity</b>: Linear in N.
304 //! <b>Note</b>: Non-standard extension.
305 BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list<value_type> il)
306 : base_t(ordered_range, il.begin(), il.end())
309 //! <b>Effects</b>: Constructs an empty map using the specified comparison object,
310 //! and inserts elements from the ordered unique range [il.begin(), il.end()). This function
311 //! is more efficient than the normal range creation for ordered ranges.
313 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
316 //! <b>Complexity</b>: Linear in N.
318 //! <b>Note</b>: Non-standard extension.
319 BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp)
320 : base_t(ordered_range, il.begin(), il.end(), comp)
323 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
324 //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
325 //! is more efficient than the normal range creation for ordered ranges.
327 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
330 //! <b>Complexity</b>: Linear in N.
332 //! <b>Note</b>: Non-standard extension.
333 BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, std::initializer_list<value_type> il
334 , const Compare& comp, const allocator_type& a)
335 : base_t(ordered_range, il.begin(), il.end(), comp, a)
340 //! <b>Effects</b>: Copy constructs a map.
342 //! <b>Complexity</b>: Linear in x.size().
343 BOOST_CONTAINER_FORCEINLINE map(const map& x)
344 : base_t(static_cast<const base_t&>(x))
347 //! <b>Effects</b>: Move constructs a map. Constructs *this using x's resources.
349 //! <b>Complexity</b>: Constant.
351 //! <b>Postcondition</b>: x is emptied.
352 BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x)
353 BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value)
354 : base_t(BOOST_MOVE_BASE(base_t, x))
357 //! <b>Effects</b>: Copy constructs a map using the specified allocator.
359 //! <b>Complexity</b>: Linear in x.size().
360 BOOST_CONTAINER_FORCEINLINE map(const map& x, const allocator_type &a)
361 : base_t(static_cast<const base_t&>(x), a)
364 //! <b>Effects</b>: Move constructs a map using the specified allocator.
365 //! Constructs *this using x's resources.
367 //! <b>Complexity</b>: Constant if x == x.get_allocator(), linear otherwise.
369 //! <b>Postcondition</b>: x is emptied.
370 BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x, const allocator_type &a)
371 : base_t(BOOST_MOVE_BASE(base_t, x), a)
374 //! <b>Effects</b>: Makes *this a copy of x.
376 //! <b>Complexity</b>: Linear in x.size().
377 BOOST_CONTAINER_FORCEINLINE map& operator=(BOOST_COPY_ASSIGN_REF(map) x)
378 { return static_cast<map&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
380 //! <b>Effects</b>: this->swap(x.get()).
382 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
383 //! is false and (allocation throws or value_type's move constructor throws)
385 //! <b>Complexity</b>: Constant if allocator_traits_type::
386 //! propagate_on_container_move_assignment is true or
387 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
388 BOOST_CONTAINER_FORCEINLINE map& operator=(BOOST_RV_REF(map) x)
389 BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
390 allocator_traits_type::is_always_equal::value) &&
391 boost::container::container_detail::is_nothrow_move_assignable<Compare>::value)
392 { return static_cast<map&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
394 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
395 //! <b>Effects</b>: Assign content of il to *this.
397 BOOST_CONTAINER_FORCEINLINE map& operator=(std::initializer_list<value_type> il)
400 insert(il.begin(), il.end());
405 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
407 //! <b>Effects</b>: Returns a copy of the allocator that
408 //! was passed to the object's constructor.
410 //! <b>Complexity</b>: Constant.
411 allocator_type get_allocator() const;
413 //! <b>Effects</b>: Returns a reference to the internal allocator.
415 //! <b>Throws</b>: Nothing
417 //! <b>Complexity</b>: Constant.
419 //! <b>Note</b>: Non-standard extension.
420 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW;
422 //! <b>Effects</b>: Returns a reference to the internal allocator.
424 //! <b>Throws</b>: Nothing
426 //! <b>Complexity</b>: Constant.
428 //! <b>Note</b>: Non-standard extension.
429 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
431 //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
433 //! <b>Throws</b>: Nothing.
435 //! <b>Complexity</b>: Constant.
436 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
438 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
440 //! <b>Throws</b>: Nothing.
442 //! <b>Complexity</b>: Constant.
443 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
445 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
447 //! <b>Throws</b>: Nothing.
449 //! <b>Complexity</b>: Constant.
450 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
452 //! <b>Effects</b>: Returns an iterator to the end of the container.
454 //! <b>Throws</b>: Nothing.
456 //! <b>Complexity</b>: Constant.
457 iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
459 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
461 //! <b>Throws</b>: Nothing.
463 //! <b>Complexity</b>: Constant.
464 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
466 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
468 //! <b>Throws</b>: Nothing.
470 //! <b>Complexity</b>: Constant.
471 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
473 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
474 //! of the reversed container.
476 //! <b>Throws</b>: Nothing.
478 //! <b>Complexity</b>: Constant.
479 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
481 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
482 //! of the reversed container.
484 //! <b>Throws</b>: Nothing.
486 //! <b>Complexity</b>: Constant.
487 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
489 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
490 //! of the reversed container.
492 //! <b>Throws</b>: Nothing.
494 //! <b>Complexity</b>: Constant.
495 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
497 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
498 //! of the reversed container.
500 //! <b>Throws</b>: Nothing.
502 //! <b>Complexity</b>: Constant.
503 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
505 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
506 //! of the reversed container.
508 //! <b>Throws</b>: Nothing.
510 //! <b>Complexity</b>: Constant.
511 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
513 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
514 //! of the reversed container.
516 //! <b>Throws</b>: Nothing.
518 //! <b>Complexity</b>: Constant.
519 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
521 //! <b>Effects</b>: Returns true if the container contains no elements.
523 //! <b>Throws</b>: Nothing.
525 //! <b>Complexity</b>: Constant.
526 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
528 //! <b>Effects</b>: Returns the number of the elements contained in the container.
530 //! <b>Throws</b>: Nothing.
532 //! <b>Complexity</b>: Constant.
533 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
535 //! <b>Effects</b>: Returns the largest possible size of the container.
537 //! <b>Throws</b>: Nothing.
539 //! <b>Complexity</b>: Constant.
540 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW;
542 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
544 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
545 //! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
546 //! value_type(x, T()) into the map.
548 //! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
550 //! <b>Complexity</b>: Logarithmic.
551 mapped_type& operator[](const key_type &k);
553 //! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
554 //! value_type(boost::move(x), T()) into the map (the key is move-constructed)
556 //! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
558 //! <b>Complexity</b>: Logarithmic.
559 mapped_type& operator[](key_type &&k);
560 #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
561 //in compilers like GCC 3.4, we can't catch temporaries
562 BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
563 BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
565 BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
568 //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
569 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
570 //! as if by insert, constructing it from value_type(k, forward<M>(obj)).
572 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
573 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
574 //! references obtained to that element before it was extracted become valid.
576 //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
577 //! took place. The iterator component is pointing at the element that was inserted or updated.
579 //! <b>Complexity</b>: Logarithmic in the size of the container.
581 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(const key_type& k, BOOST_FWD_REF(M) obj)
582 { return this->base_t::insert_or_assign(const_iterator(), k, ::boost::forward<M>(obj)); }
584 //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
585 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
586 //! as if by insert, constructing it from value_type(k, move(obj)).
588 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
589 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
590 //! references obtained to that element before it was extracted become valid.
592 //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
593 //! took place. The iterator component is pointing at the element that was inserted or updated.
595 //! <b>Complexity</b>: Logarithmic in the size of the container.
597 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
598 { return this->base_t::insert_or_assign(const_iterator(), ::boost::move(k), ::boost::forward<M>(obj)); }
600 //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
601 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
602 //! as if by insert, constructing it from value_type(k, forward<M>(obj)) and the new element
603 //! to the container as close as possible to the position just before hint.
605 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
606 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
607 //! references obtained to that element before it was extracted become valid.
609 //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
610 //! took place. The iterator component is pointing at the element that was inserted or updated.
612 //! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
613 //! the new element is inserted just before hint.
615 BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj)
616 { return this->base_t::insert_or_assign(hint, k, ::boost::forward<M>(obj)); }
618 //! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
619 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
620 //! as if by insert, constructing it from value_type(k, move(obj)) and the new element
621 //! to the container as close as possible to the position just before hint.
623 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
624 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
625 //! references obtained to that element before it was extracted become valid.
627 //! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
628 //! took place. The iterator component is pointing at the element that was inserted or updated.
630 //! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
631 //! the new element is inserted just before hint.
633 BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
634 { return this->base_t::insert_or_assign(hint, ::boost::move(k), ::boost::forward<M>(obj)); }
636 //! <b>Returns</b>: A reference to the element whose key is equivalent to x.
637 //! Throws: An exception object of type out_of_range if no such element is present.
638 //! <b>Complexity</b>: logarithmic.
639 T& at(const key_type& k)
641 iterator i = this->find(k);
642 if(i == this->end()){
643 throw_out_of_range("map::at key not found");
648 //! <b>Returns</b>: A reference to the element whose key is equivalent to x.
649 //! Throws: An exception object of type out_of_range if no such element is present.
650 //! <b>Complexity</b>: logarithmic.
651 const T& at(const key_type& k) const
653 const_iterator i = this->find(k);
654 if(i == this->end()){
655 throw_out_of_range("map::at key not found");
660 //////////////////////////////////////////////
664 //////////////////////////////////////////////
666 //! <b>Effects</b>: Inserts x if and only if there is no element in the container
667 //! with key equivalent to the key of x.
669 //! <b>Returns</b>: The bool component of the returned pair is true if and only
670 //! if the insertion takes place, and the iterator component of the pair
671 //! points to the element with key equivalent to the key of x.
673 //! <b>Complexity</b>: Logarithmic.
674 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const value_type& x)
675 { return this->base_t::insert_unique(x); }
677 //! <b>Effects</b>: Inserts a new value_type created from the pair if and only if
678 //! there is no element in the container with key equivalent to the key of x.
680 //! <b>Returns</b>: The bool component of the returned pair is true if and only
681 //! if the insertion takes place, and the iterator component of the pair
682 //! points to the element with key equivalent to the key of x.
684 //! <b>Complexity</b>: Logarithmic.
685 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const nonconst_value_type& x)
686 { return this->try_emplace(x.first, x.second); }
688 //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
689 //! only if there is no element in the container with key equivalent to the key of x.
691 //! <b>Returns</b>: The bool component of the returned pair is true if and only
692 //! if the insertion takes place, and the iterator component of the pair
693 //! points to the element with key equivalent to the key of x.
695 //! <b>Complexity</b>: Logarithmic.
696 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(nonconst_value_type) x)
697 { return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
699 //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
700 //! only if there is no element in the container with key equivalent to the key of x.
702 //! <b>Returns</b>: The bool component of the returned pair is true if and only
703 //! if the insertion takes place, and the iterator component of the pair
704 //! points to the element with key equivalent to the key of x.
706 //! <b>Complexity</b>: Logarithmic.
707 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
708 { return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
710 //! <b>Effects</b>: Move constructs a new value from x if and only if there is
711 //! no element in the container with key equivalent to the key of x.
713 //! <b>Returns</b>: The bool component of the returned pair is true if and only
714 //! if the insertion takes place, and the iterator component of the pair
715 //! points to the element with key equivalent to the key of x.
717 //! <b>Complexity</b>: Logarithmic.
718 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
719 { return this->base_t::insert_unique(boost::move(x)); }
721 //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
722 //! no element in the container with key equivalent to the key of x.
723 //! p is a hint pointing to where the insert should start to search.
725 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
728 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
729 //! is inserted right before p.
730 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
731 { return this->base_t::insert_unique(p, x); }
733 //! <b>Effects</b>: Move constructs a new value from x if and only if there is
734 //! no element in the container with key equivalent to the key of x.
735 //! p is a hint pointing to where the insert should start to search.
737 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
740 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
741 //! is inserted right before p.
742 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
743 { return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
745 //! <b>Effects</b>: Move constructs a new value from x if and only if there is
746 //! no element in the container with key equivalent to the key of x.
747 //! p is a hint pointing to where the insert should start to search.
749 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
752 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
753 //! is inserted right before p.
754 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
755 { return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
757 //! <b>Effects</b>: Inserts a copy of x in the container.
758 //! p is a hint pointing to where the insert should start to search.
760 //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
762 //! <b>Complexity</b>: Logarithmic.
763 iterator insert(const_iterator p, const nonconst_value_type& x)
764 { return this->try_emplace(p, x.first, x.second); }
766 //! <b>Effects</b>: Inserts an element move constructed from x in the container.
767 //! p is a hint pointing to where the insert should start to search.
769 //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
771 //! <b>Complexity</b>: Logarithmic.
772 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
773 { return this->base_t::insert_unique(p, boost::move(x)); }
775 //! <b>Requires</b>: first, last are not iterators into *this.
777 //! <b>Effects</b>: inserts each element from the range [first,last) if and only
778 //! if there is no element with key equivalent to the key of that element.
780 //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
781 template <class InputIterator>
782 BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
783 { this->base_t::insert_unique(first, last); }
785 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
786 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
787 //! if there is no element with key equivalent to the key of that element.
789 //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
790 BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
791 { this->base_t::insert_unique(il.begin(), il.end()); }
794 //! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
796 //! <b>Effects</b>: If nh is empty, has no effect. Otherwise, inserts the element owned
797 //! by nh if and only if there is no element in the container with a key equivalent to nh.key().
799 //! <b>Returns</b>: If nh is empty, insert_return_type.inserted is false, insert_return_type.position
800 //! is end(), and insert_return_type.node is empty. Otherwise if the insertion took place,
801 //! insert_return_type.inserted is true, insert_return_type.position points to the inserted element,
802 //! and insert_return_type.node is empty; if the insertion failed, insert_return_type.inserted is
803 //! false, insert_return_type.node has the previous value of nh, and insert_return_type.position
804 //! points to an element with a key equivalent to nh.key().
806 //! <b>Complexity</b>: Logarithmic
807 insert_return_type insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
809 typename base_t::node_type n(boost::move(nh));
810 typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(boost::move(n)));
811 return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
814 //! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
815 //! to the position just prior to "hint".
817 //! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
818 //! right before "hint".
819 insert_return_type insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
821 typename base_t::node_type n(boost::move(nh));
822 typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(hint, boost::move(n)));
823 return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
826 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
828 //! <b>Effects</b>: Inserts an object x of type T constructed with
829 //! std::forward<Args>(args)... in the container if and only if there is
830 //! no element in the container with an equivalent key.
831 //! p is a hint pointing to where the insert should start to search.
833 //! <b>Returns</b>: The bool component of the returned pair is true if and only
834 //! if the insertion takes place, and the iterator component of the pair
835 //! points to the element with key equivalent to the key of x.
837 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
838 //! is inserted right before p.
839 template <class... Args>
840 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
841 { return this->base_t::emplace_unique(boost::forward<Args>(args)...); }
843 //! <b>Effects</b>: Inserts an object of type T constructed with
844 //! std::forward<Args>(args)... in the container if and only if there is
845 //! no element in the container with an equivalent key.
846 //! p is a hint pointing to where the insert should start to search.
848 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
851 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
852 //! is inserted right before p.
853 template <class... Args>
854 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
855 { return this->base_t::emplace_hint_unique(p, boost::forward<Args>(args)...); }
857 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
858 //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
860 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
861 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
862 //! forward_as_tuple(forward<Args>(args)...).
864 //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
865 //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
867 //! <b>Complexity</b>: Logarithmic.
868 template <class... Args>
869 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k, BOOST_FWD_REF(Args)... args)
870 { return this->base_t::try_emplace(const_iterator(), k, boost::forward<Args>(args)...); }
872 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
873 //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
875 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
876 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
877 //! forward_as_tuple(forward<Args>(args)...).
879 //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
881 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
882 //! is inserted right before p.
883 template <class... Args>
884 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k, BOOST_FWD_REF(Args)... args)
885 { return this->base_t::try_emplace(hint, k, boost::forward<Args>(args)...).first; }
887 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
888 //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
890 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
891 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
892 //! forward_as_tuple(forward<Args>(args)...).
894 //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
895 //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
897 //! <b>Complexity</b>: Logarithmic.
898 template <class... Args>
899 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
900 { return this->base_t::try_emplace(const_iterator(), boost::move(k), boost::forward<Args>(args)...); }
902 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
903 //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
905 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
906 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
907 //! forward_as_tuple(forward<Args>(args)...).
909 //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
911 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
912 //! is inserted right before p.
913 template <class... Args>
914 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
915 { return this->base_t::try_emplace(hint, boost::move(k), boost::forward<Args>(args)...).first; }
917 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
919 #define BOOST_CONTAINER_MAP_EMPLACE_CODE(N) \
920 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
921 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
922 { return this->base_t::emplace_unique(BOOST_MOVE_FWD##N); }\
924 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
925 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
926 { return this->base_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
928 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
929 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
930 { return this->base_t::try_emplace(const_iterator(), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
932 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
933 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
934 { return this->base_t::try_emplace(hint, k BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
936 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
937 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
938 { return this->base_t::try_emplace(const_iterator(), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
940 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
941 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
942 { return this->base_t::try_emplace(hint, boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
944 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MAP_EMPLACE_CODE)
945 #undef BOOST_CONTAINER_MAP_EMPLACE_CODE
947 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
949 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
951 //! <b>Effects</b>: Erases the element pointed to by p.
953 //! <b>Returns</b>: Returns an iterator pointing to the element immediately
954 //! following q prior to the element being erased. If no such element exists,
957 //! <b>Complexity</b>: Amortized constant time
958 iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
960 //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
962 //! <b>Returns</b>: Returns the number of erased elements.
964 //! <b>Complexity</b>: log(size()) + count(k)
965 size_type erase(const key_type& x) BOOST_NOEXCEPT_OR_NOTHROW;
967 //! <b>Effects</b>: Erases all the elements in the range [first, last).
969 //! <b>Returns</b>: Returns last.
971 //! <b>Complexity</b>: log(size())+N where N is the distance from first to last.
972 iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW;
976 //! <b>Effects</b>: Removes the first element in the container with key equivalent to k.
978 //! <b>Returns</b>: A node_type owning the element if found, otherwise an empty node_type.
980 //! <b>Complexity</b>: log(a.size()).
981 node_type extract(const key_type& k)
983 typename base_t::node_type base_nh(this->base_t::extract(k));
984 node_type nh(boost::move(base_nh));
985 return BOOST_MOVE_RET(node_type, nh);
988 //! <b>Effects</b>: Removes the element pointed to by "position".
990 //! <b>Returns</b>: A node_type owning the element, otherwise an empty node_type.
992 //! <b>Complexity</b>: Amortized constant.
993 node_type extract(const_iterator position)
995 typename base_t::node_type base_nh(this->base_t::extract(position));
996 node_type nh(boost::move(base_nh));
997 return BOOST_MOVE_RET(node_type, nh);
1000 //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
1002 //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
1003 //! the comparison object of *this. If there is an element in a with key equivalent to the
1004 //! key of an element from source, then that element is not extracted from source.
1006 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
1007 //! to those same elements but as members of *this. Iterators referring to the transferred
1008 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
1009 //! not into source.
1011 //! <b>Throws</b>: Nothing unless the comparison object throws.
1013 //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
1015 BOOST_CONTAINER_FORCEINLINE void merge(map<Key, T, C2, Allocator, Options>& source)
1017 typedef container_detail::tree
1018 <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
1019 this->merge_unique(static_cast<base2_t&>(source));
1022 //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
1024 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
1025 { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
1027 //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
1029 BOOST_CONTAINER_FORCEINLINE void merge(multimap<Key, T, C2, Allocator, Options>& source)
1031 typedef container_detail::tree
1032 <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
1033 this->base_t::merge_unique(static_cast<base2_t&>(source));
1036 //! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
1038 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
1039 { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
1041 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1042 //! <b>Effects</b>: Swaps the contents of *this and x.
1044 //! <b>Throws</b>: Nothing.
1046 //! <b>Complexity</b>: Constant.
1048 BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
1049 && boost::container::container_detail::is_nothrow_swappable<Compare>::value )
1051 //! <b>Effects</b>: erase(a.begin(),a.end()).
1053 //! <b>Postcondition</b>: size() == 0.
1055 //! <b>Complexity</b>: linear in size().
1056 void clear() BOOST_NOEXCEPT_OR_NOTHROW;
1058 //! <b>Effects</b>: Returns the comparison object out
1059 //! of which a was constructed.
1061 //! <b>Complexity</b>: Constant.
1062 key_compare key_comp() const;
1064 //! <b>Effects</b>: Returns an object of value_compare constructed out
1065 //! of the comparison object.
1067 //! <b>Complexity</b>: Constant.
1068 value_compare value_comp() const;
1070 //! <b>Returns</b>: An iterator pointing to an element with the key
1071 //! equivalent to x, or end() if such an element is not found.
1073 //! <b>Complexity</b>: Logarithmic.
1074 iterator find(const key_type& x);
1076 //! <b>Returns</b>: A const_iterator pointing to an element with the key
1077 //! equivalent to x, or end() if such an element is not found.
1079 //! <b>Complexity</b>: Logarithmic.
1080 const_iterator find(const key_type& x) const;
1082 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1084 //! <b>Returns</b>: The number of elements with key equivalent to x.
1086 //! <b>Complexity</b>: log(size())+count(k)
1087 BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
1088 { return static_cast<size_type>(this->find(x) != this->cend()); }
1090 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1092 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1093 //! than k, or a.end() if such an element is not found.
1095 //! <b>Complexity</b>: Logarithmic
1096 iterator lower_bound(const key_type& x);
1098 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1099 //! less than k, or a.end() if such an element is not found.
1101 //! <b>Complexity</b>: Logarithmic
1102 const_iterator lower_bound(const key_type& x) const;
1104 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1105 //! than x, or end() if such an element is not found.
1107 //! <b>Complexity</b>: Logarithmic
1108 iterator upper_bound(const key_type& x);
1110 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1111 //! less than x, or end() if such an element is not found.
1113 //! <b>Complexity</b>: Logarithmic
1114 const_iterator upper_bound(const key_type& x) const;
1116 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1118 //! <b>Complexity</b>: Logarithmic
1119 std::pair<iterator,iterator> equal_range(const key_type& x);
1121 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1123 //! <b>Complexity</b>: Logarithmic
1124 std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
1126 //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
1128 //! <b>Complexity</b>: Linear
1131 //! <b>Effects</b>: Returns true if x and y are equal
1133 //! <b>Complexity</b>: Linear to the number of elements in the container.
1134 friend bool operator==(const map& x, const map& y);
1136 //! <b>Effects</b>: Returns true if x and y are unequal
1138 //! <b>Complexity</b>: Linear to the number of elements in the container.
1139 friend bool operator!=(const map& x, const map& y);
1141 //! <b>Effects</b>: Returns true if x is less than y
1143 //! <b>Complexity</b>: Linear to the number of elements in the container.
1144 friend bool operator<(const map& x, const map& y);
1146 //! <b>Effects</b>: Returns true if x is greater than y
1148 //! <b>Complexity</b>: Linear to the number of elements in the container.
1149 friend bool operator>(const map& x, const map& y);
1151 //! <b>Effects</b>: Returns true if x is equal or less than y
1153 //! <b>Complexity</b>: Linear to the number of elements in the container.
1154 friend bool operator<=(const map& x, const map& y);
1156 //! <b>Effects</b>: Returns true if x is equal or greater than y
1158 //! <b>Complexity</b>: Linear to the number of elements in the container.
1159 friend bool operator>=(const map& x, const map& y);
1161 //! <b>Effects</b>: x.swap(y)
1163 //! <b>Complexity</b>: Constant.
1164 friend void swap(map& x, map& y);
1166 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1168 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1170 template<class KeyConvertible>
1171 BOOST_CONTAINER_FORCEINLINE mapped_type& priv_subscript(BOOST_FWD_REF(KeyConvertible) k)
1173 return this->try_emplace(boost::forward<KeyConvertible>(k)).first->second;
1175 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1179 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1181 } //namespace container {
1183 //!has_trivial_destructor_after_move<> == true_type
1184 //!specialization for optimizations
1185 template <class Key, class T, class Compare, class Allocator>
1186 struct has_trivial_destructor_after_move<boost::container::map<Key, T, Compare, Allocator> >
1188 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
1189 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
1190 ::boost::has_trivial_destructor_after_move<pointer>::value &&
1191 ::boost::has_trivial_destructor_after_move<Compare>::value;
1194 namespace container {
1196 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1198 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1200 //! A multimap is a kind of associative container that supports equivalent keys
1201 //! (possibly containing multiple copies of the same key value) and provides for
1202 //! fast retrieval of values of another type T based on the keys. The multimap class
1203 //! supports bidirectional iterators.
1205 //! A multimap satisfies all of the requirements of a container and of a reversible
1206 //! container and of an associative container. The <code>value_type</code> stored
1207 //! by this container is the value_type is std::pair<const Key, T>.
1209 //! \tparam Key is the key_type of the map
1210 //! \tparam Value is the <code>mapped_type</code>
1211 //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
1212 //! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
1213 //! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
1214 //! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
1215 template < class Key, class T, class Compare = std::less<Key>
1216 , class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults>
1218 template <class Key, class T, class Compare, class Allocator, class Options>
1222 : public container_detail::tree
1223 < std::pair<const Key, T>
1224 , container_detail::select1st<Key>
1225 , Compare, Allocator, Options>
1228 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1230 BOOST_COPYABLE_AND_MOVABLE(multimap)
1232 typedef container_detail::select1st<Key> select_1st_t;
1233 typedef std::pair<const Key, T> value_type_impl;
1234 typedef container_detail::tree
1235 <value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
1236 typedef container_detail::pair <Key, T> movable_value_type_impl;
1237 typedef typename base_t::value_compare value_compare_impl;
1238 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1240 typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
1243 //////////////////////////////////////////////
1247 //////////////////////////////////////////////
1249 typedef Key key_type;
1250 typedef T mapped_type;
1251 typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
1252 typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
1253 typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
1254 typedef typename boost::container::allocator_traits<Allocator>::reference reference;
1255 typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
1256 typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
1257 typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
1258 typedef Allocator allocator_type;
1259 typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
1260 typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
1261 typedef Compare key_compare;
1262 typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
1263 typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
1264 typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
1265 typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
1266 typedef std::pair<key_type, mapped_type> nonconst_value_type;
1267 typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
1268 typedef BOOST_CONTAINER_IMPDEF(node_handle<
1269 typename base_t::stored_allocator_type
1270 BOOST_MOVE_I pair_key_mapped_of_value
1271 <key_type BOOST_MOVE_I mapped_type> >) node_type;
1273 //allocator_type::value_type type must be std::pair<CONST Key, T>
1274 BOOST_STATIC_ASSERT((container_detail::is_same<typename allocator_type::value_type, std::pair<const Key, T> >::value));
1276 //////////////////////////////////////////////
1278 // construct/copy/destroy
1280 //////////////////////////////////////////////
1282 //! <b>Effects</b>: Default constructs an empty multimap.
1284 //! <b>Complexity</b>: Constant.
1285 BOOST_CONTAINER_FORCEINLINE multimap()
1286 BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value &&
1287 container_detail::is_nothrow_default_constructible<Compare>::value)
1291 //! <b>Effects</b>: Constructs an empty multimap using the specified allocator
1292 //! object and allocator.
1294 //! <b>Complexity</b>: Constant.
1295 BOOST_CONTAINER_FORCEINLINE explicit multimap(const allocator_type& a)
1299 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison.
1301 //! <b>Complexity</b>: Constant.
1302 BOOST_CONTAINER_FORCEINLINE explicit multimap(const Compare& comp)
1306 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison and allocator.
1308 //! <b>Complexity</b>: Constant.
1309 BOOST_CONTAINER_FORCEINLINE multimap(const Compare& comp, const allocator_type& a)
1313 //! <b>Effects</b>: Constructs an empty multimap and
1314 //! inserts elements from the range [first ,last ).
1316 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1317 //! the predicate and otherwise N logN, where N is last - first.
1318 template <class InputIterator>
1319 BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last)
1320 : base_t(false, first, last)
1323 //! <b>Effects</b>: Constructs an empty multimap using the specified
1324 //! allocator, and inserts elements from the range [first ,last ).
1326 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1327 //! the predicate and otherwise N logN, where N is last - first.
1328 template <class InputIterator>
1329 BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last, const allocator_type& a)
1330 : base_t(false, first, last, Compare(), a)
1333 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
1334 //! inserts elements from the range [first ,last ).
1336 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1337 //! the predicate and otherwise N logN, where N is last - first.
1338 template <class InputIterator>
1339 BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last, const Compare& comp)
1340 : base_t(false, first, last, comp)
1343 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object
1344 //! and allocator, and inserts elements from the range [first ,last ).
1346 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1347 //! the predicate and otherwise N logN, where N is last - first.
1348 template <class InputIterator>
1349 BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last,
1350 const Compare& comp, const allocator_type& a)
1351 : base_t(false, first, last, comp, a)
1354 //! <b>Effects</b>: Constructs an empty multimap and
1355 //! inserts elements from the ordered range [first ,last). This function
1356 //! is more efficient than the normal range creation for ordered ranges.
1358 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1360 //! <b>Complexity</b>: Linear in N.
1362 //! <b>Note</b>: Non-standard extension.
1363 template <class InputIterator>
1364 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last)
1365 : base_t(ordered_range, first, last)
1368 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
1369 //! inserts elements from the ordered range [first ,last). This function
1370 //! is more efficient than the normal range creation for ordered ranges.
1372 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1374 //! <b>Complexity</b>: Linear in N.
1376 //! <b>Note</b>: Non-standard extension.
1377 template <class InputIterator>
1378 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
1379 : base_t(ordered_range, first, last, comp)
1382 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
1383 //! allocator, and inserts elements from the ordered range [first ,last). This function
1384 //! is more efficient than the normal range creation for ordered ranges.
1386 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1388 //! <b>Complexity</b>: Linear in N.
1390 //! <b>Note</b>: Non-standard extension.
1391 template <class InputIterator>
1392 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp,
1393 const allocator_type& a)
1394 : base_t(ordered_range, first, last, comp, a)
1397 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1398 //! <b>Effects</b>: Constructs an empty multimap and
1399 //! and inserts elements from the range [il.begin(), il.end()).
1401 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1402 //! the predicate and otherwise N logN, where N is il.first() - il.end().
1403 BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il)
1404 : base_t(false, il.begin(), il.end())
1407 //! <b>Effects</b>: Constructs an empty multimap using the specified
1408 //! allocator, and inserts elements from the range [il.begin(), il.end()).
1410 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1411 //! the predicate and otherwise N logN, where N is il.first() - il.end().
1412 BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const allocator_type& a)
1413 : base_t(false, il.begin(), il.end(), Compare(), a)
1416 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
1417 //! inserts elements from the range [il.begin(), il.end()).
1419 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1420 //! the predicate and otherwise N logN, where N is il.first() - il.end().
1421 BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const Compare& comp)
1422 : base_t(false, il.begin(), il.end(), comp)
1425 //! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
1426 //! allocator, and inserts elements from the range [il.begin(), il.end()).
1428 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1429 //! the predicate and otherwise N logN, where N is il.first() - il.end().
1430 BOOST_CONTAINER_FORCEINLINE multimap(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
1431 : base_t(false, il.begin(), il.end(), comp, a)
1435 //! <b>Effects</b>: Constructs an empty map and
1436 //! inserts elements from the ordered range [il.begin(), il.end()). This function
1437 //! is more efficient than the normal range creation for ordered ranges.
1439 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1441 //! <b>Complexity</b>: Linear in N.
1443 //! <b>Note</b>: Non-standard extension.
1444 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il)
1445 : base_t(ordered_range, il.begin(), il.end())
1448 //! <b>Effects</b>: Constructs an empty map using the specified comparison object and
1449 //! inserts elements from the ordered range [il.begin(), il.end()). This function
1450 //! is more efficient than the normal range creation for ordered ranges.
1452 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1454 //! <b>Complexity</b>: Linear in N.
1456 //! <b>Note</b>: Non-standard extension.
1457 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
1458 : base_t(ordered_range, il.begin(), il.end(), comp)
1461 //! <b>Effects</b>: Constructs an empty map and
1462 //! inserts elements from the ordered range [il.begin(), il.end()). This function
1463 //! is more efficient than the normal range creation for ordered ranges.
1465 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1467 //! <b>Complexity</b>: Linear in N.
1469 //! <b>Note</b>: Non-standard extension.
1470 BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
1471 : base_t(ordered_range, il.begin(), il.end(), comp, a)
1476 //! <b>Effects</b>: Copy constructs a multimap.
1478 //! <b>Complexity</b>: Linear in x.size().
1479 BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x)
1480 : base_t(static_cast<const base_t&>(x))
1483 //! <b>Effects</b>: Move constructs a multimap. Constructs *this using x's resources.
1485 //! <b>Complexity</b>: Constant.
1487 //! <b>Postcondition</b>: x is emptied.
1488 BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x)
1489 BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value)
1490 : base_t(BOOST_MOVE_BASE(base_t, x))
1493 //! <b>Effects</b>: Copy constructs a multimap.
1495 //! <b>Complexity</b>: Linear in x.size().
1496 BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x, const allocator_type &a)
1497 : base_t(static_cast<const base_t&>(x), a)
1500 //! <b>Effects</b>: Move constructs a multimap using the specified allocator.
1501 //! Constructs *this using x's resources.
1502 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
1504 //! <b>Postcondition</b>: x is emptied.
1505 BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x, const allocator_type &a)
1506 : base_t(BOOST_MOVE_BASE(base_t, x), a)
1509 //! <b>Effects</b>: Makes *this a copy of x.
1511 //! <b>Complexity</b>: Linear in x.size().
1512 BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_COPY_ASSIGN_REF(multimap) x)
1513 { return static_cast<multimap&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
1515 //! <b>Effects</b>: this->swap(x.get()).
1517 //! <b>Complexity</b>: Constant.
1518 BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_RV_REF(multimap) x)
1519 BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
1520 allocator_traits_type::is_always_equal::value) &&
1521 boost::container::container_detail::is_nothrow_move_assignable<Compare>::value)
1522 { return static_cast<multimap&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
1524 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1525 //! <b>Effects</b>: Assign content of il to *this.
1527 BOOST_CONTAINER_FORCEINLINE multimap& operator=(std::initializer_list<value_type> il)
1530 insert(il.begin(), il.end());
1535 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1537 //! @copydoc ::boost::container::set::get_allocator()
1538 allocator_type get_allocator() const;
1540 //! @copydoc ::boost::container::set::get_stored_allocator()
1541 stored_allocator_type &get_stored_allocator();
1543 //! @copydoc ::boost::container::set::get_stored_allocator() const
1544 const stored_allocator_type &get_stored_allocator() const;
1546 //! @copydoc ::boost::container::set::begin()
1549 //! @copydoc ::boost::container::set::begin() const
1550 const_iterator begin() const;
1552 //! @copydoc ::boost::container::set::cbegin() const
1553 const_iterator cbegin() const;
1555 //! @copydoc ::boost::container::set::end()
1556 iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
1558 //! @copydoc ::boost::container::set::end() const
1559 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
1561 //! @copydoc ::boost::container::set::cend() const
1562 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
1564 //! @copydoc ::boost::container::set::rbegin()
1565 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
1567 //! @copydoc ::boost::container::set::rbegin() const
1568 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1570 //! @copydoc ::boost::container::set::crbegin() const
1571 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1573 //! @copydoc ::boost::container::set::rend()
1574 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
1576 //! @copydoc ::boost::container::set::rend() const
1577 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
1579 //! @copydoc ::boost::container::set::crend() const
1580 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
1582 //! @copydoc ::boost::container::set::empty() const
1585 //! @copydoc ::boost::container::set::size() const
1586 size_type size() const;
1588 //! @copydoc ::boost::container::set::max_size() const
1589 size_type max_size() const;
1591 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1593 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1595 //! <b>Effects</b>: Inserts an object of type T constructed with
1596 //! std::forward<Args>(args)... in the container.
1597 //! p is a hint pointing to where the insert should start to search.
1599 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1600 //! to the key of x.
1602 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1603 //! is inserted right before p.
1604 template <class... Args>
1605 BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_FWD_REF(Args)... args)
1606 { return this->base_t::emplace_equal(boost::forward<Args>(args)...); }
1608 //! <b>Effects</b>: Inserts an object of type T constructed with
1609 //! std::forward<Args>(args)... in the container.
1610 //! p is a hint pointing to where the insert should start to search.
1612 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1613 //! to the key of x.
1615 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1616 //! is inserted right before p.
1617 template <class... Args>
1618 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
1619 { return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
1621 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1623 #define BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE(N) \
1624 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1625 BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
1626 { return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\
1628 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1629 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1630 { return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
1632 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE)
1633 #undef BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE
1635 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1637 //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
1638 //! newly inserted element.
1640 //! <b>Complexity</b>: Logarithmic.
1641 BOOST_CONTAINER_FORCEINLINE iterator insert(const value_type& x)
1642 { return this->base_t::insert_equal(x); }
1644 //! <b>Effects</b>: Inserts a new value constructed from x and returns
1645 //! the iterator pointing to the newly inserted element.
1647 //! <b>Complexity</b>: Logarithmic.
1648 BOOST_CONTAINER_FORCEINLINE iterator insert(const nonconst_value_type& x)
1649 { return this->base_t::emplace_equal(x); }
1651 //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
1652 //! the iterator pointing to the newly inserted element.
1654 //! <b>Complexity</b>: Logarithmic.
1655 BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(nonconst_value_type) x)
1656 { return this->base_t::emplace_equal(boost::move(x)); }
1658 //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
1659 //! the iterator pointing to the newly inserted element.
1661 //! <b>Complexity</b>: Logarithmic.
1662 iterator insert(BOOST_RV_REF(movable_value_type) x)
1663 { return this->base_t::emplace_equal(boost::move(x)); }
1665 //! <b>Effects</b>: Inserts a copy of x in the container.
1666 //! p is a hint pointing to where the insert should start to search.
1668 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1669 //! to the key of x.
1671 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1672 //! is inserted right before p.
1673 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
1674 { return this->base_t::insert_equal(p, x); }
1676 //! <b>Effects</b>: Inserts a new value constructed from x in the container.
1677 //! p is a hint pointing to where the insert should start to search.
1679 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1680 //! to the key of x.
1682 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1683 //! is inserted right before p.
1684 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const nonconst_value_type& x)
1685 { return this->base_t::emplace_hint_equal(p, x); }
1687 //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
1688 //! p is a hint pointing to where the insert should start to search.
1690 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1691 //! to the key of x.
1693 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1694 //! is inserted right before p.
1695 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
1696 { return this->base_t::emplace_hint_equal(p, boost::move(x)); }
1698 //! <b>Effects</b>: Inserts a new value move constructed from x in the container.
1699 //! p is a hint pointing to where the insert should start to search.
1701 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1702 //! to the key of x.
1704 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
1705 //! is inserted right before p.
1706 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
1707 { return this->base_t::emplace_hint_equal(p, boost::move(x)); }
1709 //! <b>Requires</b>: first, last are not iterators into *this.
1711 //! <b>Effects</b>: inserts each element from the range [first,last) .
1713 //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
1714 template <class InputIterator>
1715 BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
1716 { this->base_t::insert_equal(first, last); }
1718 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1719 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end().
1721 //! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
1722 BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
1723 { this->base_t::insert_equal(il.begin(), il.end()); }
1726 //! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
1728 //! <b>Effects/Returns</b>: If nh is empty, has no effect and returns end(). Otherwise, inserts
1729 //! the element owned by nh and returns an iterator pointing to the newly inserted element.
1730 //! If a range containing elements with keys equivalent to nh.key() exists,
1731 //! the element is inserted at the end of that range. nh is always emptied.
1733 //! <b>Complexity</b>: Logarithmic
1734 iterator insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
1736 typename base_t::node_type n(boost::move(nh));
1737 return this->base_t::insert_equal_node(boost::move(n));
1740 //! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
1741 //! to the position just prior to "hint".
1743 //! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
1744 //! right before "hint".
1745 iterator insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
1747 typename base_t::node_type n(boost::move(nh));
1748 return this->base_t::insert_equal_node(hint, boost::move(n));
1751 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1753 //! @copydoc ::boost::container::set::erase(const_iterator)
1754 iterator erase(const_iterator p);
1756 //! @copydoc ::boost::container::set::erase(const key_type&)
1757 size_type erase(const key_type& x);
1759 //! @copydoc ::boost::container::set::erase(const_iterator,const_iterator)
1760 iterator erase(const_iterator first, const_iterator last);
1763 //! @copydoc ::boost::container::map::extract(const key_type&)
1764 node_type extract(const key_type& k)
1766 typename base_t::node_type base_nh(this->base_t::extract(k));
1767 return node_type(boost::move(base_nh));
1770 //! @copydoc ::boost::container::map::extract(const_iterator)
1771 node_type extract(const_iterator position)
1773 typename base_t::node_type base_nh(this->base_t::extract(position));
1774 return node_type (boost::move(base_nh));
1777 //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
1779 //! <b>Effects</b>: Extracts each element in source and insert it into a using
1780 //! the comparison object of *this.
1782 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
1783 //! to those same elements but as members of *this. Iterators referring to the transferred
1784 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
1785 //! not into source.
1787 //! <b>Throws</b>: Nothing unless the comparison object throws.
1789 //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
1791 BOOST_CONTAINER_FORCEINLINE void merge(multimap<Key, T, C2, Allocator, Options>& source)
1793 typedef container_detail::tree
1794 <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
1795 this->base_t::merge_equal(static_cast<base2_t&>(source));
1798 //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
1800 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
1801 { return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
1803 //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
1805 BOOST_CONTAINER_FORCEINLINE void merge(map<Key, T, C2, Allocator, Options>& source)
1807 typedef container_detail::tree
1808 <value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
1809 this->base_t::merge_equal(static_cast<base2_t&>(source));
1812 //! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
1814 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
1815 { return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
1817 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1818 //! @copydoc ::boost::container::set::swap
1819 void swap(multiset& x)
1820 BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
1821 && boost::container::container_detail::is_nothrow_swappable<Compare>::value );
1823 //! @copydoc ::boost::container::set::clear
1824 void clear() BOOST_NOEXCEPT_OR_NOTHROW;
1826 //! @copydoc ::boost::container::set::key_comp
1827 key_compare key_comp() const;
1829 //! @copydoc ::boost::container::set::value_comp
1830 value_compare value_comp() const;
1832 //! <b>Returns</b>: An iterator pointing to an element with the key
1833 //! equivalent to x, or end() if such an element is not found.
1835 //! <b>Complexity</b>: Logarithmic.
1836 iterator find(const key_type& x);
1838 //! <b>Returns</b>: A const iterator pointing to an element with the key
1839 //! equivalent to x, or end() if such an element is not found.
1841 //! <b>Complexity</b>: Logarithmic.
1842 const_iterator find(const key_type& x) const;
1844 //! <b>Returns</b>: The number of elements with key equivalent to x.
1846 //! <b>Complexity</b>: log(size())+count(k)
1847 size_type count(const key_type& x) const;
1849 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1850 //! than k, or a.end() if such an element is not found.
1852 //! <b>Complexity</b>: Logarithmic
1853 iterator lower_bound(const key_type& x);
1855 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1856 //! less than k, or a.end() if such an element is not found.
1858 //! <b>Complexity</b>: Logarithmic
1859 const_iterator lower_bound(const key_type& x) const;
1861 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1862 //! than x, or end() if such an element is not found.
1864 //! <b>Complexity</b>: Logarithmic
1865 iterator upper_bound(const key_type& x);
1867 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1868 //! less than x, or end() if such an element is not found.
1870 //! <b>Complexity</b>: Logarithmic
1871 const_iterator upper_bound(const key_type& x) const;
1873 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1875 //! <b>Complexity</b>: Logarithmic
1876 std::pair<iterator,iterator> equal_range(const key_type& x);
1878 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1880 //! <b>Complexity</b>: Logarithmic
1881 std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
1883 //! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
1885 //! <b>Complexity</b>: Linear
1888 //! <b>Effects</b>: Returns true if x and y are equal
1890 //! <b>Complexity</b>: Linear to the number of elements in the container.
1891 friend bool operator==(const multimap& x, const multimap& y);
1893 //! <b>Effects</b>: Returns true if x and y are unequal
1895 //! <b>Complexity</b>: Linear to the number of elements in the container.
1896 friend bool operator!=(const multimap& x, const multimap& y);
1898 //! <b>Effects</b>: Returns true if x is less than y
1900 //! <b>Complexity</b>: Linear to the number of elements in the container.
1901 friend bool operator<(const multimap& x, const multimap& y);
1903 //! <b>Effects</b>: Returns true if x is greater than y
1905 //! <b>Complexity</b>: Linear to the number of elements in the container.
1906 friend bool operator>(const multimap& x, const multimap& y);
1908 //! <b>Effects</b>: Returns true if x is equal or less than y
1910 //! <b>Complexity</b>: Linear to the number of elements in the container.
1911 friend bool operator<=(const multimap& x, const multimap& y);
1913 //! <b>Effects</b>: Returns true if x is equal or greater than y
1915 //! <b>Complexity</b>: Linear to the number of elements in the container.
1916 friend bool operator>=(const multimap& x, const multimap& y);
1918 //! <b>Effects</b>: x.swap(y)
1920 //! <b>Complexity</b>: Constant.
1921 friend void swap(multimap& x, multimap& y);
1923 #endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1926 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1928 } //namespace container {
1930 //!has_trivial_destructor_after_move<> == true_type
1931 //!specialization for optimizations
1932 template <class Key, class T, class Compare, class Allocator>
1933 struct has_trivial_destructor_after_move<boost::container::multimap<Key, T, Compare, Allocator> >
1935 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
1936 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
1937 ::boost::has_trivial_destructor_after_move<pointer>::value &&
1938 ::boost::has_trivial_destructor_after_move<Compare>::value;
1941 namespace container {
1943 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1947 #include <boost/container/detail/config_end.hpp>
1949 #endif // BOOST_CONTAINER_MAP_HPP