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