Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / container / flat_set.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
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)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_FLAT_SET_HPP
11 #define BOOST_CONTAINER_FLAT_SET_HPP
12
13 #ifndef BOOST_CONFIG_HPP
14 #  include <boost/config.hpp>
15 #endif
16
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
18 #  pragma once
19 #endif
20
21 #include <boost/container/detail/config_begin.hpp>
22 #include <boost/container/detail/workaround.hpp>
23
24 // container
25 #include <boost/container/allocator_traits.hpp>
26 #include <boost/container/container_fwd.hpp>
27 #include <boost/container/new_allocator.hpp> //new_allocator
28 // container/detail
29 #include <boost/container/detail/flat_tree.hpp>
30 #include <boost/container/detail/mpl.hpp>
31 // move
32 #include <boost/move/traits.hpp>
33 #include <boost/move/utility_core.hpp>
34 // move/detail
35 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
36 #include <boost/move/detail/fwd_macros.hpp>
37 #endif
38 #include <boost/move/detail/move_helpers.hpp>
39 // intrusive/detail
40 #include <boost/intrusive/detail/minimal_pair_header.hpp>      //pair
41 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
42 // std
43 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
44 #include <initializer_list>
45 #endif
46
47 namespace boost {
48 namespace container {
49
50 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
51 template <class Key, class Compare, class AllocatorOrContainer>
52 class flat_multiset;
53 #endif
54
55 //! flat_set is a Sorted Associative Container that stores objects of type Key.
56 //! It is also a Unique Associative Container, meaning that no two elements are the same.
57 //!
58 //! flat_set is similar to std::set but it's implemented by as an ordered sequence container.
59 //! The underlying sequence container is by default <i>vector</i> but it can also work
60 //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
61 //!
62 //! Using vector-like sequence containers means that inserting a new element into a flat_set might invalidate
63 //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
64 //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
65 //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
66 //!
67 //! This container provides random-access iterators.
68 //!
69 //! \tparam Key is the type to be inserted in the set, which is also the key_type
70 //! \tparam Compare is the comparison functor used to order keys
71 //! \tparam AllocatorOrContainer is either:
72 //!   - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
73 //!     (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
74 //!   - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
75 //!     sequence container with random-access iterators.
76 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
77 template <class Key, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator<Key> >
78 #else
79 template <class Key, class Compare, class AllocatorOrContainer>
80 #endif
81 class flat_set
82    ///@cond
83    : public dtl::flat_tree<Key, dtl::identity<Key>, Compare, AllocatorOrContainer>
84    ///@endcond
85 {
86    #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
87    private:
88    BOOST_COPYABLE_AND_MOVABLE(flat_set)
89    typedef dtl::flat_tree<Key, dtl::identity<Key>, Compare, AllocatorOrContainer> tree_t;
90
91    public:
92    tree_t &tree()
93    {  return *this;  }
94
95    const tree_t &tree() const
96    {  return *this;  }
97
98    #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
99
100    public:
101    //////////////////////////////////////////////
102    //
103    //                    types
104    //
105    //////////////////////////////////////////////
106    typedef Key                                                                      key_type;
107    typedef Compare                                                                  key_compare;
108    typedef Key                                                                      value_type;
109    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type)                   sequence_type;
110    typedef typename sequence_type::allocator_type                                   allocator_type;
111    typedef ::boost::container::allocator_traits<allocator_type>                     allocator_traits_type;
112    typedef typename sequence_type::pointer                                          pointer;
113    typedef typename sequence_type::const_pointer                                    const_pointer;
114    typedef typename sequence_type::reference                                        reference;
115    typedef typename sequence_type::const_reference                                  const_reference;
116    typedef typename sequence_type::size_type                                        size_type;
117    typedef typename sequence_type::difference_type                                  difference_type;
118    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type)           stored_allocator_type;
119    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare)                   value_compare;
120
121    typedef typename sequence_type::iterator                                         iterator;
122    typedef typename sequence_type::const_iterator                                   const_iterator;
123    typedef typename sequence_type::reverse_iterator                                 reverse_iterator;
124    typedef typename sequence_type::const_reverse_iterator                           const_reverse_iterator;
125
126    public:
127    //////////////////////////////////////////////
128    //
129    //          construct/copy/destroy
130    //
131    //////////////////////////////////////////////
132
133    //! <b>Effects</b>: Default constructs an empty container.
134    //!
135    //! <b>Complexity</b>: Constant.
136    BOOST_CONTAINER_FORCEINLINE
137    flat_set() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
138                                 dtl::is_nothrow_default_constructible<Compare>::value)
139       : tree_t()
140    {}
141
142    //! <b>Effects</b>: Constructs an empty container using the specified
143    //! comparison object.
144    //!
145    //! <b>Complexity</b>: Constant.
146    BOOST_CONTAINER_FORCEINLINE
147    explicit flat_set(const Compare& comp)
148       : tree_t(comp)
149    {}
150
151    //! <b>Effects</b>: Constructs an empty container using the specified allocator.
152    //!
153    //! <b>Complexity</b>: Constant.
154    BOOST_CONTAINER_FORCEINLINE
155    explicit flat_set(const allocator_type& a)
156       : tree_t(a)
157    {}
158
159    //! <b>Effects</b>: Constructs an empty container using the specified
160    //! comparison object and allocator.
161    //!
162    //! <b>Complexity</b>: Constant.
163    BOOST_CONTAINER_FORCEINLINE
164    flat_set(const Compare& comp, const allocator_type& a)
165       : tree_t(comp, a)
166    {}
167
168    //! <b>Effects</b>: Constructs an empty container and
169    //! inserts elements from the range [first ,last ).
170    //!
171    //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
172    //! comp and otherwise N logN, where N is last - first.
173    template <class InputIterator>
174    BOOST_CONTAINER_FORCEINLINE
175    flat_set(InputIterator first, InputIterator last)
176       : tree_t(true, first, last)
177    {}
178
179    //! <b>Effects</b>: Constructs an empty container using the specified
180    //! allocator, and inserts elements from the range [first ,last ).
181    //!
182    //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
183    //! comp and otherwise N logN, where N is last - first.
184    template <class InputIterator>
185    BOOST_CONTAINER_FORCEINLINE
186    flat_set(InputIterator first, InputIterator last, const allocator_type& a)
187       : tree_t(true, first, last, a)
188    {}
189
190    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
191    //! inserts elements from the range [first ,last ).
192    //!
193    //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
194    //! comp and otherwise N logN, where N is last - first.
195    template <class InputIterator>
196    BOOST_CONTAINER_FORCEINLINE
197    flat_set(InputIterator first, InputIterator last, const Compare& comp)
198       : tree_t(true, first, last, comp)
199    {}
200
201    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
202    //! allocator, and inserts elements from the range [first ,last ).
203    //!
204    //! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
205    //! comp and otherwise N logN, where N is last - first.
206    template <class InputIterator>
207    BOOST_CONTAINER_FORCEINLINE
208    flat_set(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
209       : tree_t(true, first, last, comp, a)
210    {}
211
212    //! <b>Effects</b>: Constructs an empty container and
213    //! inserts elements from the ordered unique range [first ,last). This function
214    //! is more efficient than the normal range creation for ordered ranges.
215    //!
216    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
217    //! unique values.
218    //!
219    //! <b>Complexity</b>: Linear in N.
220    //!
221    //! <b>Note</b>: Non-standard extension.
222    template <class InputIterator>
223    BOOST_CONTAINER_FORCEINLINE
224    flat_set(ordered_unique_range_t, InputIterator first, InputIterator last)
225       : tree_t(ordered_unique_range, first, last)
226    {}
227
228    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
229    //! inserts elements from the ordered unique range [first ,last). This function
230    //! is more efficient than the normal range creation for ordered ranges.
231    //!
232    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
233    //! unique values.
234    //!
235    //! <b>Complexity</b>: Linear in N.
236    //!
237    //! <b>Note</b>: Non-standard extension.
238    template <class InputIterator>
239    BOOST_CONTAINER_FORCEINLINE
240    flat_set(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
241       : tree_t(ordered_unique_range, first, last, comp)
242    {}
243
244    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
245    //! allocator, and inserts elements from the ordered unique range [first ,last). This function
246    //! is more efficient than the normal range creation for ordered ranges.
247    //!
248    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
249    //! unique values.
250    //!
251    //! <b>Complexity</b>: Linear in N.
252    //!
253    //! <b>Note</b>: Non-standard extension.
254    template <class InputIterator>
255    BOOST_CONTAINER_FORCEINLINE
256    flat_set(ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
257       : tree_t(ordered_unique_range, first, last, comp, a)
258    {}
259
260    //! <b>Effects</b>: Constructs an empty container using the specified allocator and
261    //! inserts elements from the ordered unique range [first ,last). This function
262    //! is more efficient than the normal range creation for ordered ranges.
263    //!
264    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
265    //! unique values.
266    //!
267    //! <b>Complexity</b>: Linear in N.
268    //!
269    //! <b>Note</b>: Non-standard extension.
270    template <class InputIterator>
271    BOOST_CONTAINER_FORCEINLINE
272       flat_set(ordered_unique_range_t, InputIterator first, InputIterator last, const allocator_type& a)
273       : tree_t(ordered_unique_range, first, last, Compare(), a)
274    {}
275
276 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
277    //! <b>Effects</b>: Constructs an empty container and
278    //! inserts elements from the range [il.begin(), il.end()).
279    //!
280    //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
281    //! comp and otherwise N logN, where N is il.begin() - il.end().
282    BOOST_CONTAINER_FORCEINLINE flat_set(std::initializer_list<value_type> il)
283       : tree_t(true, il.begin(), il.end())
284    {}
285
286    //! <b>Effects</b>: Constructs an empty container using the specified
287    //! allocator, and inserts elements from the range [il.begin(), il.end()).
288    //!
289    //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
290    //! comp and otherwise N logN, where N is il.begin() - il.end().
291    BOOST_CONTAINER_FORCEINLINE flat_set(std::initializer_list<value_type> il, const allocator_type& a)
292       : tree_t(true, il.begin(), il.end(), a)
293    {}
294
295    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
296    //! inserts elements from the range [il.begin(), il.end()).
297    //!
298    //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
299    //! comp and otherwise N logN, where N is il.begin() - il.end().
300    BOOST_CONTAINER_FORCEINLINE flat_set(std::initializer_list<value_type> il, const Compare& comp)
301       : tree_t(true, il.begin(), il.end(), comp)
302    {}
303
304    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
305    //! allocator, and inserts elements from the range [il.begin(), il.end()).
306    //!
307    //! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
308    //! comp and otherwise N logN, where N is il.begin() - il.end().
309    BOOST_CONTAINER_FORCEINLINE flat_set(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
310       : tree_t(true, il.begin(), il.end(), comp, a)
311    {}
312
313    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
314    //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
315    //! is more efficient than the normal range creation for ordered ranges.
316    //!
317    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
318    //! unique values.
319    //!
320    //! <b>Complexity</b>: Linear in N.
321    //!
322    //! <b>Note</b>: Non-standard extension.
323    BOOST_CONTAINER_FORCEINLINE flat_set(ordered_unique_range_t, std::initializer_list<value_type> il)
324       : tree_t(ordered_unique_range, il.begin(), il.end())
325    {}
326
327    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
328    //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
329    //! is more efficient than the normal range creation for ordered ranges.
330    //!
331    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
332    //! unique values.
333    //!
334    //! <b>Complexity</b>: Linear in N.
335    //!
336    //! <b>Note</b>: Non-standard extension.
337    BOOST_CONTAINER_FORCEINLINE flat_set(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp)
338       : tree_t(ordered_unique_range, il.begin(), il.end(), comp)
339    {}
340
341    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
342    //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
343    //! is more efficient than the normal range creation for ordered ranges.
344    //!
345    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
346    //! unique values.
347    //!
348    //! <b>Complexity</b>: Linear in N.
349    //!
350    //! <b>Note</b>: Non-standard extension.
351    BOOST_CONTAINER_FORCEINLINE flat_set(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
352       : tree_t(ordered_unique_range, il.begin(), il.end(), comp, a)
353    {}
354 #endif
355
356    //! <b>Effects</b>: Copy constructs the container.
357    //!
358    //! <b>Complexity</b>: Linear in x.size().
359    BOOST_CONTAINER_FORCEINLINE flat_set(const flat_set& x)
360       : tree_t(static_cast<const tree_t&>(x))
361    {}
362
363    //! <b>Effects</b>: Move constructs thecontainer. Constructs *this using x's resources.
364    //!
365    //! <b>Complexity</b>: Constant.
366    //!
367    //! <b>Postcondition</b>: x is emptied.
368    BOOST_CONTAINER_FORCEINLINE flat_set(BOOST_RV_REF(flat_set) x)
369       BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
370       : tree_t(BOOST_MOVE_BASE(tree_t, x))
371    {}
372
373    //! <b>Effects</b>: Copy constructs a container using the specified allocator.
374    //!
375    //! <b>Complexity</b>: Linear in x.size().
376    BOOST_CONTAINER_FORCEINLINE flat_set(const flat_set& x, const allocator_type &a)
377       : tree_t(static_cast<const tree_t&>(x), a)
378    {}
379
380    //! <b>Effects</b>: Move constructs a container using the specified allocator.
381    //!                 Constructs *this using x's resources.
382    //!
383    //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise
384    BOOST_CONTAINER_FORCEINLINE flat_set(BOOST_RV_REF(flat_set) x, const allocator_type &a)
385       : tree_t(BOOST_MOVE_BASE(tree_t, x), a)
386    {}
387
388    //! <b>Effects</b>: Makes *this a copy of x.
389    //!
390    //! <b>Complexity</b>: Linear in x.size().
391    BOOST_CONTAINER_FORCEINLINE flat_set& operator=(BOOST_COPY_ASSIGN_REF(flat_set) x)
392    {  return static_cast<flat_set&>(this->tree_t::operator=(static_cast<const tree_t&>(x)));  }
393
394    //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
395    //!   is false and (allocation throws or value_type's move constructor throws)
396    //!
397    //! <b>Complexity</b>: Constant if allocator_traits_type::
398    //!   propagate_on_container_move_assignment is true or
399    //!   this->get>allocator() == x.get_allocator(). Linear otherwise.
400    BOOST_CONTAINER_FORCEINLINE flat_set& operator=(BOOST_RV_REF(flat_set) x)
401       BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
402                           allocator_traits_type::is_always_equal::value) &&
403                            boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
404    {  return static_cast<flat_set&>(this->tree_t::operator=(BOOST_MOVE_BASE(tree_t, x)));  }
405
406 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
407    //! <b>Effects</b>: Copy all elements from il to *this.
408    //!
409    //! <b>Complexity</b>: Linear in il.size().
410    flat_set& operator=(std::initializer_list<value_type> il)
411    {
412        this->clear();
413        this->insert(il.begin(), il.end());
414        return *this;
415    }
416 #endif
417
418    #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
419    //! <b>Effects</b>: Returns a copy of the allocator that
420    //!   was passed to the object's constructor.
421    //!
422    //! <b>Complexity</b>: Constant.
423    allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
424
425    //! <b>Effects</b>: Returns a reference to the internal allocator.
426    //!
427    //! <b>Throws</b>: Nothing
428    //!
429    //! <b>Complexity</b>: Constant.
430    //!
431    //! <b>Note</b>: Non-standard extension.
432    stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW;
433
434    //! <b>Effects</b>: Returns a reference to the internal allocator.
435    //!
436    //! <b>Throws</b>: Nothing
437    //!
438    //! <b>Complexity</b>: Constant.
439    //!
440    //! <b>Note</b>: Non-standard extension.
441    const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
442
443    //! <b>Effects</b>: Returns an iterator to the first element contained in the container.
444    //!
445    //! <b>Throws</b>: Nothing.
446    //!
447    //! <b>Complexity</b>: Constant.
448    iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
449
450    //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
451    //!
452    //! <b>Throws</b>: Nothing.
453    //!
454    //! <b>Complexity</b>: Constant.
455    const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
456
457    //! <b>Effects</b>: Returns an iterator to the end of the container.
458    //!
459    //! <b>Throws</b>: Nothing.
460    //!
461    //! <b>Complexity</b>: Constant.
462    iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
463
464    //! <b>Effects</b>: Returns a const_iterator to the end of the container.
465    //!
466    //! <b>Throws</b>: Nothing.
467    //!
468    //! <b>Complexity</b>: Constant.
469    const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
470
471    //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
472    //! of the reversed container.
473    //!
474    //! <b>Throws</b>: Nothing.
475    //!
476    //! <b>Complexity</b>: Constant.
477    reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
478
479    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
480    //! of the reversed container.
481    //!
482    //! <b>Throws</b>: Nothing.
483    //!
484    //! <b>Complexity</b>: Constant.
485    const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
486
487    //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
488    //! of the reversed container.
489    //!
490    //! <b>Throws</b>: Nothing.
491    //!
492    //! <b>Complexity</b>: Constant.
493    reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
494
495    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
496    //! of the reversed container.
497    //!
498    //! <b>Throws</b>: Nothing.
499    //!
500    //! <b>Complexity</b>: Constant.
501    const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
502
503    //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
504    //!
505    //! <b>Throws</b>: Nothing.
506    //!
507    //! <b>Complexity</b>: Constant.
508    const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
509
510    //! <b>Effects</b>: Returns a const_iterator to the end of the container.
511    //!
512    //! <b>Throws</b>: Nothing.
513    //!
514    //! <b>Complexity</b>: Constant.
515    const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
516
517    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
518    //! of the reversed container.
519    //!
520    //! <b>Throws</b>: Nothing.
521    //!
522    //! <b>Complexity</b>: Constant.
523    const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
524
525    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
526    //! of the reversed container.
527    //!
528    //! <b>Throws</b>: Nothing.
529    //!
530    //! <b>Complexity</b>: Constant.
531    const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
532
533    //! <b>Effects</b>: Returns true if the container contains no elements.
534    //!
535    //! <b>Throws</b>: Nothing.
536    //!
537    //! <b>Complexity</b>: Constant.
538    bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
539
540    //! <b>Effects</b>: Returns the number of the elements contained in the container.
541    //!
542    //! <b>Throws</b>: Nothing.
543    //!
544    //! <b>Complexity</b>: Constant.
545    size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
546
547    //! <b>Effects</b>: Returns the largest possible size of the container.
548    //!
549    //! <b>Throws</b>: Nothing.
550    //!
551    //! <b>Complexity</b>: Constant.
552    size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW;
553
554    //! <b>Effects</b>: Number of elements for which memory has been allocated.
555    //!   capacity() is always greater than or equal to size().
556    //!
557    //! <b>Throws</b>: Nothing.
558    //!
559    //! <b>Complexity</b>: Constant.
560    size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW;
561
562    //! <b>Effects</b>: If n is less than or equal to capacity(), or the
563    //!   underlying container has no `reserve` member, this call has no
564    //!   effect. Otherwise, it is a request for allocation of additional memory.
565    //!   If the request is successful, then capacity() is greater than or equal to
566    //!   n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
567    //!
568    //! <b>Throws</b>: If memory allocation allocation throws or T's copy constructor throws.
569    //!
570    //! <b>Note</b>: If capacity() is less than "cnt", iterators and references to
571    //!   to values might be invalidated.
572    void reserve(size_type cnt);
573
574    //! <b>Effects</b>: Tries to deallocate the excess of memory created
575    //    with previous allocations. The size of the vector is unchanged
576    //!
577    //! <b>Throws</b>: If memory allocation throws, or Key's copy constructor throws.
578    //!
579    //! <b>Complexity</b>: Linear to size().
580    void shrink_to_fit();
581
582    #endif   //   #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
583
584    //////////////////////////////////////////////
585    //
586    //                modifiers
587    //
588    //////////////////////////////////////////////
589
590    #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
591
592    //! <b>Effects</b>: Inserts an object x of type Key constructed with
593    //!   std::forward<Args>(args)... if and only if there is no element in the container
594    //!   with key equivalent to the key of x.
595    //!
596    //! <b>Returns</b>: The bool component of the returned pair is true if and only
597    //!   if the insertion takes place, and the iterator component of the pair
598    //!   points to the element with key equivalent to the key of x.
599    //!
600    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
601    //!   to the elements with bigger keys than x.
602    //!
603    //! <b>Note</b>: If an element is inserted it might invalidate elements.
604    template <class... Args>
605    BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
606    {  return this->tree_t::emplace_unique(boost::forward<Args>(args)...); }
607
608    //! <b>Effects</b>: Inserts an object of type Key constructed with
609    //!   std::forward<Args>(args)... in the container if and only if there is
610    //!   no element in the container with key equivalent to the key of x.
611    //!   p is a hint pointing to where the insert should start to search.
612    //!
613    //! <b>Returns</b>: An iterator pointing to the element with key equivalent
614    //!   to the key of x.
615    //!
616    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
617    //!   right before p) plus insertion linear to the elements with bigger keys than x.
618    //!
619    //! <b>Note</b>: If an element is inserted it might invalidate elements.
620    template <class... Args>
621    BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
622    {  return this->tree_t::emplace_hint_unique(p, boost::forward<Args>(args)...); }
623
624    #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
625
626    #define BOOST_CONTAINER_FLAT_SET_EMPLACE_CODE(N) \
627    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
628    BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
629    {  return this->tree_t::emplace_unique(BOOST_MOVE_FWD##N);  }\
630    \
631    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
632    BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
633    {  return this->tree_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
634    //
635    BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_SET_EMPLACE_CODE)
636    #undef BOOST_CONTAINER_FLAT_SET_EMPLACE_CODE
637
638    #endif   // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
639
640    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
641    //! <b>Effects</b>: Inserts x if and only if there is no element in the container
642    //!   with key equivalent to the key of x.
643    //!
644    //! <b>Returns</b>: The bool component of the returned pair is true if and only
645    //!   if the insertion takes place, and the iterator component of the pair
646    //!   points to the element with key equivalent to the key of x.
647    //!
648    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
649    //!   to the elements with bigger keys than x.
650    //!
651    //! <b>Note</b>: If an element is inserted it might invalidate elements.
652    std::pair<iterator, bool> insert(const value_type &x);
653
654    //! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
655    //! only if there is no element in the container with key equivalent to the key of x.
656    //!
657    //! <b>Returns</b>: The bool component of the returned pair is true if and only
658    //!   if the insertion takes place, and the iterator component of the pair
659    //!   points to the element with key equivalent to the key of x.
660    //!
661    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
662    //!   to the elements with bigger keys than x.
663    //!
664    //! <b>Note</b>: If an element is inserted it might invalidate elements.
665    std::pair<iterator, bool> insert(value_type &&x);
666    #else
667    private:
668    typedef std::pair<iterator, bool> insert_return_pair;
669    public:
670    BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, insert_return_pair, this->priv_insert)
671    #endif
672
673    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
674    //! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
675    //!   no element in the container with key equivalent to the key of x.
676    //!   p is a hint pointing to where the insert should start to search.
677    //!
678    //! <b>Returns</b>: An iterator pointing to the element with key equivalent
679    //!   to the key of x.
680    //!
681    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
682    //!   right before p) plus insertion linear to the elements with bigger keys than x.
683    //!
684    //! <b>Note</b>: If an element is inserted it might invalidate elements.
685    iterator insert(const_iterator p, const value_type &x);
686
687    //! <b>Effects</b>: Inserts an element move constructed from x in the container.
688    //!   p is a hint pointing to where the insert should start to search.
689    //!
690    //! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
691    //!
692    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
693    //!   right before p) plus insertion linear to the elements with bigger keys than x.
694    //!
695    //! <b>Note</b>: If an element is inserted it might invalidate elements.
696    iterator insert(const_iterator p, value_type &&x);
697    #else
698    BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
699    #endif
700
701    //! <b>Requires</b>: first, last are not iterators into *this.
702    //!
703    //! <b>Effects</b>: inserts each element from the range [first,last) if and only
704    //!   if there is no element with key equivalent to the key of that element.
705    //!
706    //! <b>Complexity</b>: N log(N).
707    //!
708    //! <b>Note</b>: If an element is inserted it might invalidate elements.
709    template <class InputIterator>
710    BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
711       {  this->tree_t::insert_unique(first, last);  }
712
713    //! <b>Requires</b>: first, last are not iterators into *this and
714    //! must be ordered according to the predicate and must be
715    //! unique values.
716    //!
717    //! <b>Effects</b>: inserts each element from the range [first,last) .This function
718    //! is more efficient than the normal range creation for ordered ranges.
719    //!
720    //! <b>Complexity</b>: Linear.
721    //!
722    //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
723    template <class InputIterator>
724    BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, InputIterator first, InputIterator last)
725       {  this->tree_t::insert_unique(ordered_unique_range, first, last);  }
726
727 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
728    //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
729    //!   if there is no element with key equivalent to the key of that element.
730    //!
731    //! <b>Complexity</b>: N log(N).
732    //!
733    //! <b>Note</b>: If an element is inserted it might invalidate elements.
734    BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
735    {  this->tree_t::insert_unique(il.begin(), il.end()); }
736
737    //! <b>Requires</b>: Range [il.begin(), il.end()) must be ordered according to the predicate
738    //! and must be unique values.
739    //!
740    //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) .This function
741    //! is more efficient than the normal range creation for ordered ranges.
742    //!
743    //! <b>Complexity</b>: Linear.
744    //!
745    //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
746    BOOST_CONTAINER_FORCEINLINE void insert(ordered_unique_range_t, std::initializer_list<value_type> il)
747    {  this->tree_t::insert_unique(ordered_unique_range, il.begin(), il.end()); }
748 #endif
749
750    //! @copydoc ::boost::container::flat_map::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
751    template<class C2>
752    BOOST_CONTAINER_FORCEINLINE void merge(flat_set<Key, C2, AllocatorOrContainer>& source)
753    {  this->tree_t::merge_unique(source.tree());   }
754
755    //! @copydoc ::boost::container::flat_set::merge(flat_set<Key, C2, AllocatorOrContainer>&)
756    template<class C2>
757    BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_set<Key, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
758    {  return this->merge(static_cast<flat_set<Key, C2, AllocatorOrContainer>&>(source));   }
759
760    //! @copydoc ::boost::container::flat_map::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
761    template<class C2>
762    BOOST_CONTAINER_FORCEINLINE void merge(flat_multiset<Key, C2, AllocatorOrContainer>& source)
763    {  this->tree_t::merge_unique(source.tree());   }
764
765    //! @copydoc ::boost::container::flat_set::merge(flat_multiset<Key, C2, AllocatorOrContainer>&)
766    template<class C2>
767    BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multiset<Key, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
768    {  return this->merge(static_cast<flat_multiset<Key, C2, AllocatorOrContainer>&>(source));   }
769
770    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
771
772    //! <b>Effects</b>: Erases the element pointed to by p.
773    //!
774    //! <b>Returns</b>: Returns an iterator pointing to the element immediately
775    //!   following q prior to the element being erased. If no such element exists,
776    //!   returns end().
777    //!
778    //! <b>Complexity</b>: Linear to the elements with keys bigger than p
779    //!
780    //! <b>Note</b>: Invalidates elements with keys
781    //!   not less than the erased element.
782    iterator erase(const_iterator p);
783
784    //! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
785    //!
786    //! <b>Returns</b>: Returns the number of erased elements.
787    //!
788    //! <b>Complexity</b>: Logarithmic search time plus erasure time
789    //!   linear to the elements with bigger keys.
790    size_type erase(const key_type& x);
791
792    //! <b>Effects</b>: Erases all the elements in the range [first, last).
793    //!
794    //! <b>Returns</b>: Returns last.
795    //!
796    //! <b>Complexity</b>: size()*N where N is the distance from first to last.
797    //!
798    //! <b>Complexity</b>: Logarithmic search time plus erasure time
799    //!   linear to the elements with bigger keys.
800    iterator erase(const_iterator first, const_iterator last);
801
802    //! <b>Effects</b>: Swaps the contents of *this and x.
803    //!
804    //! <b>Throws</b>: Nothing.
805    //!
806    //! <b>Complexity</b>: Constant.
807    void swap(flat_set& x)
808       BOOST_NOEXCEPT_IF(  allocator_traits_type::is_always_equal::value
809                                  && boost::container::dtl::is_nothrow_swappable<Compare>::value );
810
811    //! <b>Effects</b>: erase(begin(),end()).
812    //!
813    //! <b>Postcondition</b>: size() == 0.
814    //!
815    //! <b>Complexity</b>: linear in size().
816    void clear() BOOST_NOEXCEPT_OR_NOTHROW;
817
818    //! <b>Effects</b>: Returns the comparison object out
819    //!   of which a was constructed.
820    //!
821    //! <b>Complexity</b>: Constant.
822    key_compare key_comp() const;
823
824    //! <b>Effects</b>: Returns an object of value_compare constructed out
825    //!   of the comparison object.
826    //!
827    //! <b>Complexity</b>: Constant.
828    value_compare value_comp() const;
829
830    //! <b>Returns</b>: An iterator pointing to an element with the key
831    //!   equivalent to x, or end() if such an element is not found.
832    //!
833    //! <b>Complexity</b>: Logarithmic.
834    iterator find(const key_type& x);
835
836    //! <b>Returns</b>: A const_iterator pointing to an element with the key
837    //!   equivalent to x, or end() if such an element is not found.
838    //!
839    //! <b>Complexity</b>: Logarithmic.
840    const_iterator find(const key_type& x) const;
841
842    //! <b>Requires</b>: This overload is available only if
843    //! key_compare::is_transparent exists.
844    //!
845    //! <b>Returns</b>: An iterator pointing to an element with the key
846    //!   equivalent to x, or end() if such an element is not found.
847    //!
848    //! <b>Complexity</b>: Logarithmic.
849    template<typename K>
850    iterator find(const K& x);
851
852    //! <b>Requires</b>: This overload is available only if
853    //! key_compare::is_transparent exists.
854    //!
855    //! <b>Returns</b>: A const_iterator pointing to an element with the key
856    //!   equivalent to x, or end() if such an element is not found.
857    //!
858    //! <b>Complexity</b>: Logarithmic.
859    template<typename K>
860    const_iterator find(const K& x) const;
861
862    //! <b>Requires</b>: size() >= n.
863    //!
864    //! <b>Effects</b>: Returns an iterator to the nth element
865    //!   from the beginning of the container. Returns end()
866    //!   if n == size().
867    //!
868    //! <b>Throws</b>: Nothing.
869    //!
870    //! <b>Complexity</b>: Constant.
871    //!
872    //! <b>Note</b>: Non-standard extension
873    iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW;
874
875    //! <b>Requires</b>: size() >= n.
876    //!
877    //! <b>Effects</b>: Returns a const_iterator to the nth element
878    //!   from the beginning of the container. Returns end()
879    //!   if n == size().
880    //!
881    //! <b>Throws</b>: Nothing.
882    //!
883    //! <b>Complexity</b>: Constant.
884    //!
885    //! <b>Note</b>: Non-standard extension
886    const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW;
887
888    //! <b>Requires</b>: begin() <= p <= end().
889    //!
890    //! <b>Effects</b>: Returns the index of the element pointed by p
891    //!   and size() if p == end().
892    //!
893    //! <b>Throws</b>: Nothing.
894    //!
895    //! <b>Complexity</b>: Constant.
896    //!
897    //! <b>Note</b>: Non-standard extension
898    size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
899
900    //! <b>Requires</b>: begin() <= p <= end().
901    //!
902    //! <b>Effects</b>: Returns the index of the element pointed by p
903    //!   and size() if p == end().
904    //!
905    //! <b>Throws</b>: Nothing.
906    //!
907    //! <b>Complexity</b>: Constant.
908    //!
909    //! <b>Note</b>: Non-standard extension
910    size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW;
911
912    #endif   //   #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
913
914    //! <b>Returns</b>: The number of elements with key equivalent to x.
915    //!
916    //! <b>Complexity</b>: log(size())+count(k)
917    BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
918    {  return static_cast<size_type>(this->tree_t::find(x) != this->tree_t::cend());  }
919
920    //! <b>Requires</b>: This overload is available only if
921    //! key_compare::is_transparent exists.
922    //!
923    //! <b>Returns</b>: The number of elements with key equivalent to x.
924    //!
925    //! <b>Complexity</b>: log(size())+count(k)
926    template<typename K>
927    BOOST_CONTAINER_FORCEINLINE size_type count(const K& x) const
928       //Don't use find() != end optimization here as transparent comparators with key K might
929       //return a different range than key_type (which can only return a single element range)
930    {  return this->tree_t::count(x);  }
931
932    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
933
934    //! <b>Returns</b>: Returns true if there is an element with key
935    //!   equivalent to key in the container, otherwise false.
936    //!
937    //! <b>Complexity</b>: log(size()).
938    bool contains(const key_type& x) const;
939
940    //! <b>Requires</b>: This overload is available only if
941    //! key_compare::is_transparent exists.
942    //!
943    //! <b>Returns</b>: Returns true if there is an element with key
944    //!   equivalent to key in the container, otherwise false.
945    //!
946    //! <b>Complexity</b>: log(size()).
947    template<typename K>
948    bool contains(const K& x) const;
949
950    //! <b>Returns</b>: An iterator pointing to the first element with key not less
951    //!   than x, or end() if such an element is not found.
952    //!
953    //! <b>Complexity</b>: Logarithmic
954    iterator lower_bound(const key_type& x);
955
956    //! <b>Returns</b>: A const iterator pointing to the first element with key not
957    //!   less than x, or end() if such an element is not found.
958    //!
959    //! <b>Complexity</b>: Logarithmic
960    const_iterator lower_bound(const key_type& x) const;
961
962    //! <b>Requires</b>: This overload is available only if
963    //! key_compare::is_transparent exists.
964    //!
965    //! <b>Returns</b>: An iterator pointing to the first element with key not less
966    //!   than x, or end() if such an element is not found.
967    //!
968    //! <b>Complexity</b>: Logarithmic
969    template<typename K>
970    iterator lower_bound(const K& x);
971
972    //! <b>Requires</b>: This overload is available only if
973    //! key_compare::is_transparent exists.
974    //!
975    //! <b>Returns</b>: A const iterator pointing to the first element with key not
976    //!   less than x, or end() if such an element is not found.
977    //!
978    //! <b>Complexity</b>: Logarithmic
979    template<typename K>
980    const_iterator lower_bound(const K& x) const;
981
982    //! <b>Returns</b>: An iterator pointing to the first element with key greater
983    //!   than x, or end() if such an element is not found.
984    //!
985    //! <b>Complexity</b>: Logarithmic
986    iterator upper_bound(const key_type& x);
987
988    //! <b>Returns</b>: A const iterator pointing to the first element with key 
989    //!   greater than x, or end() if such an element is not found.
990    //!
991    //! <b>Complexity</b>: Logarithmic
992    const_iterator upper_bound(const key_type& x) const;
993
994    //! <b>Requires</b>: This overload is available only if
995    //! key_compare::is_transparent exists.
996    //!
997    //! <b>Returns</b>: An iterator pointing to the first element with key greater
998    //!   than x, or end() if such an element is not found.
999    //!
1000    //! <b>Complexity</b>: Logarithmic
1001    template<typename K>
1002    iterator upper_bound(const K& x);
1003
1004    //! <b>Requires</b>: This overload is available only if
1005    //! key_compare::is_transparent exists.
1006    //!
1007    //! <b>Returns</b>: A const iterator pointing to the first element with key
1008    //!   greater than x, or end() if such an element is not found.
1009    //!
1010    //! <b>Complexity</b>: Logarithmic
1011    template<typename K>
1012    const_iterator upper_bound(const K& x) const;
1013
1014    #endif   //   #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1015
1016    //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1017    //!
1018    //! <b>Complexity</b>: Logarithmic
1019    BOOST_CONTAINER_FORCEINLINE std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
1020    {  return this->tree_t::lower_bound_range(x);  }
1021
1022    //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1023    //!
1024    //! <b>Complexity</b>: Logarithmic
1025    BOOST_CONTAINER_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type& x)
1026    {  return this->tree_t::lower_bound_range(x);  }
1027
1028    //! <b>Requires</b>: This overload is available only if
1029    //! key_compare::is_transparent exists.
1030    //!
1031    //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1032    //!
1033    //! <b>Complexity</b>: Logarithmic
1034    template<typename K>
1035    std::pair<iterator,iterator> equal_range(const K& x)
1036       //Don't use lower_bound_range optimization here as transparent comparators with key K might
1037       //return a different range than key_type (which can only return a single element range)
1038    {  return this->tree_t::equal_range(x);  }
1039
1040    //! <b>Requires</b>: This overload is available only if
1041    //! key_compare::is_transparent exists.
1042    //!
1043    //! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
1044    //!
1045    //! <b>Complexity</b>: Logarithmic
1046    template<typename K>
1047    std::pair<const_iterator,const_iterator> equal_range(const K& x) const
1048       //Don't use lower_bound_range optimization here as transparent comparators with key K might
1049       //return a different range than key_type (which can only return a single element range)
1050    {  return this->tree_t::equal_range(x);  }
1051
1052    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1053
1054    //! <b>Effects</b>: Returns true if x and y are equal
1055    //!
1056    //! <b>Complexity</b>: Linear to the number of elements in the container.
1057    friend bool operator==(const flat_set& x, const flat_set& y);
1058
1059    //! <b>Effects</b>: Returns true if x and y are unequal
1060    //!
1061    //! <b>Complexity</b>: Linear to the number of elements in the container.
1062    friend bool operator!=(const flat_set& x, const flat_set& y);
1063
1064    //! <b>Effects</b>: Returns true if x is less than y
1065    //!
1066    //! <b>Complexity</b>: Linear to the number of elements in the container.
1067    friend bool operator<(const flat_set& x, const flat_set& y);
1068
1069    //! <b>Effects</b>: Returns true if x is greater than y
1070    //!
1071    //! <b>Complexity</b>: Linear to the number of elements in the container.
1072    friend bool operator>(const flat_set& x, const flat_set& y);
1073
1074    //! <b>Effects</b>: Returns true if x is equal or less than y
1075    //!
1076    //! <b>Complexity</b>: Linear to the number of elements in the container.
1077    friend bool operator<=(const flat_set& x, const flat_set& y);
1078
1079    //! <b>Effects</b>: Returns true if x is equal or greater than y
1080    //!
1081    //! <b>Complexity</b>: Linear to the number of elements in the container.
1082    friend bool operator>=(const flat_set& x, const flat_set& y);
1083
1084    //! <b>Effects</b>: x.swap(y)
1085    //!
1086    //! <b>Complexity</b>: Constant.
1087    friend void swap(flat_set& x, flat_set& y);
1088
1089    //! <b>Effects</b>: Extracts the internal sequence container.
1090    //!
1091    //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
1092    //!
1093    //! <b>Postcondition</b>: this->empty()
1094    //!
1095    //! <b>Throws</b>: If secuence_type's move constructor throws 
1096    sequence_type extract_sequence();
1097
1098    #endif   //#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1099
1100    //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1101    //!   one passed externally using the move assignment. Erases non-unique elements.
1102    //!
1103    //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
1104    //!
1105    //! <b>Throws</b>: If the comparison or the move constructor throws
1106    BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
1107    {  this->tree_t::adopt_sequence_unique(boost::move(seq));  }
1108
1109    //! <b>Requires</b>: seq shall be ordered according to this->compare()
1110    //!   and shall contain unique elements.
1111    //!
1112    //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1113    //!   one passed externally using the move assignment.
1114    //!
1115    //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
1116    //!
1117    //! <b>Throws</b>: If the move assignment throws
1118    BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_unique_range_t, BOOST_RV_REF(sequence_type) seq)
1119    {  this->tree_t::adopt_sequence_unique(ordered_unique_range_t(), boost::move(seq));  }
1120
1121    #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1122    private:
1123    template<class KeyType>
1124    BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> priv_insert(BOOST_FWD_REF(KeyType) x)
1125    {  return this->tree_t::insert_unique(::boost::forward<KeyType>(x));  }
1126
1127    template<class KeyType>
1128    BOOST_CONTAINER_FORCEINLINE iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
1129    {  return this->tree_t::insert_unique(p, ::boost::forward<KeyType>(x)); }
1130    #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1131 };
1132
1133 #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
1134
1135 template <typename InputIterator>
1136 flat_set(InputIterator, InputIterator) ->
1137    flat_set< it_based_value_type_t<InputIterator> >;
1138
1139 template < typename InputIterator, typename AllocatorOrCompare>
1140     flat_set(InputIterator, InputIterator, AllocatorOrCompare const&) ->
1141     flat_set< it_based_value_type_t<InputIterator>
1142             , typename dtl::if_c< // Compare
1143                 dtl::is_allocator<AllocatorOrCompare>::value
1144                 , std::less<it_based_value_type_t<InputIterator>>
1145                 , AllocatorOrCompare
1146             >::type
1147             , typename dtl::if_c< // Allocator
1148                 dtl::is_allocator<AllocatorOrCompare>::value
1149                 , AllocatorOrCompare
1150                 , new_allocator<it_based_value_type_t<InputIterator>>
1151                 >::type
1152             >;
1153
1154 template < typename InputIterator, typename Compare, typename Allocator
1155          , typename = dtl::require_nonallocator_t<Compare>
1156          , typename = dtl::require_allocator_t<Allocator>>
1157 flat_set(InputIterator, InputIterator, Compare const&, Allocator const&) ->
1158    flat_set< it_based_value_type_t<InputIterator>
1159            , Compare
1160            , Allocator>;
1161
1162 template <typename InputIterator>
1163 flat_set(ordered_unique_range_t, InputIterator, InputIterator) ->
1164    flat_set< it_based_value_type_t<InputIterator>>;
1165
1166
1167 template < typename InputIterator, typename AllocatorOrCompare>
1168     flat_set(ordered_unique_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
1169     flat_set< it_based_value_type_t<InputIterator>
1170             , typename dtl::if_c< // Compare
1171                 dtl::is_allocator<AllocatorOrCompare>::value
1172                 , std::less<it_based_value_type_t<InputIterator>>
1173                 , AllocatorOrCompare
1174             >::type
1175             , typename dtl::if_c< // Allocator
1176                 dtl::is_allocator<AllocatorOrCompare>::value
1177                 , AllocatorOrCompare
1178                 , new_allocator<it_based_value_type_t<InputIterator>>
1179                 >::type
1180             >;
1181
1182 template < typename InputIterator, typename Compare, typename Allocator
1183          , typename = dtl::require_nonallocator_t<Compare>
1184          , typename = dtl::require_allocator_t<Allocator>>
1185 flat_set(ordered_unique_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
1186    flat_set< it_based_value_type_t<InputIterator>
1187            , Compare
1188            , Allocator>;
1189
1190 #endif
1191
1192 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1193
1194 }  //namespace container {
1195
1196 //!has_trivial_destructor_after_move<> == true_type
1197 //!specialization for optimizations
1198 template <class Key, class Compare, class AllocatorOrContainer>
1199 struct has_trivial_destructor_after_move<boost::container::flat_set<Key, Compare, AllocatorOrContainer> >
1200 {
1201    typedef ::boost::container::dtl::flat_tree<Key, ::boost::container::dtl::identity<Key>, Compare, AllocatorOrContainer> tree;
1202    static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
1203 };
1204
1205 namespace container {
1206
1207 #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1208
1209 //! flat_multiset is a Sorted Associative Container that stores objects of type Key and
1210 //! can store multiple copies of the same key value.
1211 //!
1212 //! flat_multiset is similar to std::multiset but it's implemented by as an ordered sequence container.
1213 //! The underlying sequence container is by default <i>vector</i> but it can also work
1214 //! user-provided vector-like SequenceContainers (like <i>static_vector</i> or <i>small_vector</i>).
1215 //!
1216 //! Using vector-like sequence containers means that inserting a new element into a flat_multiset might invalidate
1217 //! previous iterators and references (unless that sequence container is <i>stable_vector</i> or a similar
1218 //! container that offers stable pointers and references). Similarly, erasing an element might invalidate
1219 //! iterators and references pointing to elements that come after (their keys are bigger) the erased element.
1220 //!
1221 //! This container provides random-access iterators.
1222 //!
1223 //! \tparam Key is the type to be inserted in the multiset, which is also the key_type
1224 //! \tparam Compare is the comparison functor used to order keys
1225 //! \tparam AllocatorOrContainer is either:
1226 //!   - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
1227 //!     (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
1228 //!   - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
1229 //!     sequence container with random-access iterators.
1230 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1231 template <class Key, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator<Key> >
1232 #else
1233 template <class Key, class Compare, class AllocatorOrContainer>
1234 #endif
1235 class flat_multiset
1236    ///@cond
1237    : public dtl::flat_tree<Key, dtl::identity<Key>, Compare, AllocatorOrContainer>
1238    ///@endcond
1239 {
1240    #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1241    private:
1242    BOOST_COPYABLE_AND_MOVABLE(flat_multiset)
1243    typedef dtl::flat_tree<Key, dtl::identity<Key>, Compare, AllocatorOrContainer> tree_t;
1244
1245    public:
1246    tree_t &tree()
1247    {  return *this;  }
1248
1249    const tree_t &tree() const
1250    {  return *this;  }
1251    #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1252
1253    public:
1254    //////////////////////////////////////////////
1255    //
1256    //                    types
1257    //
1258    //////////////////////////////////////////////
1259    typedef Key                                                                      key_type;
1260    typedef Compare                                                                  key_compare;
1261    typedef Key                                                                      value_type;
1262    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::sequence_type)                   sequence_type;
1263    typedef typename sequence_type::allocator_type                                   allocator_type;
1264    typedef ::boost::container::allocator_traits<allocator_type>                     allocator_traits_type;
1265    typedef typename sequence_type::pointer                                          pointer;
1266    typedef typename sequence_type::const_pointer                                    const_pointer;
1267    typedef typename sequence_type::reference                                        reference;
1268    typedef typename sequence_type::const_reference                                  const_reference;
1269    typedef typename sequence_type::size_type                                        size_type;
1270    typedef typename sequence_type::difference_type                                  difference_type;
1271    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::stored_allocator_type)           stored_allocator_type;
1272    typedef typename BOOST_CONTAINER_IMPDEF(tree_t::value_compare)                   value_compare;
1273
1274    typedef typename sequence_type::iterator                                         iterator;
1275    typedef typename sequence_type::const_iterator                                   const_iterator;
1276    typedef typename sequence_type::reverse_iterator                                 reverse_iterator;
1277    typedef typename sequence_type::const_reverse_iterator                           const_reverse_iterator;
1278
1279    //! @copydoc ::boost::container::flat_set::flat_set()
1280    BOOST_CONTAINER_FORCEINLINE flat_multiset() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<AllocatorOrContainer>::value &&
1281                                                                  dtl::is_nothrow_default_constructible<Compare>::value)
1282       : tree_t()
1283    {}
1284
1285    //! @copydoc ::boost::container::flat_set::flat_set(const Compare&)
1286    BOOST_CONTAINER_FORCEINLINE explicit flat_multiset(const Compare& comp)
1287       : tree_t(comp)
1288    {}
1289
1290    //! @copydoc ::boost::container::flat_set::flat_set(const allocator_type&)
1291    BOOST_CONTAINER_FORCEINLINE explicit flat_multiset(const allocator_type& a)
1292       : tree_t(a)
1293    {}
1294
1295    //! @copydoc ::boost::container::flat_set::flat_set(const Compare&, const allocator_type&)
1296    BOOST_CONTAINER_FORCEINLINE flat_multiset(const Compare& comp, const allocator_type& a)
1297       : tree_t(comp, a)
1298    {}
1299
1300    //! @copydoc ::boost::container::flat_set::flat_set(InputIterator, InputIterator)
1301    template <class InputIterator>
1302    BOOST_CONTAINER_FORCEINLINE flat_multiset(InputIterator first, InputIterator last)
1303       : tree_t(false, first, last)
1304    {}
1305
1306    //! @copydoc ::boost::container::flat_set::flat_set(InputIterator, InputIterator, const allocator_type&)
1307    template <class InputIterator>
1308    BOOST_CONTAINER_FORCEINLINE flat_multiset(InputIterator first, InputIterator last, const allocator_type& a)
1309       : tree_t(false, first, last, a)
1310    {}
1311
1312    //! @copydoc ::boost::container::flat_set::flat_set(InputIterator, InputIterator, const Compare& comp)
1313    template <class InputIterator>
1314    BOOST_CONTAINER_FORCEINLINE flat_multiset(InputIterator first, InputIterator last, const Compare& comp)
1315       : tree_t(false, first, last, comp)
1316    {}
1317
1318    //! @copydoc ::boost::container::flat_set::flat_set(InputIterator, InputIterator, const Compare& comp, const allocator_type&)
1319    template <class InputIterator>
1320    BOOST_CONTAINER_FORCEINLINE flat_multiset(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
1321       : tree_t(false, first, last, comp, a)
1322    {}
1323
1324    //! <b>Effects</b>: Constructs an empty flat_multiset and
1325    //! inserts elements from the ordered range [first ,last ). This function
1326    //! is more efficient than the normal range creation for ordered ranges.
1327    //!
1328    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1329    //!
1330    //! <b>Complexity</b>: Linear in N.
1331    //!
1332    //! <b>Note</b>: Non-standard extension.
1333    template <class InputIterator>
1334    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, InputIterator first, InputIterator last)
1335       : tree_t(ordered_range, first, last)
1336    {}
1337
1338    //! <b>Effects</b>: Constructs an empty flat_multiset using the specified comparison object and
1339    //! inserts elements from the ordered range [first ,last ). This function
1340    //! is more efficient than the normal range creation for ordered ranges.
1341    //!
1342    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1343    //!
1344    //! <b>Complexity</b>: Linear in N.
1345    //!
1346    //! <b>Note</b>: Non-standard extension.
1347    template <class InputIterator>
1348    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp)
1349       : tree_t(ordered_range, first, last, comp)
1350    {}
1351
1352    //! <b>Effects</b>: Constructs an empty flat_multiset using the specified comparison object and
1353    //! allocator, and inserts elements from the ordered range [first, last ). This function
1354    //! is more efficient than the normal range creation for ordered ranges.
1355    //!
1356    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1357    //!
1358    //! <b>Complexity</b>: Linear in N.
1359    //!
1360    //! <b>Note</b>: Non-standard extension.
1361    template <class InputIterator>
1362    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
1363       : tree_t(ordered_range, first, last, comp, a)
1364    {}
1365
1366    //! <b>Effects</b>: Constructs an empty flat_multiset using the specified allocator and
1367    //! inserts elements from the ordered range [first ,last ). This function
1368    //! is more efficient than the normal range creation for ordered ranges.
1369    //!
1370    //! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
1371    //!
1372    //! <b>Complexity</b>: Linear in N.
1373    //!
1374    //! <b>Note</b>: Non-standard extension.
1375    template <class InputIterator>
1376    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, InputIterator first, InputIterator last, const allocator_type &a)
1377       : tree_t(ordered_range, first, last, Compare(), a)
1378    {}
1379
1380 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1381    //! @copydoc ::boost::container::flat_set::flat_set(std::initializer_list<value_type)
1382    BOOST_CONTAINER_FORCEINLINE flat_multiset(std::initializer_list<value_type> il)
1383       : tree_t(false, il.begin(), il.end())
1384    {}
1385
1386    //! @copydoc ::boost::container::flat_set::flat_set(std::initializer_list<value_type>, const allocator_type&)
1387    BOOST_CONTAINER_FORCEINLINE flat_multiset(std::initializer_list<value_type> il, const allocator_type& a)
1388       : tree_t(false, il.begin(), il.end(), a)
1389    {}
1390
1391    //! @copydoc ::boost::container::flat_set::flat_set(std::initializer_list<value_type>, const Compare& comp)
1392    BOOST_CONTAINER_FORCEINLINE flat_multiset(std::initializer_list<value_type> il, const Compare& comp)
1393       : tree_t(false, il.begin(), il.end(), comp)
1394    {}
1395
1396    //! @copydoc ::boost::container::flat_set::flat_set(std::initializer_list<value_type>, const Compare& comp, const allocator_type&)
1397    BOOST_CONTAINER_FORCEINLINE flat_multiset(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
1398       : tree_t(false, il.begin(), il.end(), comp, a)
1399    {}
1400
1401    //! <b>Effects</b>: Constructs an empty containerand
1402    //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
1403    //! is more efficient than the normal range creation for ordered ranges.
1404    //!
1405    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1406    //!
1407    //! <b>Complexity</b>: Linear in N.
1408    //!
1409    //! <b>Note</b>: Non-standard extension.
1410    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, std::initializer_list<value_type> il)
1411       : tree_t(ordered_range, il.begin(), il.end())
1412    {}
1413
1414    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
1415    //! inserts elements from the ordered unique range [il.begin(), il.end()). This function
1416    //! is more efficient than the normal range creation for ordered ranges.
1417    //!
1418    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1419    //!
1420    //! <b>Complexity</b>: Linear in N.
1421    //!
1422    //! <b>Note</b>: Non-standard extension.
1423    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp)
1424       : tree_t(ordered_range, il.begin(), il.end(), comp)
1425    {}
1426
1427    //! <b>Effects</b>: Constructs an empty container using the specified comparison object and
1428    //! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
1429    //! is more efficient than the normal range creation for ordered ranges.
1430    //!
1431    //! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
1432    //!
1433    //! <b>Complexity</b>: Linear in N.
1434    //!
1435    //! <b>Note</b>: Non-standard extension.
1436    BOOST_CONTAINER_FORCEINLINE flat_multiset(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
1437       : tree_t(ordered_range, il.begin(), il.end(), comp, a)
1438    {}
1439 #endif
1440
1441    //! @copydoc ::boost::container::flat_set::flat_set(const flat_set &)
1442    BOOST_CONTAINER_FORCEINLINE flat_multiset(const flat_multiset& x)
1443       : tree_t(static_cast<const tree_t&>(x))
1444    {}
1445
1446    //! @copydoc ::boost::container::flat_set::flat_set(flat_set &&)
1447    BOOST_CONTAINER_FORCEINLINE flat_multiset(BOOST_RV_REF(flat_multiset) x)
1448       BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
1449       : tree_t(boost::move(static_cast<tree_t&>(x)))
1450    {}
1451
1452    //! @copydoc ::boost::container::flat_set::flat_set(const flat_set &, const allocator_type &)
1453    BOOST_CONTAINER_FORCEINLINE flat_multiset(const flat_multiset& x, const allocator_type &a)
1454       : tree_t(static_cast<const tree_t&>(x), a)
1455    {}
1456
1457    //! @copydoc ::boost::container::flat_set::flat_set(flat_set &&, const allocator_type &)
1458    BOOST_CONTAINER_FORCEINLINE flat_multiset(BOOST_RV_REF(flat_multiset) x, const allocator_type &a)
1459       : tree_t(BOOST_MOVE_BASE(tree_t, x), a)
1460    {}
1461
1462    //! @copydoc ::boost::container::flat_set::operator=(const flat_set &)
1463    BOOST_CONTAINER_FORCEINLINE flat_multiset& operator=(BOOST_COPY_ASSIGN_REF(flat_multiset) x)
1464    {  return static_cast<flat_multiset&>(this->tree_t::operator=(static_cast<const tree_t&>(x)));  }
1465
1466    //! @copydoc ::boost::container::flat_set::operator=(flat_set &&)
1467    BOOST_CONTAINER_FORCEINLINE flat_multiset& operator=(BOOST_RV_REF(flat_multiset) x)
1468       BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
1469                           allocator_traits_type::is_always_equal::value) &&
1470                            boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
1471    {  return static_cast<flat_multiset&>(this->tree_t::operator=(BOOST_MOVE_BASE(tree_t, x)));  }
1472
1473 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1474    //! @copydoc ::boost::container::flat_set::operator=(std::initializer_list<value_type>)
1475    flat_multiset& operator=(std::initializer_list<value_type> il)
1476    {
1477        this->clear();
1478        this->insert(il.begin(), il.end());
1479        return *this;
1480    }
1481 #endif
1482
1483    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1484
1485    //! @copydoc ::boost::container::flat_set::get_allocator()
1486    allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
1487
1488    //! @copydoc ::boost::container::flat_set::get_stored_allocator()
1489    stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW;
1490
1491    //! @copydoc ::boost::container::flat_set::get_stored_allocator() const
1492    const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
1493
1494    //! @copydoc ::boost::container::flat_set::begin()
1495    iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
1496
1497    //! @copydoc ::boost::container::flat_set::begin() const
1498    const_iterator begin() const;
1499
1500    //! @copydoc ::boost::container::flat_set::cbegin() const
1501    const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1502
1503    //! @copydoc ::boost::container::flat_set::end()
1504    iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
1505
1506    //! @copydoc ::boost::container::flat_set::end() const
1507    const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
1508
1509    //! @copydoc ::boost::container::flat_set::cend() const
1510    const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
1511
1512    //! @copydoc ::boost::container::flat_set::rbegin()
1513    reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
1514
1515    //! @copydoc ::boost::container::flat_set::rbegin() const
1516    const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1517
1518    //! @copydoc ::boost::container::flat_set::crbegin() const
1519    const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
1520
1521    //! @copydoc ::boost::container::flat_set::rend()
1522    reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
1523
1524    //! @copydoc ::boost::container::flat_set::rend() const
1525    const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
1526
1527    //! @copydoc ::boost::container::flat_set::crend() const
1528    const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
1529
1530    //! @copydoc ::boost::container::flat_set::empty() const
1531    bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
1532
1533    //! @copydoc ::boost::container::flat_set::size() const
1534    size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
1535
1536    //! @copydoc ::boost::container::flat_set::max_size() const
1537    size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW;
1538
1539    //! @copydoc ::boost::container::flat_set::capacity() const
1540    size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW;
1541
1542    //! @copydoc ::boost::container::flat_set::reserve(size_type)
1543    void reserve(size_type cnt);
1544
1545    //! @copydoc ::boost::container::flat_set::shrink_to_fit()
1546    void shrink_to_fit();
1547
1548    #endif   //   #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1549
1550    //////////////////////////////////////////////
1551    //
1552    //                modifiers
1553    //
1554    //////////////////////////////////////////////
1555
1556    #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1557
1558    //! <b>Effects</b>: Inserts an object of type Key constructed with
1559    //!   std::forward<Args>(args)... and returns the iterator pointing to the
1560    //!   newly inserted element.
1561    //!
1562    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1563    //!   to the elements with bigger keys than x.
1564    //!
1565    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1566    template <class... Args>
1567    BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_FWD_REF(Args)... args)
1568    {  return this->tree_t::emplace_equal(boost::forward<Args>(args)...); }
1569
1570    //! <b>Effects</b>: Inserts an object of type Key constructed with
1571    //!   std::forward<Args>(args)... in the container.
1572    //!   p is a hint pointing to where the insert should start to search.
1573    //!
1574    //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1575    //!   to the key of x.
1576    //!
1577    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1578    //!   right before p) plus insertion linear to the elements with bigger keys than x.
1579    //!
1580    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1581    template <class... Args>
1582    BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
1583    {  return this->tree_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
1584
1585    #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1586
1587    #define BOOST_CONTAINER_FLAT_MULTISET_EMPLACE_CODE(N) \
1588    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1589    BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
1590    {  return this->tree_t::emplace_equal(BOOST_MOVE_FWD##N);  }\
1591    \
1592    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1593    BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1594    {  return this->tree_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
1595    //
1596    BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_FLAT_MULTISET_EMPLACE_CODE)
1597    #undef BOOST_CONTAINER_FLAT_MULTISET_EMPLACE_CODE
1598
1599    #endif   // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1600
1601    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1602    //! <b>Effects</b>: Inserts x and returns the iterator pointing to the
1603    //!   newly inserted element.
1604    //!
1605    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1606    //!   to the elements with bigger keys than x.
1607    //!
1608    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1609    iterator insert(const value_type &x);
1610
1611    //! <b>Effects</b>: Inserts a new value_type move constructed from x
1612    //!   and returns the iterator pointing to the newly inserted element.
1613    //!
1614    //! <b>Complexity</b>: Logarithmic search time plus linear insertion
1615    //!   to the elements with bigger keys than x.
1616    //!
1617    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1618    iterator insert(value_type &&x);
1619    #else
1620    BOOST_MOVE_CONVERSION_AWARE_CATCH(insert, value_type, iterator, this->priv_insert)
1621    #endif
1622
1623    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1624    //! <b>Effects</b>: Inserts a copy of x in the container.
1625    //!   p is a hint pointing to where the insert should start to search.
1626    //!
1627    //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1628    //!   to the key of x.
1629    //!
1630    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1631    //!   right before p) plus insertion linear to the elements with bigger keys than x.
1632    //!
1633    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1634    iterator insert(const_iterator p, const value_type &x);
1635
1636    //! <b>Effects</b>: Inserts a new value move constructed  from x in the container.
1637    //!   p is a hint pointing to where the insert should start to search.
1638    //!
1639    //! <b>Returns</b>: An iterator pointing to the element with key equivalent
1640    //!   to the key of x.
1641    //!
1642    //! <b>Complexity</b>: Logarithmic search time (constant if x is inserted
1643    //!   right before p) plus insertion linear to the elements with bigger keys than x.
1644    //!
1645    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1646    iterator insert(const_iterator p, value_type &&x);
1647    #else
1648    BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, value_type, iterator, this->priv_insert, const_iterator, const_iterator)
1649    #endif
1650
1651    //! <b>Requires</b>: first, last are not iterators into *this.
1652    //!
1653    //! <b>Effects</b>: inserts each element from the range [first,last) .
1654    //!
1655    //! <b>Complexity</b>: N log(N).
1656    //!
1657    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1658    template <class InputIterator>
1659    BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
1660       {  this->tree_t::insert_equal(first, last);  }
1661
1662    //! <b>Requires</b>: first, last are not iterators into *this and
1663    //! must be ordered according to the predicate.
1664    //!
1665    //! <b>Effects</b>: inserts each element from the range [first,last) .This function
1666    //! is more efficient than the normal range creation for ordered ranges.
1667    //!
1668    //! <b>Complexity</b>: Linear.
1669    //!
1670    //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
1671    template <class InputIterator>
1672    BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, InputIterator first, InputIterator last)
1673       {  this->tree_t::insert_equal(ordered_range, first, last);  }
1674
1675 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1676    //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()).
1677    //!
1678    //! <b>Complexity</b>: N log(N).
1679    //!
1680    //! <b>Note</b>: If an element is inserted it might invalidate elements.
1681    BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
1682    {  this->tree_t::insert_equal(il.begin(), il.end()); }
1683
1684    //! <b>Requires</b>: Range [il.begin(), il.end()) must be ordered according to the predicate.
1685    //!
1686    //! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()). This function
1687    //! is more efficient than the normal range creation for ordered ranges.
1688    //!
1689    //! <b>Complexity</b>: Linear.
1690    //!
1691    //! <b>Note</b>: Non-standard extension. If an element is inserted it might invalidate elements.
1692    BOOST_CONTAINER_FORCEINLINE void insert(ordered_range_t, std::initializer_list<value_type> il)
1693    {  this->tree_t::insert_equal(ordered_range, il.begin(), il.end()); }
1694 #endif
1695
1696    //! @copydoc ::boost::container::flat_multimap::merge(flat_multimap<Key, T, C2, AllocatorOrContainer>&)
1697    template<class C2>
1698    BOOST_CONTAINER_FORCEINLINE void merge(flat_multiset<Key, C2, AllocatorOrContainer>& source)
1699    {  this->tree_t::merge_equal(source.tree());   }
1700
1701    //! @copydoc ::boost::container::flat_multiset::merge(flat_multiset<Key, C2, AllocatorOrContainer>&)
1702    template<class C2>
1703    BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_multiset<Key, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
1704    {  return this->merge(static_cast<flat_multiset<Key, C2, AllocatorOrContainer>&>(source));   }
1705
1706    //! @copydoc ::boost::container::flat_multimap::merge(flat_map<Key, T, C2, AllocatorOrContainer>&)
1707    template<class C2>
1708    BOOST_CONTAINER_FORCEINLINE void merge(flat_set<Key, C2, AllocatorOrContainer>& source)
1709    {  this->tree_t::merge_equal(source.tree());   }
1710
1711    //! @copydoc ::boost::container::flat_multiset::merge(flat_set<Key, C2, AllocatorOrContainer>&)
1712    template<class C2>
1713    BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG flat_set<Key, C2, AllocatorOrContainer> BOOST_RV_REF_END source)
1714    {  return this->merge(static_cast<flat_set<Key, C2, AllocatorOrContainer>&>(source));   }
1715
1716    #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1717
1718    //! @copydoc ::boost::container::flat_set::erase(const_iterator)
1719    iterator erase(const_iterator p);
1720
1721    //! @copydoc ::boost::container::flat_set::erase(const key_type&)
1722    size_type erase(const key_type& x);
1723
1724    //! @copydoc ::boost::container::flat_set::erase(const_iterator,const_iterator)
1725    iterator erase(const_iterator first, const_iterator last);
1726
1727    //! @copydoc ::boost::container::flat_set::swap
1728    void swap(flat_multiset& x)
1729       BOOST_NOEXCEPT_IF(  allocator_traits_type::is_always_equal::value
1730                                  && boost::container::dtl::is_nothrow_swappable<Compare>::value );
1731
1732    //! @copydoc ::boost::container::flat_set::clear
1733    void clear() BOOST_NOEXCEPT_OR_NOTHROW;
1734
1735    //! @copydoc ::boost::container::flat_set::key_comp
1736    key_compare key_comp() const;
1737
1738    //! @copydoc ::boost::container::flat_set::value_comp
1739    value_compare value_comp() const;
1740
1741    //! @copydoc ::boost::container::flat_set::find(const key_type& )
1742    iterator find(const key_type& x);
1743
1744    //! @copydoc ::boost::container::flat_set::find(const key_type& ) const
1745    const_iterator find(const key_type& x) const;
1746
1747    //! @copydoc ::boost::container::flat_set::nth(size_type)
1748    iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW;
1749
1750    //! @copydoc ::boost::container::flat_set::nth(size_type) const
1751    const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW;
1752
1753    //! @copydoc ::boost::container::flat_set::index_of(iterator)
1754    size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
1755
1756    //! @copydoc ::boost::container::flat_set::index_of(const_iterator) const
1757    size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW;
1758
1759    //! @copydoc ::boost::container::flat_set::count(const key_type& ) const
1760    size_type count(const key_type& x) const;
1761
1762    //! @copydoc ::boost::container::flat_set::contains(const key_type& ) const
1763    bool contains(const key_type& x) const;
1764
1765    //! @copydoc ::boost::container::flat_set::contains(const K& ) const
1766    template<typename K>
1767    bool contains(const K& x) const;
1768
1769    //! @copydoc ::boost::container::flat_set::lower_bound(const key_type& )
1770    iterator lower_bound(const key_type& x);
1771
1772    //! @copydoc ::boost::container::flat_set::lower_bound(const key_type& ) const
1773    const_iterator lower_bound(const key_type& x) const;
1774
1775    //! @copydoc ::boost::container::flat_set::upper_bound(const key_type& )
1776    iterator upper_bound(const key_type& x);
1777
1778    //! @copydoc ::boost::container::flat_set::upper_bound(const key_type& ) const
1779    const_iterator upper_bound(const key_type& x) const;
1780
1781    //! @copydoc ::boost::container::flat_set::equal_range(const key_type& ) const
1782    std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
1783
1784    //! @copydoc ::boost::container::flat_set::equal_range(const key_type& )
1785    std::pair<iterator,iterator> equal_range(const key_type& x);
1786
1787    //! <b>Effects</b>: Returns true if x and y are equal
1788    //!
1789    //! <b>Complexity</b>: Linear to the number of elements in the container.
1790    friend bool operator==(const flat_multiset& x, const flat_multiset& y);
1791
1792    //! <b>Effects</b>: Returns true if x and y are unequal
1793    //!
1794    //! <b>Complexity</b>: Linear to the number of elements in the container.
1795    friend bool operator!=(const flat_multiset& x, const flat_multiset& y);
1796
1797    //! <b>Effects</b>: Returns true if x is less than y
1798    //!
1799    //! <b>Complexity</b>: Linear to the number of elements in the container.
1800    friend bool operator<(const flat_multiset& x, const flat_multiset& y);
1801
1802    //! <b>Effects</b>: Returns true if x is greater than y
1803    //!
1804    //! <b>Complexity</b>: Linear to the number of elements in the container.
1805    friend bool operator>(const flat_multiset& x, const flat_multiset& y);
1806
1807    //! <b>Effects</b>: Returns true if x is equal or less than y
1808    //!
1809    //! <b>Complexity</b>: Linear to the number of elements in the container.
1810    friend bool operator<=(const flat_multiset& x, const flat_multiset& y);
1811
1812    //! <b>Effects</b>: Returns true if x is equal or greater than y
1813    //!
1814    //! <b>Complexity</b>: Linear to the number of elements in the container.
1815    friend bool operator>=(const flat_multiset& x, const flat_multiset& y);
1816
1817    //! <b>Effects</b>: x.swap(y)
1818    //!
1819    //! <b>Complexity</b>: Constant.
1820    friend void swap(flat_multiset& x, flat_multiset& y);
1821
1822    //! <b>Effects</b>: Extracts the internal sequence container.
1823    //!
1824    //! <b>Complexity</b>: Same as the move constructor of sequence_type, usually constant.
1825    //!
1826    //! <b>Postcondition</b>: this->empty()
1827    //!
1828    //! <b>Throws</b>: If secuence_type's move constructor throws 
1829    sequence_type extract_sequence();
1830
1831    #endif   //#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
1832
1833    //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1834    //!   one passed externally using the move assignment.
1835    //!
1836    //! <b>Complexity</b>: Assuming O(1) move assignment, O(NlogN) with N = seq.size()
1837    //!
1838    //! <b>Throws</b>: If the comparison or the move constructor throws
1839    BOOST_CONTAINER_FORCEINLINE void adopt_sequence(BOOST_RV_REF(sequence_type) seq)
1840    {  this->tree_t::adopt_sequence_equal(boost::move(seq));  }
1841
1842    //! <b>Requires</b>: seq shall be ordered according to this->compare()
1843    //!
1844    //! <b>Effects</b>: Discards the internally hold sequence container and adopts the
1845    //!   one passed externally using the move assignment.
1846    //!
1847    //! <b>Complexity</b>: Assuming O(1) move assignment, O(1)
1848    //!
1849    //! <b>Throws</b>: If the move assignment throws
1850    BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_range_t, BOOST_RV_REF(sequence_type) seq)
1851    {  this->tree_t::adopt_sequence_equal(ordered_range_t(), boost::move(seq));  }
1852
1853    #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1854    private:
1855    template <class KeyType>
1856    BOOST_CONTAINER_FORCEINLINE iterator priv_insert(BOOST_FWD_REF(KeyType) x)
1857    {  return this->tree_t::insert_equal(::boost::forward<KeyType>(x));  }
1858
1859    template <class KeyType>
1860    BOOST_CONTAINER_FORCEINLINE iterator priv_insert(const_iterator p, BOOST_FWD_REF(KeyType) x)
1861    {  return this->tree_t::insert_equal(p, ::boost::forward<KeyType>(x)); }
1862    #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1863 };
1864
1865 #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
1866
1867 template <typename InputIterator>
1868 flat_multiset(InputIterator, InputIterator) ->
1869    flat_multiset< it_based_value_type_t<InputIterator> >;
1870
1871
1872 template < typename InputIterator, typename AllocatorOrCompare>
1873 flat_multiset(InputIterator, InputIterator, AllocatorOrCompare const&) ->
1874     flat_multiset < it_based_value_type_t<InputIterator>
1875                   , typename dtl::if_c< // Compare
1876                       dtl::is_allocator<AllocatorOrCompare>::value
1877                       , std::less<it_based_value_type_t<InputIterator>>
1878                       , AllocatorOrCompare
1879                   >::type
1880                   , typename dtl::if_c< // Allocator
1881                       dtl::is_allocator<AllocatorOrCompare>::value
1882                       , AllocatorOrCompare
1883                       , new_allocator<it_based_value_type_t<InputIterator>>
1884                       >::type
1885                   >;
1886
1887 template < typename InputIterator, typename Compare, typename Allocator
1888          , typename = dtl::require_nonallocator_t<Compare>
1889          , typename = dtl::require_allocator_t<Allocator>>
1890 flat_multiset(InputIterator, InputIterator, Compare const&, Allocator const&) ->
1891    flat_multiset< it_based_value_type_t<InputIterator>
1892            , Compare
1893            , Allocator>;
1894
1895 template <typename InputIterator>
1896 flat_multiset(ordered_range_t, InputIterator, InputIterator) ->
1897    flat_multiset< it_based_value_type_t<InputIterator>>;
1898
1899 template < typename InputIterator, typename AllocatorOrCompare>
1900 flat_multiset(ordered_range_t, InputIterator, InputIterator, AllocatorOrCompare const&) ->
1901     flat_multiset < it_based_value_type_t<InputIterator>
1902                   , typename dtl::if_c< // Compare
1903                       dtl::is_allocator<AllocatorOrCompare>::value
1904                       , std::less<it_based_value_type_t<InputIterator>>
1905                       , AllocatorOrCompare
1906                   >::type
1907                   , typename dtl::if_c< // Allocator
1908                       dtl::is_allocator<AllocatorOrCompare>::value
1909                       , AllocatorOrCompare
1910                       , new_allocator<it_based_value_type_t<InputIterator>>
1911                       >::type
1912                   >;
1913
1914 template < typename InputIterator, typename Compare, typename Allocator
1915          , typename = dtl::require_nonallocator_t<Compare>
1916          , typename = dtl::require_allocator_t<Allocator>>
1917 flat_multiset(ordered_range_t, InputIterator, InputIterator, Compare const&, Allocator const&) ->
1918    flat_multiset< it_based_value_type_t<InputIterator>
1919            , Compare
1920            , Allocator>;
1921
1922 #endif
1923
1924 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1925
1926 }  //namespace container {
1927
1928 //!has_trivial_destructor_after_move<> == true_type
1929 //!specialization for optimizations
1930 template <class Key, class Compare, class AllocatorOrContainer>
1931 struct has_trivial_destructor_after_move<boost::container::flat_multiset<Key, Compare, AllocatorOrContainer> >
1932 {
1933    typedef ::boost::container::dtl::flat_tree<Key, ::boost::container::dtl::identity<Key>, Compare, AllocatorOrContainer> tree;
1934    static const bool value = ::boost::has_trivial_destructor_after_move<tree>::value;
1935 };
1936
1937 namespace container {
1938
1939 #endif   //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1940
1941 }}
1942
1943 #include <boost/container/detail/config_end.hpp>
1944
1945 #endif   // BOOST_CONTAINER_FLAT_SET_HPP