fix doc example typo
[boost.git] / boost / intrusive / set.hpp
blob40d7c6b78ccb5684d5bbde6f7b27292008f9a977
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2008
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_SET_HPP
14 #define BOOST_INTRUSIVE_SET_HPP
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
19 #include <boost/intrusive/rbtree.hpp>
20 #include <iterator>
22 namespace boost {
23 namespace intrusive {
25 //! The class template set is an intrusive container, that mimics most of
26 //! the interface of std::set as described in the C++ standard.
27 //!
28 //! The template parameter \c T is the type to be managed by the container.
29 //! The user can specify additional options and if no options are provided
30 //! default options are used.
31 //!
32 //! The container supports the following options:
33 //! \c base_hook<>/member_hook<>/value_traits<>,
34 //! \c constant_time_size<>, \c size_type<> and
35 //! \c compare<>.
36 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
37 template<class T, class ...Options>
38 #else
39 template<class Config>
40 #endif
41 class set_impl
43 /// @cond
44 typedef rbtree_impl<Config> tree_type;
45 //! This class is
46 //! non-copyable
47 set_impl (const set_impl&);
49 //! This class is
50 //! non-assignable
51 set_impl &operator =(const set_impl&);
53 typedef tree_type implementation_defined;
54 /// @endcond
56 public:
57 typedef typename implementation_defined::value_type value_type;
58 typedef typename implementation_defined::value_traits value_traits;
59 typedef typename implementation_defined::pointer pointer;
60 typedef typename implementation_defined::const_pointer const_pointer;
61 typedef typename implementation_defined::reference reference;
62 typedef typename implementation_defined::const_reference const_reference;
63 typedef typename implementation_defined::difference_type difference_type;
64 typedef typename implementation_defined::size_type size_type;
65 typedef typename implementation_defined::value_compare value_compare;
66 typedef typename implementation_defined::key_compare key_compare;
67 typedef typename implementation_defined::iterator iterator;
68 typedef typename implementation_defined::const_iterator const_iterator;
69 typedef typename implementation_defined::reverse_iterator reverse_iterator;
70 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
71 typedef typename implementation_defined::insert_commit_data insert_commit_data;
72 typedef typename implementation_defined::node_traits node_traits;
73 typedef typename implementation_defined::node node;
74 typedef typename implementation_defined::node_ptr node_ptr;
75 typedef typename implementation_defined::const_node_ptr const_node_ptr;
76 typedef typename implementation_defined::node_algorithms node_algorithms;
78 /// @cond
79 private:
80 tree_type tree_;
81 /// @endcond
83 public:
84 //! <b>Effects</b>: Constructs an empty set.
85 //!
86 //! <b>Complexity</b>: Constant.
87 //!
88 //! <b>Throws</b>: If value_traits::node_traits::node
89 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
90 //! or the copy constructor of the value_compare object throws.
91 set_impl( const value_compare &cmp = value_compare()
92 , const value_traits &v_traits = value_traits())
93 : tree_(cmp, v_traits)
96 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
97 //! cmp must be a comparison function that induces a strict weak ordering.
98 //!
99 //! <b>Effects</b>: Constructs an empty set and inserts elements from
100 //! [b, e).
101 //!
102 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
103 //! comp and otherwise N * log N, where N is std::distance(last, first).
104 //!
105 //! <b>Throws</b>: If value_traits::node_traits::node
106 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
107 //! or the copy constructor/operator() of the value_compare object throws.
108 template<class Iterator>
109 set_impl( Iterator b, Iterator e
110 , const value_compare &cmp = value_compare()
111 , const value_traits &v_traits = value_traits())
112 : tree_(true, b, e, cmp, v_traits)
115 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
116 //! are not deleted (i.e. no destructors are called).
117 //!
118 //! <b>Complexity</b>: Linear to the number of elements on the container.
119 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
120 //!
121 //! <b>Throws</b>: Nothing.
122 ~set_impl()
125 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the set.
126 //!
127 //! <b>Complexity</b>: Constant.
128 //!
129 //! <b>Throws</b>: Nothing.
130 iterator begin()
131 { return tree_.begin(); }
133 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
134 //!
135 //! <b>Complexity</b>: Constant.
136 //!
137 //! <b>Throws</b>: Nothing.
138 const_iterator begin() const
139 { return tree_.begin(); }
141 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
142 //!
143 //! <b>Complexity</b>: Constant.
144 //!
145 //! <b>Throws</b>: Nothing.
146 const_iterator cbegin() const
147 { return tree_.cbegin(); }
149 //! <b>Effects</b>: Returns an iterator pointing to the end of the set.
150 //!
151 //! <b>Complexity</b>: Constant.
152 //!
153 //! <b>Throws</b>: Nothing.
154 iterator end()
155 { return tree_.end(); }
157 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
158 //!
159 //! <b>Complexity</b>: Constant.
160 //!
161 //! <b>Throws</b>: Nothing.
162 const_iterator end() const
163 { return tree_.end(); }
165 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
166 //!
167 //! <b>Complexity</b>: Constant.
168 //!
169 //! <b>Throws</b>: Nothing.
170 const_iterator cend() const
171 { return tree_.cend(); }
173 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
174 //! reversed set.
175 //!
176 //! <b>Complexity</b>: Constant.
177 //!
178 //! <b>Throws</b>: Nothing.
179 reverse_iterator rbegin()
180 { return tree_.rbegin(); }
182 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
183 //! of the reversed set.
184 //!
185 //! <b>Complexity</b>: Constant.
186 //!
187 //! <b>Throws</b>: Nothing.
188 const_reverse_iterator rbegin() const
189 { return tree_.rbegin(); }
191 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
192 //! of the reversed set.
193 //!
194 //! <b>Complexity</b>: Constant.
195 //!
196 //! <b>Throws</b>: Nothing.
197 const_reverse_iterator crbegin() const
198 { return tree_.crbegin(); }
200 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
201 //! of the reversed set.
202 //!
203 //! <b>Complexity</b>: Constant.
204 //!
205 //! <b>Throws</b>: Nothing.
206 reverse_iterator rend()
207 { return tree_.rend(); }
209 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
210 //! of the reversed set.
211 //!
212 //! <b>Complexity</b>: Constant.
213 //!
214 //! <b>Throws</b>: Nothing.
215 const_reverse_iterator rend() const
216 { return tree_.rend(); }
218 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
219 //! of the reversed set.
220 //!
221 //! <b>Complexity</b>: Constant.
222 //!
223 //! <b>Throws</b>: Nothing.
224 const_reverse_iterator crend() const
225 { return tree_.crend(); }
227 //! <b>Precondition</b>: end_iterator must be a valid end iterator
228 //! of set.
229 //!
230 //! <b>Effects</b>: Returns a reference to the set associated to the end iterator
231 //!
232 //! <b>Throws</b>: Nothing.
233 //!
234 //! <b>Complexity</b>: Constant.
235 static set_impl &container_from_end_iterator(iterator end_iterator)
237 return *detail::parent_from_member<set_impl, tree_type>
238 ( &tree_type::container_from_end_iterator(end_iterator)
239 , &set_impl::tree_);
242 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
243 //! of set.
244 //!
245 //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator
246 //!
247 //! <b>Throws</b>: Nothing.
248 //!
249 //! <b>Complexity</b>: Constant.
250 static const set_impl &container_from_end_iterator(const_iterator end_iterator)
252 return *detail::parent_from_member<set_impl, tree_type>
253 ( &tree_type::container_from_end_iterator(end_iterator)
254 , &set_impl::tree_);
257 //! <b>Precondition</b>: it must be a valid iterator of set.
258 //!
259 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
260 //!
261 //! <b>Throws</b>: Nothing.
262 //!
263 //! <b>Complexity</b>: Logarithmic.
264 static set_impl &container_from_iterator(iterator it)
266 return *detail::parent_from_member<set_impl, tree_type>
267 ( &tree_type::container_from_iterator(it)
268 , &set_impl::tree_);
271 //! <b>Precondition</b>: it must be a valid const_iterator of set.
272 //!
273 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
274 //!
275 //! <b>Throws</b>: Nothing.
276 //!
277 //! <b>Complexity</b>: Logarithmic.
278 static const set_impl &container_from_iterator(const_iterator it)
280 return *detail::parent_from_member<set_impl, tree_type>
281 ( &tree_type::container_from_iterator(it)
282 , &set_impl::tree_);
285 //! <b>Effects</b>: Returns the key_compare object used by the set.
286 //!
287 //! <b>Complexity</b>: Constant.
288 //!
289 //! <b>Throws</b>: If key_compare copy-constructor throws.
290 key_compare key_comp() const
291 { return tree_.value_comp(); }
293 //! <b>Effects</b>: Returns the value_compare object used by the set.
294 //!
295 //! <b>Complexity</b>: Constant.
296 //!
297 //! <b>Throws</b>: If value_compare copy-constructor throws.
298 value_compare value_comp() const
299 { return tree_.value_comp(); }
301 //! <b>Effects</b>: Returns true if the container is empty.
302 //!
303 //! <b>Complexity</b>: Constant.
304 //!
305 //! <b>Throws</b>: Nothing.
306 bool empty() const
307 { return tree_.empty(); }
309 //! <b>Effects</b>: Returns the number of elements stored in the set.
310 //!
311 //! <b>Complexity</b>: Linear to elements contained in *this if,
312 //! constant-time size option is enabled. Constant-time otherwise.
313 //!
314 //! <b>Throws</b>: Nothing.
315 size_type size() const
316 { return tree_.size(); }
318 //! <b>Effects</b>: Swaps the contents of two sets.
319 //!
320 //! <b>Complexity</b>: Constant.
321 //!
322 //! <b>Throws</b>: If the swap() call for the comparison functor
323 //! found using ADL throws. Strong guarantee.
324 void swap(set_impl& other)
325 { tree_.swap(other.tree_); }
327 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
328 //! Cloner should yield to nodes equivalent to the original nodes.
330 //! <b>Effects</b>: Erases all the elements from *this
331 //! calling Disposer::operator()(pointer), clones all the
332 //! elements from src calling Cloner::operator()(const_reference )
333 //! and inserts them on *this. Copies the predicate from the source container.
335 //! If cloner throws, all cloned elements are unlinked and disposed
336 //! calling Disposer::operator()(pointer).
337 //!
338 //! <b>Complexity</b>: Linear to erased plus inserted elements.
339 //!
340 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
341 template <class Cloner, class Disposer>
342 void clone_from(const set_impl &src, Cloner cloner, Disposer disposer)
343 { tree_.clone_from(src.tree_, cloner, disposer); }
345 //! <b>Requires</b>: value must be an lvalue
346 //!
347 //! <b>Effects</b>: Tries to inserts value into the set.
349 //! <b>Returns</b>: If the value
350 //! is not already present inserts it and returns a pair containing the
351 //! iterator to the new value and true. If there is an equivalent value
352 //! returns a pair containing an iterator to the already present value
353 //! and false.
354 //!
355 //! <b>Complexity</b>: Average complexity for insert element is at
356 //! most logarithmic.
357 //!
358 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
359 //!
360 //! <b>Note</b>: Does not affect the validity of iterators and references.
361 //! No copy-constructors are called.
362 std::pair<iterator, bool> insert(reference value)
363 { return tree_.insert_unique(value); }
365 //! <b>Requires</b>: value must be an lvalue
366 //!
367 //! <b>Effects</b>: Tries to to insert x into the set, using "hint"
368 //! as a hint to where it will be inserted.
370 //! <b>Returns</b>: An iterator that points to the position where the
371 //! new element was inserted into the set.
372 //!
373 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
374 //! constant time if t is inserted immediately before hint.
375 //!
376 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
377 //!
378 //! <b>Note</b>: Does not affect the validity of iterators and references.
379 //! No copy-constructors are called.
380 iterator insert(const_iterator hint, reference value)
381 { return tree_.insert_unique(hint, value); }
383 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
384 //! the same strict weak ordering as value_compare. The difference is that
385 //! key_value_comp compares an arbitrary key with the contained values.
386 //!
387 //! <b>Effects</b>: Checks if a value can be inserted in the set, using
388 //! a user provided key instead of the value itself.
390 //! <b>Returns</b>: If there is an equivalent value
391 //! returns a pair containing an iterator to the already present value
392 //! and false. If the value can be inserted returns true in the returned
393 //! pair boolean and fills "commit_data" that is meant to be used with
394 //! the "insert_commit" function.
395 //!
396 //! <b>Complexity</b>: Average complexity is at most logarithmic.
398 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
399 //!
400 //! <b>Notes</b>: This function is used to improve performance when constructing
401 //! a value_type is expensive: if there is an equivalent value
402 //! the constructed object must be discarded. Many times, the part of the
403 //! node that is used to impose the order is much cheaper to construct
404 //! than the value_type and this function offers the possibility to use that
405 //! part to check if the insertion will be successful.
407 //! If the check is successful, the user can construct the value_type and use
408 //! "insert_commit" to insert the object in constant-time. This gives a total
409 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
411 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
412 //! objects are inserted or erased from the set.
413 template<class KeyType, class KeyValueCompare>
414 std::pair<iterator, bool> insert_check
415 (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
416 { return tree_.insert_unique_check(key, key_value_comp, commit_data); }
418 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
419 //! the same strict weak ordering as value_compare. The difference is that
420 //! key_value_comp compares an arbitrary key with the contained values.
421 //!
422 //! <b>Effects</b>: Checks if a value can be inserted in the set, using
423 //! a user provided key instead of the value itself, using "hint"
424 //! as a hint to where it will be inserted.
426 //! <b>Returns</b>: If there is an equivalent value
427 //! returns a pair containing an iterator to the already present value
428 //! and false. If the value can be inserted returns true in the returned
429 //! pair boolean and fills "commit_data" that is meant to be used with
430 //! the "insert_commit" function.
431 //!
432 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
433 //! constant time if t is inserted immediately before hint.
435 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
436 //!
437 //! <b>Notes</b>: This function is used to improve performance when constructing
438 //! a value_type is expensive: if there is an equivalent value
439 //! the constructed object must be discarded. Many times, the part of the
440 //! constructing that is used to impose the order is much cheaper to construct
441 //! than the value_type and this function offers the possibility to use that key
442 //! to check if the insertion will be successful.
444 //! If the check is successful, the user can construct the value_type and use
445 //! "insert_commit" to insert the object in constant-time. This can give a total
446 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
447 //!
448 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
449 //! objects are inserted or erased from the set.
450 template<class KeyType, class KeyValueCompare>
451 std::pair<iterator, bool> insert_check
452 (const_iterator hint, const KeyType &key
453 ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
454 { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }
456 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
457 //! must have been obtained from a previous call to "insert_check".
458 //! No objects should have been inserted or erased from the set between
459 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
460 //!
461 //! <b>Effects</b>: Inserts the value in the set using the information obtained
462 //! from the "commit_data" that a previous "insert_check" filled.
464 //! <b>Returns</b>: An iterator to the newly inserted object.
465 //!
466 //! <b>Complexity</b>: Constant time.
468 //! <b>Throws</b>: Nothing.
469 //!
470 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
471 //! previously executed to fill "commit_data". No value should be inserted or
472 //! erased between the "insert_check" and "insert_commit" calls.
473 iterator insert_commit(reference value, const insert_commit_data &commit_data)
474 { return tree_.insert_unique_commit(value, commit_data); }
476 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
477 //! of type value_type.
478 //!
479 //! <b>Effects</b>: Inserts a range into the set.
480 //!
481 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
482 //! size of the range. However, it is linear in N if the range is already sorted
483 //! by value_comp().
484 //!
485 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
486 //!
487 //! <b>Note</b>: Does not affect the validity of iterators and references.
488 //! No copy-constructors are called.
489 template<class Iterator>
490 void insert(Iterator b, Iterator e)
491 { tree_.insert_unique(b, e); }
493 //! <b>Effects</b>: Erases the element pointed to by pos.
494 //!
495 //! <b>Complexity</b>: Average complexity is constant time.
496 //!
497 //! <b>Returns</b>: An iterator to the element after the erased element.
499 //! <b>Throws</b>: Nothing.
500 //!
501 //! <b>Note</b>: Invalidates the iterators (but not the references)
502 //! to the erased elements. No destructors are called.
503 iterator erase(const_iterator i)
504 { return tree_.erase(i); }
506 //! <b>Effects</b>: Erases the range pointed to by b end e.
507 //!
508 //! <b>Complexity</b>: Average complexity for erase range is at most
509 //! O(log(size() + N)), where N is the number of elements in the range.
510 //!
511 //! <b>Returns</b>: An iterator to the element after the erased elements.
512 //!
513 //! <b>Throws</b>: Nothing.
514 //!
515 //! <b>Note</b>: Invalidates the iterators (but not the references)
516 //! to the erased elements. No destructors are called.
517 iterator erase(const_iterator b, const_iterator e)
518 { return tree_.erase(b, e); }
520 //! <b>Effects</b>: Erases all the elements with the given value.
521 //!
522 //! <b>Returns</b>: The number of erased elements.
523 //!
524 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
525 //!
526 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
527 //!
528 //! <b>Note</b>: Invalidates the iterators (but not the references)
529 //! to the erased elements. No destructors are called.
530 size_type erase(const_reference value)
531 { return tree_.erase(value); }
533 //! <b>Effects</b>: Erases all the elements that compare equal with
534 //! the given key and the given comparison functor.
535 //!
536 //! <b>Returns</b>: The number of erased elements.
537 //!
538 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
539 //!
540 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
541 //!
542 //! <b>Note</b>: Invalidates the iterators (but not the references)
543 //! to the erased elements. No destructors are called.
544 template<class KeyType, class KeyValueCompare>
545 size_type erase(const KeyType& key, KeyValueCompare comp
546 /// @cond
547 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
548 /// @endcond
550 { return tree_.erase(key, comp); }
552 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
554 //! <b>Effects</b>: Erases the element pointed to by pos.
555 //! Disposer::operator()(pointer) is called for the removed element.
556 //!
557 //! <b>Complexity</b>: Average complexity for erase element is constant time.
558 //!
559 //! <b>Returns</b>: An iterator to the element after the erased element.
560 //!
561 //! <b>Throws</b>: Nothing.
562 //!
563 //! <b>Note</b>: Invalidates the iterators
564 //! to the erased elements.
565 template<class Disposer>
566 iterator erase_and_dispose(const_iterator i, Disposer disposer)
567 { return tree_.erase_and_dispose(i, disposer); }
569 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
570 template<class Disposer>
571 iterator erase_and_dispose(iterator i, Disposer disposer)
572 { return this->erase_and_dispose(const_iterator(i), disposer); }
573 #endif
575 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
577 //! <b>Effects</b>: Erases the range pointed to by b end e.
578 //! Disposer::operator()(pointer) is called for the removed elements.
579 //!
580 //! <b>Complexity</b>: Average complexity for erase range is at most
581 //! O(log(size() + N)), where N is the number of elements in the range.
582 //!
583 //! <b>Returns</b>: An iterator to the element after the erased elements.
584 //!
585 //! <b>Throws</b>: Nothing.
586 //!
587 //! <b>Note</b>: Invalidates the iterators
588 //! to the erased elements.
589 template<class Disposer>
590 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
591 { return tree_.erase_and_dispose(b, e, disposer); }
593 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
595 //! <b>Effects</b>: Erases all the elements with the given value.
596 //! Disposer::operator()(pointer) is called for the removed elements.
597 //!
598 //! <b>Throws</b>: If the internal value_compare ordering function throws.
599 //!
600 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
601 //!
602 //! <b>Throws</b>: Nothing.
603 //!
604 //! <b>Note</b>: Invalidates the iterators (but not the references)
605 //! to the erased elements. No destructors are called.
606 template<class Disposer>
607 size_type erase_and_dispose(const_reference value, Disposer disposer)
608 { return tree_.erase_and_dispose(value, disposer); }
610 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
612 //! <b>Effects</b>: Erases all the elements with the given key.
613 //! according to the comparison functor "comp".
614 //! Disposer::operator()(pointer) is called for the removed elements.
616 //! <b>Returns</b>: The number of erased elements.
617 //!
618 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
619 //!
620 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
621 //!
622 //! <b>Note</b>: Invalidates the iterators
623 //! to the erased elements.
624 template<class KeyType, class KeyValueCompare, class Disposer>
625 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
626 /// @cond
627 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
628 /// @endcond
630 { return tree_.erase_and_dispose(key, comp, disposer); }
632 //! <b>Effects</b>: Erases all the elements of the container.
633 //!
634 //! <b>Complexity</b>: Linear to the number of elements on the container.
635 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
636 //!
637 //! <b>Throws</b>: Nothing.
638 //!
639 //! <b>Note</b>: Invalidates the iterators (but not the references)
640 //! to the erased elements. No destructors are called.
641 void clear()
642 { return tree_.clear(); }
644 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
645 //!
646 //! <b>Effects</b>: Erases all the elements of the container.
647 //!
648 //! <b>Complexity</b>: Linear to the number of elements on the container.
649 //! Disposer::operator()(pointer) is called for the removed elements.
650 //!
651 //! <b>Throws</b>: Nothing.
652 //!
653 //! <b>Note</b>: Invalidates the iterators (but not the references)
654 //! to the erased elements. No destructors are called.
655 template<class Disposer>
656 void clear_and_dispose(Disposer disposer)
657 { return tree_.clear_and_dispose(disposer); }
659 //! <b>Effects</b>: Returns the number of contained elements with the given key
660 //!
661 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
662 //! to number of objects with the given key.
663 //!
664 //! <b>Throws</b>: If the internal value_compare ordering function throws.
665 size_type count(const_reference value) const
666 { return tree_.find(value) != end(); }
668 //! <b>Effects</b>: Returns the number of contained elements with the same key
669 //! compared with the given comparison functor.
670 //!
671 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
672 //! to number of objects with the given key.
673 //!
674 //! <b>Throws</b>: If comp ordering function throws.
675 template<class KeyType, class KeyValueCompare>
676 size_type count(const KeyType& key, KeyValueCompare comp) const
677 { return tree_.find(key, comp) != end(); }
679 //! <b>Effects</b>: Returns an iterator to the first element whose
680 //! key is not less than k or end() if that element does not exist.
681 //!
682 //! <b>Complexity</b>: Logarithmic.
683 //!
684 //! <b>Throws</b>: If the internal value_compare ordering function throws.
685 iterator lower_bound(const_reference value)
686 { return tree_.lower_bound(value); }
688 //! <b>Requires</b>: comp must imply the same element order as
689 //! value_compare. Usually key is the part of the value_type
690 //! that is used in the ordering functor.
692 //! <b>Effects</b>: Returns an iterator to the first element whose
693 //! key according to the comparison functor is not less than k or
694 //! end() if that element does not exist.
695 //!
696 //! <b>Complexity</b>: Logarithmic.
697 //!
698 //! <b>Throws</b>: If comp ordering function throws.
699 //!
700 //! <b>Note</b>: This function is used when constructing a value_type
701 //! is expensive and the value_type can be compared with a cheaper
702 //! key type. Usually this key is part of the value_type.
703 template<class KeyType, class KeyValueCompare>
704 iterator lower_bound(const KeyType& key, KeyValueCompare comp)
705 { return tree_.lower_bound(key, comp); }
707 //! <b>Effects</b>: Returns a const iterator to the first element whose
708 //! key is not less than k or end() if that element does not exist.
709 //!
710 //! <b>Complexity</b>: Logarithmic.
711 //!
712 //! <b>Throws</b>: If the internal value_compare ordering function throws.
713 const_iterator lower_bound(const_reference value) const
714 { return tree_.lower_bound(value); }
716 //! <b>Requires</b>: comp must imply the same element order as
717 //! value_compare. Usually key is the part of the value_type
718 //! that is used in the ordering functor.
720 //! <b>Effects</b>: Returns a const_iterator to the first element whose
721 //! key according to the comparison functor is not less than k or
722 //! end() if that element does not exist.
723 //!
724 //! <b>Complexity</b>: Logarithmic.
725 //!
726 //! <b>Throws</b>: If comp ordering function throws.
727 //!
728 //! <b>Note</b>: This function is used when constructing a value_type
729 //! is expensive and the value_type can be compared with a cheaper
730 //! key type. Usually this key is part of the value_type.
731 template<class KeyType, class KeyValueCompare>
732 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
733 { return tree_.lower_bound(key, comp); }
735 //! <b>Effects</b>: Returns an iterator to the first element whose
736 //! key is greater than k or end() if that element does not exist.
737 //!
738 //! <b>Complexity</b>: Logarithmic.
739 //!
740 //! <b>Throws</b>: If the internal value_compare ordering function throws.
741 iterator upper_bound(const_reference value)
742 { return tree_.upper_bound(value); }
744 //! <b>Requires</b>: comp must imply the same element order as
745 //! value_compare. Usually key is the part of the value_type
746 //! that is used in the ordering functor.
748 //! <b>Effects</b>: Returns an iterator to the first element whose
749 //! key according to the comparison functor is greater than key or
750 //! end() if that element does not exist.
751 //!
752 //! <b>Complexity</b>: Logarithmic.
753 //!
754 //! <b>Throws</b>: If comp ordering function throws.
756 //! <b>Note</b>: This function is used when constructing a value_type
757 //! is expensive and the value_type can be compared with a cheaper
758 //! key type. Usually this key is part of the value_type.
759 template<class KeyType, class KeyValueCompare>
760 iterator upper_bound(const KeyType& key, KeyValueCompare comp)
761 { return tree_.upper_bound(key, comp); }
763 //! <b>Effects</b>: Returns an iterator to the first element whose
764 //! key is greater than k or end() if that element does not exist.
765 //!
766 //! <b>Complexity</b>: Logarithmic.
767 //!
768 //! <b>Throws</b>: If the internal value_compare ordering function throws.
769 const_iterator upper_bound(const_reference value) const
770 { return tree_.upper_bound(value); }
772 //! <b>Requires</b>: comp must imply the same element order as
773 //! value_compare. Usually key is the part of the value_type
774 //! that is used in the ordering functor.
776 //! <b>Effects</b>: Returns a const_iterator to the first element whose
777 //! key according to the comparison functor is greater than key or
778 //! end() if that element does not exist.
779 //!
780 //! <b>Complexity</b>: Logarithmic.
781 //!
782 //! <b>Throws</b>: If comp ordering function throws.
784 //! <b>Note</b>: This function is used when constructing a value_type
785 //! is expensive and the value_type can be compared with a cheaper
786 //! key type. Usually this key is part of the value_type.
787 template<class KeyType, class KeyValueCompare>
788 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
789 { return tree_.upper_bound(key, comp); }
791 //! <b>Effects</b>: Finds an iterator to the first element whose value is
792 //! "value" or end() if that element does not exist.
794 //! <b>Complexity</b>: Logarithmic.
795 //!
796 //! <b>Throws</b>: If the internal value_compare ordering function throws.
797 iterator find(const_reference value)
798 { return tree_.find(value); }
800 //! <b>Requires</b>: comp must imply the same element order as
801 //! value_compare. Usually key is the part of the value_type
802 //! that is used in the ordering functor.
804 //! <b>Effects</b>: Finds an iterator to the first element whose key is
805 //! "key" according to the comparison functor or end() if that element
806 //! does not exist.
808 //! <b>Complexity</b>: Logarithmic.
809 //!
810 //! <b>Throws</b>: If comp ordering function throws.
812 //! <b>Note</b>: This function is used when constructing a value_type
813 //! is expensive and the value_type can be compared with a cheaper
814 //! key type. Usually this key is part of the value_type.
815 template<class KeyType, class KeyValueCompare>
816 iterator find(const KeyType& key, KeyValueCompare comp)
817 { return tree_.find(key, comp); }
819 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
820 //! "value" or end() if that element does not exist.
821 //!
822 //! <b>Complexity</b>: Logarithmic.
823 //!
824 //! <b>Throws</b>: If the internal value_compare ordering function throws.
825 const_iterator find(const_reference value) const
826 { return tree_.find(value); }
828 //! <b>Requires</b>: comp must imply the same element order as
829 //! value_compare. Usually key is the part of the value_type
830 //! that is used in the ordering functor.
832 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
833 //! "key" according to the comparison functor or end() if that element
834 //! does not exist.
835 //!
836 //! <b>Complexity</b>: Logarithmic.
837 //!
838 //! <b>Throws</b>: If comp ordering function throws.
840 //! <b>Note</b>: This function is used when constructing a value_type
841 //! is expensive and the value_type can be compared with a cheaper
842 //! key type. Usually this key is part of the value_type.
843 template<class KeyType, class KeyValueCompare>
844 const_iterator find(const KeyType& key, KeyValueCompare comp) const
845 { return tree_.find(key, comp); }
847 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
848 //! an empty range that indicates the position where those elements would be
849 //! if they there is no elements with key k.
850 //!
851 //! <b>Complexity</b>: Logarithmic.
852 //!
853 //! <b>Throws</b>: If the internal value_compare ordering function throws.
854 std::pair<iterator,iterator> equal_range(const_reference value)
855 { return tree_.equal_range(value); }
857 //! <b>Requires</b>: comp must imply the same element order as
858 //! value_compare. Usually key is the part of the value_type
859 //! that is used in the ordering functor.
861 //! <b>Effects</b>: Finds a range containing all elements whose key is k
862 //! according to the comparison functor or an empty range
863 //! that indicates the position where those elements would be
864 //! if they there is no elements with key k.
865 //!
866 //! <b>Complexity</b>: Logarithmic.
867 //!
868 //! <b>Throws</b>: If comp ordering function throws.
870 //! <b>Note</b>: This function is used when constructing a value_type
871 //! is expensive and the value_type can be compared with a cheaper
872 //! key type. Usually this key is part of the value_type.
873 template<class KeyType, class KeyValueCompare>
874 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
875 { return tree_.equal_range(key, comp); }
877 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
878 //! an empty range that indicates the position where those elements would be
879 //! if they there is no elements with key k.
880 //!
881 //! <b>Complexity</b>: Logarithmic.
882 //!
883 //! <b>Throws</b>: If the internal value_compare ordering function throws.
884 std::pair<const_iterator, const_iterator>
885 equal_range(const_reference value) const
886 { return tree_.equal_range(value); }
888 //! <b>Requires</b>: comp must imply the same element order as
889 //! value_compare. Usually key is the part of the value_type
890 //! that is used in the ordering functor.
892 //! <b>Effects</b>: Finds a range containing all elements whose key is k
893 //! according to the comparison functor or an empty range
894 //! that indicates the position where those elements would be
895 //! if they there is no elements with key k.
896 //!
897 //! <b>Complexity</b>: Logarithmic.
898 //!
899 //! <b>Throws</b>: If comp ordering function throws.
901 //! <b>Note</b>: This function is used when constructing a value_type
902 //! is expensive and the value_type can be compared with a cheaper
903 //! key type. Usually this key is part of the value_type.
904 template<class KeyType, class KeyValueCompare>
905 std::pair<const_iterator, const_iterator>
906 equal_range(const KeyType& key, KeyValueCompare comp) const
907 { return tree_.equal_range(key, comp); }
909 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
910 //! appropriate type. Otherwise the behavior is undefined.
911 //!
912 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
913 //! that points to the value
914 //!
915 //! <b>Complexity</b>: Constant.
916 //!
917 //! <b>Throws</b>: Nothing.
918 //!
919 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
920 //! is stateless.
921 static iterator s_iterator_to(reference value)
922 { return tree_type::s_iterator_to(value); }
924 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
925 //! appropriate type. Otherwise the behavior is undefined.
926 //!
927 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
928 //! set that points to the value
929 //!
930 //! <b>Complexity</b>: Constant.
931 //!
932 //! <b>Throws</b>: Nothing.
933 //!
934 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
935 //! is stateless.
936 static const_iterator s_iterator_to(const_reference value)
937 { return tree_type::s_iterator_to(value); }
939 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
940 //! appropriate type. Otherwise the behavior is undefined.
941 //!
942 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
943 //! that points to the value
944 //!
945 //! <b>Complexity</b>: Constant.
946 //!
947 //! <b>Throws</b>: Nothing.
948 iterator iterator_to(reference value)
949 { return tree_.iterator_to(value); }
951 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
952 //! appropriate type. Otherwise the behavior is undefined.
953 //!
954 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
955 //! set that points to the value
956 //!
957 //! <b>Complexity</b>: Constant.
958 //!
959 //! <b>Throws</b>: Nothing.
960 const_iterator iterator_to(const_reference value) const
961 { return tree_.iterator_to(value); }
963 //! <b>Requires</b>: value shall not be in a set/multiset.
964 //!
965 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
966 //! state.
967 //!
968 //! <b>Throws</b>: Nothing.
969 //!
970 //! <b>Complexity</b>: Constant time.
971 //!
972 //! <b>Note</b>: This function puts the hook in the well-known default state
973 //! used by auto_unlink and safe hooks.
974 static void init_node(reference value)
975 { tree_type::init_node(value); }
977 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
978 //!
979 //! <b>Complexity</b>: Average complexity is constant time.
980 //!
981 //! <b>Throws</b>: Nothing.
982 //!
983 //! <b>Notes</b>: This function breaks the tree and the tree can
984 //! only be used for more unlink_leftmost_without_rebalance calls.
985 //! This function is normally used to achieve a step by step
986 //! controlled destruction of the tree.
987 pointer unlink_leftmost_without_rebalance()
988 { return tree_.unlink_leftmost_without_rebalance(); }
990 //! <b>Requires</b>: replace_this must be a valid iterator of *this
991 //! and with_this must not be inserted in any tree.
992 //!
993 //! <b>Effects</b>: Replaces replace_this in its position in the
994 //! tree with with_this. The tree does not need to be rebalanced.
995 //!
996 //! <b>Complexity</b>: Constant.
997 //!
998 //! <b>Throws</b>: Nothing.
999 //!
1000 //! <b>Note</b>: This function will break container ordering invariants if
1001 //! with_this is not equivalent to *replace_this according to the
1002 //! ordering rules. This function is faster than erasing and inserting
1003 //! the node, since no rebalancing or comparison is needed.
1004 void replace_node(iterator replace_this, reference with_this)
1005 { tree_.replace_node(replace_this, with_this); }
1007 /// @cond
1008 friend bool operator==(const set_impl &x, const set_impl &y)
1009 { return x.tree_ == y.tree_; }
1011 friend bool operator<(const set_impl &x, const set_impl &y)
1012 { return x.tree_ < y.tree_; }
1013 /// @endcond
1016 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1017 template<class T, class ...Options>
1018 #else
1019 template<class Config>
1020 #endif
1021 inline bool operator!=
1022 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1023 (const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
1024 #else
1025 (const set_impl<Config> &x, const set_impl<Config> &y)
1026 #endif
1027 { return !(x == y); }
1029 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1030 template<class T, class ...Options>
1031 #else
1032 template<class Config>
1033 #endif
1034 inline bool operator>
1035 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1036 (const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
1037 #else
1038 (const set_impl<Config> &x, const set_impl<Config> &y)
1039 #endif
1040 { return y < x; }
1042 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1043 template<class T, class ...Options>
1044 #else
1045 template<class Config>
1046 #endif
1047 inline bool operator<=
1048 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1049 (const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
1050 #else
1051 (const set_impl<Config> &x, const set_impl<Config> &y)
1052 #endif
1053 { return !(y < x); }
1055 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1056 template<class T, class ...Options>
1057 #else
1058 template<class Config>
1059 #endif
1060 inline bool operator>=
1061 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1062 (const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
1063 #else
1064 (const set_impl<Config> &x, const set_impl<Config> &y)
1065 #endif
1066 { return !(x < y); }
1068 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1069 template<class T, class ...Options>
1070 #else
1071 template<class Config>
1072 #endif
1073 inline void swap
1074 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1075 (set_impl<T, Options...> &x, set_impl<T, Options...> &y)
1076 #else
1077 (set_impl<Config> &x, set_impl<Config> &y)
1078 #endif
1079 { x.swap(y); }
1081 //! Helper metafunction to define a \c set that yields to the same type when the
1082 //! same options (either explicitly or implicitly) are used.
1083 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1084 template<class T, class ...Options>
1085 #else
1086 template<class T, class O1 = none, class O2 = none
1087 , class O3 = none, class O4 = none>
1088 #endif
1089 struct make_set
1091 /// @cond
1092 typedef set_impl
1093 < typename make_rbtree_opt<T,
1094 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1095 O1, O2, O3, O4
1096 #else
1097 Options...
1098 #endif
1099 >::type
1100 > implementation_defined;
1101 /// @endcond
1102 typedef implementation_defined type;
1105 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1106 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1107 template<class T, class O1, class O2, class O3, class O4>
1108 #else
1109 template<class T, class ...Options>
1110 #endif
1111 class set
1112 : public make_set<T,
1113 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1114 O1, O2, O3, O4
1115 #else
1116 Options...
1117 #endif
1118 >::type
1120 typedef typename make_set
1121 <T,
1122 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1123 O1, O2, O3, O4
1124 #else
1125 Options...
1126 #endif
1127 >::type Base;
1129 public:
1130 typedef typename Base::value_compare value_compare;
1131 typedef typename Base::value_traits value_traits;
1132 typedef typename Base::iterator iterator;
1133 typedef typename Base::const_iterator const_iterator;
1135 //Assert if passed value traits are compatible with the type
1136 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
1138 set( const value_compare &cmp = value_compare()
1139 , const value_traits &v_traits = value_traits())
1140 : Base(cmp, v_traits)
1143 template<class Iterator>
1144 set( Iterator b, Iterator e
1145 , const value_compare &cmp = value_compare()
1146 , const value_traits &v_traits = value_traits())
1147 : Base(b, e, cmp, v_traits)
1150 static set &container_from_end_iterator(iterator end_iterator)
1151 { return static_cast<set &>(Base::container_from_end_iterator(end_iterator)); }
1153 static const set &container_from_end_iterator(const_iterator end_iterator)
1154 { return static_cast<const set &>(Base::container_from_end_iterator(end_iterator)); }
1156 static set &container_from_iterator(iterator it)
1157 { return static_cast<set &>(Base::container_from_iterator(it)); }
1159 static const set &container_from_iterator(const_iterator it)
1160 { return static_cast<const set &>(Base::container_from_iterator(it)); }
1163 #endif
1165 //! The class template multiset is an intrusive container, that mimics most of
1166 //! the interface of std::multiset as described in the C++ standard.
1167 //!
1168 //! The template parameter \c T is the type to be managed by the container.
1169 //! The user can specify additional options and if no options are provided
1170 //! default options are used.
1172 //! The container supports the following options:
1173 //! \c base_hook<>/member_hook<>/value_traits<>,
1174 //! \c constant_time_size<>, \c size_type<> and
1175 //! \c compare<>.
1176 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1177 template<class T, class ...Options>
1178 #else
1179 template<class Config>
1180 #endif
1181 class multiset_impl
1183 /// @cond
1184 typedef rbtree_impl<Config> tree_type;
1186 //Non-copyable and non-assignable
1187 multiset_impl (const multiset_impl&);
1188 multiset_impl &operator =(const multiset_impl&);
1189 typedef tree_type implementation_defined;
1190 /// @endcond
1192 public:
1193 typedef typename implementation_defined::value_type value_type;
1194 typedef typename implementation_defined::value_traits value_traits;
1195 typedef typename implementation_defined::pointer pointer;
1196 typedef typename implementation_defined::const_pointer const_pointer;
1197 typedef typename implementation_defined::reference reference;
1198 typedef typename implementation_defined::const_reference const_reference;
1199 typedef typename implementation_defined::difference_type difference_type;
1200 typedef typename implementation_defined::size_type size_type;
1201 typedef typename implementation_defined::value_compare value_compare;
1202 typedef typename implementation_defined::key_compare key_compare;
1203 typedef typename implementation_defined::iterator iterator;
1204 typedef typename implementation_defined::const_iterator const_iterator;
1205 typedef typename implementation_defined::reverse_iterator reverse_iterator;
1206 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
1207 typedef typename implementation_defined::insert_commit_data insert_commit_data;
1208 typedef typename implementation_defined::node_traits node_traits;
1209 typedef typename implementation_defined::node node;
1210 typedef typename implementation_defined::node_ptr node_ptr;
1211 typedef typename implementation_defined::const_node_ptr const_node_ptr;
1212 typedef typename implementation_defined::node_algorithms node_algorithms;
1214 /// @cond
1215 private:
1216 tree_type tree_;
1217 /// @endcond
1219 public:
1220 //! <b>Effects</b>: Constructs an empty multiset.
1221 //!
1222 //! <b>Complexity</b>: Constant.
1223 //!
1224 //! <b>Throws</b>: If value_traits::node_traits::node
1225 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1226 //! or the copy constructor/operator() of the value_compare object throws.
1227 multiset_impl( const value_compare &cmp = value_compare()
1228 , const value_traits &v_traits = value_traits())
1229 : tree_(cmp, v_traits)
1232 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1233 //! cmp must be a comparison function that induces a strict weak ordering.
1234 //!
1235 //! <b>Effects</b>: Constructs an empty multiset and inserts elements from
1236 //! [b, e).
1237 //!
1238 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1239 //! comp and otherwise N * log N, where N is the distance between first and last
1240 //!
1241 //! <b>Throws</b>: If value_traits::node_traits::node
1242 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1243 //! or the copy constructor/operator() of the value_compare object throws.
1244 template<class Iterator>
1245 multiset_impl( Iterator b, Iterator e
1246 , const value_compare &cmp = value_compare()
1247 , const value_traits &v_traits = value_traits())
1248 : tree_(false, b, e, cmp, v_traits)
1251 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
1252 //! are not deleted (i.e. no destructors are called).
1253 //!
1254 //! <b>Complexity</b>: Linear to the number of elements on the container.
1255 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1256 //!
1257 //! <b>Throws</b>: Nothing.
1258 ~multiset_impl()
1261 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the multiset.
1262 //!
1263 //! <b>Complexity</b>: Constant.
1264 //!
1265 //! <b>Throws</b>: Nothing.
1266 iterator begin()
1267 { return tree_.begin(); }
1269 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
1270 //!
1271 //! <b>Complexity</b>: Constant.
1272 //!
1273 //! <b>Throws</b>: Nothing.
1274 const_iterator begin() const
1275 { return tree_.begin(); }
1277 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
1278 //!
1279 //! <b>Complexity</b>: Constant.
1280 //!
1281 //! <b>Throws</b>: Nothing.
1282 const_iterator cbegin() const
1283 { return tree_.cbegin(); }
1285 //! <b>Effects</b>: Returns an iterator pointing to the end of the multiset.
1286 //!
1287 //! <b>Complexity</b>: Constant.
1288 //!
1289 //! <b>Throws</b>: Nothing.
1290 iterator end()
1291 { return tree_.end(); }
1293 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
1294 //!
1295 //! <b>Complexity</b>: Constant.
1296 //!
1297 //! <b>Throws</b>: Nothing.
1298 const_iterator end() const
1299 { return tree_.end(); }
1301 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
1302 //!
1303 //! <b>Complexity</b>: Constant.
1304 //!
1305 //! <b>Throws</b>: Nothing.
1306 const_iterator cend() const
1307 { return tree_.cend(); }
1309 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1310 //! reversed multiset.
1311 //!
1312 //! <b>Complexity</b>: Constant.
1313 //!
1314 //! <b>Throws</b>: Nothing.
1315 reverse_iterator rbegin()
1316 { return tree_.rbegin(); }
1318 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1319 //! of the reversed multiset.
1320 //!
1321 //! <b>Complexity</b>: Constant.
1322 //!
1323 //! <b>Throws</b>: Nothing.
1324 const_reverse_iterator rbegin() const
1325 { return tree_.rbegin(); }
1327 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1328 //! of the reversed multiset.
1329 //!
1330 //! <b>Complexity</b>: Constant.
1331 //!
1332 //! <b>Throws</b>: Nothing.
1333 const_reverse_iterator crbegin() const
1334 { return tree_.crbegin(); }
1336 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1337 //! of the reversed multiset.
1338 //!
1339 //! <b>Complexity</b>: Constant.
1340 //!
1341 //! <b>Throws</b>: Nothing.
1342 reverse_iterator rend()
1343 { return tree_.rend(); }
1345 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1346 //! of the reversed multiset.
1347 //!
1348 //! <b>Complexity</b>: Constant.
1349 //!
1350 //! <b>Throws</b>: Nothing.
1351 const_reverse_iterator rend() const
1352 { return tree_.rend(); }
1354 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1355 //! of the reversed multiset.
1356 //!
1357 //! <b>Complexity</b>: Constant.
1358 //!
1359 //! <b>Throws</b>: Nothing.
1360 const_reverse_iterator crend() const
1361 { return tree_.crend(); }
1363 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1364 //! of multiset.
1365 //!
1366 //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
1367 //!
1368 //! <b>Throws</b>: Nothing.
1369 //!
1370 //! <b>Complexity</b>: Constant.
1371 static multiset_impl &container_from_end_iterator(iterator end_iterator)
1373 return *detail::parent_from_member<multiset_impl, tree_type>
1374 ( &tree_type::container_from_end_iterator(end_iterator)
1375 , &multiset_impl::tree_);
1378 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1379 //! of multiset.
1380 //!
1381 //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
1382 //!
1383 //! <b>Throws</b>: Nothing.
1384 //!
1385 //! <b>Complexity</b>: Constant.
1386 static const multiset_impl &container_from_end_iterator(const_iterator end_iterator)
1388 return *detail::parent_from_member<multiset_impl, tree_type>
1389 ( &tree_type::container_from_end_iterator(end_iterator)
1390 , &multiset_impl::tree_);
1393 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1394 //!
1395 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1396 //!
1397 //! <b>Throws</b>: Nothing.
1398 //!
1399 //! <b>Complexity</b>: Constant.
1400 static multiset_impl &container_from_iterator(iterator it)
1402 return *detail::parent_from_member<multiset_impl, tree_type>
1403 ( &tree_type::container_from_iterator(it)
1404 , &multiset_impl::tree_);
1407 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1408 //!
1409 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1410 //!
1411 //! <b>Throws</b>: Nothing.
1412 //!
1413 //! <b>Complexity</b>: Constant.
1414 static const multiset_impl &container_from_iterator(const_iterator it)
1416 return *detail::parent_from_member<multiset_impl, tree_type>
1417 ( &tree_type::container_from_iterator(it)
1418 , &multiset_impl::tree_);
1421 //! <b>Effects</b>: Returns the key_compare object used by the multiset.
1422 //!
1423 //! <b>Complexity</b>: Constant.
1424 //!
1425 //! <b>Throws</b>: If key_compare copy-constructor throws.
1426 key_compare key_comp() const
1427 { return tree_.value_comp(); }
1429 //! <b>Effects</b>: Returns the value_compare object used by the multiset.
1430 //!
1431 //! <b>Complexity</b>: Constant.
1432 //!
1433 //! <b>Throws</b>: If value_compare copy-constructor throws.
1434 value_compare value_comp() const
1435 { return tree_.value_comp(); }
1437 //! <b>Effects</b>: Returns true if the container is empty.
1438 //!
1439 //! <b>Complexity</b>: Constant.
1440 //!
1441 //! <b>Throws</b>: Nothing.
1442 bool empty() const
1443 { return tree_.empty(); }
1445 //! <b>Effects</b>: Returns the number of elements stored in the multiset.
1446 //!
1447 //! <b>Complexity</b>: Linear to elements contained in *this if,
1448 //! constant-time size option is enabled. Constant-time otherwise.
1449 //!
1450 //! <b>Throws</b>: Nothing.
1451 size_type size() const
1452 { return tree_.size(); }
1454 //! <b>Effects</b>: Swaps the contents of two multisets.
1455 //!
1456 //! <b>Complexity</b>: Constant.
1457 //!
1458 //! <b>Throws</b>: If the swap() call for the comparison functor
1459 //! found using ADL throws. Strong guarantee.
1460 void swap(multiset_impl& other)
1461 { tree_.swap(other.tree_); }
1463 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1464 //! Cloner should yield to nodes equivalent to the original nodes.
1466 //! <b>Effects</b>: Erases all the elements from *this
1467 //! calling Disposer::operator()(pointer), clones all the
1468 //! elements from src calling Cloner::operator()(const_reference )
1469 //! and inserts them on *this. Copies the predicate from the source container.
1471 //! If cloner throws, all cloned elements are unlinked and disposed
1472 //! calling Disposer::operator()(pointer).
1473 //!
1474 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1475 //!
1476 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1477 template <class Cloner, class Disposer>
1478 void clone_from(const multiset_impl &src, Cloner cloner, Disposer disposer)
1479 { tree_.clone_from(src.tree_, cloner, disposer); }
1481 //! <b>Requires</b>: value must be an lvalue
1482 //!
1483 //! <b>Effects</b>: Inserts value into the multiset.
1484 //!
1485 //! <b>Returns</b>: An iterator that points to the position where the new
1486 //! element was inserted.
1487 //!
1488 //! <b>Complexity</b>: Average complexity for insert element is at
1489 //! most logarithmic.
1490 //!
1491 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1492 //!
1493 //! <b>Note</b>: Does not affect the validity of iterators and references.
1494 //! No copy-constructors are called.
1495 iterator insert(reference value)
1496 { return tree_.insert_equal(value); }
1498 //! <b>Requires</b>: value must be an lvalue
1499 //!
1500 //! <b>Effects</b>: Inserts x into the multiset, using pos as a hint to
1501 //! where it will be inserted.
1502 //!
1503 //! <b>Returns</b>: An iterator that points to the position where the new
1504 //! element was inserted.
1505 //!
1506 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1507 //! constant time if t is inserted immediately before hint.
1508 //!
1509 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1510 //!
1511 //! <b>Note</b>: Does not affect the validity of iterators and references.
1512 //! No copy-constructors are called.
1513 iterator insert(const_iterator hint, reference value)
1514 { return tree_.insert_equal(hint, value); }
1516 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1517 //! of type value_type.
1518 //!
1519 //! <b>Effects</b>: Inserts a range into the multiset.
1520 //!
1521 //! <b>Returns</b>: An iterator that points to the position where the new
1522 //! element was inserted.
1523 //!
1524 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1525 //! size of the range. However, it is linear in N if the range is already sorted
1526 //! by value_comp().
1527 //!
1528 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1529 //!
1530 //! <b>Note</b>: Does not affect the validity of iterators and references.
1531 //! No copy-constructors are called.
1532 template<class Iterator>
1533 void insert(Iterator b, Iterator e)
1534 { tree_.insert_equal(b, e); }
1536 //! <b>Effects</b>: Erases the element pointed to by pos.
1537 //!
1538 //! <b>Complexity</b>: Average complexity is constant time.
1539 //!
1540 //! <b>Returns</b>: An iterator to the element after the erased element.
1542 //! <b>Throws</b>: Nothing.
1543 //!
1544 //! <b>Note</b>: Invalidates the iterators (but not the references)
1545 //! to the erased elements. No destructors are called.
1546 iterator erase(const_iterator i)
1547 { return tree_.erase(i); }
1549 //! <b>Effects</b>: Erases the range pointed to by b end e.
1551 //! <b>Returns</b>: An iterator to the element after the erased elements.
1552 //!
1553 //! <b>Complexity</b>: Average complexity for erase range is at most
1554 //! O(log(size() + N)), where N is the number of elements in the range.
1555 //!
1556 //! <b>Throws</b>: Nothing.
1557 //!
1558 //! <b>Note</b>: Invalidates the iterators (but not the references)
1559 //! to the erased elements. No destructors are called.
1560 iterator erase(const_iterator b, iterator e)
1561 { return tree_.erase(b, e); }
1563 //! <b>Effects</b>: Erases all the elements with the given value.
1564 //!
1565 //! <b>Returns</b>: The number of erased elements.
1566 //!
1567 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1568 //!
1569 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1570 //!
1571 //! <b>Note</b>: Invalidates the iterators (but not the references)
1572 //! to the erased elements. No destructors are called.
1573 size_type erase(const_reference value)
1574 { return tree_.erase(value); }
1576 //! <b>Effects</b>: Erases all the elements that compare equal with
1577 //! the given key and the given comparison functor.
1578 //!
1579 //! <b>Returns</b>: The number of erased elements.
1580 //!
1581 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1582 //!
1583 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1584 //!
1585 //! <b>Note</b>: Invalidates the iterators (but not the references)
1586 //! to the erased elements. No destructors are called.
1587 template<class KeyType, class KeyValueCompare>
1588 size_type erase(const KeyType& key, KeyValueCompare comp
1589 /// @cond
1590 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1591 /// @endcond
1593 { return tree_.erase(key, comp); }
1595 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1597 //! <b>Returns</b>: An iterator to the element after the erased element.
1599 //! <b>Effects</b>: Erases the element pointed to by pos.
1600 //! Disposer::operator()(pointer) is called for the removed element.
1601 //!
1602 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1603 //!
1604 //! <b>Throws</b>: Nothing.
1605 //!
1606 //! <b>Note</b>: Invalidates the iterators
1607 //! to the erased elements.
1608 template<class Disposer>
1609 iterator erase_and_dispose(const_iterator i, Disposer disposer)
1610 { return tree_.erase_and_dispose(i, disposer); }
1612 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1613 template<class Disposer>
1614 iterator erase_and_dispose(iterator i, Disposer disposer)
1615 { return this->erase_and_dispose(const_iterator(i), disposer); }
1616 #endif
1618 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1620 //! <b>Returns</b>: An iterator to the element after the erased elements.
1622 //! <b>Effects</b>: Erases the range pointed to by b end e.
1623 //! Disposer::operator()(pointer) is called for the removed elements.
1624 //!
1625 //! <b>Complexity</b>: Average complexity for erase range is at most
1626 //! O(log(size() + N)), where N is the number of elements in the range.
1627 //!
1628 //! <b>Throws</b>: Nothing.
1629 //!
1630 //! <b>Note</b>: Invalidates the iterators
1631 //! to the erased elements.
1632 template<class Disposer>
1633 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
1634 { return tree_.erase_and_dispose(b, e, disposer); }
1636 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1638 //! <b>Effects</b>: Erases all the elements with the given value.
1639 //! Disposer::operator()(pointer) is called for the removed elements.
1640 //!
1641 //! <b>Returns</b>: The number of erased elements.
1642 //!
1643 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1644 //!
1645 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1646 //!
1647 //! <b>Note</b>: Invalidates the iterators (but not the references)
1648 //! to the erased elements. No destructors are called.
1649 template<class Disposer>
1650 size_type erase_and_dispose(const_reference value, Disposer disposer)
1651 { return tree_.erase_and_dispose(value, disposer); }
1653 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1655 //! <b>Effects</b>: Erases all the elements with the given key.
1656 //! according to the comparison functor "comp".
1657 //! Disposer::operator()(pointer) is called for the removed elements.
1659 //! <b>Returns</b>: The number of erased elements.
1660 //!
1661 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1662 //!
1663 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1664 //!
1665 //! <b>Note</b>: Invalidates the iterators
1666 //! to the erased elements.
1667 template<class KeyType, class KeyValueCompare, class Disposer>
1668 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
1669 /// @cond
1670 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1671 /// @endcond
1673 { return tree_.erase_and_dispose(key, comp, disposer); }
1675 //! <b>Effects</b>: Erases all the elements of the container.
1676 //!
1677 //! <b>Complexity</b>: Linear to the number of elements on the container.
1678 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1679 //!
1680 //! <b>Throws</b>: Nothing.
1681 //!
1682 //! <b>Note</b>: Invalidates the iterators (but not the references)
1683 //! to the erased elements. No destructors are called.
1684 void clear()
1685 { return tree_.clear(); }
1687 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1688 //!
1689 //! <b>Effects</b>: Erases all the elements of the container.
1690 //!
1691 //! <b>Complexity</b>: Linear to the number of elements on the container.
1692 //! Disposer::operator()(pointer) is called for the removed elements.
1693 //!
1694 //! <b>Throws</b>: Nothing.
1695 //!
1696 //! <b>Note</b>: Invalidates the iterators (but not the references)
1697 //! to the erased elements. No destructors are called.
1698 template<class Disposer>
1699 void clear_and_dispose(Disposer disposer)
1700 { return tree_.clear_and_dispose(disposer); }
1702 //! <b>Effects</b>: Returns the number of contained elements with the given key
1703 //!
1704 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1705 //! to number of objects with the given key.
1706 //!
1707 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1708 size_type count(const_reference value) const
1709 { return tree_.count(value); }
1711 //! <b>Effects</b>: Returns the number of contained elements with the same key
1712 //! compared with the given comparison functor.
1713 //!
1714 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1715 //! to number of objects with the given key.
1716 //!
1717 //! <b>Throws</b>: If comp ordering function throws.
1718 template<class KeyType, class KeyValueCompare>
1719 size_type count(const KeyType& key, KeyValueCompare comp) const
1720 { return tree_.count(key, comp); }
1722 //! <b>Effects</b>: Returns an iterator to the first element whose
1723 //! key is not less than k or end() if that element does not exist.
1724 //!
1725 //! <b>Complexity</b>: Logarithmic.
1726 //!
1727 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1728 iterator lower_bound(const_reference value)
1729 { return tree_.lower_bound(value); }
1731 //! <b>Requires</b>: comp must imply the same element order as
1732 //! value_compare. Usually key is the part of the value_type
1733 //! that is used in the ordering functor.
1735 //! <b>Effects</b>: Returns an iterator to the first element whose
1736 //! key according to the comparison functor is not less than k or
1737 //! end() if that element does not exist.
1738 //!
1739 //! <b>Complexity</b>: Logarithmic.
1740 //!
1741 //! <b>Throws</b>: If comp ordering function throws.
1742 //!
1743 //! <b>Note</b>: This function is used when constructing a value_type
1744 //! is expensive and the value_type can be compared with a cheaper
1745 //! key type. Usually this key is part of the value_type.
1746 template<class KeyType, class KeyValueCompare>
1747 iterator lower_bound(const KeyType& key, KeyValueCompare comp)
1748 { return tree_.lower_bound(key, comp); }
1750 //! <b>Effects</b>: Returns a const iterator to the first element whose
1751 //! key is not less than k or end() if that element does not exist.
1752 //!
1753 //! <b>Complexity</b>: Logarithmic.
1754 //!
1755 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1756 const_iterator lower_bound(const_reference value) const
1757 { return tree_.lower_bound(value); }
1759 //! <b>Requires</b>: comp must imply the same element order as
1760 //! value_compare. Usually key is the part of the value_type
1761 //! that is used in the ordering functor.
1763 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1764 //! key according to the comparison functor is not less than k or
1765 //! end() if that element does not exist.
1766 //!
1767 //! <b>Complexity</b>: Logarithmic.
1768 //!
1769 //! <b>Throws</b>: If comp ordering function throws.
1770 //!
1771 //! <b>Note</b>: This function is used when constructing a value_type
1772 //! is expensive and the value_type can be compared with a cheaper
1773 //! key type. Usually this key is part of the value_type.
1774 template<class KeyType, class KeyValueCompare>
1775 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
1776 { return tree_.lower_bound(key, comp); }
1778 //! <b>Effects</b>: Returns an iterator to the first element whose
1779 //! key is greater than k or end() if that element does not exist.
1780 //!
1781 //! <b>Complexity</b>: Logarithmic.
1782 //!
1783 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1784 iterator upper_bound(const_reference value)
1785 { return tree_.upper_bound(value); }
1787 //! <b>Requires</b>: comp must imply the same element order as
1788 //! value_compare. Usually key is the part of the value_type
1789 //! that is used in the ordering functor.
1791 //! <b>Effects</b>: Returns an iterator to the first element whose
1792 //! key according to the comparison functor is greater than key or
1793 //! end() if that element does not exist.
1794 //!
1795 //! <b>Complexity</b>: Logarithmic.
1796 //!
1797 //! <b>Throws</b>: If comp ordering function throws.
1799 //! <b>Note</b>: This function is used when constructing a value_type
1800 //! is expensive and the value_type can be compared with a cheaper
1801 //! key type. Usually this key is part of the value_type.
1802 template<class KeyType, class KeyValueCompare>
1803 iterator upper_bound(const KeyType& key, KeyValueCompare comp)
1804 { return tree_.upper_bound(key, comp); }
1806 //! <b>Effects</b>: Returns an iterator to the first element whose
1807 //! key is greater than k or end() if that element does not exist.
1808 //!
1809 //! <b>Complexity</b>: Logarithmic.
1810 //!
1811 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1812 const_iterator upper_bound(const_reference value) const
1813 { return tree_.upper_bound(value); }
1815 //! <b>Requires</b>: comp must imply the same element order as
1816 //! value_compare. Usually key is the part of the value_type
1817 //! that is used in the ordering functor.
1819 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1820 //! key according to the comparison functor is greater than key or
1821 //! end() if that element does not exist.
1822 //!
1823 //! <b>Complexity</b>: Logarithmic.
1824 //!
1825 //! <b>Throws</b>: If comp ordering function throws.
1827 //! <b>Note</b>: This function is used when constructing a value_type
1828 //! is expensive and the value_type can be compared with a cheaper
1829 //! key type. Usually this key is part of the value_type.
1830 template<class KeyType, class KeyValueCompare>
1831 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
1832 { return tree_.upper_bound(key, comp); }
1834 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1835 //! "value" or end() if that element does not exist.
1837 //! <b>Complexity</b>: Logarithmic.
1838 //!
1839 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1840 iterator find(const_reference value)
1841 { return tree_.find(value); }
1843 //! <b>Requires</b>: comp must imply the same element order as
1844 //! value_compare. Usually key is the part of the value_type
1845 //! that is used in the ordering functor.
1847 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1848 //! "key" according to the comparison functor or end() if that element
1849 //! does not exist.
1851 //! <b>Complexity</b>: Logarithmic.
1852 //!
1853 //! <b>Throws</b>: If comp ordering function throws.
1855 //! <b>Note</b>: This function is used when constructing a value_type
1856 //! is expensive and the value_type can be compared with a cheaper
1857 //! key type. Usually this key is part of the value_type.
1858 template<class KeyType, class KeyValueCompare>
1859 iterator find(const KeyType& key, KeyValueCompare comp)
1860 { return tree_.find(key, comp); }
1862 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1863 //! "value" or end() if that element does not exist.
1864 //!
1865 //! <b>Complexity</b>: Logarithmic.
1866 //!
1867 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1868 const_iterator find(const_reference value) const
1869 { return tree_.find(value); }
1871 //! <b>Requires</b>: comp must imply the same element order as
1872 //! value_compare. Usually key is the part of the value_type
1873 //! that is used in the ordering functor.
1875 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1876 //! "key" according to the comparison functor or end() if that element
1877 //! does not exist.
1878 //!
1879 //! <b>Complexity</b>: Logarithmic.
1880 //!
1881 //! <b>Throws</b>: If comp ordering function throws.
1883 //! <b>Note</b>: This function is used when constructing a value_type
1884 //! is expensive and the value_type can be compared with a cheaper
1885 //! key type. Usually this key is part of the value_type.
1886 template<class KeyType, class KeyValueCompare>
1887 const_iterator find(const KeyType& key, KeyValueCompare comp) const
1888 { return tree_.find(key, comp); }
1890 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1891 //! an empty range that indicates the position where those elements would be
1892 //! if they there is no elements with key k.
1893 //!
1894 //! <b>Complexity</b>: Logarithmic.
1895 //!
1896 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1897 std::pair<iterator,iterator> equal_range(const_reference value)
1898 { return tree_.equal_range(value); }
1900 //! <b>Requires</b>: comp must imply the same element order as
1901 //! value_compare. Usually key is the part of the value_type
1902 //! that is used in the ordering functor.
1904 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1905 //! according to the comparison functor or an empty range
1906 //! that indicates the position where those elements would be
1907 //! if they there is no elements with key k.
1908 //!
1909 //! <b>Complexity</b>: Logarithmic.
1910 //!
1911 //! <b>Throws</b>: If comp ordering function throws.
1913 //! <b>Note</b>: This function is used when constructing a value_type
1914 //! is expensive and the value_type can be compared with a cheaper
1915 //! key type. Usually this key is part of the value_type.
1916 template<class KeyType, class KeyValueCompare>
1917 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
1918 { return tree_.equal_range(key, comp); }
1920 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1921 //! an empty range that indicates the position where those elements would be
1922 //! if they there is no elements with key k.
1923 //!
1924 //! <b>Complexity</b>: Logarithmic.
1925 //!
1926 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1927 std::pair<const_iterator, const_iterator>
1928 equal_range(const_reference value) const
1929 { return tree_.equal_range(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>: Finds a range containing all elements whose key is k
1936 //! according to the comparison functor or an empty range
1937 //! that indicates the position where those elements would be
1938 //! if they there is no elements with key k.
1939 //!
1940 //! <b>Complexity</b>: Logarithmic.
1941 //!
1942 //! <b>Throws</b>: If comp ordering function throws.
1944 //! <b>Note</b>: This function is used when constructing a value_type
1945 //! is expensive and the value_type can be compared with a cheaper
1946 //! key type. Usually this key is part of the value_type.
1947 template<class KeyType, class KeyValueCompare>
1948 std::pair<const_iterator, const_iterator>
1949 equal_range(const KeyType& key, KeyValueCompare comp) const
1950 { return tree_.equal_range(key, comp); }
1952 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1953 //! appropriate type. Otherwise the behavior is undefined.
1954 //!
1955 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1956 //! that points to the value
1957 //!
1958 //! <b>Complexity</b>: Constant.
1959 //!
1960 //! <b>Throws</b>: Nothing.
1961 //!
1962 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1963 //! is stateless.
1964 static iterator s_iterator_to(reference value)
1965 { return tree_type::s_iterator_to(value); }
1967 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1968 //! appropriate type. Otherwise the behavior is undefined.
1969 //!
1970 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1971 //! set that points to the value
1972 //!
1973 //! <b>Complexity</b>: Constant.
1974 //!
1975 //! <b>Throws</b>: Nothing.
1976 //!
1977 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1978 //! is stateless.
1979 static const_iterator s_iterator_to(const_reference value)
1980 { return tree_type::s_iterator_to(value); }
1982 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1983 //! appropriate type. Otherwise the behavior is undefined.
1984 //!
1985 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1986 //! that points to the value
1987 //!
1988 //! <b>Complexity</b>: Constant.
1989 //!
1990 //! <b>Throws</b>: Nothing.
1991 iterator iterator_to(reference value)
1992 { return tree_.iterator_to(value); }
1994 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1995 //! appropriate type. Otherwise the behavior is undefined.
1996 //!
1997 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1998 //! set that points to the value
1999 //!
2000 //! <b>Complexity</b>: Constant.
2001 //!
2002 //! <b>Throws</b>: Nothing.
2003 const_iterator iterator_to(const_reference value) const
2004 { return tree_.iterator_to(value); }
2006 //! <b>Requires</b>: value shall not be in a set/multiset.
2007 //!
2008 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2009 //! state.
2010 //!
2011 //! <b>Throws</b>: Nothing.
2012 //!
2013 //! <b>Complexity</b>: Constant time.
2014 //!
2015 //! <b>Note</b>: This function puts the hook in the well-known default state
2016 //! used by auto_unlink and safe hooks.
2017 static void init_node(reference value)
2018 { tree_type::init_node(value); }
2020 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2021 //!
2022 //! <b>Complexity</b>: Average complexity is constant time.
2023 //!
2024 //! <b>Throws</b>: Nothing.
2025 //!
2026 //! <b>Notes</b>: This function breaks the tree and the tree can
2027 //! only be used for more unlink_leftmost_without_rebalance calls.
2028 //! This function is normally used to achieve a step by step
2029 //! controlled destruction of the tree.
2030 pointer unlink_leftmost_without_rebalance()
2031 { return tree_.unlink_leftmost_without_rebalance(); }
2033 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2034 //! and with_this must not be inserted in any tree.
2035 //!
2036 //! <b>Effects</b>: Replaces replace_this in its position in the
2037 //! tree with with_this. The tree does not need to be rebalanced.
2038 //!
2039 //! <b>Complexity</b>: Constant.
2040 //!
2041 //! <b>Throws</b>: Nothing.
2042 //!
2043 //! <b>Note</b>: This function will break container ordering invariants if
2044 //! with_this is not equivalent to *replace_this according to the
2045 //! ordering rules. This function is faster than erasing and inserting
2046 //! the node, since no rebalancing or comparison is needed.
2047 void replace_node(iterator replace_this, reference with_this)
2048 { tree_.replace_node(replace_this, with_this); }
2050 //! <b>Effects</b>: removes "value" from the container.
2051 //!
2052 //! <b>Throws</b>: Nothing.
2053 //!
2054 //! <b>Complexity</b>: Logarithmic time.
2055 //!
2056 //! <b>Note</b>: This static function is only usable with non-constant
2057 //! time size containers that have stateless comparison functors.
2059 //! If the user calls
2060 //! this function with a constant time size container or stateful comparison
2061 //! functor a compilation error will be issued.
2062 static void remove_node(reference value)
2063 { tree_type::remove_node(value); }
2065 /// @cond
2066 friend bool operator==(const multiset_impl &x, const multiset_impl &y)
2067 { return x.tree_ == y.tree_; }
2069 friend bool operator<(const multiset_impl &x, const multiset_impl &y)
2070 { return x.tree_ < y.tree_; }
2071 /// @endcond
2074 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2075 template<class T, class ...Options>
2076 #else
2077 template<class Config>
2078 #endif
2079 inline bool operator!=
2080 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2081 (const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
2082 #else
2083 (const multiset_impl<Config> &x, const multiset_impl<Config> &y)
2084 #endif
2085 { return !(x == y); }
2087 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2088 template<class T, class ...Options>
2089 #else
2090 template<class Config>
2091 #endif
2092 inline bool operator>
2093 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2094 (const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
2095 #else
2096 (const multiset_impl<Config> &x, const multiset_impl<Config> &y)
2097 #endif
2098 { return y < x; }
2100 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2101 template<class T, class ...Options>
2102 #else
2103 template<class Config>
2104 #endif
2105 inline bool operator<=
2106 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2107 (const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
2108 #else
2109 (const multiset_impl<Config> &x, const multiset_impl<Config> &y)
2110 #endif
2111 { return !(y < x); }
2113 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2114 template<class T, class ...Options>
2115 #else
2116 template<class Config>
2117 #endif
2118 inline bool operator>=
2119 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2120 (const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
2121 #else
2122 (const multiset_impl<Config> &x, const multiset_impl<Config> &y)
2123 #endif
2124 { return !(x < y); }
2126 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2127 template<class T, class ...Options>
2128 #else
2129 template<class Config>
2130 #endif
2131 inline void swap
2132 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2133 (multiset_impl<T, Options...> &x, multiset_impl<T, Options...> &y)
2134 #else
2135 (multiset_impl<Config> &x, multiset_impl<Config> &y)
2136 #endif
2137 { x.swap(y); }
2139 //! Helper metafunction to define a \c multiset that yields to the same type when the
2140 //! same options (either explicitly or implicitly) are used.
2141 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2142 template<class T, class ...Options>
2143 #else
2144 template<class T, class O1 = none, class O2 = none
2145 , class O3 = none, class O4 = none>
2146 #endif
2147 struct make_multiset
2149 /// @cond
2150 typedef multiset_impl
2151 < typename make_rbtree_opt<T,
2152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2153 O1, O2, O3, O4
2154 #else
2155 Options...
2156 #endif
2157 >::type
2158 > implementation_defined;
2159 /// @endcond
2160 typedef implementation_defined type;
2163 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2165 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2166 template<class T, class O1, class O2, class O3, class O4>
2167 #else
2168 template<class T, class ...Options>
2169 #endif
2170 class multiset
2171 : public make_multiset<T,
2172 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2173 O1, O2, O3, O4
2174 #else
2175 Options...
2176 #endif
2177 >::type
2179 typedef typename make_multiset<T,
2180 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2181 O1, O2, O3, O4
2182 #else
2183 Options...
2184 #endif
2185 >::type Base;
2187 public:
2188 typedef typename Base::value_compare value_compare;
2189 typedef typename Base::value_traits value_traits;
2190 typedef typename Base::iterator iterator;
2191 typedef typename Base::const_iterator const_iterator;
2193 //Assert if passed value traits are compatible with the type
2194 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
2196 multiset( const value_compare &cmp = value_compare()
2197 , const value_traits &v_traits = value_traits())
2198 : Base(cmp, v_traits)
2201 template<class Iterator>
2202 multiset( Iterator b, Iterator e
2203 , const value_compare &cmp = value_compare()
2204 , const value_traits &v_traits = value_traits())
2205 : Base(b, e, cmp, v_traits)
2208 static multiset &container_from_end_iterator(iterator end_iterator)
2209 { return static_cast<multiset &>(Base::container_from_end_iterator(end_iterator)); }
2211 static const multiset &container_from_end_iterator(const_iterator end_iterator)
2212 { return static_cast<const multiset &>(Base::container_from_end_iterator(end_iterator)); }
2214 static multiset &container_from_iterator(iterator it)
2215 { return static_cast<multiset &>(Base::container_from_iterator(it)); }
2217 static const multiset &container_from_iterator(const_iterator it)
2218 { return static_cast<const multiset &>(Base::container_from_iterator(it)); }
2221 #endif
2223 } //namespace intrusive
2224 } //namespace boost
2226 #include <boost/intrusive/detail/config_end.hpp>
2228 #endif //BOOST_INTRUSIVE_SET_HPP