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_FLAT_MAP_HPP
11 #define BOOST_CONTAINER_FLAT_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>
24 #include <boost/container/allocator_traits.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/flat_tree.hpp>
30 #include <boost/container/detail/type_traits.hpp>
31 #include <boost/container/detail/mpl.hpp>
32 #include <boost/container/detail/algorithm.hpp> //equal()
33 #include <boost/container/detail/container_or_allocator_rebind.hpp>
35 #include <boost/move/utility_core.hpp>
36 #include <boost/move/traits.hpp>
38 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
39 #include <boost/move/detail/fwd_macros.hpp>
41 #include <boost/move/detail/move_helpers.hpp>
43 #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
44 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
46 #include <boost/core/no_exceptions_support.hpp>
48 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
49 #include <initializer_list>
55 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
57 template <class Key, class T, class Compare, class AllocatorOrContainer>
62 template<class D, class S>
63 BOOST_CONTAINER_FORCEINLINE static D &force(S &s)
64 { return *reinterpret_cast<D*>(&s); }
66 template<class D, class S>
67 BOOST_CONTAINER_FORCEINLINE static D force_copy(const S &s)
69 const D *const vp = reinterpret_cast<const D *>(&s);
76 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
78 //! A flat_map is a kind of associative container that supports unique keys (contains at
79 //! most one of each key value) and provides for fast retrieval of values of another
80 //! type T based on the keys.
82 //! A flat_map satisfies all of the requirements of a container, a reversible
83 //! container and an associative container. A flat_map also provides
84 //! most operations described for unique keys. For a
85 //! flat_map<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
86 //! (unlike std::map<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
88 //! flat_map is similar to std::map but it's implemented by as an ordered sequence container.
89 //! The underlying sequence container is by default <i>vector</i> but it can also work
90 //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
92 //! Using vector-like sequence containers means that inserting a new element into a flat_map might invalidate
93 //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
94 //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
95 //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
97 //! This container provides random-access iterators.
99 //! \tparam Key is the key_type of the map
100 //! \tparam Value is the <code>mapped_type</code>
101 //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
102 //! \tparam AllocatorOrContainer is either:
103 //! - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
104 //! (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
105 //! - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
106 //! sequence container with random-access iterators..
107 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
108 template <class Key, class T, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator< std::pair< Key, T> > >
110 template <class Key, class T, class Compare, class AllocatorOrContainer>
114 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
116 BOOST_COPYABLE_AND_MOVABLE(flat_map)
117 //This is the tree that we should store if pair was movable
118 typedef dtl::flat_tree<
122 AllocatorOrContainer> tree_t;
124 //This is the real tree stored here. It's based on a movable pair
125 typedef dtl::flat_tree<
129 typename dtl::container_or_allocator_rebind<AllocatorOrContainer, dtl::pair<Key, T> >::type
131 impl_tree_t m_flat_tree; // flat tree representing flat_map
133 typedef typename impl_tree_t::value_type impl_value_type;
134 typedef typename impl_tree_t::const_iterator impl_const_iterator;
135 typedef typename impl_tree_t::iterator impl_iterator;
136 typedef typename impl_tree_t::allocator_type impl_allocator_type;
137 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
138 typedef std::initializer_list<impl_value_type> impl_initializer_list;
141 typedef dtl::flat_tree_value_compare
143 , dtl::select1st<Key>
144 , std::pair<Key, T> > value_compare_t;
145 typedef typename tree_t::iterator iterator_t;
146 typedef typename tree_t::const_iterator const_iterator_t;
147 typedef typename tree_t::reverse_iterator reverse_iterator_t;
148 typedef typename tree_t::const_reverse_iterator const_reverse_iterator_t;
151 typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
152 typedef typename impl_tree_t::sequence_type impl_sequence_type;
154 BOOST_CONTAINER_FORCEINLINE impl_tree_t &tree()
155 { return m_flat_tree; }
157 BOOST_CONTAINER_FORCEINLINE const impl_tree_t &tree() const
158 { return m_flat_tree; }
161 typedef typename tree_t::get_stored_allocator_const_return_t get_stored_allocator_const_return_t;
162 typedef typename tree_t::get_stored_allocator_noconst_return_t get_stored_allocator_noconst_return_t;
163 typedef typename impl_tree_t::get_stored_allocator_const_return_t impl_get_stored_allocator_const_return_t;
164 typedef typename impl_tree_t::get_stored_allocator_noconst_return_t impl_get_stored_allocator_noconst_return_t;
166 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
170 //////////////////////////////////////////////
174 //////////////////////////////////////////////
175 typedef Key key_type;
176 typedef T mapped_type;
177 typedef Compare key_compare;
178 typedef std::pair<Key, T> value_type;
179 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type) sequence_type;
180 typedef typename sequence_type::allocator_type allocator_type;
181 typedef ::boost::container::allocator_traits<allocator_type> allocator_traits_type;
182 typedef typename sequence_type::pointer pointer;
183 typedef typename sequence_type::const_pointer const_pointer;
184 typedef typename sequence_type::reference reference;
185 typedef typename sequence_type::const_reference const_reference;
186 typedef typename sequence_type::size_type size_type;
187 typedef typename sequence_type::difference_type difference_type;
188 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
189 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare) value_compare;
191 typedef typename sequence_type::iterator iterator;
192 typedef typename sequence_type::const_iterator const_iterator;
193 typedef typename sequence_type::reverse_iterator reverse_iterator;
194 typedef typename sequence_type::const_reverse_iterator const_reverse_iterator;
195 typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
197 //AllocatorOrContainer::value_type must be std::pair<Key, T>
198 BOOST_STATIC_ASSERT((dtl::is_same<std::pair<Key, T>, value_type>::value));
200 //////////////////////////////////////////////
202 // construct/copy/destroy
204 //////////////////////////////////////////////
206 //! <b>Effects</b>: Default constructs an empty flat_map.
208 //! <b>Complexity</b>: Constant.
209 BOOST_CONTAINER_FORCEINLINE flat_map() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
210 dtl::is_nothrow_default_constructible<Compare>::value)
214 //! <b>Effects</b>: Constructs an empty flat_map using the specified allocator.
216 //! <b>Complexity</b>: Constant.
217 BOOST_CONTAINER_FORCEINLINE explicit flat_map(const allocator_type& a)
218 : m_flat_tree(dtl::force<const impl_allocator_type>(a))
221 //! <b>Effects</b>: Constructs an empty flat_map using the specified
222 //! comparison object.
224 //! <b>Complexity</b>: Constant.
225 BOOST_CONTAINER_FORCEINLINE explicit flat_map(const Compare& comp)
229 //! <b>Effects</b>: Constructs an empty flat_map using the specified
230 //! comparison object and allocator.
232 //! <b>Complexity</b>: Constant.
233 BOOST_CONTAINER_FORCEINLINE flat_map(const Compare& comp, const allocator_type& a)
234 : m_flat_tree(comp, dtl::force<const impl_allocator_type>(a))
237 //! <b>Effects</b>: Constructs an empty flat_map and
238 //! and inserts elements from the range [first ,last ).
240 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
241 //! the predicate and otherwise N logN, where N is last - first.
242 template <class InputIterator>
243 BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last)
244 : m_flat_tree(true, first, last)
247 //! <b>Effects</b>: Constructs an empty flat_map using the specified
248 //! allocator, and inserts elements from the range [first ,last ).
250 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
251 //! the predicate and otherwise N logN, where N is last - first.
252 template <class InputIterator>
253 BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const allocator_type& a)
254 : m_flat_tree(true, first, last, dtl::force<const impl_allocator_type>(a))
257 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
258 //! and inserts elements from the range [first ,last ).
260 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
261 //! the predicate and otherwise N logN, where N is last - first.
262 template <class InputIterator>
263 BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const Compare& comp)
264 : m_flat_tree(true, first, last, comp)
267 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
268 //! allocator, and inserts elements from the range [first ,last ).
270 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
271 //! the predicate and otherwise N logN, where N is last - first.
272 template <class InputIterator>
273 BOOST_CONTAINER_FORCEINLINE flat_map(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
274 : m_flat_tree(true, first, last, comp, dtl::force<const impl_allocator_type>(a))
277 //! <b>Effects</b>: Constructs an empty flat_map
278 //! and inserts elements from the ordered range [first ,last). This function
279 //! is more efficient than the normal range creation for ordered ranges.
281 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
283 //! <b>Complexity</b>: Linear in N.
285 //! <b>Note</b>: Non-standard extension.
286 template <class InputIterator>
287 BOOST_CONTAINER_FORCEINLINE
288 flat_map(ordered_unique_range_t, InputIterator first, InputIterator last)
289 : m_flat_tree(ordered_range, first, last)
292 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
293 //! inserts elements from the ordered range [first ,last). This function
294 //! is more efficient than the normal range creation for ordered ranges.
296 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
298 //! <b>Complexity</b>: Linear in N.
300 //! <b>Note</b>: Non-standard extension.
301 template <class InputIterator>
302 BOOST_CONTAINER_FORCEINLINE
303 flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
304 : m_flat_tree(ordered_range, first, last, comp)
307 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
308 //! allocator, and inserts elements from the ordered range [first ,last). This function
309 //! is more efficient than the normal range creation for ordered ranges.
311 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
313 //! <b>Complexity</b>: Linear in N.
315 //! <b>Note</b>: Non-standard extension.
316 template <class InputIterator>
317 BOOST_CONTAINER_FORCEINLINE
318 flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
319 : m_flat_tree(ordered_range, first, last, comp, dtl::force<const impl_allocator_type>(a))
322 //! <b>Effects</b>: Constructs an empty flat_map using the specified allocator and
323 //! inserts elements from the ordered range [first ,last). This function
324 //! is more efficient than the normal range creation for ordered ranges.
326 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
328 //! <b>Complexity</b>: Linear in N.
330 //! <b>Note</b>: Non-standard extension.
331 template <class InputIterator>
332 BOOST_CONTAINER_FORCEINLINE
333 flat_map(ordered_unique_range_t, InputIterator first, InputIterator last, const allocator_type& a)
334 : m_flat_tree(ordered_range, first, last, Compare(), a)
337 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
338 //! <b>Effects</b>: Constructs an empty flat_map and
339 //! inserts elements from the range [il.begin() ,il.end()).
341 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
342 //! the predicate and otherwise N logN, where N is last - first.
343 BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il)
345 , dtl::force<impl_initializer_list>(il).begin()
346 , dtl::force<impl_initializer_list>(il).end())
349 //! <b>Effects</b>: Constructs an empty flat_map using the specified
350 //! allocator, and inserts elements from the range [il.begin() ,il.end()).
352 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
353 //! the predicate and otherwise N logN, where N is last - first.
354 BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const allocator_type& a)
356 , dtl::force<impl_initializer_list>(il).begin()
357 , dtl::force<impl_initializer_list>(il).end()
358 , dtl::force<const impl_allocator_type>(a))
361 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
362 //! inserts elements from the range [il.begin() ,il.end()).
364 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
365 //! the predicate and otherwise N logN, where N is last - first.
366 BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const Compare& comp)
368 , dtl::force<impl_initializer_list>(il).begin()
369 , dtl::force<impl_initializer_list>(il).end()
373 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
374 //! allocator, and inserts elements from the range [il.begin() ,il.end()).
376 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
377 //! the predicate and otherwise N logN, where N is last - first.
378 BOOST_CONTAINER_FORCEINLINE flat_map(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
380 , dtl::force<impl_initializer_list>(il).begin()
381 , dtl::force<impl_initializer_list>(il).end()
383 , dtl::force<const impl_allocator_type>(a))
386 //! <b>Effects</b>: Constructs an empty flat_map using and
387 //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
388 //! is more efficient than the normal range creation for ordered ranges.
390 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
393 //! <b>Complexity</b>: Linear in N.
395 //! <b>Note</b>: Non-standard extension.
396 BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il)
397 : m_flat_tree(ordered_unique_range
398 , dtl::force<impl_initializer_list>(il).begin()
399 , dtl::force<impl_initializer_list>(il).end())
402 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
403 //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
404 //! is more efficient than the normal range creation for ordered ranges.
406 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
409 //! <b>Complexity</b>: Linear in N.
411 //! <b>Note</b>: Non-standard extension.
412 BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp)
413 : m_flat_tree(ordered_unique_range
414 , dtl::force<impl_initializer_list>(il).begin()
415 , dtl::force<impl_initializer_list>(il).end()
419 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
420 //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
421 //! is more efficient than the normal range creation for ordered ranges.
423 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
426 //! <b>Complexity</b>: Linear in N.
428 //! <b>Note</b>: Non-standard extension.
429 BOOST_CONTAINER_FORCEINLINE flat_map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
430 : m_flat_tree( ordered_unique_range
431 , dtl::force<impl_initializer_list>(il).begin()
432 , dtl::force<impl_initializer_list>(il).end()
434 , dtl::force<const impl_allocator_type>(a))
438 //! <b>Effects</b>: Copy constructs a flat_map.
440 //! <b>Complexity</b>: Linear in x.size().
441 BOOST_CONTAINER_FORCEINLINE flat_map(const flat_map& x)
442 : m_flat_tree(x.m_flat_tree)
445 //! <b>Effects</b>: Move constructs a flat_map.
446 //! Constructs *this using x's resources.
448 //! <b>Complexity</b>: Constant.
450 //! <b>Postcondition</b>: x is emptied.
451 BOOST_CONTAINER_FORCEINLINE flat_map(BOOST_RV_REF(flat_map) x)
452 BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
453 : m_flat_tree(boost::move(x.m_flat_tree))
456 //! <b>Effects</b>: Copy constructs a flat_map using the specified allocator.
458 //! <b>Complexity</b>: Linear in x.size().
459 BOOST_CONTAINER_FORCEINLINE flat_map(const flat_map& x, const allocator_type &a)
460 : m_flat_tree(x.m_flat_tree, dtl::force<const impl_allocator_type>(a))
463 //! <b>Effects</b>: Move constructs a flat_map using the specified allocator.
464 //! Constructs *this using x's resources.
466 //! <b>Complexity</b>: Constant if x.get_allocator() == a, linear otherwise.
467 BOOST_CONTAINER_FORCEINLINE flat_map(BOOST_RV_REF(flat_map) x, const allocator_type &a)
468 : m_flat_tree(boost::move(x.m_flat_tree), dtl::force<const impl_allocator_type>(a))
471 //! <b>Effects</b>: Makes *this a copy of x.
473 //! <b>Complexity</b>: Linear in x.size().
474 BOOST_CONTAINER_FORCEINLINE flat_map& operator=(BOOST_COPY_ASSIGN_REF(flat_map) x)
475 { m_flat_tree = x.m_flat_tree; return *this; }
477 //! <b>Effects</b>: Move constructs a flat_map.
478 //! Constructs *this using x's resources.
480 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
481 //! is false and (allocation throws or value_type's move constructor throws)
483 //! <b>Complexity</b>: Constant if allocator_traits_type::
484 //! propagate_on_container_move_assignment is true or
485 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
486 BOOST_CONTAINER_FORCEINLINE flat_map& operator=(BOOST_RV_REF(flat_map) x)
487 BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
488 allocator_traits_type::is_always_equal::value) &&
489 boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
490 { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
492 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
493 //! <b>Effects</b>: Assign elements from il to *this
494 flat_map& operator=(std::initializer_list<value_type> il)
497 this->insert(il.begin(), il.end());
502 //! <b>Effects</b>: Returns a copy of the allocator that
503 //! was passed to the object's constructor.
505 //! <b>Complexity</b>: Constant.
506 BOOST_CONTAINER_FORCEINLINE allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
507 { return dtl::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
509 //! <b>Effects</b>: Returns a reference to the internal allocator.
511 //! <b>Throws</b>: Nothing
513 //! <b>Complexity</b>: Constant.
515 //! <b>Note</b>: Non-standard extension.
516 BOOST_CONTAINER_FORCEINLINE get_stored_allocator_noconst_return_t get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
518 impl_get_stored_allocator_noconst_return_t r = m_flat_tree.get_stored_allocator();
519 return dtl::force<stored_allocator_type>(r);
522 //! <b>Effects</b>: Returns a reference to the internal allocator.
524 //! <b>Throws</b>: Nothing
526 //! <b>Complexity</b>: Constant.
528 //! <b>Note</b>: Non-standard extension.
529 BOOST_CONTAINER_FORCEINLINE get_stored_allocator_const_return_t get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
531 impl_get_stored_allocator_const_return_t r = m_flat_tree.get_stored_allocator();
532 return dtl::force<const stored_allocator_type>(r);
535 //////////////////////////////////////////////
539 //////////////////////////////////////////////
541 //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
543 //! <b>Throws</b>: Nothing.
545 //! <b>Complexity</b>: Constant.
546 BOOST_CONTAINER_FORCEINLINE iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
547 { return dtl::force_copy<iterator>(m_flat_tree.begin()); }
549 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
551 //! <b>Throws</b>: Nothing.
553 //! <b>Complexity</b>: Constant.
554 BOOST_CONTAINER_FORCEINLINE const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
555 { return dtl::force_copy<const_iterator>(m_flat_tree.begin()); }
557 //! <b>Effects</b>: Returns an iterator to the end of the container.
559 //! <b>Throws</b>: Nothing.
561 //! <b>Complexity</b>: Constant.
562 BOOST_CONTAINER_FORCEINLINE iterator end() BOOST_NOEXCEPT_OR_NOTHROW
563 { return dtl::force_copy<iterator>(m_flat_tree.end()); }
565 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
567 //! <b>Throws</b>: Nothing.
569 //! <b>Complexity</b>: Constant.
570 BOOST_CONTAINER_FORCEINLINE const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
571 { return dtl::force_copy<const_iterator>(m_flat_tree.end()); }
573 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
574 //! of the reversed container.
576 //! <b>Throws</b>: Nothing.
578 //! <b>Complexity</b>: Constant.
579 BOOST_CONTAINER_FORCEINLINE reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
580 { return dtl::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
582 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
583 //! of the reversed container.
585 //! <b>Throws</b>: Nothing.
587 //! <b>Complexity</b>: Constant.
588 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
589 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
591 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
592 //! of the reversed container.
594 //! <b>Throws</b>: Nothing.
596 //! <b>Complexity</b>: Constant.
597 BOOST_CONTAINER_FORCEINLINE reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
598 { return dtl::force_copy<reverse_iterator>(m_flat_tree.rend()); }
600 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
601 //! of the reversed container.
603 //! <b>Throws</b>: Nothing.
605 //! <b>Complexity</b>: Constant.
606 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
607 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
609 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
611 //! <b>Throws</b>: Nothing.
613 //! <b>Complexity</b>: Constant.
614 BOOST_CONTAINER_FORCEINLINE const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
615 { return dtl::force_copy<const_iterator>(m_flat_tree.cbegin()); }
617 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
619 //! <b>Throws</b>: Nothing.
621 //! <b>Complexity</b>: Constant.
622 BOOST_CONTAINER_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
623 { return dtl::force_copy<const_iterator>(m_flat_tree.cend()); }
625 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
626 //! of the reversed container.
628 //! <b>Throws</b>: Nothing.
630 //! <b>Complexity</b>: Constant.
631 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
632 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
634 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
635 //! of the reversed container.
637 //! <b>Throws</b>: Nothing.
639 //! <b>Complexity</b>: Constant.
640 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
641 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
643 //////////////////////////////////////////////
647 //////////////////////////////////////////////
649 //! <b>Effects</b>: Returns true if the container contains no elements.
651 //! <b>Throws</b>: Nothing.
653 //! <b>Complexity</b>: Constant.
654 BOOST_CONTAINER_FORCEINLINE bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
655 { return m_flat_tree.empty(); }
657 //! <b>Effects</b>: Returns the number of the elements contained in the container.
659 //! <b>Throws</b>: Nothing.
661 //! <b>Complexity</b>: Constant.
662 BOOST_CONTAINER_FORCEINLINE size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
663 { return m_flat_tree.size(); }
665 //! <b>Effects</b>: Returns the largest possible size of the container.
667 //! <b>Throws</b>: Nothing.
669 //! <b>Complexity</b>: Constant.
670 BOOST_CONTAINER_FORCEINLINE size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
671 { return m_flat_tree.max_size(); }
673 //! <b>Effects</b>: Number of elements for which memory has been allocated.
674 //! capacity() is always greater than or equal to size().
676 //! <b>Throws</b>: Nothing.
678 //! <b>Complexity</b>: Constant.
679 BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
680 { return m_flat_tree.capacity(); }
682 //! <b>Effects</b>: If n is less than or equal to capacity(), or the
683 //! underlying container has no `reserve` member, this call has no
684 //! effect. Otherwise, it is a request for allocation of additional memory.
685 //! If the request is successful, then capacity() is greater than or equal to
686 //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
688 //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
690 //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
691 //! to values might be invalidated.
692 BOOST_CONTAINER_FORCEINLINE void reserve(size_type cnt)
693 { m_flat_tree.reserve(cnt); }
695 //! <b>Effects</b>: Tries to deallocate the excess of memory created
696 // with previous allocations. The size of the vector is unchanged
698 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
700 //! <b>Complexity</b>: Linear to size().
701 BOOST_CONTAINER_FORCEINLINE void shrink_to_fit()
702 { m_flat_tree.shrink_to_fit(); }
704 //////////////////////////////////////////////
708 //////////////////////////////////////////////
710 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
711 //! Effects: If there is no key equivalent to x in the flat_map, inserts
712 //! value_type(x, T()) into the flat_map.
714 //! Returns: A reference to the mapped_type corresponding to x in *this.
716 //! Complexity: Logarithmic.
717 mapped_type &operator[](const key_type& k);
719 //! Effects: If there is no key equivalent to x in the flat_map, inserts
720 //! value_type(move(x), T()) into the flat_map (the key is move-constructed)
722 //! Returns: A reference to the mapped_type corresponding to x in *this.
724 //! Complexity: Logarithmic.
725 mapped_type &operator[](key_type &&k) ;
726 #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
727 //in compilers like GCC 3.4, we can't catch temporaries
728 BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
729 BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
731 BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
734 //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
735 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
736 //! as if by insert, constructing it from value_type(k, forward<M>(obj)).
738 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
739 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
740 //! references obtained to that element before it was extracted become valid.
742 //! Returns: The bool component is true if the insertion took place and false if the assignment
743 //! took place. The iterator component is pointing at the element that was inserted or updated.
745 //! Complexity: Logarithmic in the size of the container.
747 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(const key_type& k, BOOST_FWD_REF(M) obj)
749 return dtl::force_copy< std::pair<iterator, bool> >
750 (this->m_flat_tree.insert_or_assign
751 ( impl_const_iterator(), k, ::boost::forward<M>(obj))
755 //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
756 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
757 //! as if by insert, constructing it from value_type(k, move(obj)).
759 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
760 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
761 //! references obtained to that element before it was extracted become valid.
763 //! Returns: The bool component is true if the insertion took place and false if the assignment
764 //! took place. The iterator component is pointing at the element that was inserted or updated.
766 //! Complexity: Logarithmic in the size of the container.
768 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
770 return dtl::force_copy< std::pair<iterator, bool> >
771 (this->m_flat_tree.insert_or_assign
772 ( impl_const_iterator(), ::boost::move(k), ::boost::forward<M>(obj))
776 //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
777 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
778 //! as if by insert, constructing it from value_type(k, forward<M>(obj)) and the new element
779 //! to the container as close as possible to the position just before hint.
781 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
782 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
783 //! references obtained to that element before it was extracted become valid.
785 //! Returns: The bool component is true if the insertion took place and false if the assignment
786 //! took place. The iterator component is pointing at the element that was inserted or updated.
788 //! Complexity: Logarithmic in the size of the container in general, but amortized constant if
789 //! the new element is inserted just before hint.
791 BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj)
793 return dtl::force_copy<iterator>
794 (this->m_flat_tree.insert_or_assign
795 ( dtl::force_copy<impl_const_iterator>(hint)
796 , k, ::boost::forward<M>(obj)).first
800 //! Effects: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
801 //! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
802 //! as if by insert, constructing it from value_type(k, move(obj)) and the new element
803 //! to the container as close as possible to the position just before hint.
805 //! No iterators or references are invalidated. If the insertion is successful, pointers and references
806 //! to the element obtained while it is held in the node handle are invalidated, and pointers and
807 //! references obtained to that element before it was extracted become valid.
809 //! Returns: The bool component is true if the insertion took place and false if the assignment
810 //! took place. The iterator component is pointing at the element that was inserted or updated.
812 //! Complexity: Logarithmic in the size of the container in general, but amortized constant if
813 //! the new element is inserted just before hint.
815 BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
817 return dtl::force_copy<iterator>
818 (this->m_flat_tree.insert_or_assign
819 ( dtl::force_copy<impl_const_iterator>(hint)
820 , ::boost::move(k), ::boost::forward<M>(obj)).first
824 //! @copydoc ::boost::container::flat_set::nth(size_type)
825 BOOST_CONTAINER_FORCEINLINE iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
826 { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
828 //! @copydoc ::boost::container::flat_set::nth(size_type) const
829 BOOST_CONTAINER_FORCEINLINE const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
830 { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
832 //! @copydoc ::boost::container::flat_set::index_of(iterator)
833 BOOST_CONTAINER_FORCEINLINE size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
834 { return m_flat_tree.index_of(dtl::force_copy<impl_iterator>(p)); }
836 //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
837 BOOST_CONTAINER_FORCEINLINE size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
838 { return m_flat_tree.index_of(dtl::force_copy<impl_const_iterator>(p)); }
840 //! Returns: A reference to the element whose key is equivalent to x.
842 //! Throws: An exception object of type out_of_range if no such element is present.
844 //! Complexity: logarithmic.
845 T& at(const key_type& k)
847 iterator i = this->find(k);
848 if(i == this->end()){
849 throw_out_of_range("flat_map::at key not found");
854 //! Returns: A reference to the element whose key is equivalent to x.
856 //! Throws: An exception object of type out_of_range if no such element is present.
858 //! Complexity: logarithmic.
859 const T& at(const key_type& k) const
861 const_iterator i = this->find(k);
862 if(i == this->end()){
863 throw_out_of_range("flat_map::at key not found");
868 //////////////////////////////////////////////
872 //////////////////////////////////////////////
874 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
876 //! <b>Effects</b>: Inserts an object x of type T constructed with
877 //! std::forward<Args>(args)... if and only if there is no element in the container
878 //! with key equivalent to the key of x.
880 //! <b>Returns</b>: The bool component of the returned pair is true if and only
881 //! if the insertion takes place, and the iterator component of the pair
882 //! points to the element with key equivalent to the key of x.
884 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
885 //! to the elements with bigger keys than x.
887 //! <b>Note</b>: If an element is inserted it might invalidate elements.
888 template <class... Args>
889 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
890 { return dtl::force_copy< std::pair<iterator, bool> >(m_flat_tree.emplace_unique(boost::forward<Args>(args)...)); }
892 //! <b>Effects</b>: Inserts an object of type T constructed with
893 //! std::forward<Args>(args)... in the container if and only if there is
894 //! no element in the container with key equivalent to the key of x.
895 //! p is a hint pointing to where the insert should start to search.
897 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
900 //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
901 //! right before p) plus insertion linear to the elements with bigger keys than x.
903 //! <b>Note</b>: If an element is inserted it might invalidate elements.
904 template <class... Args>
905 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
907 return dtl::force_copy<iterator>
908 (m_flat_tree.emplace_hint_unique( dtl::force_copy<impl_const_iterator>(hint)
909 , boost::forward<Args>(args)...));
912 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
913 //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
915 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
916 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
917 //! forward_as_tuple(forward<Args>(args)...).
919 //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
920 //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
922 //! <b>Complexity</b>: Logarithmic.
923 template <class... Args>
924 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k, BOOST_FWD_REF(Args)... args)
926 return dtl::force_copy< std::pair<iterator, bool> >(
927 m_flat_tree.try_emplace(impl_const_iterator(), k, boost::forward<Args>(args)...));
930 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
931 //! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
933 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
934 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
935 //! forward_as_tuple(forward<Args>(args)...).
937 //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
939 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
940 //! is inserted right before p.
941 template <class... Args>
942 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k, BOOST_FWD_REF(Args)... args)
944 return dtl::force_copy<iterator>(m_flat_tree.try_emplace
945 (dtl::force_copy<impl_const_iterator>(hint), k, boost::forward<Args>(args)...).first);
948 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
949 //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
951 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
952 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
953 //! forward_as_tuple(forward<Args>(args)...).
955 //! <b>Returns</b>: The bool component of the returned pair is true if and only if the
956 //! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
958 //! <b>Complexity</b>: Logarithmic.
959 template <class... Args>
960 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
962 return dtl::force_copy< std::pair<iterator, bool> >
963 (m_flat_tree.try_emplace(impl_const_iterator(), boost::move(k), boost::forward<Args>(args)...));
966 //! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
967 //! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
969 //! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
970 //! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
971 //! forward_as_tuple(forward<Args>(args)...).
973 //! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
975 //! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
976 //! is inserted right before p.
977 template <class... Args>
978 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
980 return dtl::force_copy<iterator>
981 (m_flat_tree.try_emplace(dtl::force_copy
982 <impl_const_iterator>(hint), boost::move(k), boost::forward<Args>(args)...).first);
985 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
987 #define BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE(N) \
988 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
989 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
991 return dtl::force_copy< std::pair<iterator, bool> >\
992 (m_flat_tree.emplace_unique(BOOST_MOVE_FWD##N));\
995 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
996 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
998 return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_unique\
999 (dtl::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
1001 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1002 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1004 return dtl::force_copy< std::pair<iterator, bool> >\
1005 (m_flat_tree.try_emplace(impl_const_iterator(), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
1008 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1009 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1010 { return dtl::force_copy<iterator>(m_flat_tree.try_emplace\
1011 (dtl::force_copy<impl_const_iterator>(hint), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first); }\
1013 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1014 BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1016 return dtl::force_copy< std::pair<iterator, bool> >\
1017 (m_flat_tree.try_emplace(impl_const_iterator(), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
1020 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1021 BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1022 { return dtl::force_copy<iterator>(m_flat_tree.try_emplace\
1023 (dtl::force_copy<impl_const_iterator>(hint), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first); }\
1025 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE)
1026 #undef BOOST_CONTAINER_FLAT_MAP_EMPLACE_CODE
1028 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1030 //! <b>Effects</b>: Inserts x if and only if there is no element in the container
1031 //! with key equivalent to the key of x.
1033 //! <b>Returns</b>: The bool component of the returned pair is true if and only
1034 //! if the insertion takes place, and the iterator component of the pair
1035 //! points to the element with key equivalent to the key of x.
1037 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1038 //! to the elements with bigger keys than x.
1040 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1041 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const value_type& x)
1042 { return dtl::force_copy<std::pair<iterator,bool> >(
1043 m_flat_tree.insert_unique(dtl::force<const impl_value_type>(x))); }
1045 //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
1046 //! only if there is no element in the container with key equivalent to the key of x.
1048 //! <b>Returns</b>: The bool component of the returned pair is true if and only
1049 //! if the insertion takes place, and the iterator component of the pair
1050 //! points to the element with key equivalent to the key of x.
1052 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1053 //! to the elements with bigger keys than x.
1055 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1056 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
1057 { return dtl::force_copy<std::pair<iterator,bool> >(
1058 m_flat_tree.insert_unique(boost::move(dtl::force<impl_value_type>(x)))); }
1060 //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
1061 //! only if there is no element in the container with key equivalent to the key of x.
1063 //! <b>Returns</b>: The bool component of the returned pair is true if and only
1064 //! if the insertion takes place, and the iterator component of the pair
1065 //! points to the element with key equivalent to the key of x.
1067 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1068 //! to the elements with bigger keys than x.
1070 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1071 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
1073 return dtl::force_copy<std::pair<iterator,bool> >
1074 (m_flat_tree.insert_unique(boost::move(x)));
1077 //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
1078 //! no element in the container with key equivalent to the key of x.
1079 //! p is a hint pointing to where the insert should start to search.
1081 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1082 //! to the key of x.
1084 //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1085 //! right before p) plus insertion linear to the elements with bigger keys than x.
1087 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1088 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
1090 return dtl::force_copy<iterator>(
1091 m_flat_tree.insert_unique( dtl::force_copy<impl_const_iterator>(p)
1092 , dtl::force<const impl_value_type>(x)));
1095 //! <b>Effects</b>: Inserts an element move constructed from x in the container.
1096 //! p is a hint pointing to where the insert should start to search.
1098 //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
1100 //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1101 //! right before p) plus insertion linear to the elements with bigger keys than x.
1103 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1104 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
1106 return dtl::force_copy<iterator>
1107 (m_flat_tree.insert_unique( dtl::force_copy<impl_const_iterator>(p)
1108 , boost::move(dtl::force<impl_value_type>(x))));
1111 //! <b>Effects</b>: Inserts an element move constructed from x in the container.
1112 //! p is a hint pointing to where the insert should start to search.
1114 //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
1116 //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1117 //! right before p) plus insertion linear to the elements with bigger keys than x.
1119 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1120 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
1122 return dtl::force_copy<iterator>(
1123 m_flat_tree.insert_unique(dtl::force_copy<impl_const_iterator>(p), boost::move(x)));
1126 //! <b>Requires</b>: first, last are not iterators into *this.
1128 //! <b>Effects</b>: inserts each element from the range [first,last) if and only
1129 //! if there is no element with key equivalent to the key of that element.
1131 //! <b>Complexity</b>: N log(size()+N).
1133 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1134 template <class InputIterator>
1135 BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
1136 { m_flat_tree.insert_unique(first, last); }
1138 //! <b>Requires</b>: first, last are not iterators into *this.
1140 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
1143 //! <b>Effects</b>: inserts each element from the range [first,last) if and only
1144 //! if there is no element with key equivalent to the key of that element. This
1145 //! function is more efficient than the normal range creation for ordered ranges.
1147 //! <b>Complexity</b>: Linear.
1149 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1151 //! <b>Note</b>: Non-standard extension.
1152 template <class InputIterator>
1153 BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, InputIterator first, InputIterator last)
1154 { m_flat_tree.insert_unique(ordered_unique_range, first, last); }
1156 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1157 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
1158 //! if there is no element with key equivalent to the key of that element.
1160 //! <b>Complexity</b>: N log(N).
1162 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1163 BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
1165 m_flat_tree.insert_unique( dtl::force<impl_initializer_list>(il).begin()
1166 , dtl::force<impl_initializer_list>(il).end());
1169 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
1172 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
1173 //! if there is no element with key equivalent to the key of that element. This
1174 //! function is more efficient than the normal range creation for ordered ranges.
1176 //! <b>Complexity</b>: Linear.
1178 //! <b>Note</b>: If an element is inserted it might invalidate elements.
1180 //! <b>Note</b>: Non-standard extension.
1181 BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, std::initializer_list<value_type> il)
1183 m_flat_tree.insert_unique(ordered_unique_range
1184 , dtl::force<impl_initializer_list>(il).begin()
1185 , dtl::force<impl_initializer_list>(il).end());
1189 //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
1191 //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
1192 //! the comparison object of *this. If there is an element in a with key equivalent to the
1193 //! key of an element from source, then that element is not extracted from source.
1195 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
1196 //! to those same elements but as members of *this. Iterators referring to the transferred
1197 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
1198 //! not into source.
1200 //! <b>Throws</b>: Nothing unless the comparison object throws.
1202 //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
1204 BOOST_CONTAINER_FORCEINLINE void merge(flat_map<Key, T, C2, AllocatorOrContainer>& source)
1205 { m_flat_tree.merge_unique(source.tree()); }
1207 //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
1209 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_map<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
1210 { return this->merge(static_cast<flat_map<Key, T, C2, AllocatorOrContainer>&>(source)); }
1212 //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
1214 BOOST_CONTAINER_FORCEINLINE void merge(flat_multimap<Key, T, C2, AllocatorOrContainer>& source)
1215 { m_flat_tree.merge_unique(source.tree()); }
1217 //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
1219 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multimap<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
1220 { return this->merge(static_cast<flat_multimap<Key, T, C2, AllocatorOrContainer>&>(source)); }
1222 //! <b>Effects</b>: Erases the element pointed to by p.
1224 //! <b>Returns</b>: Returns an iterator pointing to the element immediately
1225 //! following q prior to the element being erased. If no such element exists,
1228 //! <b>Complexity</b>: Linear to the elements with keys bigger than p
1230 //! <b>Note</b>: Invalidates elements with keys
1231 //! not less than the erased element.
1232 BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator p)
1234 return dtl::force_copy<iterator>
1235 (m_flat_tree.erase(dtl::force_copy<impl_const_iterator>(p)));
1238 //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
1240 //! <b>Returns</b>: Returns the number of erased elements.
1242 //! <b>Complexity</b>: Logarithmic search time plus erasure time
1243 //! linear to the elements with bigger keys.
1244 BOOST_CONTAINER_FORCEINLINE size_type erase(const key_type& x)
1245 { return m_flat_tree.erase(x); }
1247 //! <b>Effects</b>: Erases all the elements in the range [first, last).
1249 //! <b>Returns</b>: Returns last.
1251 //! <b>Complexity</b>: size()*N where N is the distance from first to last.
1253 //! <b>Complexity</b>: Logarithmic search time plus erasure time
1254 //! linear to the elements with bigger keys.
1255 BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator first, const_iterator last)
1257 return dtl::force_copy<iterator>(
1258 m_flat_tree.erase( dtl::force_copy<impl_const_iterator>(first)
1259 , dtl::force_copy<impl_const_iterator>(last)));
1262 //! <b>Effects</b>: Swaps the contents of *this and x.
1264 //! <b>Throws</b>: Nothing.
1266 //! <b>Complexity</b>: Constant.
1267 BOOST_CONTAINER_FORCEINLINE void swap(flat_map& x)
1268 BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
1269 && boost::container::dtl::is_nothrow_swappable<Compare>::value )
1270 { m_flat_tree.swap(x.m_flat_tree); }
1272 //! <b>Effects</b>: erase(begin(),end()).
1274 //! <b>Postcondition</b>: size() == 0.
1276 //! <b>Complexity</b>: linear in size().
1277 BOOST_CONTAINER_FORCEINLINE void clear() BOOST_NOEXCEPT_OR_NOTHROW
1278 { m_flat_tree.clear(); }
1280 //////////////////////////////////////////////
1284 //////////////////////////////////////////////
1286 //! <b>Effects</b>: Returns the comparison object out
1287 //! of which a was constructed.
1289 //! <b>Complexity</b>: Constant.
1290 BOOST_CONTAINER_FORCEINLINE key_compare key_comp() const
1291 { return dtl::force_copy<key_compare>(m_flat_tree.key_comp()); }
1293 //! <b>Effects</b>: Returns an object of value_compare constructed out
1294 //! of the comparison object.
1296 //! <b>Complexity</b>: Constant.
1297 BOOST_CONTAINER_FORCEINLINE value_compare value_comp() const
1298 { return value_compare(dtl::force_copy<key_compare>(m_flat_tree.key_comp())); }
1300 //////////////////////////////////////////////
1304 //////////////////////////////////////////////
1306 //! <b>Returns</b>: An iterator pointing to an element with the key
1307 //! equivalent to x, or end() if such an element is not found.
1309 //! <b>Complexity</b>: Logarithmic.
1310 BOOST_CONTAINER_FORCEINLINE iterator find(const key_type& x)
1311 { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
1313 //! <b>Returns</b>: A const_iterator pointing to an element with the key
1314 //! equivalent to x, or end() if such an element is not found.
1316 //! <b>Complexity</b>: Logarithmic.
1317 BOOST_CONTAINER_FORCEINLINE const_iterator find(const key_type& x) const
1318 { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
1320 //! <b>Requires</b>: This overload is available only if
1321 //! key_compare::is_transparent exists.
1323 //! <b>Returns</b>: An iterator pointing to an element with the key
1324 //! equivalent to x, or end() if such an element is not found.
1326 //! <b>Complexity</b>: Logarithmic.
1328 BOOST_CONTAINER_FORCEINLINE iterator find(const K& x)
1329 { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
1331 //! <b>Requires</b>: This overload is available only if
1332 //! key_compare::is_transparent exists.
1334 //! <b>Returns</b>: A const_iterator pointing to an element with the key
1335 //! equivalent to x, or end() if such an element is not found.
1337 //! <b>Complexity</b>: Logarithmic.
1339 BOOST_CONTAINER_FORCEINLINE const_iterator find(const K& x) const
1340 { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
1342 //! <b>Returns</b>: The number of elements with key equivalent to x.
1344 //! <b>Complexity</b>: log(size())+count(k)
1345 BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
1346 { return static_cast<size_type>(m_flat_tree.find(x) != m_flat_tree.end()); }
1348 //! <b>Requires</b>: This overload is available only if
1349 //! key_compare::is_transparent exists.
1351 //! <b>Returns</b>: The number of elements with key equivalent to x.
1353 //! <b>Complexity</b>: log(size())+count(k)
1355 BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
1356 //Don't use find() != end optimization here as transparent comparators with key K might
1357 //return a different range than key_type (which can only return a single element range)
1358 { return m_flat_tree.count(x); }
1360 //! <b>Returns</b>: Returns true if there is an element with key
1361 //! equivalent to key in the container, otherwise false.
1363 //! <b>Complexity</b>: log(size()).
1364 bool contains(const key_type& x) const
1365 { return m_flat_tree.find(x) != m_flat_tree.end(); }
1367 //! <b>Requires</b>: This overload is available only if
1368 //! key_compare::is_transparent exists.
1370 //! <b>Returns</b>: Returns true if there is an element with key
1371 //! equivalent to key in the container, otherwise false.
1373 //! <b>Complexity</b>: log(size()).
1374 template<typename K>
1375 bool contains(const K& x) const
1376 { return m_flat_tree.find(x) != m_flat_tree.end(); }
1378 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1379 //! than x, or end() if such an element is not found.
1381 //! <b>Complexity</b>: Logarithmic.
1382 BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const key_type& x)
1383 { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
1385 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1386 //! less than x, or end() if such an element is not found.
1388 //! <b>Complexity</b>: Logarithmic.
1389 BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const key_type& x) const
1390 { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
1392 //! <b>Requires</b>: This overload is available only if
1393 //! key_compare::is_transparent exists.
1395 //! <b>Returns</b>: An iterator pointing to the first element with key not less
1396 //! than x, or end() if such an element is not found.
1398 //! <b>Complexity</b>: Logarithmic.
1400 BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const K& x)
1401 { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
1403 //! <b>Requires</b>: This overload is available only if
1404 //! key_compare::is_transparent exists.
1406 //! <b>Returns</b>: A const iterator pointing to the first element with key not
1407 //! less than x, or end() if such an element is not found.
1409 //! <b>Complexity</b>: Logarithmic.
1411 BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const K& x) const
1412 { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
1414 //! <b>Returns</b>: An iterator pointing to the first element with key greater
1415 //! than x, or end() if such an element is not found.
1417 //! <b>Complexity</b>: Logarithmic.
1418 BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const key_type& x)
1419 { return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
1421 //! <b>Returns</b>: A const iterator pointing to the first element with key
1422 //! greater than x, or end() if such an element is not found.
1424 //! <b>Complexity</b>: Logarithmic.
1425 BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const key_type& x) const
1426 { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
1428 //! <b>Requires</b>: This overload is available only if
1429 //! key_compare::is_transparent exists.
1431 //! <b>Returns</b>: An iterator pointing to the first element with key greater
1432 //! than x, or end() if such an element is not found.
1434 //! <b>Complexity</b>: Logarithmic.
1436 BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const K& x)
1437 { return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
1439 //! <b>Requires</b>: This overload is available only if
1440 //! key_compare::is_transparent exists.
1442 //! <b>Returns</b>: A const iterator pointing to the first element with key
1443 //! greater than x, or end() if such an element is not found.
1445 //! <b>Complexity</b>: Logarithmic.
1447 BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const K& x) const
1448 { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
1450 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1452 //! <b>Complexity</b>: Logarithmic.
1453 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type& x)
1454 { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.lower_bound_range(x)); }
1456 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1458 //! <b>Complexity</b>: Logarithmic.
1459 BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
1460 { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.lower_bound_range(x)); }
1462 //! <b>Requires</b>: This overload is available only if
1463 //! key_compare::is_transparent exists.
1465 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1467 //! <b>Complexity</b>: Logarithmic.
1469 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const K& x)
1470 //Don't use lower_bound_range optimization here as transparent comparators with key K might
1471 //return a different range than key_type (which can only return a single element range)
1472 { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
1474 //! <b>Requires</b>: This overload is available only if
1475 //! key_compare::is_transparent exists.
1477 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1479 //! <b>Complexity</b>: Logarithmic.
1481 BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const K& x) const
1482 //Don't use lower_bound_range optimization here as transparent comparators with key K might
1483 //return a different range than key_type (which can only return a single element range)
1484 { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
1486 //! <b>Effects</b>: Extracts the internal sequence container.
1488 //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
1490 //! <b>Postcondition</b>: this->empty()
1492 //! <b>Throws</b>: If secuence_type's move constructor throws
1493 BOOST_CONTAINER_FORCEINLINE sequence_type extract_sequence()
1495 return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
1498 //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1499 //! one passed externally using the move assignment. Erases non-unique elements.
1501 //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
1503 //! <b>Throws</b>: If the comparison or the move constructor throws
1504 BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
1505 { this->m_flat_tree.adopt_sequence_unique(boost::move(dtl::force<impl_sequence_type>(seq))); }
1507 //! <b>Requires</b>: seq shall be ordered according to this->compare()
1508 //! and shall contain unique elements.
1510 //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1511 //! one passed externally using the move assignment.
1513 //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
1515 //! <b>Throws</b>: If the move assignment throws
1516 BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_unique_range_t, BOOST_RV_REF(sequence_type) seq)
1517 { this->m_flat_tree.adopt_sequence_unique(ordered_unique_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
1519 //! <b>Effects</b>: Returns true if x and y are equal
1521 //! <b>Complexity</b>: Linear to the number of elements in the container.
1522 BOOST_CONTAINER_FORCEINLINE friend bool operator==(const flat_map& x, const flat_map& y)
1523 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
1525 //! <b>Effects</b>: Returns true if x and y are unequal
1527 //! <b>Complexity</b>: Linear to the number of elements in the container.
1528 BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const flat_map& x, const flat_map& y)
1529 { return !(x == y); }
1531 //! <b>Effects</b>: Returns true if x is less than y
1533 //! <b>Complexity</b>: Linear to the number of elements in the container.
1534 BOOST_CONTAINER_FORCEINLINE friend bool operator<(const flat_map& x, const flat_map& y)
1535 { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1537 //! <b>Effects</b>: Returns true if x is greater than y
1539 //! <b>Complexity</b>: Linear to the number of elements in the container.
1540 BOOST_CONTAINER_FORCEINLINE friend bool operator>(const flat_map& x, const flat_map& y)
1543 //! <b>Effects</b>: Returns true if x is equal or less than y
1545 //! <b>Complexity</b>: Linear to the number of elements in the container.
1546 BOOST_CONTAINER_FORCEINLINE friend bool operator<=(const flat_map& x, const flat_map& y)
1547 { return !(y < x); }
1549 //! <b>Effects</b>: Returns true if x is equal or greater than y
1551 //! <b>Complexity</b>: Linear to the number of elements in the container.
1552 BOOST_CONTAINER_FORCEINLINE friend bool operator>=(const flat_map& x, const flat_map& y)
1553 { return !(x < y); }
1555 //! <b>Effects</b>: x.swap(y)
1557 //! <b>Complexity</b>: Constant.
1558 BOOST_CONTAINER_FORCEINLINE friend void swap(flat_map& x, flat_map& y)
1561 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1563 mapped_type &priv_subscript(const key_type& k)
1565 iterator i = lower_bound(k);
1566 // i->first is greater than or equivalent to k.
1567 if (i == end() || key_comp()(k, (*i).first)){
1568 dtl::value_init<mapped_type> m;
1569 i = insert(i, impl_value_type(k, ::boost::move(m.m_t)));
1573 mapped_type &priv_subscript(BOOST_RV_REF(key_type) mk)
1576 iterator i = lower_bound(k);
1577 // i->first is greater than or equivalent to k.
1578 if (i == end() || key_comp()(k, (*i).first)){
1579 dtl::value_init<mapped_type> m;
1580 i = insert(i, impl_value_type(boost::move(k), ::boost::move(m.m_t)));
1584 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1587 #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
1589 template <typename InputIterator>
1590 flat_map(InputIterator, InputIterator) ->
1591 flat_map< it_based_non_const_first_type_t<InputIterator>
1592 , it_based_second_type_t<InputIterator>>;
1594 template < typename InputIterator, typename AllocatorOrCompare>
1595 flat_map(InputIterator, InputIterator, AllocatorOrCompare const&) ->
1596 flat_map< it_based_non_const_first_type_t<InputIterator>
1597 , it_based_second_type_t<InputIterator>
1598 , typename dtl::if_c< // Compare
1599 dtl::is_allocator<AllocatorOrCompare>::value
1600 , std::less<it_based_non_const_first_type_t<InputIterator>>
1601 , AllocatorOrCompare
1603 , typename dtl::if_c< // Allocator
1604 dtl::is_allocator<AllocatorOrCompare>::value
1605 , AllocatorOrCompare
1606 , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
1610 template < typename InputIterator, typename Compare, typename Allocator
1611 , typename = dtl::require_nonallocator_t<Compare>
1612 , typename = dtl::require_allocator_t<Allocator>>
1613 flat_map(InputIterator, InputIterator, Compare const&, Allocator const&) ->
1614 flat_map< it_based_non_const_first_type_t<InputIterator>
1615 , it_based_second_type_t<InputIterator>
1619 template <typename InputIterator>
1620 flat_map(ordered_unique_range_t, InputIterator, InputIterator) ->
1621 flat_map< it_based_non_const_first_type_t<InputIterator>
1622 , it_based_second_type_t<InputIterator>>;
1624 template < typename InputIterator, typename AllocatorOrCompare>
1625 flat_map(ordered_unique_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
1626 flat_map< it_based_non_const_first_type_t<InputIterator>
1627 , it_based_second_type_t<InputIterator>
1628 , typename dtl::if_c< // Compare
1629 dtl::is_allocator<AllocatorOrCompare>::value
1630 , std::less<it_based_non_const_first_type_t<InputIterator>>
1631 , AllocatorOrCompare
1633 , typename dtl::if_c< // Allocator
1634 dtl::is_allocator<AllocatorOrCompare>::value
1635 , AllocatorOrCompare
1636 , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
1640 template < typename InputIterator, typename Compare, typename Allocator
1641 , typename = dtl::require_nonallocator_t<Compare>
1642 , typename = dtl::require_allocator_t<Allocator>>
1643 flat_map(ordered_unique_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
1644 flat_map< it_based_non_const_first_type_t<InputIterator>
1645 , it_based_second_type_t<InputIterator>
1651 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1653 } //namespace container {
1655 //!has_trivial_destructor_after_move<> == true_type
1656 //!specialization for optimizations
1657 template <class Key, class T, class Compare, class AllocatorOrContainer>
1658 struct has_trivial_destructor_after_move<boost::container::flat_map<Key, T, Compare, AllocatorOrContainer> >
1660 typedef ::boost::container::dtl::pair<Key, T> value_t;
1661 typedef typename ::boost::container::dtl::container_or_allocator_rebind<AllocatorOrContainer, value_t>::type alloc_or_cont_t;
1662 typedef ::boost::container::dtl::flat_tree<value_t,::boost::container::dtl::select1st<Key>, Compare, alloc_or_cont_t> tree;
1663 static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
1666 namespace container {
1668 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1670 //! A flat_multimap is a kind of associative container that supports equivalent keys
1671 //! (possibly containing multiple copies of the same key value) and provides for
1672 //! fast retrieval of values of another type T based on the keys.
1674 //! A flat_multimap satisfies all of the requirements of a container and of a reversible
1675 //! container and of an associative container. For a
1676 //! flat_multimap<Key,T> the key_type is Key and the value_type is std::pair<Key,T>
1677 //! (unlike std::multimap<Key, T> which value_type is std::pair<<b>const</b> Key, T>).
1679 //! flat_multimap is similar to std::multimap but it's implemented by as an ordered sequence container.
1680 //! The underlying sequence container is by default <i>vector</i> but it can also work
1681 //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
1683 //! Using vector-like sequence containers means that inserting a new element into a flat_multimap might invalidate
1684 //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
1685 //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
1686 //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
1688 //! This container provides random-access iterators.
1690 //! \tparam Key is the key_type of the map
1691 //! \tparam Value is the <code>mapped_type</code>
1692 //! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
1693 //! \tparam AllocatorOrContainer is either:
1694 //! - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
1695 //! (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
1696 //! - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
1697 //! sequence container with random-access iterators.
1698 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1699 template <class Key, class T, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator< std::pair< Key, T> > >
1701 template <class Key, class T, class Compare, class AllocatorOrContainer>
1705 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1707 BOOST_COPYABLE_AND_MOVABLE(flat_multimap)
1708 typedef dtl::flat_tree<
1710 dtl::select1st<Key>,
1712 AllocatorOrContainer> tree_t;
1713 //This is the real tree stored here. It's based on a movable pair
1714 typedef dtl::flat_tree<
1716 dtl::select1st<Key>,
1718 typename dtl::container_or_allocator_rebind<AllocatorOrContainer, dtl::pair<Key, T> >::type
1720 impl_tree_t m_flat_tree; // flat tree representing flat_map
1722 typedef typename impl_tree_t::value_type impl_value_type;
1723 typedef typename impl_tree_t::const_iterator impl_const_iterator;
1724 typedef typename impl_tree_t::iterator impl_iterator;
1725 typedef typename impl_tree_t::allocator_type impl_allocator_type;
1726 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1727 typedef std::initializer_list<impl_value_type> impl_initializer_list;
1730 typedef dtl::flat_tree_value_compare
1732 , dtl::select1st<Key>
1733 , std::pair<Key, T> > value_compare_t;
1734 typedef typename tree_t::iterator iterator_t;
1735 typedef typename tree_t::const_iterator const_iterator_t;
1736 typedef typename tree_t::reverse_iterator reverse_iterator_t;
1737 typedef typename tree_t::const_reverse_iterator const_reverse_iterator_t;
1740 typedef typename impl_tree_t::stored_allocator_type impl_stored_allocator_type;
1741 typedef typename impl_tree_t::sequence_type impl_sequence_type;
1743 BOOST_CONTAINER_FORCEINLINE impl_tree_t &tree()
1744 { return m_flat_tree; }
1746 BOOST_CONTAINER_FORCEINLINE const impl_tree_t &tree() const
1747 { return m_flat_tree; }
1750 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1754 //////////////////////////////////////////////
1758 //////////////////////////////////////////////
1759 typedef Key key_type;
1760 typedef T mapped_type;
1761 typedef Compare key_compare;
1762 typedef std::pair<Key, T> value_type;
1763 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type) sequence_type;
1764 typedef typename sequence_type::allocator_type allocator_type;
1765 typedef ::boost::container::allocator_traits<allocator_type> allocator_traits_type;
1766 typedef typename sequence_type::pointer pointer;
1767 typedef typename sequence_type::const_pointer const_pointer;
1768 typedef typename sequence_type::reference reference;
1769 typedef typename sequence_type::const_reference const_reference;
1770 typedef typename sequence_type::size_type size_type;
1771 typedef typename sequence_type::difference_type difference_type;
1772 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type) stored_allocator_type;
1773 typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare) value_compare;
1775 typedef typename sequence_type::iterator iterator;
1776 typedef typename sequence_type::const_iterator const_iterator;
1777 typedef typename sequence_type::reverse_iterator reverse_iterator;
1778 typedef typename sequence_type::const_reverse_iterator const_reverse_iterator;
1779 typedef BOOST_CONTAINER_IMPDEF(impl_value_type) movable_value_type;
1781 //AllocatorOrContainer::value_type must be std::pair<Key, T>
1782 BOOST_STATIC_ASSERT((dtl::is_same<std::pair<Key, T>, value_type>::value));
1784 //////////////////////////////////////////////
1786 // construct/copy/destroy
1788 //////////////////////////////////////////////
1790 //! <b>Effects</b>: Default constructs an empty flat_map.
1792 //! <b>Complexity</b>: Constant.
1793 BOOST_CONTAINER_FORCEINLINE flat_multimap()
1794 BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
1795 dtl::is_nothrow_default_constructible<Compare>::value)
1799 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified allocator.
1801 //! <b>Complexity</b>: Constant.
1802 BOOST_CONTAINER_FORCEINLINE explicit flat_multimap(const allocator_type& a)
1803 : m_flat_tree(dtl::force<const impl_allocator_type>(a))
1806 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison
1809 //! <b>Complexity</b>: Constant.
1810 BOOST_CONTAINER_FORCEINLINE explicit flat_multimap(const Compare& comp)
1814 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison
1815 //! object and allocator.
1817 //! <b>Complexity</b>: Constant.
1818 BOOST_CONTAINER_FORCEINLINE
1819 flat_multimap(const Compare& comp, const allocator_type& a)
1820 : m_flat_tree(comp, dtl::force<const impl_allocator_type>(a))
1823 //! <b>Effects</b>: Constructs an empty flat_multimap
1824 //! and inserts elements from the range [first ,last ).
1826 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1827 //! the predicate and otherwise N logN, where N is last - first.
1828 template <class InputIterator>
1829 BOOST_CONTAINER_FORCEINLINE
1830 flat_multimap(InputIterator first, InputIterator last)
1831 : m_flat_tree(false, first, last)
1834 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified
1835 //! allocator, and inserts elements from the range [first ,last ).
1837 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1838 //! the predicate and otherwise N logN, where N is last - first.
1839 template <class InputIterator>
1840 BOOST_CONTAINER_FORCEINLINE
1841 flat_multimap(InputIterator first, InputIterator last, const allocator_type& a)
1842 : m_flat_tree(false, first, last, dtl::force<const impl_allocator_type>(a))
1845 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object
1846 //! and inserts elements from the range [first ,last ).
1848 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1849 //! the predicate and otherwise N logN, where N is last - first.
1850 template <class InputIterator>
1851 BOOST_CONTAINER_FORCEINLINE
1852 flat_multimap(InputIterator first, InputIterator last, const Compare& comp)
1853 : m_flat_tree(false, first, last, comp)
1856 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object
1857 //! and allocator, and inserts elements from the range [first ,last ).
1859 //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
1860 //! the predicate and otherwise N logN, where N is last - first.
1861 template <class InputIterator>
1862 BOOST_CONTAINER_FORCEINLINE
1863 flat_multimap(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
1864 : m_flat_tree(false, first, last, comp, dtl::force<const impl_allocator_type>(a))
1867 //! <b>Effects</b>: Constructs an empty flat_multimap
1868 //! and inserts elements from the ordered range [first ,last). This function
1869 //! is more efficient than the normal range creation for ordered ranges.
1871 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1873 //! <b>Complexity</b>: Linear in N.
1875 //! <b>Note</b>: Non-standard extension.
1876 template <class InputIterator>
1877 BOOST_CONTAINER_FORCEINLINE
1878 flat_multimap(ordered_range_t, InputIterator first, InputIterator last)
1879 : m_flat_tree(ordered_range, first, last)
1882 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
1883 //! inserts elements from the ordered range [first ,last). This function
1884 //! is more efficient than the normal range creation for ordered ranges.
1886 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1888 //! <b>Complexity</b>: Linear in N.
1890 //! <b>Note</b>: Non-standard extension.
1891 template <class InputIterator>
1892 BOOST_CONTAINER_FORCEINLINE
1893 flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
1894 : m_flat_tree(ordered_range, first, last, comp)
1897 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
1898 //! allocator, and inserts elements from the ordered range [first ,last). This function
1899 //! is more efficient than the normal range creation for ordered ranges.
1901 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1903 //! <b>Complexity</b>: Linear in N.
1905 //! <b>Note</b>: Non-standard extension.
1906 template <class InputIterator>
1907 BOOST_CONTAINER_FORCEINLINE
1908 flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
1909 : m_flat_tree(ordered_range, first, last, comp, a)
1912 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
1913 //! inserts elements from the ordered range [first ,last). This function
1914 //! is more efficient than the normal range creation for ordered ranges.
1916 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1918 //! <b>Complexity</b>: Linear in N.
1920 //! <b>Note</b>: Non-standard extension.
1921 template <class InputIterator>
1922 BOOST_CONTAINER_FORCEINLINE
1923 flat_multimap(ordered_range_t, InputIterator first, InputIterator last, const allocator_type &a)
1924 : m_flat_tree(ordered_range, first, last, Compare(), a)
1927 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1928 //! <b>Effects</b>: Constructs an empty flat_map and
1929 //! inserts elements from the range [il.begin(), il.end()).
1931 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
1932 //! the predicate and otherwise N logN, where N is last - first.
1933 BOOST_CONTAINER_FORCEINLINE
1934 flat_multimap(std::initializer_list<value_type> il)
1935 : m_flat_tree( false
1936 , dtl::force<impl_initializer_list>(il).begin()
1937 , dtl::force<impl_initializer_list>(il).end())
1940 //! <b>Effects</b>: Constructs an empty flat_map using the specified
1941 //! allocator, and inserts elements from the range [il.begin(), il.end()).
1943 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
1944 //! the predicate and otherwise N logN, where N is last - first.
1945 BOOST_CONTAINER_FORCEINLINE
1946 flat_multimap(std::initializer_list<value_type> il, const allocator_type& a)
1948 , dtl::force<impl_initializer_list>(il).begin()
1949 , dtl::force<impl_initializer_list>(il).end()
1950 , dtl::force<const impl_allocator_type>(a))
1953 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
1954 //! inserts elements from the range [il.begin(), il.end()).
1956 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
1957 //! the predicate and otherwise N logN, where N is last - first.
1958 BOOST_CONTAINER_FORCEINLINE
1959 flat_multimap(std::initializer_list<value_type> il, const Compare& comp)
1961 , dtl::force<impl_initializer_list>(il).begin()
1962 , dtl::force<impl_initializer_list>(il).end(), comp)
1965 //! <b>Effects</b>: Constructs an empty flat_map using the specified comparison object and
1966 //! allocator, and inserts elements from the range [il.begin(), il.end()).
1968 //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
1969 //! the predicate and otherwise N logN, where N is last - first.
1970 BOOST_CONTAINER_FORCEINLINE
1971 flat_multimap(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
1972 : m_flat_tree( false
1973 , dtl::force<impl_initializer_list>(il).begin()
1974 , dtl::force<impl_initializer_list>(il).end()
1975 , comp, dtl::force<const impl_allocator_type>(a))
1978 //! <b>Effects</b>: Constructs an empty flat_multimap and
1979 //! inserts elements from the ordered range [il.begin(), il.end()). This function
1980 //! is more efficient than the normal range creation for ordered ranges.
1982 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1984 //! <b>Complexity</b>: Linear in N.
1986 //! <b>Note</b>: Non-standard extension.
1987 BOOST_CONTAINER_FORCEINLINE
1988 flat_multimap(ordered_range_t, std::initializer_list<value_type> il)
1989 : m_flat_tree( ordered_range
1990 , dtl::force<impl_initializer_list>(il).begin()
1991 , dtl::force<impl_initializer_list>(il).end())
1994 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
1995 //! inserts elements from the ordered range [il.begin(), il.end()). This function
1996 //! is more efficient than the normal range creation for ordered ranges.
1998 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
2000 //! <b>Complexity</b>: Linear in N.
2002 //! <b>Note</b>: Non-standard extension.
2003 BOOST_CONTAINER_FORCEINLINE
2004 flat_multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
2005 : m_flat_tree( ordered_range
2006 , dtl::force<impl_initializer_list>(il).begin()
2007 , dtl::force<impl_initializer_list>(il).end(), comp)
2010 //! <b>Effects</b>: Constructs an empty flat_multimap using the specified comparison object and
2011 //! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function
2012 //! is more efficient than the normal range creation for ordered ranges.
2014 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
2016 //! <b>Complexity</b>: Linear in N.
2018 //! <b>Note</b>: Non-standard extension.
2019 BOOST_CONTAINER_FORCEINLINE
2020 flat_multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
2021 : m_flat_tree( ordered_range
2022 , dtl::force<impl_initializer_list>(il).begin()
2023 , dtl::force<impl_initializer_list>(il).end()
2024 , comp, dtl::force<const impl_allocator_type>(a))
2028 //! <b>Effects</b>: Copy constructs a flat_multimap.
2030 //! <b>Complexity</b>: Linear in x.size().
2031 BOOST_CONTAINER_FORCEINLINE
2032 flat_multimap(const flat_multimap& x)
2033 : m_flat_tree(x.m_flat_tree)
2036 //! <b>Effects</b>: Move constructs a flat_multimap. Constructs *this using x's resources.
2038 //! <b>Complexity</b>: Constant.
2040 //! <b>Postcondition</b>: x is emptied.
2041 BOOST_CONTAINER_FORCEINLINE
2042 flat_multimap(BOOST_RV_REF(flat_multimap) x)
2043 BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
2044 : m_flat_tree(boost::move(x.m_flat_tree))
2047 //! <b>Effects</b>: Copy constructs a flat_multimap using the specified allocator.
2049 //! <b>Complexity</b>: Linear in x.size().
2050 BOOST_CONTAINER_FORCEINLINE
2051 flat_multimap(const flat_multimap& x, const allocator_type &a)
2052 : m_flat_tree(x.m_flat_tree, dtl::force<const impl_allocator_type>(a))
2055 //! <b>Effects</b>: Move constructs a flat_multimap using the specified allocator.
2056 //! Constructs *this using x's resources.
2058 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
2059 BOOST_CONTAINER_FORCEINLINE
2060 flat_multimap(BOOST_RV_REF(flat_multimap) x, const allocator_type &a)
2061 : m_flat_tree(boost::move(x.m_flat_tree), dtl::force<const impl_allocator_type>(a))
2064 //! <b>Effects</b>: Makes *this a copy of x.
2066 //! <b>Complexity</b>: Linear in x.size().
2067 BOOST_CONTAINER_FORCEINLINE
2068 flat_multimap& operator=(BOOST_COPY_ASSIGN_REF(flat_multimap) x)
2069 { m_flat_tree = x.m_flat_tree; return *this; }
2071 //! <b>Effects</b>: this->swap(x.get()).
2073 //! <b>Complexity</b>: Constant.
2074 BOOST_CONTAINER_FORCEINLINE
2075 flat_multimap& operator=(BOOST_RV_REF(flat_multimap) x)
2076 BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
2077 allocator_traits_type::is_always_equal::value) &&
2078 boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
2079 { m_flat_tree = boost::move(x.m_flat_tree); return *this; }
2081 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
2082 //! <b>Effects</b>: Assign content of il to *this
2084 //! <b>Complexity</b>: Linear in il.size().
2085 BOOST_CONTAINER_FORCEINLINE
2086 flat_multimap& operator=(std::initializer_list<value_type> il)
2089 this->insert(il.begin(), il.end());
2094 //! <b>Effects</b>: Returns a copy of the allocator that
2095 //! was passed to the object's constructor.
2097 //! <b>Complexity</b>: Constant.
2098 BOOST_CONTAINER_FORCEINLINE
2099 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
2100 { return dtl::force_copy<allocator_type>(m_flat_tree.get_allocator()); }
2102 //! <b>Effects</b>: Returns a reference to the internal allocator.
2104 //! <b>Throws</b>: Nothing
2106 //! <b>Complexity</b>: Constant.
2108 //! <b>Note</b>: Non-standard extension.
2109 BOOST_CONTAINER_FORCEINLINE
2110 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
2111 { return dtl::force<stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
2113 //! <b>Effects</b>: Returns a reference to the internal allocator.
2115 //! <b>Throws</b>: Nothing
2117 //! <b>Complexity</b>: Constant.
2119 //! <b>Note</b>: Non-standard extension.
2120 BOOST_CONTAINER_FORCEINLINE
2121 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
2122 { return dtl::force<const stored_allocator_type>(m_flat_tree.get_stored_allocator()); }
2124 //////////////////////////////////////////////
2128 //////////////////////////////////////////////
2130 //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
2132 //! <b>Throws</b>: Nothing.
2134 //! <b>Complexity</b>: Constant.
2135 BOOST_CONTAINER_FORCEINLINE
2136 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
2137 { return dtl::force_copy<iterator>(m_flat_tree.begin()); }
2139 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
2141 //! <b>Throws</b>: Nothing.
2143 //! <b>Complexity</b>: Constant.
2144 BOOST_CONTAINER_FORCEINLINE
2145 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
2146 { return dtl::force_copy<const_iterator>(m_flat_tree.begin()); }
2148 //! <b>Effects</b>: Returns an iterator to the end of the container.
2150 //! <b>Throws</b>: Nothing.
2152 //! <b>Complexity</b>: Constant.
2153 BOOST_CONTAINER_FORCEINLINE
2154 iterator end() BOOST_NOEXCEPT_OR_NOTHROW
2155 { return dtl::force_copy<iterator>(m_flat_tree.end()); }
2157 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
2159 //! <b>Throws</b>: Nothing.
2161 //! <b>Complexity</b>: Constant.
2162 BOOST_CONTAINER_FORCEINLINE
2163 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
2164 { return dtl::force_copy<const_iterator>(m_flat_tree.end()); }
2166 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
2167 //! of the reversed container.
2169 //! <b>Throws</b>: Nothing.
2171 //! <b>Complexity</b>: Constant.
2172 BOOST_CONTAINER_FORCEINLINE
2173 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
2174 { return dtl::force_copy<reverse_iterator>(m_flat_tree.rbegin()); }
2176 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
2177 //! of the reversed container.
2179 //! <b>Throws</b>: Nothing.
2181 //! <b>Complexity</b>: Constant.
2182 BOOST_CONTAINER_FORCEINLINE
2183 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
2184 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rbegin()); }
2186 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
2187 //! of the reversed container.
2189 //! <b>Throws</b>: Nothing.
2191 //! <b>Complexity</b>: Constant.
2192 BOOST_CONTAINER_FORCEINLINE
2193 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
2194 { return dtl::force_copy<reverse_iterator>(m_flat_tree.rend()); }
2196 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
2197 //! of the reversed container.
2199 //! <b>Throws</b>: Nothing.
2201 //! <b>Complexity</b>: Constant.
2202 BOOST_CONTAINER_FORCEINLINE
2203 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
2204 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.rend()); }
2206 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
2208 //! <b>Throws</b>: Nothing.
2210 //! <b>Complexity</b>: Constant.
2211 BOOST_CONTAINER_FORCEINLINE
2212 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
2213 { return dtl::force_copy<const_iterator>(m_flat_tree.cbegin()); }
2215 //! <b>Effects</b>: Returns a const_iterator to the end of the container.
2217 //! <b>Throws</b>: Nothing.
2219 //! <b>Complexity</b>: Constant.
2220 BOOST_CONTAINER_FORCEINLINE
2221 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
2222 { return dtl::force_copy<const_iterator>(m_flat_tree.cend()); }
2224 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
2225 //! of the reversed container.
2227 //! <b>Throws</b>: Nothing.
2229 //! <b>Complexity</b>: Constant.
2230 BOOST_CONTAINER_FORCEINLINE
2231 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
2232 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crbegin()); }
2234 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
2235 //! of the reversed container.
2237 //! <b>Throws</b>: Nothing.
2239 //! <b>Complexity</b>: Constant.
2240 BOOST_CONTAINER_FORCEINLINE
2241 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
2242 { return dtl::force_copy<const_reverse_iterator>(m_flat_tree.crend()); }
2244 //////////////////////////////////////////////
2248 //////////////////////////////////////////////
2250 //! <b>Effects</b>: Returns true if the container contains no elements.
2252 //! <b>Throws</b>: Nothing.
2254 //! <b>Complexity</b>: Constant.
2255 BOOST_CONTAINER_FORCEINLINE
2256 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
2257 { return m_flat_tree.empty(); }
2259 //! <b>Effects</b>: Returns the number of the elements contained in the container.
2261 //! <b>Throws</b>: Nothing.
2263 //! <b>Complexity</b>: Constant.
2264 BOOST_CONTAINER_FORCEINLINE
2265 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
2266 { return m_flat_tree.size(); }
2268 //! <b>Effects</b>: Returns the largest possible size of the container.
2270 //! <b>Throws</b>: Nothing.
2272 //! <b>Complexity</b>: Constant.
2273 BOOST_CONTAINER_FORCEINLINE
2274 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
2275 { return m_flat_tree.max_size(); }
2277 //! <b>Effects</b>: Number of elements for which memory has been allocated.
2278 //! capacity() is always greater than or equal to size().
2280 //! <b>Throws</b>: Nothing.
2282 //! <b>Complexity</b>: Constant.
2283 BOOST_CONTAINER_FORCEINLINE
2284 size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
2285 { return m_flat_tree.capacity(); }
2287 //! <b>Effects</b>: If n is less than or equal to capacity(), or the
2288 //! underlying container has no `reserve` member, this call has no
2289 //! effect. Otherwise, it is a request for allocation of additional memory.
2290 //! If the request is successful, then capacity() is greater than or equal to
2291 //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
2293 //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
2295 //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
2296 //! to values might be invalidated.
2297 BOOST_CONTAINER_FORCEINLINE
2298 void reserve(size_type cnt)
2299 { m_flat_tree.reserve(cnt); }
2301 //! <b>Effects</b>: Tries to deallocate the excess of memory created
2302 // with previous allocations. The size of the vector is unchanged
2304 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
2306 //! <b>Complexity</b>: Linear to size().
2307 BOOST_CONTAINER_FORCEINLINE
2308 void shrink_to_fit()
2309 { m_flat_tree.shrink_to_fit(); }
2311 //! @copydoc ::boost::container::flat_set::nth(size_type)
2312 BOOST_CONTAINER_FORCEINLINE
2313 iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
2314 { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
2316 //! @copydoc ::boost::container::flat_set::nth(size_type) const
2317 BOOST_CONTAINER_FORCEINLINE
2318 const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
2319 { return dtl::force_copy<iterator>(m_flat_tree.nth(n)); }
2321 //! @copydoc ::boost::container::flat_set::index_of(iterator)
2322 BOOST_CONTAINER_FORCEINLINE
2323 size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
2324 { return m_flat_tree.index_of(dtl::force_copy<impl_iterator>(p)); }
2326 //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
2327 BOOST_CONTAINER_FORCEINLINE
2328 size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
2329 { return m_flat_tree.index_of(dtl::force_copy<impl_const_iterator>(p)); }
2331 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
2333 //! <b>Effects</b>: Inserts an object of type T constructed with
2334 //! std::forward<Args>(args)... and returns the iterator pointing to the
2335 //! newly inserted element.
2337 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
2338 //! to the elements with bigger keys than x.
2340 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2341 template <class... Args>
2342 BOOST_CONTAINER_FORCEINLINE
2343 iterator emplace(BOOST_FWD_REF(Args)... args)
2344 { return dtl::force_copy<iterator>(m_flat_tree.emplace_equal(boost::forward<Args>(args)...)); }
2346 //! <b>Effects</b>: Inserts an object of type T constructed with
2347 //! std::forward<Args>(args)... in the container.
2348 //! p is a hint pointing to where the insert should start to search.
2350 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
2351 //! to the key of x.
2353 //! <b>Complexity</b>: Logarithmic search time (constant time if the value
2354 //! is to be inserted before p) plus linear insertion
2355 //! to the elements with bigger keys than x.
2357 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2358 template <class... Args>
2359 BOOST_CONTAINER_FORCEINLINE
2360 iterator emplace_hint(const_iterator hint, BOOST_FWD_REF(Args)... args)
2362 return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_equal
2363 (dtl::force_copy<impl_const_iterator>(hint), boost::forward<Args>(args)...));
2366 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
2368 #define BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE(N) \
2369 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
2370 BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
2371 { return dtl::force_copy<iterator>(m_flat_tree.emplace_equal(BOOST_MOVE_FWD##N)); }\
2373 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
2374 BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
2376 return dtl::force_copy<iterator>(m_flat_tree.emplace_hint_equal\
2377 (dtl::force_copy<impl_const_iterator>(hint) BOOST_MOVE_I##N BOOST_MOVE_FWD##N));\
2380 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE)
2381 #undef BOOST_CONTAINER_FLAT_MULTIMAP_EMPLACE_CODE
2383 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
2385 //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
2386 //! newly inserted element.
2388 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
2389 //! to the elements with bigger keys than x.
2391 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2392 BOOST_CONTAINER_FORCEINLINE iterator insert(const value_type& x)
2394 return dtl::force_copy<iterator>(
2395 m_flat_tree.insert_equal(dtl::force<const impl_value_type>(x)));
2398 //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
2399 //! the iterator pointing to the newly inserted element.
2401 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
2402 //! to the elements with bigger keys than x.
2404 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2405 BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(value_type) x)
2406 { return dtl::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
2408 //! <b>Effects</b>: Inserts a new value move-constructed from x and returns
2409 //! the iterator pointing to the newly inserted element.
2411 //! <b>Complexity</b>: Logarithmic search time plus linear insertion
2412 //! to the elements with bigger keys than x.
2414 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2415 BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(impl_value_type) x)
2416 { return dtl::force_copy<iterator>(m_flat_tree.insert_equal(boost::move(x))); }
2418 //! <b>Effects</b>: Inserts a copy of x in the container.
2419 //! p is a hint pointing to where the insert should start to search.
2421 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
2422 //! to the key of x.
2424 //! <b>Complexity</b>: Logarithmic search time (constant time if the value
2425 //! is to be inserted before p) plus linear insertion
2426 //! to the elements with bigger keys than x.
2428 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2429 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
2431 return dtl::force_copy<iterator>
2432 (m_flat_tree.insert_equal( dtl::force_copy<impl_const_iterator>(p)
2433 , dtl::force<const impl_value_type>(x)));
2436 //! <b>Effects</b>: Inserts a value move constructed from x in the container.
2437 //! p is a hint pointing to where the insert should start to search.
2439 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
2440 //! to the key of x.
2442 //! <b>Complexity</b>: Logarithmic search time (constant time if the value
2443 //! is to be inserted before p) plus linear insertion
2444 //! to the elements with bigger keys than x.
2446 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2447 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
2449 return dtl::force_copy<iterator>
2450 (m_flat_tree.insert_equal(dtl::force_copy<impl_const_iterator>(p)
2454 //! <b>Effects</b>: Inserts a value move constructed from x in the container.
2455 //! p is a hint pointing to where the insert should start to search.
2457 //! <b>Returns</b>: An iterator pointing to the element with key equivalent
2458 //! to the key of x.
2460 //! <b>Complexity</b>: Logarithmic search time (constant time if the value
2461 //! is to be inserted before p) plus linear insertion
2462 //! to the elements with bigger keys than x.
2464 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2465 BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(impl_value_type) x)
2467 return dtl::force_copy<iterator>(
2468 m_flat_tree.insert_equal(dtl::force_copy<impl_const_iterator>(p), boost::move(x)));
2471 //! <b>Requires</b>: first, last are not iterators into *this.
2473 //! <b>Effects</b>: inserts each element from the range [first,last) .
2475 //! <b>Complexity</b>: N log(N).
2477 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2478 template <class InputIterator>
2479 BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
2480 { m_flat_tree.insert_equal(first, last); }
2482 //! <b>Requires</b>: first, last are not iterators into *this.
2484 //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
2486 //! <b>Effects</b>: inserts each element from the range [first,last) if and only
2487 //! if there is no element with key equivalent to the key of that element. This
2488 //! function is more efficient than the normal range creation for ordered ranges.
2490 //! <b>Complexity</b>: Linear.
2492 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2494 //! <b>Note</b>: Non-standard extension.
2495 template <class InputIterator>
2496 BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, InputIterator first, InputIterator last)
2497 { m_flat_tree.insert_equal(ordered_range, first, last); }
2499 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
2500 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) .
2502 //! <b>Complexity</b>: N log(N).
2504 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2505 BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
2507 m_flat_tree.insert_equal( dtl::force<impl_initializer_list>(il).begin()
2508 , dtl::force<impl_initializer_list>(il).end());
2511 //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
2513 //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
2514 //! if there is no element with key equivalent to the key of that element. This
2515 //! function is more efficient than the normal range creation for ordered ranges.
2517 //! <b>Complexity</b>: Linear.
2519 //! <b>Note</b>: If an element is inserted it might invalidate elements.
2521 //! <b>Note</b>: Non-standard extension.
2522 BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, std::initializer_list<value_type> il)
2524 m_flat_tree.insert_equal( ordered_range
2525 , dtl::force<impl_initializer_list>(il).begin()
2526 , dtl::force<impl_initializer_list>(il).end());
2530 //! <b>Requires</b>: this->get_allocator() == source.get_allocator().
2532 //! <b>Effects</b>: Extracts each element in source and insert it into a using
2533 //! the comparison object of *this.
2535 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
2536 //! to those same elements but as members of *this. Iterators referring to the transferred
2537 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
2538 //! not into source.
2540 //! <b>Throws</b>: Nothing unless the comparison object throws.
2542 //! <b>Complexity</b>: N log(size() + N) (N has the value source.size())
2544 BOOST_CONTAINER_FORCEINLINE void merge(flat_multimap<Key, T, C2, AllocatorOrContainer>& source)
2545 { m_flat_tree.merge_equal(source.tree()); }
2547 //! @copydoc ::boost::container::flat_multimap::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
2549 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multimap<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
2550 { return this->merge(static_cast<flat_multimap<Key, T, C2, AllocatorOrContainer>&>(source)); }
2552 //! @copydoc ::boost::container::flat_multimap::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
2554 BOOST_CONTAINER_FORCEINLINE void merge(flat_map<Key, T, C2, AllocatorOrContainer>& source)
2555 { m_flat_tree.merge_equal(source.tree()); }
2557 //! @copydoc ::boost::container::flat_multimap::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
2559 BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_map<Key, T, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
2560 { return this->merge(static_cast<flat_map<Key, T, C2, AllocatorOrContainer>&>(source)); }
2562 //! <b>Effects</b>: Erases the element pointed to by p.
2564 //! <b>Returns</b>: Returns an iterator pointing to the element immediately
2565 //! following q prior to the element being erased. If no such element exists,
2568 //! <b>Complexity</b>: Linear to the elements with keys bigger than p
2570 //! <b>Note</b>: Invalidates elements with keys
2571 //! not less than the erased element.
2572 BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator p)
2574 return dtl::force_copy<iterator>(
2575 m_flat_tree.erase(dtl::force_copy<impl_const_iterator>(p)));
2578 //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
2580 //! <b>Returns</b>: Returns the number of erased elements.
2582 //! <b>Complexity</b>: Logarithmic search time plus erasure time
2583 //! linear to the elements with bigger keys.
2584 BOOST_CONTAINER_FORCEINLINE size_type erase(const key_type& x)
2585 { return m_flat_tree.erase(x); }
2587 //! <b>Effects</b>: Erases all the elements in the range [first, last).
2589 //! <b>Returns</b>: Returns last.
2591 //! <b>Complexity</b>: size()*N where N is the distance from first to last.
2593 //! <b>Complexity</b>: Logarithmic search time plus erasure time
2594 //! linear to the elements with bigger keys.
2595 BOOST_CONTAINER_FORCEINLINE iterator erase(const_iterator first, const_iterator last)
2597 return dtl::force_copy<iterator>
2598 (m_flat_tree.erase( dtl::force_copy<impl_const_iterator>(first)
2599 , dtl::force_copy<impl_const_iterator>(last)));
2602 //! <b>Effects</b>: Swaps the contents of *this and x.
2604 //! <b>Throws</b>: Nothing.
2606 //! <b>Complexity</b>: Constant.
2607 BOOST_CONTAINER_FORCEINLINE void swap(flat_multimap& x)
2608 BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
2609 && boost::container::dtl::is_nothrow_swappable<Compare>::value )
2610 { m_flat_tree.swap(x.m_flat_tree); }
2612 //! <b>Effects</b>: erase(begin(),end()).
2614 //! <b>Postcondition</b>: size() == 0.
2616 //! <b>Complexity</b>: linear in size().
2617 BOOST_CONTAINER_FORCEINLINE void clear() BOOST_NOEXCEPT_OR_NOTHROW
2618 { m_flat_tree.clear(); }
2620 //////////////////////////////////////////////
2624 //////////////////////////////////////////////
2626 //! <b>Effects</b>: Returns the comparison object out
2627 //! of which a was constructed.
2629 //! <b>Complexity</b>: Constant.
2630 BOOST_CONTAINER_FORCEINLINE key_compare key_comp() const
2631 { return dtl::force_copy<key_compare>(m_flat_tree.key_comp()); }
2633 //! <b>Effects</b>: Returns an object of value_compare constructed out
2634 //! of the comparison object.
2636 //! <b>Complexity</b>: Constant.
2637 BOOST_CONTAINER_FORCEINLINE value_compare value_comp() const
2638 { return value_compare(dtl::force_copy<key_compare>(m_flat_tree.key_comp())); }
2640 //////////////////////////////////////////////
2644 //////////////////////////////////////////////
2646 //! <b>Returns</b>: An iterator pointing to an element with the key
2647 //! equivalent to x, or end() if such an element is not found.
2649 //! <b>Complexity</b>: Logarithmic.
2650 BOOST_CONTAINER_FORCEINLINE iterator find(const key_type& x)
2651 { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
2653 //! <b>Returns</b>: An const_iterator pointing to an element with the key
2654 //! equivalent to x, or end() if such an element is not found.
2656 //! <b>Complexity</b>: Logarithmic.
2657 BOOST_CONTAINER_FORCEINLINE const_iterator find(const key_type& x) const
2658 { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
2660 //! <b>Requires</b>: This overload is available only if
2661 //! key_compare::is_transparent exists.
2663 //! <b>Returns</b>: An iterator pointing to an element with the key
2664 //! equivalent to x, or end() if such an element is not found.
2666 //! <b>Complexity</b>: Logarithmic.
2668 BOOST_CONTAINER_FORCEINLINE iterator find(const K& x)
2669 { return dtl::force_copy<iterator>(m_flat_tree.find(x)); }
2671 //! <b>Requires</b>: This overload is available only if
2672 //! key_compare::is_transparent exists.
2674 //! <b>Returns</b>: An const_iterator pointing to an element with the key
2675 //! equivalent to x, or end() if such an element is not found.
2677 //! <b>Complexity</b>: Logarithmic.
2679 BOOST_CONTAINER_FORCEINLINE const_iterator find(const K& x) const
2680 { return dtl::force_copy<const_iterator>(m_flat_tree.find(x)); }
2682 //! <b>Returns</b>: The number of elements with key equivalent to x.
2684 //! <b>Complexity</b>: log(size())+count(k)
2685 BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
2686 { return m_flat_tree.count(x); }
2688 //! <b>Requires</b>: This overload is available only if
2689 //! key_compare::is_transparent exists.
2691 //! <b>Returns</b>: The number of elements with key equivalent to x.
2693 //! <b>Complexity</b>: log(size())+count(k)
2695 BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
2696 { return m_flat_tree.count(x); }
2698 //! <b>Returns</b>: Returns true if there is an element with key
2699 //! equivalent to key in the container, otherwise false.
2701 //! <b>Complexity</b>: log(size()).
2702 bool contains(const key_type& x) const
2703 { return m_flat_tree.find(x) != m_flat_tree.end(); }
2705 //! <b>Requires</b>: This overload is available only if
2706 //! key_compare::is_transparent exists.
2708 //! <b>Returns</b>: Returns true if there is an element with key
2709 //! equivalent to key in the container, otherwise false.
2711 //! <b>Complexity</b>: log(size()).
2712 template<typename K>
2713 bool contains(const K& x) const
2714 { return m_flat_tree.find(x) != m_flat_tree.end(); }
2716 //! <b>Returns</b>: An iterator pointing to the first element with key not less
2717 //! than x, or end() if such an element is not found.
2719 //! <b>Complexity</b>: Logarithmic
2720 BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const key_type& x)
2721 { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
2723 //! <b>Returns</b>: An iterator pointing to the first element with key not less
2724 //! than x, or end() if such an element is not found.
2726 //! <b>Complexity</b>: Logarithmic
2727 BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const key_type& x) const
2728 { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
2730 //! <b>Requires</b>: This overload is available only if
2731 //! key_compare::is_transparent exists.
2733 //! <b>Returns</b>: An iterator pointing to the first element with key not less
2734 //! than x, or end() if such an element is not found.
2736 //! <b>Complexity</b>: Logarithmic
2738 BOOST_CONTAINER_FORCEINLINE iterator lower_bound(const K& x)
2739 { return dtl::force_copy<iterator>(m_flat_tree.lower_bound(x)); }
2741 //! <b>Requires</b>: This overload is available only if
2742 //! key_compare::is_transparent exists.
2744 //! <b>Returns</b>: An iterator pointing to the first element with key not less
2745 //! than x, or end() if such an element is not found.
2747 //! <b>Complexity</b>: Logarithmic
2749 BOOST_CONTAINER_FORCEINLINE const_iterator lower_bound(const K& x) const
2750 { return dtl::force_copy<const_iterator>(m_flat_tree.lower_bound(x)); }
2752 //! <b>Returns</b>: An iterator pointing to the first element with key greater
2753 //! than x, or end() if such an element is not found.
2755 //! <b>Complexity</b>: Logarithmic
2756 BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const key_type& x)
2757 {return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
2759 //! <b>Returns</b>: A const iterator pointing to the first element with key
2760 //! greater than x, or end() if such an element is not found.
2762 //! <b>Complexity</b>: Logarithmic
2763 BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const key_type& x) const
2764 { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
2766 //! <b>Requires</b>: This overload is available only if
2767 //! key_compare::is_transparent exists.
2769 //! <b>Returns</b>: An iterator pointing to the first element with key greater
2770 //! than x, or end() if such an element is not found.
2772 //! <b>Complexity</b>: Logarithmic
2774 BOOST_CONTAINER_FORCEINLINE iterator upper_bound(const K& x)
2775 {return dtl::force_copy<iterator>(m_flat_tree.upper_bound(x)); }
2777 //! <b>Requires</b>: This overload is available only if
2778 //! key_compare::is_transparent exists.
2780 //! <b>Returns</b>: A const iterator pointing to the first element with key
2781 //! greater than x, or end() if such an element is not found.
2783 //! <b>Complexity</b>: Logarithmic
2785 BOOST_CONTAINER_FORCEINLINE const_iterator upper_bound(const K& x) const
2786 { return dtl::force_copy<const_iterator>(m_flat_tree.upper_bound(x)); }
2788 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
2790 //! <b>Complexity</b>: Logarithmic
2791 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type& x)
2792 { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
2794 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
2796 //! <b>Complexity</b>: Logarithmic
2797 BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
2798 { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
2800 //! <b>Requires</b>: This overload is available only if
2801 //! key_compare::is_transparent exists.
2803 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
2805 //! <b>Complexity</b>: Logarithmic
2807 BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const K& x)
2808 { return dtl::force_copy<std::pair<iterator,iterator> >(m_flat_tree.equal_range(x)); }
2810 //! <b>Requires</b>: This overload is available only if
2811 //! key_compare::is_transparent exists.
2813 //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
2815 //! <b>Complexity</b>: Logarithmic
2817 BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const K& x) const
2818 { return dtl::force_copy<std::pair<const_iterator,const_iterator> >(m_flat_tree.equal_range(x)); }
2820 //! <b>Effects</b>: Extracts the internal sequence container.
2822 //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
2824 //! <b>Postcondition</b>: this->empty()
2826 //! <b>Throws</b>: If secuence_type's move constructor throws
2827 BOOST_CONTAINER_FORCEINLINE sequence_type extract_sequence()
2829 return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
2832 //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
2833 //! one passed externally using the move assignment.
2835 //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
2837 //! <b>Throws</b>: If the comparison or the move constructor throws
2838 BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
2839 { this->m_flat_tree.adopt_sequence_equal(boost::move(dtl::force<impl_sequence_type>(seq))); }
2841 //! <b>Requires</b>: seq shall be ordered according to this->compare().
2843 //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
2844 //! one passed externally using the move assignment.
2846 //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
2848 //! <b>Throws</b>: If the move assignment throws
2849 BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_range_t, BOOST_RV_REF(sequence_type) seq)
2850 { this->m_flat_tree.adopt_sequence_equal(ordered_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
2852 //! <b>Effects</b>: Returns true if x and y are equal
2854 //! <b>Complexity</b>: Linear to the number of elements in the container.
2855 BOOST_CONTAINER_FORCEINLINE friend bool operator==(const flat_multimap& x, const flat_multimap& y)
2856 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
2858 //! <b>Effects</b>: Returns true if x and y are unequal
2860 //! <b>Complexity</b>: Linear to the number of elements in the container.
2861 BOOST_CONTAINER_FORCEINLINE friend bool operator!=(const flat_multimap& x, const flat_multimap& y)
2862 { return !(x == y); }
2864 //! <b>Effects</b>: Returns true if x is less than y
2866 //! <b>Complexity</b>: Linear to the number of elements in the container.
2867 BOOST_CONTAINER_FORCEINLINE friend bool operator<(const flat_multimap& x, const flat_multimap& y)
2868 { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
2870 //! <b>Effects</b>: Returns true if x is greater than y
2872 //! <b>Complexity</b>: Linear to the number of elements in the container.
2873 BOOST_CONTAINER_FORCEINLINE friend bool operator>(const flat_multimap& x, const flat_multimap& y)
2876 //! <b>Effects</b>: Returns true if x is equal or less than y
2878 //! <b>Complexity</b>: Linear to the number of elements in the container.
2879 BOOST_CONTAINER_FORCEINLINE friend bool operator<=(const flat_multimap& x, const flat_multimap& y)
2880 { return !(y < x); }
2882 //! <b>Effects</b>: Returns true if x is equal or greater than y
2884 //! <b>Complexity</b>: Linear to the number of elements in the container.
2885 BOOST_CONTAINER_FORCEINLINE friend bool operator>=(const flat_multimap& x, const flat_multimap& y)
2886 { return !(x < y); }
2888 //! <b>Effects</b>: x.swap(y)
2890 //! <b>Complexity</b>: Constant.
2891 BOOST_CONTAINER_FORCEINLINE friend void swap(flat_multimap& x, flat_multimap& y)
2895 #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
2897 template <typename InputIterator>
2898 flat_multimap(InputIterator, InputIterator) ->
2899 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2900 , it_based_second_type_t<InputIterator>>;
2902 template < typename InputIterator, typename AllocatorOrCompare>
2903 flat_multimap(InputIterator, InputIterator, AllocatorOrCompare const&) ->
2904 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2905 , it_based_second_type_t<InputIterator>
2906 , typename dtl::if_c< // Compare
2907 dtl::is_allocator<AllocatorOrCompare>::value
2908 , std::less<it_based_non_const_first_type_t<InputIterator>>
2909 , AllocatorOrCompare
2911 , typename dtl::if_c< // Allocator
2912 dtl::is_allocator<AllocatorOrCompare>::value
2913 , AllocatorOrCompare
2914 , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
2918 template < typename InputIterator, typename Compare, typename Allocator
2919 , typename = dtl::require_nonallocator_t<Compare>
2920 , typename = dtl::require_allocator_t<Allocator>>
2921 flat_multimap(InputIterator, InputIterator, Compare const&, Allocator const&) ->
2922 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2923 , it_based_second_type_t<InputIterator>
2927 template <typename InputIterator>
2928 flat_multimap(ordered_range_t, InputIterator, InputIterator) ->
2929 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2930 , it_based_second_type_t<InputIterator>>;
2932 template < typename InputIterator, typename AllocatorOrCompare>
2933 flat_multimap(ordered_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
2934 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2935 , it_based_second_type_t<InputIterator>
2936 , typename dtl::if_c< // Compare
2937 dtl::is_allocator<AllocatorOrCompare>::value
2938 , std::less<it_based_non_const_first_type_t<InputIterator>>
2939 , AllocatorOrCompare
2941 , typename dtl::if_c< // Allocator
2942 dtl::is_allocator<AllocatorOrCompare>::value
2943 , AllocatorOrCompare
2944 , new_allocator<std::pair<it_based_non_const_first_type_t<InputIterator>, it_based_second_type_t<InputIterator>>>
2948 template < typename InputIterator, typename Compare, typename Allocator
2949 , typename = dtl::require_nonallocator_t<Compare>
2950 , typename = dtl::require_allocator_t<Allocator>>
2951 flat_multimap(ordered_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
2952 flat_multimap< it_based_non_const_first_type_t<InputIterator>
2953 , it_based_second_type_t<InputIterator>
2961 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
2965 //!has_trivial_destructor_after_move<> == true_type
2966 //!specialization for optimizations
2967 template <class Key, class T, class Compare, class AllocatorOrContainer>
2968 struct has_trivial_destructor_after_move< boost::container::flat_multimap<Key, T, Compare, AllocatorOrContainer> >
2970 typedef ::boost::container::dtl::pair<Key, T> value_t;
2971 typedef typename ::boost::container::dtl::container_or_allocator_rebind<AllocatorOrContainer, value_t>::type alloc_or_cont_t;
2972 typedef ::boost::container::dtl::flat_tree<value_t,::boost::container::dtl::select1st<Key>, Compare, alloc_or_cont_t> tree;
2973 static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
2976 } //namespace boost {
2978 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
2980 #include <boost/container/detail/config_end.hpp>
2982 #endif // BOOST_CONTAINER_FLAT_MAP_HPP