1
/////////////////////////////////////////////////////////////////////////////
3
// (C) Copyright Ion Gaztanaga 2007-2009
5
// Distributed under the Boost Software License, Version 1.0.
6
// (See accompanying file LICENSE_1_0.txt or copy at
7
// http://www.boost.org/LICENSE_1_0.txt)
9
// See http://www.boost.org/libs/intrusive for documentation.
11
/////////////////////////////////////////////////////////////////////////////
12
#ifndef BOOST_INTRUSIVE_SG_SET_HPP
13
#define BOOST_INTRUSIVE_SG_SET_HPP
15
#include <boost/intrusive/detail/config_begin.hpp>
16
#include <boost/intrusive/intrusive_fwd.hpp>
17
#include <boost/intrusive/sgtree.hpp>
18
#include <boost/intrusive/detail/mpl.hpp>
24
//! The class template sg_set is an intrusive container, that mimics most of
25
//! the interface of std::set as described in the C++ standard.
27
//! The template parameter \c T is the type to be managed by the container.
28
//! The user can specify additional options and if no options are provided
29
//! default options are used.
31
//! The container supports the following options:
32
//! \c base_hook<>/member_hook<>/value_traits<>,
33
//! \c constant_time_size<>, \c size_type<> and
35
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36
template<class T, class ...Options>
38
template<class Config>
43
typedef sgtree_impl<Config> tree_type;
46
sg_set_impl (const sg_set_impl&);
50
sg_set_impl &operator =(const sg_set_impl&);
52
typedef tree_type implementation_defined;
56
typedef typename implementation_defined::value_type value_type;
57
typedef typename implementation_defined::value_traits value_traits;
58
typedef typename implementation_defined::pointer pointer;
59
typedef typename implementation_defined::const_pointer const_pointer;
60
typedef typename implementation_defined::reference reference;
61
typedef typename implementation_defined::const_reference const_reference;
62
typedef typename implementation_defined::difference_type difference_type;
63
typedef typename implementation_defined::size_type size_type;
64
typedef typename implementation_defined::value_compare value_compare;
65
typedef typename implementation_defined::key_compare key_compare;
66
typedef typename implementation_defined::iterator iterator;
67
typedef typename implementation_defined::const_iterator const_iterator;
68
typedef typename implementation_defined::reverse_iterator reverse_iterator;
69
typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
70
typedef typename implementation_defined::insert_commit_data insert_commit_data;
71
typedef typename implementation_defined::node_traits node_traits;
72
typedef typename implementation_defined::node node;
73
typedef typename implementation_defined::node_ptr node_ptr;
74
typedef typename implementation_defined::const_node_ptr const_node_ptr;
75
typedef typename implementation_defined::node_algorithms node_algorithms;
83
//! <b>Effects</b>: Constructs an empty sg_set.
85
//! <b>Complexity</b>: Constant.
87
//! <b>Throws</b>: If value_traits::node_traits::node
88
//! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
89
//! or the copy constructor of the value_compare object throws.
90
sg_set_impl( const value_compare &cmp = value_compare()
91
, const value_traits &v_traits = value_traits())
92
: tree_(cmp, v_traits)
95
//! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
96
//! cmp must be a comparison function that induces a strict weak ordering.
98
//! <b>Effects</b>: Constructs an empty sg_set and inserts elements from
101
//! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
102
//! comp and otherwise N * log N, where N is std::distance(last, first).
104
//! <b>Throws</b>: If value_traits::node_traits::node
105
//! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
106
//! or the copy constructor/operator() of the value_compare object throws.
107
template<class Iterator>
108
sg_set_impl( Iterator b, Iterator e
109
, const value_compare &cmp = value_compare()
110
, const value_traits &v_traits = value_traits())
111
: tree_(true, b, e, cmp, v_traits)
114
//! <b>Effects</b>: Detaches all elements from this. The objects in the sg_set
115
//! are not deleted (i.e. no destructors are called).
117
//! <b>Complexity</b>: Linear to the number of elements on the container.
118
//! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
120
//! <b>Throws</b>: Nothing.
124
//! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_set.
126
//! <b>Complexity</b>: Constant.
128
//! <b>Throws</b>: Nothing.
130
{ return tree_.begin(); }
132
//! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set.
134
//! <b>Complexity</b>: Constant.
136
//! <b>Throws</b>: Nothing.
137
const_iterator begin() const
138
{ return tree_.begin(); }
140
//! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set.
142
//! <b>Complexity</b>: Constant.
144
//! <b>Throws</b>: Nothing.
145
const_iterator cbegin() const
146
{ return tree_.cbegin(); }
148
//! <b>Effects</b>: Returns an iterator pointing to the end of the sg_set.
150
//! <b>Complexity</b>: Constant.
152
//! <b>Throws</b>: Nothing.
154
{ return tree_.end(); }
156
//! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set.
158
//! <b>Complexity</b>: Constant.
160
//! <b>Throws</b>: Nothing.
161
const_iterator end() const
162
{ return tree_.end(); }
164
//! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set.
166
//! <b>Complexity</b>: Constant.
168
//! <b>Throws</b>: Nothing.
169
const_iterator cend() const
170
{ return tree_.cend(); }
172
//! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
175
//! <b>Complexity</b>: Constant.
177
//! <b>Throws</b>: Nothing.
178
reverse_iterator rbegin()
179
{ return tree_.rbegin(); }
181
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
182
//! of the reversed sg_set.
184
//! <b>Complexity</b>: Constant.
186
//! <b>Throws</b>: Nothing.
187
const_reverse_iterator rbegin() const
188
{ return tree_.rbegin(); }
190
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
191
//! of the reversed sg_set.
193
//! <b>Complexity</b>: Constant.
195
//! <b>Throws</b>: Nothing.
196
const_reverse_iterator crbegin() const
197
{ return tree_.crbegin(); }
199
//! <b>Effects</b>: Returns a reverse_iterator pointing to the end
200
//! of the reversed sg_set.
202
//! <b>Complexity</b>: Constant.
204
//! <b>Throws</b>: Nothing.
205
reverse_iterator rend()
206
{ return tree_.rend(); }
208
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
209
//! of the reversed sg_set.
211
//! <b>Complexity</b>: Constant.
213
//! <b>Throws</b>: Nothing.
214
const_reverse_iterator rend() const
215
{ return tree_.rend(); }
217
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
218
//! of the reversed sg_set.
220
//! <b>Complexity</b>: Constant.
222
//! <b>Throws</b>: Nothing.
223
const_reverse_iterator crend() const
224
{ return tree_.crend(); }
226
//! <b>Precondition</b>: end_iterator must be a valid end iterator
229
//! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
231
//! <b>Throws</b>: Nothing.
233
//! <b>Complexity</b>: Constant.
234
static sg_set_impl &container_from_end_iterator(iterator end_iterator)
236
return *detail::parent_from_member<sg_set_impl, tree_type>
237
( &tree_type::container_from_end_iterator(end_iterator)
238
, &sg_set_impl::tree_);
241
//! <b>Precondition</b>: end_iterator must be a valid end const_iterator
244
//! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
246
//! <b>Throws</b>: Nothing.
248
//! <b>Complexity</b>: Constant.
249
static const sg_set_impl &container_from_end_iterator(const_iterator end_iterator)
251
return *detail::parent_from_member<sg_set_impl, tree_type>
252
( &tree_type::container_from_end_iterator(end_iterator)
253
, &sg_set_impl::tree_);
256
//! <b>Precondition</b>: it must be a valid iterator of set.
258
//! <b>Effects</b>: Returns a reference to the set associated to the iterator
260
//! <b>Throws</b>: Nothing.
262
//! <b>Complexity</b>: Logarithmic.
263
static sg_set_impl &container_from_iterator(iterator it)
265
return *detail::parent_from_member<sg_set_impl, tree_type>
266
( &tree_type::container_from_iterator(it)
267
, &sg_set_impl::tree_);
270
//! <b>Precondition</b>: it must be a valid const_iterator of set.
272
//! <b>Effects</b>: Returns a const reference to the set associated to the iterator
274
//! <b>Throws</b>: Nothing.
276
//! <b>Complexity</b>: Logarithmic.
277
static const sg_set_impl &container_from_iterator(const_iterator it)
279
return *detail::parent_from_member<sg_set_impl, tree_type>
280
( &tree_type::container_from_iterator(it)
281
, &sg_set_impl::tree_);
284
//! <b>Effects</b>: Returns the key_compare object used by the sg_set.
286
//! <b>Complexity</b>: Constant.
288
//! <b>Throws</b>: If key_compare copy-constructor throws.
289
key_compare key_comp() const
290
{ return tree_.value_comp(); }
292
//! <b>Effects</b>: Returns the value_compare object used by the sg_set.
294
//! <b>Complexity</b>: Constant.
296
//! <b>Throws</b>: If value_compare copy-constructor throws.
297
value_compare value_comp() const
298
{ return tree_.value_comp(); }
300
//! <b>Effects</b>: Returns true if the container is empty.
302
//! <b>Complexity</b>: Constant.
304
//! <b>Throws</b>: Nothing.
306
{ return tree_.empty(); }
308
//! <b>Effects</b>: Returns the number of elements stored in the sg_set.
310
//! <b>Complexity</b>: Linear to elements contained in *this if,
311
//! constant-time size option is enabled. Constant-time otherwise.
313
//! <b>Throws</b>: Nothing.
314
size_type size() const
315
{ return tree_.size(); }
317
//! <b>Effects</b>: Swaps the contents of two sets.
319
//! <b>Complexity</b>: Constant.
321
//! <b>Throws</b>: If the swap() call for the comparison functor
322
//! found using ADL throws. Strong guarantee.
323
void swap(sg_set_impl& other)
324
{ tree_.swap(other.tree_); }
326
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
327
//! Cloner should yield to nodes equivalent to the original nodes.
329
//! <b>Effects</b>: Erases all the elements from *this
330
//! calling Disposer::operator()(pointer), clones all the
331
//! elements from src calling Cloner::operator()(const_reference )
332
//! and inserts them on *this. Copies the predicate from the source container.
334
//! If cloner throws, all cloned elements are unlinked and disposed
335
//! calling Disposer::operator()(pointer).
337
//! <b>Complexity</b>: Linear to erased plus inserted elements.
339
//! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
340
template <class Cloner, class Disposer>
341
void clone_from(const sg_set_impl &src, Cloner cloner, Disposer disposer)
342
{ tree_.clone_from(src.tree_, cloner, disposer); }
344
//! <b>Requires</b>: value must be an lvalue
346
//! <b>Effects</b>: Tries to inserts value into the sg_set.
348
//! <b>Returns</b>: If the value
349
//! is not already present inserts it and returns a pair containing the
350
//! iterator to the new value and true. If there is an equivalent value
351
//! returns a pair containing an iterator to the already present value
354
//! <b>Complexity</b>: Average complexity for insert element is at
355
//! most logarithmic.
357
//! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
359
//! <b>Note</b>: Does not affect the validity of iterators and references.
360
//! No copy-constructors are called.
361
std::pair<iterator, bool> insert(reference value)
362
{ return tree_.insert_unique(value); }
364
//! <b>Requires</b>: value must be an lvalue
366
//! <b>Effects</b>: Tries to to insert x into the sg_set, using "hint"
367
//! as a hint to where it will be inserted.
369
//! <b>Returns</b>: An iterator that points to the position where the
370
//! new element was inserted into the sg_set.
372
//! <b>Complexity</b>: Logarithmic in general, but it's amortized
373
//! constant time if t is inserted immediately before hint.
375
//! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
377
//! <b>Note</b>: Does not affect the validity of iterators and references.
378
//! No copy-constructors are called.
379
iterator insert(const_iterator hint, reference value)
380
{ return tree_.insert_unique(hint, value); }
382
//! <b>Requires</b>: key_value_comp must be a comparison function that induces
383
//! the same strict weak ordering as value_compare. The difference is that
384
//! key_value_comp compares an arbitrary key with the contained values.
386
//! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using
387
//! a user provided key instead of the value itself.
389
//! <b>Returns</b>: If there is an equivalent value
390
//! returns a pair containing an iterator to the already present value
391
//! and false. If the value can be inserted returns true in the returned
392
//! pair boolean and fills "commit_data" that is meant to be used with
393
//! the "insert_commit" function.
395
//! <b>Complexity</b>: Average complexity is at most logarithmic.
397
//! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
399
//! <b>Notes</b>: This function is used to improve performance when constructing
400
//! a value_type is expensive: if there is an equivalent value
401
//! the constructed object must be discarded. Many times, the part of the
402
//! node that is used to impose the order is much cheaper to construct
403
//! than the value_type and this function offers the possibility to use that
404
//! part to check if the insertion will be successful.
406
//! If the check is successful, the user can construct the value_type and use
407
//! "insert_commit" to insert the object in constant-time. This gives a total
408
//! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
410
//! "commit_data" remains valid for a subsequent "insert_commit" only if no more
411
//! objects are inserted or erased from the sg_set.
412
template<class KeyType, class KeyValueCompare>
413
std::pair<iterator, bool> insert_check
414
(const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
415
{ return tree_.insert_unique_check(key, key_value_comp, commit_data); }
417
//! <b>Requires</b>: key_value_comp must be a comparison function that induces
418
//! the same strict weak ordering as value_compare. The difference is that
419
//! key_value_comp compares an arbitrary key with the contained values.
421
//! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using
422
//! a user provided key instead of the value itself, using "hint"
423
//! as a hint to where it will be inserted.
425
//! <b>Returns</b>: If there is an equivalent value
426
//! returns a pair containing an iterator to the already present value
427
//! and false. If the value can be inserted returns true in the returned
428
//! pair boolean and fills "commit_data" that is meant to be used with
429
//! the "insert_commit" function.
431
//! <b>Complexity</b>: Logarithmic in general, but it's amortized
432
//! constant time if t is inserted immediately before hint.
434
//! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
436
//! <b>Notes</b>: This function is used to improve performance when constructing
437
//! a value_type is expensive: if there is an equivalent value
438
//! the constructed object must be discarded. Many times, the part of the
439
//! constructing that is used to impose the order is much cheaper to construct
440
//! than the value_type and this function offers the possibility to use that key
441
//! to check if the insertion will be successful.
443
//! If the check is successful, the user can construct the value_type and use
444
//! "insert_commit" to insert the object in constant-time. This can give a total
445
//! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
447
//! "commit_data" remains valid for a subsequent "insert_commit" only if no more
448
//! objects are inserted or erased from the sg_set.
449
template<class KeyType, class KeyValueCompare>
450
std::pair<iterator, bool> insert_check
451
(const_iterator hint, const KeyType &key
452
,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
453
{ return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }
455
//! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
456
//! must have been obtained from a previous call to "insert_check".
457
//! No objects should have been inserted or erased from the sg_set between
458
//! the "insert_check" that filled "commit_data" and the call to "insert_commit".
460
//! <b>Effects</b>: Inserts the value in the sg_set using the information obtained
461
//! from the "commit_data" that a previous "insert_check" filled.
463
//! <b>Returns</b>: An iterator to the newly inserted object.
465
//! <b>Complexity</b>: Constant time.
467
//! <b>Throws</b>: Nothing.
469
//! <b>Notes</b>: This function has only sense if a "insert_check" has been
470
//! previously executed to fill "commit_data". No value should be inserted or
471
//! erased between the "insert_check" and "insert_commit" calls.
472
iterator insert_commit(reference value, const insert_commit_data &commit_data)
473
{ return tree_.insert_unique_commit(value, commit_data); }
475
//! <b>Requires</b>: Dereferencing iterator must yield an lvalue
476
//! of type value_type.
478
//! <b>Effects</b>: Inserts a range into the sg_set.
480
//! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
481
//! size of the range. However, it is linear in N if the range is already sorted
484
//! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
486
//! <b>Note</b>: Does not affect the validity of iterators and references.
487
//! No copy-constructors are called.
488
template<class Iterator>
489
void insert(Iterator b, Iterator e)
490
{ tree_.insert_unique(b, e); }
492
//! <b>Requires</b>: value must be an lvalue, "pos" must be
493
//! a valid iterator (or end) and must be the succesor of value
494
//! once inserted according to the predicate. "value" must not be equal to any
495
//! inserted key according to the predicate.
497
//! <b>Effects</b>: Inserts x into the tree before "pos".
499
//! <b>Complexity</b>: Constant time.
501
//! <b>Throws</b>: Nothing.
503
//! <b>Note</b>: This function does not check preconditions so if "pos" is not
504
//! the successor of "value" or "value" is not unique tree ordering and uniqueness
505
//! invariants will be broken respectively.
506
//! This is a low-level function to be used only for performance reasons
507
//! by advanced users.
508
iterator insert_before(const_iterator pos, reference value)
509
{ return tree_.insert_before(pos, value); }
511
//! <b>Requires</b>: value must be an lvalue, and it must be greater than
512
//! any inserted key according to the predicate.
514
//! <b>Effects</b>: Inserts x into the tree in the last position.
516
//! <b>Complexity</b>: Constant time.
518
//! <b>Throws</b>: Nothing.
520
//! <b>Note</b>: This function does not check preconditions so if value is
521
//! less than or equal to the greatest inserted key tree ordering invariant will be broken.
522
//! This function is slightly more efficient than using "insert_before".
523
//! This is a low-level function to be used only for performance reasons
524
//! by advanced users.
525
void push_back(reference value)
526
{ tree_.push_back(value); }
528
//! <b>Requires</b>: value must be an lvalue, and it must be less
529
//! than any inserted key according to the predicate.
531
//! <b>Effects</b>: Inserts x into the tree in the first position.
533
//! <b>Complexity</b>: Constant time.
535
//! <b>Throws</b>: Nothing.
537
//! <b>Note</b>: This function does not check preconditions so if value is
538
//! greater than or equal to the the mimum inserted key tree ordering or uniqueness
539
//! invariants will be broken.
540
//! This function is slightly more efficient than using "insert_before".
541
//! This is a low-level function to be used only for performance reasons
542
//! by advanced users.
543
void push_front(reference value)
544
{ tree_.push_front(value); }
546
//! <b>Effects</b>: Erases the element pointed to by pos.
548
//! <b>Complexity</b>: Average complexity is constant time.
550
//! <b>Returns</b>: An iterator to the element after the erased element.
552
//! <b>Throws</b>: Nothing.
554
//! <b>Note</b>: Invalidates the iterators (but not the references)
555
//! to the erased elements. No destructors are called.
556
iterator erase(const_iterator i)
557
{ return tree_.erase(i); }
559
//! <b>Effects</b>: Erases the range pointed to by b end e.
561
//! <b>Complexity</b>: Average complexity for erase range is at most
562
//! O(log(size() + N)), where N is the number of elements in the range.
564
//! <b>Returns</b>: An iterator to the element after the erased elements.
566
//! <b>Throws</b>: Nothing.
568
//! <b>Note</b>: Invalidates the iterators (but not the references)
569
//! to the erased elements. No destructors are called.
570
iterator erase(const_iterator b, const_iterator e)
571
{ return tree_.erase(b, e); }
573
//! <b>Effects</b>: Erases all the elements with the given value.
575
//! <b>Returns</b>: The number of erased elements.
577
//! <b>Complexity</b>: O(log(size()) + this->count(value)).
579
//! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
581
//! <b>Note</b>: Invalidates the iterators (but not the references)
582
//! to the erased elements. No destructors are called.
583
size_type erase(const_reference value)
584
{ return tree_.erase(value); }
586
//! <b>Effects</b>: Erases all the elements that compare equal with
587
//! the given key and the given comparison functor.
589
//! <b>Returns</b>: The number of erased elements.
591
//! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
593
//! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
595
//! <b>Note</b>: Invalidates the iterators (but not the references)
596
//! to the erased elements. No destructors are called.
597
template<class KeyType, class KeyValueCompare>
598
size_type erase(const KeyType& key, KeyValueCompare comp
600
, typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
603
{ return tree_.erase(key, comp); }
605
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
607
//! <b>Effects</b>: Erases the element pointed to by pos.
608
//! Disposer::operator()(pointer) is called for the removed element.
610
//! <b>Complexity</b>: Average complexity for erase element is constant time.
612
//! <b>Returns</b>: An iterator to the element after the erased element.
614
//! <b>Throws</b>: Nothing.
616
//! <b>Note</b>: Invalidates the iterators
617
//! to the erased elements.
618
template<class Disposer>
619
iterator erase_and_dispose(const_iterator i, Disposer disposer)
620
{ return tree_.erase_and_dispose(i, disposer); }
622
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
623
template<class Disposer>
624
iterator erase_and_dispose(iterator i, Disposer disposer)
625
{ return this->erase_and_dispose(const_iterator(i), disposer); }
628
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
630
//! <b>Effects</b>: Erases the range pointed to by b end e.
631
//! Disposer::operator()(pointer) is called for the removed elements.
633
//! <b>Complexity</b>: Average complexity for erase range is at most
634
//! O(log(size() + N)), where N is the number of elements in the range.
636
//! <b>Returns</b>: An iterator to the element after the erased elements.
638
//! <b>Throws</b>: Nothing.
640
//! <b>Note</b>: Invalidates the iterators
641
//! to the erased elements.
642
template<class Disposer>
643
iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
644
{ return tree_.erase_and_dispose(b, e, disposer); }
646
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
648
//! <b>Effects</b>: Erases all the elements with the given value.
649
//! Disposer::operator()(pointer) is called for the removed elements.
651
//! <b>Throws</b>: If the internal value_compare ordering function throws.
653
//! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
655
//! <b>Throws</b>: Nothing.
657
//! <b>Note</b>: Invalidates the iterators (but not the references)
658
//! to the erased elements. No destructors are called.
659
template<class Disposer>
660
size_type erase_and_dispose(const_reference value, Disposer disposer)
661
{ return tree_.erase_and_dispose(value, disposer); }
663
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
665
//! <b>Effects</b>: Erases all the elements with the given key.
666
//! according to the comparison functor "comp".
667
//! Disposer::operator()(pointer) is called for the removed elements.
669
//! <b>Returns</b>: The number of erased elements.
671
//! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
673
//! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
675
//! <b>Note</b>: Invalidates the iterators
676
//! to the erased elements.
677
template<class KeyType, class KeyValueCompare, class Disposer>
678
size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
680
, typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
683
{ return tree_.erase_and_dispose(key, comp, disposer); }
685
//! <b>Effects</b>: Erases all the elements of the container.
687
//! <b>Complexity</b>: Linear to the number of elements on the container.
688
//! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
690
//! <b>Throws</b>: Nothing.
692
//! <b>Note</b>: Invalidates the iterators (but not the references)
693
//! to the erased elements. No destructors are called.
695
{ return tree_.clear(); }
697
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
699
//! <b>Effects</b>: Erases all the elements of the container.
701
//! <b>Complexity</b>: Linear to the number of elements on the container.
702
//! Disposer::operator()(pointer) is called for the removed elements.
704
//! <b>Throws</b>: Nothing.
706
//! <b>Note</b>: Invalidates the iterators (but not the references)
707
//! to the erased elements. No destructors are called.
708
template<class Disposer>
709
void clear_and_dispose(Disposer disposer)
710
{ return tree_.clear_and_dispose(disposer); }
712
//! <b>Effects</b>: Returns the number of contained elements with the given key
714
//! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
715
//! to number of objects with the given key.
717
//! <b>Throws</b>: If the internal value_compare ordering function throws.
718
size_type count(const_reference value) const
719
{ return tree_.find(value) != end(); }
721
//! <b>Effects</b>: Returns the number of contained elements with the same key
722
//! compared with the given comparison functor.
724
//! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
725
//! to number of objects with the given key.
727
//! <b>Throws</b>: If comp ordering function throws.
728
template<class KeyType, class KeyValueCompare>
729
size_type count(const KeyType& key, KeyValueCompare comp) const
730
{ return tree_.find(key, comp) != end(); }
732
//! <b>Effects</b>: Returns an iterator to the first element whose
733
//! key is not less than k or end() if that element does not exist.
735
//! <b>Complexity</b>: Logarithmic.
737
//! <b>Throws</b>: If the internal value_compare ordering function throws.
738
iterator lower_bound(const_reference value)
739
{ return tree_.lower_bound(value); }
741
//! <b>Requires</b>: comp must imply the same element order as
742
//! value_compare. Usually key is the part of the value_type
743
//! that is used in the ordering functor.
745
//! <b>Effects</b>: Returns an iterator to the first element whose
746
//! key according to the comparison functor is not less than k or
747
//! end() if that element does not exist.
749
//! <b>Complexity</b>: Logarithmic.
751
//! <b>Throws</b>: If comp ordering function throws.
753
//! <b>Note</b>: This function is used when constructing a value_type
754
//! is expensive and the value_type can be compared with a cheaper
755
//! key type. Usually this key is part of the value_type.
756
template<class KeyType, class KeyValueCompare>
757
iterator lower_bound(const KeyType& key, KeyValueCompare comp)
758
{ return tree_.lower_bound(key, comp); }
760
//! <b>Effects</b>: Returns a const iterator to the first element whose
761
//! key is not less than k or end() if that element does not exist.
763
//! <b>Complexity</b>: Logarithmic.
765
//! <b>Throws</b>: If the internal value_compare ordering function throws.
766
const_iterator lower_bound(const_reference value) const
767
{ return tree_.lower_bound(value); }
769
//! <b>Requires</b>: comp must imply the same element order as
770
//! value_compare. Usually key is the part of the value_type
771
//! that is used in the ordering functor.
773
//! <b>Effects</b>: Returns a const_iterator to the first element whose
774
//! key according to the comparison functor is not less than k or
775
//! end() if that element does not exist.
777
//! <b>Complexity</b>: Logarithmic.
779
//! <b>Throws</b>: If comp ordering function throws.
781
//! <b>Note</b>: This function is used when constructing a value_type
782
//! is expensive and the value_type can be compared with a cheaper
783
//! key type. Usually this key is part of the value_type.
784
template<class KeyType, class KeyValueCompare>
785
const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
786
{ return tree_.lower_bound(key, comp); }
788
//! <b>Effects</b>: Returns an iterator to the first element whose
789
//! key is greater than k or end() if that element does not exist.
791
//! <b>Complexity</b>: Logarithmic.
793
//! <b>Throws</b>: If the internal value_compare ordering function throws.
794
iterator upper_bound(const_reference value)
795
{ return tree_.upper_bound(value); }
797
//! <b>Requires</b>: comp must imply the same element order as
798
//! value_compare. Usually key is the part of the value_type
799
//! that is used in the ordering functor.
801
//! <b>Effects</b>: Returns an iterator to the first element whose
802
//! key according to the comparison functor is greater than key or
803
//! end() if that element does not exist.
805
//! <b>Complexity</b>: Logarithmic.
807
//! <b>Throws</b>: If comp ordering function throws.
809
//! <b>Note</b>: This function is used when constructing a value_type
810
//! is expensive and the value_type can be compared with a cheaper
811
//! key type. Usually this key is part of the value_type.
812
template<class KeyType, class KeyValueCompare>
813
iterator upper_bound(const KeyType& key, KeyValueCompare comp)
814
{ return tree_.upper_bound(key, comp); }
816
//! <b>Effects</b>: Returns an iterator to the first element whose
817
//! key is greater than k or end() if that element does not exist.
819
//! <b>Complexity</b>: Logarithmic.
821
//! <b>Throws</b>: If the internal value_compare ordering function throws.
822
const_iterator upper_bound(const_reference value) const
823
{ return tree_.upper_bound(value); }
825
//! <b>Requires</b>: comp must imply the same element order as
826
//! value_compare. Usually key is the part of the value_type
827
//! that is used in the ordering functor.
829
//! <b>Effects</b>: Returns a const_iterator to the first element whose
830
//! key according to the comparison functor is greater than key or
831
//! end() if that element does not exist.
833
//! <b>Complexity</b>: Logarithmic.
835
//! <b>Throws</b>: If comp ordering function throws.
837
//! <b>Note</b>: This function is used when constructing a value_type
838
//! is expensive and the value_type can be compared with a cheaper
839
//! key type. Usually this key is part of the value_type.
840
template<class KeyType, class KeyValueCompare>
841
const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
842
{ return tree_.upper_bound(key, comp); }
844
//! <b>Effects</b>: Finds an iterator to the first element whose value is
845
//! "value" or end() if that element does not exist.
847
//! <b>Complexity</b>: Logarithmic.
849
//! <b>Throws</b>: If the internal value_compare ordering function throws.
850
iterator find(const_reference value)
851
{ return tree_.find(value); }
853
//! <b>Requires</b>: comp must imply the same element order as
854
//! value_compare. Usually key is the part of the value_type
855
//! that is used in the ordering functor.
857
//! <b>Effects</b>: Finds an iterator to the first element whose key is
858
//! "key" according to the comparison functor or end() if that element
861
//! <b>Complexity</b>: Logarithmic.
863
//! <b>Throws</b>: If comp ordering function throws.
865
//! <b>Note</b>: This function is used when constructing a value_type
866
//! is expensive and the value_type can be compared with a cheaper
867
//! key type. Usually this key is part of the value_type.
868
template<class KeyType, class KeyValueCompare>
869
iterator find(const KeyType& key, KeyValueCompare comp)
870
{ return tree_.find(key, comp); }
872
//! <b>Effects</b>: Finds a const_iterator to the first element whose value is
873
//! "value" or end() if that element does not exist.
875
//! <b>Complexity</b>: Logarithmic.
877
//! <b>Throws</b>: If the internal value_compare ordering function throws.
878
const_iterator find(const_reference value) const
879
{ return tree_.find(value); }
881
//! <b>Requires</b>: comp must imply the same element order as
882
//! value_compare. Usually key is the part of the value_type
883
//! that is used in the ordering functor.
885
//! <b>Effects</b>: Finds a const_iterator to the first element whose key is
886
//! "key" according to the comparison functor or end() if that element
889
//! <b>Complexity</b>: Logarithmic.
891
//! <b>Throws</b>: If comp ordering function throws.
893
//! <b>Note</b>: This function is used when constructing a value_type
894
//! is expensive and the value_type can be compared with a cheaper
895
//! key type. Usually this key is part of the value_type.
896
template<class KeyType, class KeyValueCompare>
897
const_iterator find(const KeyType& key, KeyValueCompare comp) const
898
{ return tree_.find(key, comp); }
900
//! <b>Effects</b>: Finds a range containing all elements whose key is k or
901
//! an empty range that indicates the position where those elements would be
902
//! if they there is no elements with key k.
904
//! <b>Complexity</b>: Logarithmic.
906
//! <b>Throws</b>: If the internal value_compare ordering function throws.
907
std::pair<iterator,iterator> equal_range(const_reference value)
908
{ return tree_.equal_range(value); }
910
//! <b>Requires</b>: comp must imply the same element order as
911
//! value_compare. Usually key is the part of the value_type
912
//! that is used in the ordering functor.
914
//! <b>Effects</b>: Finds a range containing all elements whose key is k
915
//! according to the comparison functor or an empty range
916
//! that indicates the position where those elements would be
917
//! if they there is no elements with key k.
919
//! <b>Complexity</b>: Logarithmic.
921
//! <b>Throws</b>: If comp ordering function throws.
923
//! <b>Note</b>: This function is used when constructing a value_type
924
//! is expensive and the value_type can be compared with a cheaper
925
//! key type. Usually this key is part of the value_type.
926
template<class KeyType, class KeyValueCompare>
927
std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
928
{ return tree_.equal_range(key, comp); }
930
//! <b>Effects</b>: Finds a range containing all elements whose key is k or
931
//! an empty range that indicates the position where those elements would be
932
//! if they there is no elements with key k.
934
//! <b>Complexity</b>: Logarithmic.
936
//! <b>Throws</b>: If the internal value_compare ordering function throws.
937
std::pair<const_iterator, const_iterator>
938
equal_range(const_reference value) const
939
{ return tree_.equal_range(value); }
941
//! <b>Requires</b>: comp must imply the same element order as
942
//! value_compare. Usually key is the part of the value_type
943
//! that is used in the ordering functor.
945
//! <b>Effects</b>: Finds a range containing all elements whose key is k
946
//! according to the comparison functor or an empty range
947
//! that indicates the position where those elements would be
948
//! if they there is no elements with key k.
950
//! <b>Complexity</b>: Logarithmic.
952
//! <b>Throws</b>: If comp ordering function throws.
954
//! <b>Note</b>: This function is used when constructing a value_type
955
//! is expensive and the value_type can be compared with a cheaper
956
//! key type. Usually this key is part of the value_type.
957
template<class KeyType, class KeyValueCompare>
958
std::pair<const_iterator, const_iterator>
959
equal_range(const KeyType& key, KeyValueCompare comp) const
960
{ return tree_.equal_range(key, comp); }
962
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
963
//! appropriate type. Otherwise the behavior is undefined.
965
//! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
966
//! that points to the value
968
//! <b>Complexity</b>: Constant.
970
//! <b>Throws</b>: Nothing.
972
//! <b>Note</b>: This static function is available only if the <i>value traits</i>
974
static iterator s_iterator_to(reference value)
975
{ return tree_type::s_iterator_to(value); }
977
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
978
//! appropriate type. Otherwise the behavior is undefined.
980
//! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
981
//! sg_set that points to the value
983
//! <b>Complexity</b>: Constant.
985
//! <b>Throws</b>: Nothing.
987
//! <b>Note</b>: This static function is available only if the <i>value traits</i>
989
static const_iterator s_iterator_to(const_reference value)
990
{ return tree_type::s_iterator_to(value); }
992
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
993
//! appropriate type. Otherwise the behavior is undefined.
995
//! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
996
//! that points to the value
998
//! <b>Complexity</b>: Constant.
1000
//! <b>Throws</b>: Nothing.
1001
iterator iterator_to(reference value)
1002
{ return tree_.iterator_to(value); }
1004
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
1005
//! appropriate type. Otherwise the behavior is undefined.
1007
//! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1008
//! sg_set that points to the value
1010
//! <b>Complexity</b>: Constant.
1012
//! <b>Throws</b>: Nothing.
1013
const_iterator iterator_to(const_reference value) const
1014
{ return tree_.iterator_to(value); }
1016
//! <b>Requires</b>: value shall not be in a sg_set/sg_multiset.
1018
//! <b>Effects</b>: init_node puts the hook of a value in a well-known default
1021
//! <b>Throws</b>: Nothing.
1023
//! <b>Complexity</b>: Constant time.
1025
//! <b>Note</b>: This function puts the hook in the well-known default state
1026
//! used by auto_unlink and safe hooks.
1027
static void init_node(reference value)
1028
{ tree_type::init_node(value); }
1030
//! <b>Effects</b>: Unlinks the leftmost node from the tree.
1032
//! <b>Complexity</b>: Average complexity is constant time.
1034
//! <b>Throws</b>: Nothing.
1036
//! <b>Notes</b>: This function breaks the tree and the tree can
1037
//! only be used for more unlink_leftmost_without_rebalance calls.
1038
//! This function is normally used to achieve a step by step
1039
//! controlled destruction of the tree.
1040
pointer unlink_leftmost_without_rebalance()
1041
{ return tree_.unlink_leftmost_without_rebalance(); }
1043
//! <b>Requires</b>: replace_this must be a valid iterator of *this
1044
//! and with_this must not be inserted in any tree.
1046
//! <b>Effects</b>: Replaces replace_this in its position in the
1047
//! tree with with_this. The tree does not need to be rebalanced.
1049
//! <b>Complexity</b>: Constant.
1051
//! <b>Throws</b>: Nothing.
1053
//! <b>Note</b>: This function will break container ordering invariants if
1054
//! with_this is not equivalent to *replace_this according to the
1055
//! ordering rules. This function is faster than erasing and inserting
1056
//! the node, since no rebalancing or comparison is needed.
1057
void replace_node(iterator replace_this, reference with_this)
1058
{ tree_.replace_node(replace_this, with_this); }
1060
//! <b>Effects</b>: Rebalances the tree.
1062
//! <b>Throws</b>: Nothing.
1064
//! <b>Complexity</b>: Linear.
1066
{ tree_.rebalance(); }
1068
//! <b>Requires</b>: old_root is a node of a tree.
1070
//! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1072
//! <b>Returns</b>: The new root of the subtree.
1074
//! <b>Throws</b>: Nothing.
1076
//! <b>Complexity</b>: Linear to the elements in the subtree.
1077
iterator rebalance_subtree(iterator root)
1078
{ return tree_.rebalance_subtree(root); }
1080
//! <b>Returns</b>: The balance factor (alpha) used in this tree
1082
//! <b>Throws</b>: Nothing.
1084
//! <b>Complexity</b>: Constant.
1085
float balance_factor() const
1086
{ return tree_.balance_factor(); }
1088
//! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
1090
//! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
1091
//! the tree if the new balance factor is stricter (less) than the old factor.
1093
//! <b>Throws</b>: Nothing.
1095
//! <b>Complexity</b>: Linear to the elements in the subtree.
1096
void balance_factor(float new_alpha)
1097
{ tree_.balance_factor(new_alpha); }
1100
friend bool operator==(const sg_set_impl &x, const sg_set_impl &y)
1101
{ return x.tree_ == y.tree_; }
1103
friend bool operator<(const sg_set_impl &x, const sg_set_impl &y)
1104
{ return x.tree_ < y.tree_; }
1108
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1109
template<class T, class ...Options>
1111
template<class Config>
1113
inline bool operator!=
1114
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1115
(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1117
(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1119
{ return !(x == y); }
1121
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1122
template<class T, class ...Options>
1124
template<class Config>
1126
inline bool operator>
1127
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1128
(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1130
(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1134
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1135
template<class T, class ...Options>
1137
template<class Config>
1139
inline bool operator<=
1140
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1141
(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1143
(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1145
{ return !(y < x); }
1147
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1148
template<class T, class ...Options>
1150
template<class Config>
1152
inline bool operator>=
1153
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1154
(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1156
(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1158
{ return !(x < y); }
1160
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1161
template<class T, class ...Options>
1163
template<class Config>
1166
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1167
(sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y)
1169
(sg_set_impl<Config> &x, sg_set_impl<Config> &y)
1173
//! Helper metafunction to define a \c sg_set that yields to the same type when the
1174
//! same options (either explicitly or implicitly) are used.
1175
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1176
template<class T, class ...Options>
1178
template<class T, class O1 = none, class O2 = none
1179
, class O3 = none, class O4 = none>
1185
< typename make_sgtree_opt<T,
1186
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1192
> implementation_defined;
1194
typedef implementation_defined type;
1197
#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1199
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1200
template<class T, class O1, class O2, class O3, class O4>
1202
template<class T, class ...Options>
1205
: public make_sg_set<T,
1206
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1213
typedef typename make_sg_set
1215
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1223
typedef typename Base::value_compare value_compare;
1224
typedef typename Base::value_traits value_traits;
1225
typedef typename Base::iterator iterator;
1226
typedef typename Base::const_iterator const_iterator;
1228
//Assert if passed value traits are compatible with the type
1229
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
1231
sg_set( const value_compare &cmp = value_compare()
1232
, const value_traits &v_traits = value_traits())
1233
: Base(cmp, v_traits)
1236
template<class Iterator>
1237
sg_set( Iterator b, Iterator e
1238
, const value_compare &cmp = value_compare()
1239
, const value_traits &v_traits = value_traits())
1240
: Base(b, e, cmp, v_traits)
1243
static sg_set &container_from_end_iterator(iterator end_iterator)
1244
{ return static_cast<sg_set &>(Base::container_from_end_iterator(end_iterator)); }
1246
static const sg_set &container_from_end_iterator(const_iterator end_iterator)
1247
{ return static_cast<const sg_set &>(Base::container_from_end_iterator(end_iterator)); }
1249
static sg_set &container_from_iterator(iterator it)
1250
{ return static_cast<sg_set &>(Base::container_from_iterator(it)); }
1252
static const sg_set &container_from_iterator(const_iterator it)
1253
{ return static_cast<const sg_set &>(Base::container_from_iterator(it)); }
1258
//! The class template sg_multiset is an intrusive container, that mimics most of
1259
//! the interface of std::sg_multiset as described in the C++ standard.
1261
//! The template parameter \c T is the type to be managed by the container.
1262
//! The user can specify additional options and if no options are provided
1263
//! default options are used.
1265
//! The container supports the following options:
1266
//! \c base_hook<>/member_hook<>/value_traits<>,
1267
//! \c constant_time_size<>, \c size_type<> and
1269
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1270
template<class T, class ...Options>
1272
template<class Config>
1274
class sg_multiset_impl
1277
typedef sgtree_impl<Config> tree_type;
1279
//Non-copyable and non-assignable
1280
sg_multiset_impl (const sg_multiset_impl&);
1281
sg_multiset_impl &operator =(const sg_multiset_impl&);
1282
typedef tree_type implementation_defined;
1286
typedef typename implementation_defined::value_type value_type;
1287
typedef typename implementation_defined::value_traits value_traits;
1288
typedef typename implementation_defined::pointer pointer;
1289
typedef typename implementation_defined::const_pointer const_pointer;
1290
typedef typename implementation_defined::reference reference;
1291
typedef typename implementation_defined::const_reference const_reference;
1292
typedef typename implementation_defined::difference_type difference_type;
1293
typedef typename implementation_defined::size_type size_type;
1294
typedef typename implementation_defined::value_compare value_compare;
1295
typedef typename implementation_defined::key_compare key_compare;
1296
typedef typename implementation_defined::iterator iterator;
1297
typedef typename implementation_defined::const_iterator const_iterator;
1298
typedef typename implementation_defined::reverse_iterator reverse_iterator;
1299
typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
1300
typedef typename implementation_defined::insert_commit_data insert_commit_data;
1301
typedef typename implementation_defined::node_traits node_traits;
1302
typedef typename implementation_defined::node node;
1303
typedef typename implementation_defined::node_ptr node_ptr;
1304
typedef typename implementation_defined::const_node_ptr const_node_ptr;
1305
typedef typename implementation_defined::node_algorithms node_algorithms;
1313
//! <b>Effects</b>: Constructs an empty sg_multiset.
1315
//! <b>Complexity</b>: Constant.
1317
//! <b>Throws</b>: If value_traits::node_traits::node
1318
//! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1319
//! or the copy constructor/operator() of the value_compare object throws.
1320
sg_multiset_impl( const value_compare &cmp = value_compare()
1321
, const value_traits &v_traits = value_traits())
1322
: tree_(cmp, v_traits)
1325
//! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1326
//! cmp must be a comparison function that induces a strict weak ordering.
1328
//! <b>Effects</b>: Constructs an empty sg_multiset and inserts elements from
1331
//! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1332
//! comp and otherwise N * log N, where N is the distance between first and last
1334
//! <b>Throws</b>: If value_traits::node_traits::node
1335
//! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1336
//! or the copy constructor/operator() of the value_compare object throws.
1337
template<class Iterator>
1338
sg_multiset_impl( Iterator b, Iterator e
1339
, const value_compare &cmp = value_compare()
1340
, const value_traits &v_traits = value_traits())
1341
: tree_(false, b, e, cmp, v_traits)
1344
//! <b>Effects</b>: Detaches all elements from this. The objects in the sg_multiset
1345
//! are not deleted (i.e. no destructors are called).
1347
//! <b>Complexity</b>: Linear to the number of elements on the container.
1348
//! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1350
//! <b>Throws</b>: Nothing.
1354
//! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_multiset.
1356
//! <b>Complexity</b>: Constant.
1358
//! <b>Throws</b>: Nothing.
1360
{ return tree_.begin(); }
1362
//! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1364
//! <b>Complexity</b>: Constant.
1366
//! <b>Throws</b>: Nothing.
1367
const_iterator begin() const
1368
{ return tree_.begin(); }
1370
//! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1372
//! <b>Complexity</b>: Constant.
1374
//! <b>Throws</b>: Nothing.
1375
const_iterator cbegin() const
1376
{ return tree_.cbegin(); }
1378
//! <b>Effects</b>: Returns an iterator pointing to the end of the sg_multiset.
1380
//! <b>Complexity</b>: Constant.
1382
//! <b>Throws</b>: Nothing.
1384
{ return tree_.end(); }
1386
//! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1388
//! <b>Complexity</b>: Constant.
1390
//! <b>Throws</b>: Nothing.
1391
const_iterator end() const
1392
{ return tree_.end(); }
1394
//! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1396
//! <b>Complexity</b>: Constant.
1398
//! <b>Throws</b>: Nothing.
1399
const_iterator cend() const
1400
{ return tree_.cend(); }
1402
//! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1403
//! reversed sg_multiset.
1405
//! <b>Complexity</b>: Constant.
1407
//! <b>Throws</b>: Nothing.
1408
reverse_iterator rbegin()
1409
{ return tree_.rbegin(); }
1411
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1412
//! of the reversed sg_multiset.
1414
//! <b>Complexity</b>: Constant.
1416
//! <b>Throws</b>: Nothing.
1417
const_reverse_iterator rbegin() const
1418
{ return tree_.rbegin(); }
1420
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1421
//! of the reversed sg_multiset.
1423
//! <b>Complexity</b>: Constant.
1425
//! <b>Throws</b>: Nothing.
1426
const_reverse_iterator crbegin() const
1427
{ return tree_.crbegin(); }
1429
//! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1430
//! of the reversed sg_multiset.
1432
//! <b>Complexity</b>: Constant.
1434
//! <b>Throws</b>: Nothing.
1435
reverse_iterator rend()
1436
{ return tree_.rend(); }
1438
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1439
//! of the reversed sg_multiset.
1441
//! <b>Complexity</b>: Constant.
1443
//! <b>Throws</b>: Nothing.
1444
const_reverse_iterator rend() const
1445
{ return tree_.rend(); }
1447
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1448
//! of the reversed sg_multiset.
1450
//! <b>Complexity</b>: Constant.
1452
//! <b>Throws</b>: Nothing.
1453
const_reverse_iterator crend() const
1454
{ return tree_.crend(); }
1456
//! <b>Precondition</b>: end_iterator must be a valid end iterator
1459
//! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1461
//! <b>Throws</b>: Nothing.
1463
//! <b>Complexity</b>: Constant.
1464
static sg_multiset_impl &container_from_end_iterator(iterator end_iterator)
1466
return *detail::parent_from_member<sg_multiset_impl, tree_type>
1467
( &tree_type::container_from_end_iterator(end_iterator)
1468
, &sg_multiset_impl::tree_);
1471
//! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1474
//! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1476
//! <b>Throws</b>: Nothing.
1478
//! <b>Complexity</b>: Constant.
1479
static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator)
1481
return *detail::parent_from_member<sg_multiset_impl, tree_type>
1482
( &tree_type::container_from_end_iterator(end_iterator)
1483
, &sg_multiset_impl::tree_);
1486
//! <b>Precondition</b>: it must be a valid iterator of multiset.
1488
//! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1490
//! <b>Throws</b>: Nothing.
1492
//! <b>Complexity</b>: Constant.
1493
static sg_multiset_impl &container_from_iterator(iterator it)
1495
return *detail::parent_from_member<sg_multiset_impl, tree_type>
1496
( &tree_type::container_from_iterator(it)
1497
, &sg_multiset_impl::tree_);
1500
//! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1502
//! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1504
//! <b>Throws</b>: Nothing.
1506
//! <b>Complexity</b>: Constant.
1507
static const sg_multiset_impl &container_from_iterator(const_iterator it)
1509
return *detail::parent_from_member<sg_multiset_impl, tree_type>
1510
( &tree_type::container_from_iterator(it)
1511
, &sg_multiset_impl::tree_);
1514
//! <b>Effects</b>: Returns the key_compare object used by the sg_multiset.
1516
//! <b>Complexity</b>: Constant.
1518
//! <b>Throws</b>: If key_compare copy-constructor throws.
1519
key_compare key_comp() const
1520
{ return tree_.value_comp(); }
1522
//! <b>Effects</b>: Returns the value_compare object used by the sg_multiset.
1524
//! <b>Complexity</b>: Constant.
1526
//! <b>Throws</b>: If value_compare copy-constructor throws.
1527
value_compare value_comp() const
1528
{ return tree_.value_comp(); }
1530
//! <b>Effects</b>: Returns true if the container is empty.
1532
//! <b>Complexity</b>: Constant.
1534
//! <b>Throws</b>: Nothing.
1536
{ return tree_.empty(); }
1538
//! <b>Effects</b>: Returns the number of elements stored in the sg_multiset.
1540
//! <b>Complexity</b>: Linear to elements contained in *this if,
1541
//! constant-time size option is enabled. Constant-time otherwise.
1543
//! <b>Throws</b>: Nothing.
1544
size_type size() const
1545
{ return tree_.size(); }
1547
//! <b>Effects</b>: Swaps the contents of two sg_multisets.
1549
//! <b>Complexity</b>: Constant.
1551
//! <b>Throws</b>: If the swap() call for the comparison functor
1552
//! found using ADL throws. Strong guarantee.
1553
void swap(sg_multiset_impl& other)
1554
{ tree_.swap(other.tree_); }
1556
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1557
//! Cloner should yield to nodes equivalent to the original nodes.
1559
//! <b>Effects</b>: Erases all the elements from *this
1560
//! calling Disposer::operator()(pointer), clones all the
1561
//! elements from src calling Cloner::operator()(const_reference )
1562
//! and inserts them on *this. Copies the predicate from the source container.
1564
//! If cloner throws, all cloned elements are unlinked and disposed
1565
//! calling Disposer::operator()(pointer).
1567
//! <b>Complexity</b>: Linear to erased plus inserted elements.
1569
//! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1570
template <class Cloner, class Disposer>
1571
void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer)
1572
{ tree_.clone_from(src.tree_, cloner, disposer); }
1574
//! <b>Requires</b>: value must be an lvalue
1576
//! <b>Effects</b>: Inserts value into the sg_multiset.
1578
//! <b>Returns</b>: An iterator that points to the position where the new
1579
//! element was inserted.
1581
//! <b>Complexity</b>: Average complexity for insert element is at
1582
//! most logarithmic.
1584
//! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1586
//! <b>Note</b>: Does not affect the validity of iterators and references.
1587
//! No copy-constructors are called.
1588
iterator insert(reference value)
1589
{ return tree_.insert_equal(value); }
1591
//! <b>Requires</b>: value must be an lvalue
1593
//! <b>Effects</b>: Inserts x into the sg_multiset, using pos as a hint to
1594
//! where it will be inserted.
1596
//! <b>Returns</b>: An iterator that points to the position where the new
1597
//! element was inserted.
1599
//! <b>Complexity</b>: Logarithmic in general, but it is amortized
1600
//! constant time if t is inserted immediately before hint.
1602
//! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1604
//! <b>Note</b>: Does not affect the validity of iterators and references.
1605
//! No copy-constructors are called.
1606
iterator insert(const_iterator hint, reference value)
1607
{ return tree_.insert_equal(hint, value); }
1609
//! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1610
//! of type value_type.
1612
//! <b>Effects</b>: Inserts a range into the sg_multiset.
1614
//! <b>Returns</b>: An iterator that points to the position where the new
1615
//! element was inserted.
1617
//! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1618
//! size of the range. However, it is linear in N if the range is already sorted
1619
//! by value_comp().
1621
//! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1623
//! <b>Note</b>: Does not affect the validity of iterators and references.
1624
//! No copy-constructors are called.
1625
template<class Iterator>
1626
void insert(Iterator b, Iterator e)
1627
{ tree_.insert_equal(b, e); }
1629
//! <b>Requires</b>: value must be an lvalue, "pos" must be
1630
//! a valid iterator (or end) and must be the succesor of value
1631
//! once inserted according to the predicate
1633
//! <b>Effects</b>: Inserts x into the tree before "pos".
1635
//! <b>Complexity</b>: Constant time.
1637
//! <b>Throws</b>: Nothing.
1639
//! <b>Note</b>: This function does not check preconditions so if "pos" is not
1640
//! the successor of "value" tree ordering invariant will be broken.
1641
//! This is a low-level function to be used only for performance reasons
1642
//! by advanced users.
1643
iterator insert_before(const_iterator pos, reference value)
1644
{ return tree_.insert_before(pos, value); }
1646
//! <b>Requires</b>: value must be an lvalue, and it must be no less
1647
//! than the greatest inserted key
1649
//! <b>Effects</b>: Inserts x into the tree in the last position.
1651
//! <b>Complexity</b>: Constant time.
1653
//! <b>Throws</b>: Nothing.
1655
//! <b>Note</b>: This function does not check preconditions so if value is
1656
//! less than the greatest inserted key tree ordering invariant will be broken.
1657
//! This function is slightly more efficient than using "insert_before".
1658
//! This is a low-level function to be used only for performance reasons
1659
//! by advanced users.
1660
void push_back(reference value)
1661
{ tree_.push_back(value); }
1663
//! <b>Requires</b>: value must be an lvalue, and it must be no greater
1664
//! than the minimum inserted key
1666
//! <b>Effects</b>: Inserts x into the tree in the first position.
1668
//! <b>Complexity</b>: Constant time.
1670
//! <b>Throws</b>: Nothing.
1672
//! <b>Note</b>: This function does not check preconditions so if value is
1673
//! greater than the minimum inserted key tree ordering invariant will be broken.
1674
//! This function is slightly more efficient than using "insert_before".
1675
//! This is a low-level function to be used only for performance reasons
1676
//! by advanced users.
1677
void push_front(reference value)
1678
{ tree_.push_front(value); }
1680
//! <b>Effects</b>: Erases the element pointed to by pos.
1682
//! <b>Complexity</b>: Average complexity is constant time.
1684
//! <b>Returns</b>: An iterator to the element after the erased element.
1686
//! <b>Throws</b>: Nothing.
1688
//! <b>Note</b>: Invalidates the iterators (but not the references)
1689
//! to the erased elements. No destructors are called.
1690
iterator erase(const_iterator i)
1691
{ return tree_.erase(i); }
1693
//! <b>Effects</b>: Erases the range pointed to by b end e.
1695
//! <b>Returns</b>: An iterator to the element after the erased elements.
1697
//! <b>Complexity</b>: Average complexity for erase range is at most
1698
//! O(log(size() + N)), where N is the number of elements in the range.
1700
//! <b>Throws</b>: Nothing.
1702
//! <b>Note</b>: Invalidates the iterators (but not the references)
1703
//! to the erased elements. No destructors are called.
1704
iterator erase(const_iterator b, const_iterator e)
1705
{ return tree_.erase(b, e); }
1707
//! <b>Effects</b>: Erases all the elements with the given value.
1709
//! <b>Returns</b>: The number of erased elements.
1711
//! <b>Complexity</b>: O(log(size() + this->count(value)).
1713
//! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1715
//! <b>Note</b>: Invalidates the iterators (but not the references)
1716
//! to the erased elements. No destructors are called.
1717
size_type erase(const_reference value)
1718
{ return tree_.erase(value); }
1720
//! <b>Effects</b>: Erases all the elements that compare equal with
1721
//! the given key and the given comparison functor.
1723
//! <b>Returns</b>: The number of erased elements.
1725
//! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1727
//! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1729
//! <b>Note</b>: Invalidates the iterators (but not the references)
1730
//! to the erased elements. No destructors are called.
1731
template<class KeyType, class KeyValueCompare>
1732
size_type erase(const KeyType& key, KeyValueCompare comp
1734
, typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1737
{ return tree_.erase(key, comp); }
1739
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1741
//! <b>Returns</b>: An iterator to the element after the erased element.
1743
//! <b>Effects</b>: Erases the element pointed to by pos.
1744
//! Disposer::operator()(pointer) is called for the removed element.
1746
//! <b>Complexity</b>: Average complexity for erase element is constant time.
1748
//! <b>Throws</b>: Nothing.
1750
//! <b>Note</b>: Invalidates the iterators
1751
//! to the erased elements.
1752
template<class Disposer>
1753
iterator erase_and_dispose(const_iterator i, Disposer disposer)
1754
{ return tree_.erase_and_dispose(i, disposer); }
1756
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1757
template<class Disposer>
1758
iterator erase_and_dispose(iterator i, Disposer disposer)
1759
{ return this->erase_and_dispose(const_iterator(i), disposer); }
1762
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1764
//! <b>Returns</b>: An iterator to the element after the erased elements.
1766
//! <b>Effects</b>: Erases the range pointed to by b end e.
1767
//! Disposer::operator()(pointer) is called for the removed elements.
1769
//! <b>Complexity</b>: Average complexity for erase range is at most
1770
//! O(log(size() + N)), where N is the number of elements in the range.
1772
//! <b>Throws</b>: Nothing.
1774
//! <b>Note</b>: Invalidates the iterators
1775
//! to the erased elements.
1776
template<class Disposer>
1777
iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
1778
{ return tree_.erase_and_dispose(b, e, disposer); }
1780
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1782
//! <b>Effects</b>: Erases all the elements with the given value.
1783
//! Disposer::operator()(pointer) is called for the removed elements.
1785
//! <b>Returns</b>: The number of erased elements.
1787
//! <b>Complexity</b>: O(log(size() + this->count(value)).
1789
//! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1791
//! <b>Note</b>: Invalidates the iterators (but not the references)
1792
//! to the erased elements. No destructors are called.
1793
template<class Disposer>
1794
size_type erase_and_dispose(const_reference value, Disposer disposer)
1795
{ return tree_.erase_and_dispose(value, disposer); }
1797
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1799
//! <b>Effects</b>: Erases all the elements with the given key.
1800
//! according to the comparison functor "comp".
1801
//! Disposer::operator()(pointer) is called for the removed elements.
1803
//! <b>Returns</b>: The number of erased elements.
1805
//! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1807
//! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1809
//! <b>Note</b>: Invalidates the iterators
1810
//! to the erased elements.
1811
template<class KeyType, class KeyValueCompare, class Disposer>
1812
size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
1814
, typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1817
{ return tree_.erase_and_dispose(key, comp, disposer); }
1819
//! <b>Effects</b>: Erases all the elements of the container.
1821
//! <b>Complexity</b>: Linear to the number of elements on the container.
1822
//! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1824
//! <b>Throws</b>: Nothing.
1826
//! <b>Note</b>: Invalidates the iterators (but not the references)
1827
//! to the erased elements. No destructors are called.
1829
{ return tree_.clear(); }
1831
//! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1833
//! <b>Effects</b>: Erases all the elements of the container.
1835
//! <b>Complexity</b>: Linear to the number of elements on the container.
1836
//! Disposer::operator()(pointer) is called for the removed elements.
1838
//! <b>Throws</b>: Nothing.
1840
//! <b>Note</b>: Invalidates the iterators (but not the references)
1841
//! to the erased elements. No destructors are called.
1842
template<class Disposer>
1843
void clear_and_dispose(Disposer disposer)
1844
{ return tree_.clear_and_dispose(disposer); }
1846
//! <b>Effects</b>: Returns the number of contained elements with the given key
1848
//! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1849
//! to number of objects with the given key.
1851
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1852
size_type count(const_reference value) const
1853
{ return tree_.count(value); }
1855
//! <b>Effects</b>: Returns the number of contained elements with the same key
1856
//! compared with the given comparison functor.
1858
//! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1859
//! to number of objects with the given key.
1861
//! <b>Throws</b>: If comp ordering function throws.
1862
template<class KeyType, class KeyValueCompare>
1863
size_type count(const KeyType& key, KeyValueCompare comp) const
1864
{ return tree_.count(key, comp); }
1866
//! <b>Effects</b>: Returns an iterator to the first element whose
1867
//! key is not less than k or end() if that element does not exist.
1869
//! <b>Complexity</b>: Logarithmic.
1871
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1872
iterator lower_bound(const_reference value)
1873
{ return tree_.lower_bound(value); }
1875
//! <b>Requires</b>: comp must imply the same element order as
1876
//! value_compare. Usually key is the part of the value_type
1877
//! that is used in the ordering functor.
1879
//! <b>Effects</b>: Returns an iterator to the first element whose
1880
//! key according to the comparison functor is not less than k or
1881
//! end() if that element does not exist.
1883
//! <b>Complexity</b>: Logarithmic.
1885
//! <b>Throws</b>: If comp ordering function throws.
1887
//! <b>Note</b>: This function is used when constructing a value_type
1888
//! is expensive and the value_type can be compared with a cheaper
1889
//! key type. Usually this key is part of the value_type.
1890
template<class KeyType, class KeyValueCompare>
1891
iterator lower_bound(const KeyType& key, KeyValueCompare comp)
1892
{ return tree_.lower_bound(key, comp); }
1894
//! <b>Effects</b>: Returns a const iterator to the first element whose
1895
//! key is not less than k or end() if that element does not exist.
1897
//! <b>Complexity</b>: Logarithmic.
1899
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1900
const_iterator lower_bound(const_reference value) const
1901
{ return tree_.lower_bound(value); }
1903
//! <b>Requires</b>: comp must imply the same element order as
1904
//! value_compare. Usually key is the part of the value_type
1905
//! that is used in the ordering functor.
1907
//! <b>Effects</b>: Returns a const_iterator to the first element whose
1908
//! key according to the comparison functor is not less than k or
1909
//! end() if that element does not exist.
1911
//! <b>Complexity</b>: Logarithmic.
1913
//! <b>Throws</b>: If comp ordering function throws.
1915
//! <b>Note</b>: This function is used when constructing a value_type
1916
//! is expensive and the value_type can be compared with a cheaper
1917
//! key type. Usually this key is part of the value_type.
1918
template<class KeyType, class KeyValueCompare>
1919
const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
1920
{ return tree_.lower_bound(key, comp); }
1922
//! <b>Effects</b>: Returns an iterator to the first element whose
1923
//! key is greater than k or end() if that element does not exist.
1925
//! <b>Complexity</b>: Logarithmic.
1927
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1928
iterator upper_bound(const_reference value)
1929
{ return tree_.upper_bound(value); }
1931
//! <b>Requires</b>: comp must imply the same element order as
1932
//! value_compare. Usually key is the part of the value_type
1933
//! that is used in the ordering functor.
1935
//! <b>Effects</b>: Returns an iterator to the first element whose
1936
//! key according to the comparison functor is greater than key or
1937
//! end() if that element does not exist.
1939
//! <b>Complexity</b>: Logarithmic.
1941
//! <b>Throws</b>: If comp ordering function throws.
1943
//! <b>Note</b>: This function is used when constructing a value_type
1944
//! is expensive and the value_type can be compared with a cheaper
1945
//! key type. Usually this key is part of the value_type.
1946
template<class KeyType, class KeyValueCompare>
1947
iterator upper_bound(const KeyType& key, KeyValueCompare comp)
1948
{ return tree_.upper_bound(key, comp); }
1950
//! <b>Effects</b>: Returns an iterator to the first element whose
1951
//! key is greater than k or end() if that element does not exist.
1953
//! <b>Complexity</b>: Logarithmic.
1955
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1956
const_iterator upper_bound(const_reference value) const
1957
{ return tree_.upper_bound(value); }
1959
//! <b>Requires</b>: comp must imply the same element order as
1960
//! value_compare. Usually key is the part of the value_type
1961
//! that is used in the ordering functor.
1963
//! <b>Effects</b>: Returns a const_iterator to the first element whose
1964
//! key according to the comparison functor is greater than key or
1965
//! end() if that element does not exist.
1967
//! <b>Complexity</b>: Logarithmic.
1969
//! <b>Throws</b>: If comp ordering function throws.
1971
//! <b>Note</b>: This function is used when constructing a value_type
1972
//! is expensive and the value_type can be compared with a cheaper
1973
//! key type. Usually this key is part of the value_type.
1974
template<class KeyType, class KeyValueCompare>
1975
const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
1976
{ return tree_.upper_bound(key, comp); }
1978
//! <b>Effects</b>: Finds an iterator to the first element whose value is
1979
//! "value" or end() if that element does not exist.
1981
//! <b>Complexity</b>: Logarithmic.
1983
//! <b>Throws</b>: If the internal value_compare ordering function throws.
1984
iterator find(const_reference value)
1985
{ return tree_.find(value); }
1987
//! <b>Requires</b>: comp must imply the same element order as
1988
//! value_compare. Usually key is the part of the value_type
1989
//! that is used in the ordering functor.
1991
//! <b>Effects</b>: Finds an iterator to the first element whose key is
1992
//! "key" according to the comparison functor or end() if that element
1995
//! <b>Complexity</b>: Logarithmic.
1997
//! <b>Throws</b>: If comp ordering function throws.
1999
//! <b>Note</b>: This function is used when constructing a value_type
2000
//! is expensive and the value_type can be compared with a cheaper
2001
//! key type. Usually this key is part of the value_type.
2002
template<class KeyType, class KeyValueCompare>
2003
iterator find(const KeyType& key, KeyValueCompare comp)
2004
{ return tree_.find(key, comp); }
2006
//! <b>Effects</b>: Finds a const_iterator to the first element whose value is
2007
//! "value" or end() if that element does not exist.
2009
//! <b>Complexity</b>: Logarithmic.
2011
//! <b>Throws</b>: If the internal value_compare ordering function throws.
2012
const_iterator find(const_reference value) const
2013
{ return tree_.find(value); }
2015
//! <b>Requires</b>: comp must imply the same element order as
2016
//! value_compare. Usually key is the part of the value_type
2017
//! that is used in the ordering functor.
2019
//! <b>Effects</b>: Finds a const_iterator to the first element whose key is
2020
//! "key" according to the comparison functor or end() if that element
2023
//! <b>Complexity</b>: Logarithmic.
2025
//! <b>Throws</b>: If comp ordering function throws.
2027
//! <b>Note</b>: This function is used when constructing a value_type
2028
//! is expensive and the value_type can be compared with a cheaper
2029
//! key type. Usually this key is part of the value_type.
2030
template<class KeyType, class KeyValueCompare>
2031
const_iterator find(const KeyType& key, KeyValueCompare comp) const
2032
{ return tree_.find(key, comp); }
2034
//! <b>Effects</b>: Finds a range containing all elements whose key is k or
2035
//! an empty range that indicates the position where those elements would be
2036
//! if they there is no elements with key k.
2038
//! <b>Complexity</b>: Logarithmic.
2040
//! <b>Throws</b>: If the internal value_compare ordering function throws.
2041
std::pair<iterator,iterator> equal_range(const_reference value)
2042
{ return tree_.equal_range(value); }
2044
//! <b>Requires</b>: comp must imply the same element order as
2045
//! value_compare. Usually key is the part of the value_type
2046
//! that is used in the ordering functor.
2048
//! <b>Effects</b>: Finds a range containing all elements whose key is k
2049
//! according to the comparison functor or an empty range
2050
//! that indicates the position where those elements would be
2051
//! if they there is no elements with key k.
2053
//! <b>Complexity</b>: Logarithmic.
2055
//! <b>Throws</b>: If comp ordering function throws.
2057
//! <b>Note</b>: This function is used when constructing a value_type
2058
//! is expensive and the value_type can be compared with a cheaper
2059
//! key type. Usually this key is part of the value_type.
2060
template<class KeyType, class KeyValueCompare>
2061
std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
2062
{ return tree_.equal_range(key, comp); }
2064
//! <b>Effects</b>: Finds a range containing all elements whose key is k or
2065
//! an empty range that indicates the position where those elements would be
2066
//! if they there is no elements with key k.
2068
//! <b>Complexity</b>: Logarithmic.
2070
//! <b>Throws</b>: If the internal value_compare ordering function throws.
2071
std::pair<const_iterator, const_iterator>
2072
equal_range(const_reference value) const
2073
{ return tree_.equal_range(value); }
2075
//! <b>Requires</b>: comp must imply the same element order as
2076
//! value_compare. Usually key is the part of the value_type
2077
//! that is used in the ordering functor.
2079
//! <b>Effects</b>: Finds a range containing all elements whose key is k
2080
//! according to the comparison functor or an empty range
2081
//! that indicates the position where those elements would be
2082
//! if they there is no elements with key k.
2084
//! <b>Complexity</b>: Logarithmic.
2086
//! <b>Throws</b>: If comp ordering function throws.
2088
//! <b>Note</b>: This function is used when constructing a value_type
2089
//! is expensive and the value_type can be compared with a cheaper
2090
//! key type. Usually this key is part of the value_type.
2091
template<class KeyType, class KeyValueCompare>
2092
std::pair<const_iterator, const_iterator>
2093
equal_range(const KeyType& key, KeyValueCompare comp) const
2094
{ return tree_.equal_range(key, comp); }
2096
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2097
//! appropriate type. Otherwise the behavior is undefined.
2099
//! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
2100
//! that points to the value
2102
//! <b>Complexity</b>: Constant.
2104
//! <b>Throws</b>: Nothing.
2106
//! <b>Note</b>: This static function is available only if the <i>value traits</i>
2108
static iterator s_iterator_to(reference value)
2109
{ return tree_type::s_iterator_to(value); }
2111
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2112
//! appropriate type. Otherwise the behavior is undefined.
2114
//! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2115
//! sg_multiset that points to the value
2117
//! <b>Complexity</b>: Constant.
2119
//! <b>Throws</b>: Nothing.
2121
//! <b>Note</b>: This static function is available only if the <i>value traits</i>
2123
static const_iterator s_iterator_to(const_reference value)
2124
{ return tree_type::s_iterator_to(value); }
2126
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2127
//! appropriate type. Otherwise the behavior is undefined.
2129
//! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
2130
//! that points to the value
2132
//! <b>Complexity</b>: Constant.
2134
//! <b>Throws</b>: Nothing.
2135
iterator iterator_to(reference value)
2136
{ return tree_.iterator_to(value); }
2138
//! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2139
//! appropriate type. Otherwise the behavior is undefined.
2141
//! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2142
//! sg_multiset that points to the value
2144
//! <b>Complexity</b>: Constant.
2146
//! <b>Throws</b>: Nothing.
2147
const_iterator iterator_to(const_reference value) const
2148
{ return tree_.iterator_to(value); }
2150
//! <b>Requires</b>: value shall not be in a sg_multiset/sg_multiset.
2152
//! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2155
//! <b>Throws</b>: Nothing.
2157
//! <b>Complexity</b>: Constant time.
2159
//! <b>Note</b>: This function puts the hook in the well-known default state
2160
//! used by auto_unlink and safe hooks.
2161
static void init_node(reference value)
2162
{ tree_type::init_node(value); }
2164
//! <b>Effects</b>: Unlinks the leftmost node from the tree.
2166
//! <b>Complexity</b>: Average complexity is constant time.
2168
//! <b>Throws</b>: Nothing.
2170
//! <b>Notes</b>: This function breaks the tree and the tree can
2171
//! only be used for more unlink_leftmost_without_rebalance calls.
2172
//! This function is normally used to achieve a step by step
2173
//! controlled destruction of the tree.
2174
pointer unlink_leftmost_without_rebalance()
2175
{ return tree_.unlink_leftmost_without_rebalance(); }
2177
//! <b>Requires</b>: replace_this must be a valid iterator of *this
2178
//! and with_this must not be inserted in any tree.
2180
//! <b>Effects</b>: Replaces replace_this in its position in the
2181
//! tree with with_this. The tree does not need to be rebalanced.
2183
//! <b>Complexity</b>: Constant.
2185
//! <b>Throws</b>: Nothing.
2187
//! <b>Note</b>: This function will break container ordering invariants if
2188
//! with_this is not equivalent to *replace_this according to the
2189
//! ordering rules. This function is faster than erasing and inserting
2190
//! the node, since no rebalancing or comparison is needed.
2191
void replace_node(iterator replace_this, reference with_this)
2192
{ tree_.replace_node(replace_this, with_this); }
2194
//! <b>Effects</b>: Rebalances the tree.
2196
//! <b>Throws</b>: Nothing.
2198
//! <b>Complexity</b>: Linear.
2200
{ tree_.rebalance(); }
2202
//! <b>Requires</b>: old_root is a node of a tree.
2204
//! <b>Effects</b>: Rebalances the subtree rooted at old_root.
2206
//! <b>Returns</b>: The new root of the subtree.
2208
//! <b>Throws</b>: Nothing.
2210
//! <b>Complexity</b>: Linear to the elements in the subtree.
2211
iterator rebalance_subtree(iterator root)
2212
{ return tree_.rebalance_subtree(root); }
2214
//! <b>Returns</b>: The balance factor (alpha) used in this tree
2216
//! <b>Throws</b>: Nothing.
2218
//! <b>Complexity</b>: Constant.
2219
float balance_factor() const
2220
{ return tree_.balance_factor(); }
2222
//! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
2224
//! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
2225
//! the tree if the new balance factor is stricter (less) than the old factor.
2227
//! <b>Throws</b>: Nothing.
2229
//! <b>Complexity</b>: Linear to the elements in the subtree.
2230
void balance_factor(float new_alpha)
2231
{ tree_.balance_factor(new_alpha); }
2234
friend bool operator==(const sg_multiset_impl &x, const sg_multiset_impl &y)
2235
{ return x.tree_ == y.tree_; }
2237
friend bool operator<(const sg_multiset_impl &x, const sg_multiset_impl &y)
2238
{ return x.tree_ < y.tree_; }
2242
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2243
template<class T, class ...Options>
2245
template<class Config>
2247
inline bool operator!=
2248
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2249
(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2251
(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2253
{ return !(x == y); }
2255
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2256
template<class T, class ...Options>
2258
template<class Config>
2260
inline bool operator>
2261
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2262
(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2264
(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2268
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2269
template<class T, class ...Options>
2271
template<class Config>
2273
inline bool operator<=
2274
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2275
(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2277
(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2279
{ return !(y < x); }
2281
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2282
template<class T, class ...Options>
2284
template<class Config>
2286
inline bool operator>=
2287
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2288
(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2290
(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2292
{ return !(x < y); }
2294
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2295
template<class T, class ...Options>
2297
template<class Config>
2300
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2301
(sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y)
2303
(sg_multiset_impl<Config> &x, sg_multiset_impl<Config> &y)
2307
//! Helper metafunction to define a \c sg_multiset that yields to the same type when the
2308
//! same options (either explicitly or implicitly) are used.
2309
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2310
template<class T, class ...Options>
2312
template<class T, class O1 = none, class O2 = none
2313
, class O3 = none, class O4 = none>
2315
struct make_sg_multiset
2318
typedef sg_multiset_impl
2319
< typename make_sgtree_opt<T,
2320
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2326
> implementation_defined;
2328
typedef implementation_defined type;
2331
#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2333
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2334
template<class T, class O1, class O2, class O3, class O4>
2336
template<class T, class ...Options>
2339
: public make_sg_multiset<T,
2340
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2347
typedef typename make_sg_multiset
2349
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2357
typedef typename Base::value_compare value_compare;
2358
typedef typename Base::value_traits value_traits;
2359
typedef typename Base::iterator iterator;
2360
typedef typename Base::const_iterator const_iterator;
2362
//Assert if passed value traits are compatible with the type
2363
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
2365
sg_multiset( const value_compare &cmp = value_compare()
2366
, const value_traits &v_traits = value_traits())
2367
: Base(cmp, v_traits)
2370
template<class Iterator>
2371
sg_multiset( Iterator b, Iterator e
2372
, const value_compare &cmp = value_compare()
2373
, const value_traits &v_traits = value_traits())
2374
: Base(b, e, cmp, v_traits)
2377
static sg_multiset &container_from_end_iterator(iterator end_iterator)
2378
{ return static_cast<sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
2380
static const sg_multiset &container_from_end_iterator(const_iterator end_iterator)
2381
{ return static_cast<const sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
2383
static sg_multiset &container_from_iterator(iterator it)
2384
{ return static_cast<sg_multiset &>(Base::container_from_iterator(it)); }
2386
static const sg_multiset &container_from_iterator(const_iterator it)
2387
{ return static_cast<const sg_multiset &>(Base::container_from_iterator(it)); }
2392
} //namespace intrusive
2395
#include <boost/intrusive/detail/config_end.hpp>
2397
#endif //BOOST_INTRUSIVE_SG_SET_HPP