fix doc example typo
[boost.git] / boost / intrusive / sg_set.hpp
blob4c519c1495aaa7f53e65b8f937dab481bed9b92b
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2008
4 //
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)
8 //
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>
19 #include <iterator>
21 namespace boost {
22 namespace intrusive {
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.
26 //!
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.
30 //!
31 //! The container supports the following options:
32 //! \c base_hook<>/member_hook<>/value_traits<>,
33 //! \c constant_time_size<>, \c size_type<> and
34 //! \c compare<>.
35 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36 template<class T, class ...Options>
37 #else
38 template<class Config>
39 #endif
40 class sg_set_impl
42 /// @cond
43 typedef sgtree_impl<Config> tree_type;
44 //! This class is
45 //! non-copyable
46 sg_set_impl (const sg_set_impl&);
48 //! This class is
49 //! non-assignable
50 sg_set_impl &operator =(const sg_set_impl&);
52 typedef tree_type implementation_defined;
53 /// @endcond
55 public:
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;
77 /// @cond
78 private:
79 tree_type tree_;
80 /// @endcond
82 public:
83 //! <b>Effects</b>: Constructs an empty sg_set.
84 //!
85 //! <b>Complexity</b>: Constant.
86 //!
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.
97 //!
98 //! <b>Effects</b>: Constructs an empty sg_set and inserts elements from
99 //! [b, e).
100 //!
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).
103 //!
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).
116 //!
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.
119 //!
120 //! <b>Throws</b>: Nothing.
121 ~sg_set_impl()
124 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_set.
125 //!
126 //! <b>Complexity</b>: Constant.
127 //!
128 //! <b>Throws</b>: Nothing.
129 iterator begin()
130 { return tree_.begin(); }
132 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set.
133 //!
134 //! <b>Complexity</b>: Constant.
135 //!
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.
141 //!
142 //! <b>Complexity</b>: Constant.
143 //!
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.
149 //!
150 //! <b>Complexity</b>: Constant.
151 //!
152 //! <b>Throws</b>: Nothing.
153 iterator end()
154 { return tree_.end(); }
156 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set.
157 //!
158 //! <b>Complexity</b>: Constant.
159 //!
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.
165 //!
166 //! <b>Complexity</b>: Constant.
167 //!
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
173 //! reversed sg_set.
174 //!
175 //! <b>Complexity</b>: Constant.
176 //!
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.
183 //!
184 //! <b>Complexity</b>: Constant.
185 //!
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.
192 //!
193 //! <b>Complexity</b>: Constant.
194 //!
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.
201 //!
202 //! <b>Complexity</b>: Constant.
203 //!
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.
210 //!
211 //! <b>Complexity</b>: Constant.
212 //!
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.
219 //!
220 //! <b>Complexity</b>: Constant.
221 //!
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
227 //! of sg_set.
228 //!
229 //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
230 //!
231 //! <b>Throws</b>: Nothing.
232 //!
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
242 //! of sg_set.
243 //!
244 //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
245 //!
246 //! <b>Throws</b>: Nothing.
247 //!
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.
257 //!
258 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
259 //!
260 //! <b>Throws</b>: Nothing.
261 //!
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.
271 //!
272 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
273 //!
274 //! <b>Throws</b>: Nothing.
275 //!
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.
285 //!
286 //! <b>Complexity</b>: Constant.
287 //!
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.
293 //!
294 //! <b>Complexity</b>: Constant.
295 //!
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.
301 //!
302 //! <b>Complexity</b>: Constant.
303 //!
304 //! <b>Throws</b>: Nothing.
305 bool empty() const
306 { return tree_.empty(); }
308 //! <b>Effects</b>: Returns the number of elements stored in the sg_set.
309 //!
310 //! <b>Complexity</b>: Linear to elements contained in *this if,
311 //! constant-time size option is enabled. Constant-time otherwise.
312 //!
313 //! <b>Throws</b>: Nothing.
314 size_type size() const
315 { return tree_.size(); }
317 //! <b>Effects</b>: Swaps the contents of two sets.
318 //!
319 //! <b>Complexity</b>: Constant.
320 //!
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).
336 //!
337 //! <b>Complexity</b>: Linear to erased plus inserted elements.
338 //!
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
345 //!
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
352 //! and false.
353 //!
354 //! <b>Complexity</b>: Average complexity for insert element is at
355 //! most logarithmic.
356 //!
357 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
358 //!
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
365 //!
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.
371 //!
372 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
373 //! constant time if t is inserted immediately before hint.
374 //!
375 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
376 //!
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 ascapegoatitrary key with the contained values.
385 //!
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.
394 //!
395 //! <b>Complexity</b>: Average complexity is at most logarithmic.
397 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
398 //!
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 ascapegoatitrary key with the contained values.
420 //!
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.
430 //!
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.
435 //!
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)).
446 //!
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".
459 //!
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.
464 //!
465 //! <b>Complexity</b>: Constant time.
467 //! <b>Throws</b>: Nothing.
468 //!
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.
477 //!
478 //! <b>Effects</b>: Inserts a range into the sg_set.
479 //!
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
482 //! by value_comp().
483 //!
484 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
485 //!
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>Effects</b>: Erases the element pointed to by pos.
493 //!
494 //! <b>Complexity</b>: Average complexity is constant time.
495 //!
496 //! <b>Returns</b>: An iterator to the element after the erased element.
498 //! <b>Throws</b>: Nothing.
499 //!
500 //! <b>Note</b>: Invalidates the iterators (but not the references)
501 //! to the erased elements. No destructors are called.
502 iterator erase(const_iterator i)
503 { return tree_.erase(i); }
505 //! <b>Effects</b>: Erases the range pointed to by b end e.
506 //!
507 //! <b>Complexity</b>: Average complexity for erase range is at most
508 //! O(log(size() + N)), where N is the number of elements in the range.
509 //!
510 //! <b>Returns</b>: An iterator to the element after the erased elements.
511 //!
512 //! <b>Throws</b>: Nothing.
513 //!
514 //! <b>Note</b>: Invalidates the iterators (but not the references)
515 //! to the erased elements. No destructors are called.
516 iterator erase(const_iterator b, const_iterator e)
517 { return tree_.erase(b, e); }
519 //! <b>Effects</b>: Erases all the elements with the given value.
520 //!
521 //! <b>Returns</b>: The number of erased elements.
522 //!
523 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
524 //!
525 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
526 //!
527 //! <b>Note</b>: Invalidates the iterators (but not the references)
528 //! to the erased elements. No destructors are called.
529 size_type erase(const_reference value)
530 { return tree_.erase(value); }
532 //! <b>Effects</b>: Erases all the elements that compare equal with
533 //! the given key and the given comparison functor.
534 //!
535 //! <b>Returns</b>: The number of erased elements.
536 //!
537 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
538 //!
539 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
540 //!
541 //! <b>Note</b>: Invalidates the iterators (but not the references)
542 //! to the erased elements. No destructors are called.
543 template<class KeyType, class KeyValueCompare>
544 size_type erase(const KeyType& key, KeyValueCompare comp
545 /// @cond
546 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
547 /// @endcond
549 { return tree_.erase(key, comp); }
551 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
553 //! <b>Effects</b>: Erases the element pointed to by pos.
554 //! Disposer::operator()(pointer) is called for the removed element.
555 //!
556 //! <b>Complexity</b>: Average complexity for erase element is constant time.
557 //!
558 //! <b>Returns</b>: An iterator to the element after the erased element.
559 //!
560 //! <b>Throws</b>: Nothing.
561 //!
562 //! <b>Note</b>: Invalidates the iterators
563 //! to the erased elements.
564 template<class Disposer>
565 iterator erase_and_dispose(const_iterator i, Disposer disposer)
566 { return tree_.erase_and_dispose(i, disposer); }
568 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
569 template<class Disposer>
570 iterator erase_and_dispose(iterator i, Disposer disposer)
571 { return this->erase_and_dispose(const_iterator(i), disposer); }
572 #endif
574 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
576 //! <b>Effects</b>: Erases the range pointed to by b end e.
577 //! Disposer::operator()(pointer) is called for the removed elements.
578 //!
579 //! <b>Complexity</b>: Average complexity for erase range is at most
580 //! O(log(size() + N)), where N is the number of elements in the range.
581 //!
582 //! <b>Returns</b>: An iterator to the element after the erased elements.
583 //!
584 //! <b>Throws</b>: Nothing.
585 //!
586 //! <b>Note</b>: Invalidates the iterators
587 //! to the erased elements.
588 template<class Disposer>
589 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
590 { return tree_.erase_and_dispose(b, e, disposer); }
592 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
594 //! <b>Effects</b>: Erases all the elements with the given value.
595 //! Disposer::operator()(pointer) is called for the removed elements.
596 //!
597 //! <b>Throws</b>: If the internal value_compare ordering function throws.
598 //!
599 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
600 //!
601 //! <b>Throws</b>: Nothing.
602 //!
603 //! <b>Note</b>: Invalidates the iterators (but not the references)
604 //! to the erased elements. No destructors are called.
605 template<class Disposer>
606 size_type erase_and_dispose(const_reference value, Disposer disposer)
607 { return tree_.erase_and_dispose(value, disposer); }
609 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
611 //! <b>Effects</b>: Erases all the elements with the given key.
612 //! according to the comparison functor "comp".
613 //! Disposer::operator()(pointer) is called for the removed elements.
615 //! <b>Returns</b>: The number of erased elements.
616 //!
617 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
618 //!
619 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
620 //!
621 //! <b>Note</b>: Invalidates the iterators
622 //! to the erased elements.
623 template<class KeyType, class KeyValueCompare, class Disposer>
624 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
625 /// @cond
626 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
627 /// @endcond
629 { return tree_.erase_and_dispose(key, comp, disposer); }
631 //! <b>Effects</b>: Erases all the elements of the container.
632 //!
633 //! <b>Complexity</b>: Linear to the number of elements on the container.
634 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
635 //!
636 //! <b>Throws</b>: Nothing.
637 //!
638 //! <b>Note</b>: Invalidates the iterators (but not the references)
639 //! to the erased elements. No destructors are called.
640 void clear()
641 { return tree_.clear(); }
643 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
644 //!
645 //! <b>Effects</b>: Erases all the elements of the container.
646 //!
647 //! <b>Complexity</b>: Linear to the number of elements on the container.
648 //! Disposer::operator()(pointer) is called for the removed elements.
649 //!
650 //! <b>Throws</b>: Nothing.
651 //!
652 //! <b>Note</b>: Invalidates the iterators (but not the references)
653 //! to the erased elements. No destructors are called.
654 template<class Disposer>
655 void clear_and_dispose(Disposer disposer)
656 { return tree_.clear_and_dispose(disposer); }
658 //! <b>Effects</b>: Returns the number of contained elements with the given key
659 //!
660 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
661 //! to number of objects with the given key.
662 //!
663 //! <b>Throws</b>: If the internal value_compare ordering function throws.
664 size_type count(const_reference value) const
665 { return tree_.find(value) != end(); }
667 //! <b>Effects</b>: Returns the number of contained elements with the same key
668 //! compared with the given comparison functor.
669 //!
670 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
671 //! to number of objects with the given key.
672 //!
673 //! <b>Throws</b>: If comp ordering function throws.
674 template<class KeyType, class KeyValueCompare>
675 size_type count(const KeyType& key, KeyValueCompare comp) const
676 { return tree_.find(key, comp) != end(); }
678 //! <b>Effects</b>: Returns an iterator to the first element whose
679 //! key is not less than k or end() if that element does not exist.
680 //!
681 //! <b>Complexity</b>: Logarithmic.
682 //!
683 //! <b>Throws</b>: If the internal value_compare ordering function throws.
684 iterator lower_bound(const_reference value)
685 { return tree_.lower_bound(value); }
687 //! <b>Requires</b>: comp must imply the same element order as
688 //! value_compare. Usually key is the part of the value_type
689 //! that is used in the ordering functor.
691 //! <b>Effects</b>: Returns an iterator to the first element whose
692 //! key according to the comparison functor is not less than k or
693 //! end() if that element does not exist.
694 //!
695 //! <b>Complexity</b>: Logarithmic.
696 //!
697 //! <b>Throws</b>: If comp ordering function throws.
698 //!
699 //! <b>Note</b>: This function is used when constructing a value_type
700 //! is expensive and the value_type can be compared with a cheaper
701 //! key type. Usually this key is part of the value_type.
702 template<class KeyType, class KeyValueCompare>
703 iterator lower_bound(const KeyType& key, KeyValueCompare comp)
704 { return tree_.lower_bound(key, comp); }
706 //! <b>Effects</b>: Returns a const iterator to the first element whose
707 //! key is not less than k or end() if that element does not exist.
708 //!
709 //! <b>Complexity</b>: Logarithmic.
710 //!
711 //! <b>Throws</b>: If the internal value_compare ordering function throws.
712 const_iterator lower_bound(const_reference value) const
713 { return tree_.lower_bound(value); }
715 //! <b>Requires</b>: comp must imply the same element order as
716 //! value_compare. Usually key is the part of the value_type
717 //! that is used in the ordering functor.
719 //! <b>Effects</b>: Returns a const_iterator to the first element whose
720 //! key according to the comparison functor is not less than k or
721 //! end() if that element does not exist.
722 //!
723 //! <b>Complexity</b>: Logarithmic.
724 //!
725 //! <b>Throws</b>: If comp ordering function throws.
726 //!
727 //! <b>Note</b>: This function is used when constructing a value_type
728 //! is expensive and the value_type can be compared with a cheaper
729 //! key type. Usually this key is part of the value_type.
730 template<class KeyType, class KeyValueCompare>
731 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
732 { return tree_.lower_bound(key, comp); }
734 //! <b>Effects</b>: Returns an iterator to the first element whose
735 //! key is greater than k or end() if that element does not exist.
736 //!
737 //! <b>Complexity</b>: Logarithmic.
738 //!
739 //! <b>Throws</b>: If the internal value_compare ordering function throws.
740 iterator upper_bound(const_reference value)
741 { return tree_.upper_bound(value); }
743 //! <b>Requires</b>: comp must imply the same element order as
744 //! value_compare. Usually key is the part of the value_type
745 //! that is used in the ordering functor.
747 //! <b>Effects</b>: Returns an iterator to the first element whose
748 //! key according to the comparison functor is greater than key or
749 //! end() if that element does not exist.
750 //!
751 //! <b>Complexity</b>: Logarithmic.
752 //!
753 //! <b>Throws</b>: If comp ordering function throws.
755 //! <b>Note</b>: This function is used when constructing a value_type
756 //! is expensive and the value_type can be compared with a cheaper
757 //! key type. Usually this key is part of the value_type.
758 template<class KeyType, class KeyValueCompare>
759 iterator upper_bound(const KeyType& key, KeyValueCompare comp)
760 { return tree_.upper_bound(key, comp); }
762 //! <b>Effects</b>: Returns an iterator to the first element whose
763 //! key is greater than k or end() if that element does not exist.
764 //!
765 //! <b>Complexity</b>: Logarithmic.
766 //!
767 //! <b>Throws</b>: If the internal value_compare ordering function throws.
768 const_iterator upper_bound(const_reference value) const
769 { return tree_.upper_bound(value); }
771 //! <b>Requires</b>: comp must imply the same element order as
772 //! value_compare. Usually key is the part of the value_type
773 //! that is used in the ordering functor.
775 //! <b>Effects</b>: Returns a const_iterator to the first element whose
776 //! key according to the comparison functor is greater than key or
777 //! end() if that element does not exist.
778 //!
779 //! <b>Complexity</b>: Logarithmic.
780 //!
781 //! <b>Throws</b>: If comp ordering function throws.
783 //! <b>Note</b>: This function is used when constructing a value_type
784 //! is expensive and the value_type can be compared with a cheaper
785 //! key type. Usually this key is part of the value_type.
786 template<class KeyType, class KeyValueCompare>
787 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
788 { return tree_.upper_bound(key, comp); }
790 //! <b>Effects</b>: Finds an iterator to the first element whose value is
791 //! "value" or end() if that element does not exist.
793 //! <b>Complexity</b>: Logarithmic.
794 //!
795 //! <b>Throws</b>: If the internal value_compare ordering function throws.
796 iterator find(const_reference value)
797 { return tree_.find(value); }
799 //! <b>Requires</b>: comp must imply the same element order as
800 //! value_compare. Usually key is the part of the value_type
801 //! that is used in the ordering functor.
803 //! <b>Effects</b>: Finds an iterator to the first element whose key is
804 //! "key" according to the comparison functor or end() if that element
805 //! does not exist.
807 //! <b>Complexity</b>: Logarithmic.
808 //!
809 //! <b>Throws</b>: If comp ordering function throws.
811 //! <b>Note</b>: This function is used when constructing a value_type
812 //! is expensive and the value_type can be compared with a cheaper
813 //! key type. Usually this key is part of the value_type.
814 template<class KeyType, class KeyValueCompare>
815 iterator find(const KeyType& key, KeyValueCompare comp)
816 { return tree_.find(key, comp); }
818 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
819 //! "value" or end() if that element does not exist.
820 //!
821 //! <b>Complexity</b>: Logarithmic.
822 //!
823 //! <b>Throws</b>: If the internal value_compare ordering function throws.
824 const_iterator find(const_reference value) const
825 { return tree_.find(value); }
827 //! <b>Requires</b>: comp must imply the same element order as
828 //! value_compare. Usually key is the part of the value_type
829 //! that is used in the ordering functor.
831 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
832 //! "key" according to the comparison functor or end() if that element
833 //! does not exist.
834 //!
835 //! <b>Complexity</b>: Logarithmic.
836 //!
837 //! <b>Throws</b>: If comp ordering function throws.
839 //! <b>Note</b>: This function is used when constructing a value_type
840 //! is expensive and the value_type can be compared with a cheaper
841 //! key type. Usually this key is part of the value_type.
842 template<class KeyType, class KeyValueCompare>
843 const_iterator find(const KeyType& key, KeyValueCompare comp) const
844 { return tree_.find(key, comp); }
846 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
847 //! an empty range that indicates the position where those elements would be
848 //! if they there is no elements with key k.
849 //!
850 //! <b>Complexity</b>: Logarithmic.
851 //!
852 //! <b>Throws</b>: If the internal value_compare ordering function throws.
853 std::pair<iterator,iterator> equal_range(const_reference value)
854 { return tree_.equal_range(value); }
856 //! <b>Requires</b>: comp must imply the same element order as
857 //! value_compare. Usually key is the part of the value_type
858 //! that is used in the ordering functor.
860 //! <b>Effects</b>: Finds a range containing all elements whose key is k
861 //! according to the comparison functor or an empty range
862 //! that indicates the position where those elements would be
863 //! if they there is no elements with key k.
864 //!
865 //! <b>Complexity</b>: Logarithmic.
866 //!
867 //! <b>Throws</b>: If comp ordering function throws.
869 //! <b>Note</b>: This function is used when constructing a value_type
870 //! is expensive and the value_type can be compared with a cheaper
871 //! key type. Usually this key is part of the value_type.
872 template<class KeyType, class KeyValueCompare>
873 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
874 { return tree_.equal_range(key, comp); }
876 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
877 //! an empty range that indicates the position where those elements would be
878 //! if they there is no elements with key k.
879 //!
880 //! <b>Complexity</b>: Logarithmic.
881 //!
882 //! <b>Throws</b>: If the internal value_compare ordering function throws.
883 std::pair<const_iterator, const_iterator>
884 equal_range(const_reference value) const
885 { return tree_.equal_range(value); }
887 //! <b>Requires</b>: comp must imply the same element order as
888 //! value_compare. Usually key is the part of the value_type
889 //! that is used in the ordering functor.
891 //! <b>Effects</b>: Finds a range containing all elements whose key is k
892 //! according to the comparison functor or an empty range
893 //! that indicates the position where those elements would be
894 //! if they there is no elements with key k.
895 //!
896 //! <b>Complexity</b>: Logarithmic.
897 //!
898 //! <b>Throws</b>: If comp ordering function throws.
900 //! <b>Note</b>: This function is used when constructing a value_type
901 //! is expensive and the value_type can be compared with a cheaper
902 //! key type. Usually this key is part of the value_type.
903 template<class KeyType, class KeyValueCompare>
904 std::pair<const_iterator, const_iterator>
905 equal_range(const KeyType& key, KeyValueCompare comp) const
906 { return tree_.equal_range(key, comp); }
908 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
909 //! appropriate type. Otherwise the behavior is undefined.
910 //!
911 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
912 //! that points to the value
913 //!
914 //! <b>Complexity</b>: Constant.
915 //!
916 //! <b>Throws</b>: Nothing.
917 //!
918 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
919 //! is stateless.
920 static iterator s_iterator_to(reference value)
921 { return tree_type::s_iterator_to(value); }
923 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
924 //! appropriate type. Otherwise the behavior is undefined.
925 //!
926 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
927 //! sg_set that points to the value
928 //!
929 //! <b>Complexity</b>: Constant.
930 //!
931 //! <b>Throws</b>: Nothing.
932 //!
933 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
934 //! is stateless.
935 static const_iterator s_iterator_to(const_reference value)
936 { return tree_type::s_iterator_to(value); }
938 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
939 //! appropriate type. Otherwise the behavior is undefined.
940 //!
941 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
942 //! that points to the value
943 //!
944 //! <b>Complexity</b>: Constant.
945 //!
946 //! <b>Throws</b>: Nothing.
947 iterator iterator_to(reference value)
948 { return tree_.iterator_to(value); }
950 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
951 //! appropriate type. Otherwise the behavior is undefined.
952 //!
953 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
954 //! sg_set that points to the value
955 //!
956 //! <b>Complexity</b>: Constant.
957 //!
958 //! <b>Throws</b>: Nothing.
959 const_iterator iterator_to(const_reference value) const
960 { return tree_.iterator_to(value); }
962 //! <b>Requires</b>: value shall not be in a sg_set/sg_multiset.
963 //!
964 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
965 //! state.
966 //!
967 //! <b>Throws</b>: Nothing.
968 //!
969 //! <b>Complexity</b>: Constant time.
970 //!
971 //! <b>Note</b>: This function puts the hook in the well-known default state
972 //! used by auto_unlink and safe hooks.
973 static void init_node(reference value)
974 { tree_type::init_node(value); }
976 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
977 //!
978 //! <b>Complexity</b>: Average complexity is constant time.
979 //!
980 //! <b>Throws</b>: Nothing.
981 //!
982 //! <b>Notes</b>: This function breaks the tree and the tree can
983 //! only be used for more unlink_leftmost_without_rebalance calls.
984 //! This function is normally used to achieve a step by step
985 //! controlled destruction of the tree.
986 pointer unlink_leftmost_without_rebalance()
987 { return tree_.unlink_leftmost_without_rebalance(); }
989 //! <b>Requires</b>: replace_this must be a valid iterator of *this
990 //! and with_this must not be inserted in any tree.
991 //!
992 //! <b>Effects</b>: Replaces replace_this in its position in the
993 //! tree with with_this. The tree does not need to be rebalanced.
994 //!
995 //! <b>Complexity</b>: Constant.
996 //!
997 //! <b>Throws</b>: Nothing.
998 //!
999 //! <b>Note</b>: This function will break container ordering invariants if
1000 //! with_this is not equivalent to *replace_this according to the
1001 //! ordering rules. This function is faster than erasing and inserting
1002 //! the node, since no rebalancing or comparison is needed.
1003 void replace_node(iterator replace_this, reference with_this)
1004 { tree_.replace_node(replace_this, with_this); }
1006 //! <b>Effects</b>: Rebalances the tree.
1007 //!
1008 //! <b>Throws</b>: Nothing.
1009 //!
1010 //! <b>Complexity</b>: Linear.
1011 void rebalance()
1012 { tree_.rebalance(); }
1014 //! <b>Requires</b>: old_root is a node of a tree.
1015 //!
1016 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1018 //! <b>Returns</b>: The new root of the subtree.
1020 //! <b>Throws</b>: Nothing.
1021 //!
1022 //! <b>Complexity</b>: Linear to the elements in the subtree.
1023 iterator rebalance_subtree(iterator root)
1024 { return tree_.rebalance_subtree(root); }
1026 //! <b>Returns</b>: The balance factor (alpha) used in this tree
1028 //! <b>Throws</b>: Nothing.
1029 //!
1030 //! <b>Complexity</b>: Constant.
1031 float balance_factor() const
1032 { return tree_.balance_factor(); }
1034 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
1035 //!
1036 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
1037 //! the tree if the new balance factor is stricter (less) than the old factor.
1039 //! <b>Throws</b>: Nothing.
1040 //!
1041 //! <b>Complexity</b>: Linear to the elements in the subtree.
1042 void balance_factor(float new_alpha)
1043 { tree_.balance_factor(new_alpha); }
1045 /// @cond
1046 friend bool operator==(const sg_set_impl &x, const sg_set_impl &y)
1047 { return x.tree_ == y.tree_; }
1049 friend bool operator<(const sg_set_impl &x, const sg_set_impl &y)
1050 { return x.tree_ < y.tree_; }
1051 /// @endcond
1054 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1055 template<class T, class ...Options>
1056 #else
1057 template<class Config>
1058 #endif
1059 inline bool operator!=
1060 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1061 (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1062 #else
1063 (const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1064 #endif
1065 { return !(x == y); }
1067 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1068 template<class T, class ...Options>
1069 #else
1070 template<class Config>
1071 #endif
1072 inline bool operator>
1073 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1074 (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1075 #else
1076 (const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1077 #endif
1078 { return y < x; }
1080 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1081 template<class T, class ...Options>
1082 #else
1083 template<class Config>
1084 #endif
1085 inline bool operator<=
1086 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1087 (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1088 #else
1089 (const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1090 #endif
1091 { return !(y < x); }
1093 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1094 template<class T, class ...Options>
1095 #else
1096 template<class Config>
1097 #endif
1098 inline bool operator>=
1099 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1100 (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
1101 #else
1102 (const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
1103 #endif
1104 { return !(x < y); }
1106 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1107 template<class T, class ...Options>
1108 #else
1109 template<class Config>
1110 #endif
1111 inline void swap
1112 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1113 (sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y)
1114 #else
1115 (sg_set_impl<Config> &x, sg_set_impl<Config> &y)
1116 #endif
1117 { x.swap(y); }
1119 //! Helper metafunction to define a \c sg_set that yields to the same type when the
1120 //! same options (either explicitly or implicitly) are used.
1121 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1122 template<class T, class ...Options>
1123 #else
1124 template<class T, class O1 = none, class O2 = none
1125 , class O3 = none, class O4 = none>
1126 #endif
1127 struct make_sg_set
1129 /// @cond
1130 typedef sg_set_impl
1131 < typename make_sgtree_opt<T,
1132 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1133 O1, O2, O3, O4
1134 #else
1135 Options...
1136 #endif
1137 >::type
1138 > implementation_defined;
1139 /// @endcond
1140 typedef implementation_defined type;
1143 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1145 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1146 template<class T, class O1, class O2, class O3, class O4>
1147 #else
1148 template<class T, class ...Options>
1149 #endif
1150 class sg_set
1151 : public make_sg_set<T,
1152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1153 O1, O2, O3, O4
1154 #else
1155 Options...
1156 #endif
1157 >::type
1159 typedef typename make_sg_set
1160 <T,
1161 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1162 O1, O2, O3, O4
1163 #else
1164 Options...
1165 #endif
1166 >::type Base;
1168 public:
1169 typedef typename Base::value_compare value_compare;
1170 typedef typename Base::value_traits value_traits;
1171 typedef typename Base::iterator iterator;
1172 typedef typename Base::const_iterator const_iterator;
1174 //Assert if passed value traits are compatible with the type
1175 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
1177 sg_set( const value_compare &cmp = value_compare()
1178 , const value_traits &v_traits = value_traits())
1179 : Base(cmp, v_traits)
1182 template<class Iterator>
1183 sg_set( Iterator b, Iterator e
1184 , const value_compare &cmp = value_compare()
1185 , const value_traits &v_traits = value_traits())
1186 : Base(b, e, cmp, v_traits)
1189 static sg_set &container_from_end_iterator(iterator end_iterator)
1190 { return static_cast<sg_set &>(Base::container_from_end_iterator(end_iterator)); }
1192 static const sg_set &container_from_end_iterator(const_iterator end_iterator)
1193 { return static_cast<const sg_set &>(Base::container_from_end_iterator(end_iterator)); }
1195 static sg_set &container_from_iterator(iterator it)
1196 { return static_cast<sg_set &>(Base::container_from_iterator(it)); }
1198 static const sg_set &container_from_iterator(const_iterator it)
1199 { return static_cast<const sg_set &>(Base::container_from_iterator(it)); }
1202 #endif
1204 //! The class template sg_multiset is an intrusive container, that mimics most of
1205 //! the interface of std::sg_multiset as described in the C++ standard.
1206 //!
1207 //! The template parameter \c T is the type to be managed by the container.
1208 //! The user can specify additional options and if no options are provided
1209 //! default options are used.
1211 //! The container supports the following options:
1212 //! \c base_hook<>/member_hook<>/value_traits<>,
1213 //! \c constant_time_size<>, \c size_type<> and
1214 //! \c compare<>.
1215 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1216 template<class T, class ...Options>
1217 #else
1218 template<class Config>
1219 #endif
1220 class sg_multiset_impl
1222 /// @cond
1223 typedef sgtree_impl<Config> tree_type;
1225 //Non-copyable and non-assignable
1226 sg_multiset_impl (const sg_multiset_impl&);
1227 sg_multiset_impl &operator =(const sg_multiset_impl&);
1228 typedef tree_type implementation_defined;
1229 /// @endcond
1231 public:
1232 typedef typename implementation_defined::value_type value_type;
1233 typedef typename implementation_defined::value_traits value_traits;
1234 typedef typename implementation_defined::pointer pointer;
1235 typedef typename implementation_defined::const_pointer const_pointer;
1236 typedef typename implementation_defined::reference reference;
1237 typedef typename implementation_defined::const_reference const_reference;
1238 typedef typename implementation_defined::difference_type difference_type;
1239 typedef typename implementation_defined::size_type size_type;
1240 typedef typename implementation_defined::value_compare value_compare;
1241 typedef typename implementation_defined::key_compare key_compare;
1242 typedef typename implementation_defined::iterator iterator;
1243 typedef typename implementation_defined::const_iterator const_iterator;
1244 typedef typename implementation_defined::reverse_iterator reverse_iterator;
1245 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
1246 typedef typename implementation_defined::insert_commit_data insert_commit_data;
1247 typedef typename implementation_defined::node_traits node_traits;
1248 typedef typename implementation_defined::node node;
1249 typedef typename implementation_defined::node_ptr node_ptr;
1250 typedef typename implementation_defined::const_node_ptr const_node_ptr;
1251 typedef typename implementation_defined::node_algorithms node_algorithms;
1253 /// @cond
1254 private:
1255 tree_type tree_;
1256 /// @endcond
1258 public:
1259 //! <b>Effects</b>: Constructs an empty sg_multiset.
1260 //!
1261 //! <b>Complexity</b>: Constant.
1262 //!
1263 //! <b>Throws</b>: If value_traits::node_traits::node
1264 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1265 //! or the copy constructor/operator() of the value_compare object throws.
1266 sg_multiset_impl( const value_compare &cmp = value_compare()
1267 , const value_traits &v_traits = value_traits())
1268 : tree_(cmp, v_traits)
1271 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1272 //! cmp must be a comparison function that induces a strict weak ordering.
1273 //!
1274 //! <b>Effects</b>: Constructs an empty sg_multiset and inserts elements from
1275 //! [b, e).
1276 //!
1277 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1278 //! comp and otherwise N * log N, where N is the distance between first and last
1279 //!
1280 //! <b>Throws</b>: If value_traits::node_traits::node
1281 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1282 //! or the copy constructor/operator() of the value_compare object throws.
1283 template<class Iterator>
1284 sg_multiset_impl( Iterator b, Iterator e
1285 , const value_compare &cmp = value_compare()
1286 , const value_traits &v_traits = value_traits())
1287 : tree_(false, b, e, cmp, v_traits)
1290 //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_multiset
1291 //! are not deleted (i.e. no destructors are called).
1292 //!
1293 //! <b>Complexity</b>: Linear to the number of elements on the container.
1294 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1295 //!
1296 //! <b>Throws</b>: Nothing.
1297 ~sg_multiset_impl()
1300 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_multiset.
1301 //!
1302 //! <b>Complexity</b>: Constant.
1303 //!
1304 //! <b>Throws</b>: Nothing.
1305 iterator begin()
1306 { return tree_.begin(); }
1308 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1309 //!
1310 //! <b>Complexity</b>: Constant.
1311 //!
1312 //! <b>Throws</b>: Nothing.
1313 const_iterator begin() const
1314 { return tree_.begin(); }
1316 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1317 //!
1318 //! <b>Complexity</b>: Constant.
1319 //!
1320 //! <b>Throws</b>: Nothing.
1321 const_iterator cbegin() const
1322 { return tree_.cbegin(); }
1324 //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_multiset.
1325 //!
1326 //! <b>Complexity</b>: Constant.
1327 //!
1328 //! <b>Throws</b>: Nothing.
1329 iterator end()
1330 { return tree_.end(); }
1332 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1333 //!
1334 //! <b>Complexity</b>: Constant.
1335 //!
1336 //! <b>Throws</b>: Nothing.
1337 const_iterator end() const
1338 { return tree_.end(); }
1340 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1341 //!
1342 //! <b>Complexity</b>: Constant.
1343 //!
1344 //! <b>Throws</b>: Nothing.
1345 const_iterator cend() const
1346 { return tree_.cend(); }
1348 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1349 //! reversed sg_multiset.
1350 //!
1351 //! <b>Complexity</b>: Constant.
1352 //!
1353 //! <b>Throws</b>: Nothing.
1354 reverse_iterator rbegin()
1355 { return tree_.rbegin(); }
1357 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1358 //! of the reversed sg_multiset.
1359 //!
1360 //! <b>Complexity</b>: Constant.
1361 //!
1362 //! <b>Throws</b>: Nothing.
1363 const_reverse_iterator rbegin() const
1364 { return tree_.rbegin(); }
1366 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1367 //! of the reversed sg_multiset.
1368 //!
1369 //! <b>Complexity</b>: Constant.
1370 //!
1371 //! <b>Throws</b>: Nothing.
1372 const_reverse_iterator crbegin() const
1373 { return tree_.crbegin(); }
1375 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1376 //! of the reversed sg_multiset.
1377 //!
1378 //! <b>Complexity</b>: Constant.
1379 //!
1380 //! <b>Throws</b>: Nothing.
1381 reverse_iterator rend()
1382 { return tree_.rend(); }
1384 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1385 //! of the reversed sg_multiset.
1386 //!
1387 //! <b>Complexity</b>: Constant.
1388 //!
1389 //! <b>Throws</b>: Nothing.
1390 const_reverse_iterator rend() const
1391 { return tree_.rend(); }
1393 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1394 //! of the reversed sg_multiset.
1395 //!
1396 //! <b>Complexity</b>: Constant.
1397 //!
1398 //! <b>Throws</b>: Nothing.
1399 const_reverse_iterator crend() const
1400 { return tree_.crend(); }
1402 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1403 //! of sg_multiset.
1404 //!
1405 //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1406 //!
1407 //! <b>Throws</b>: Nothing.
1408 //!
1409 //! <b>Complexity</b>: Constant.
1410 static sg_multiset_impl &container_from_end_iterator(iterator end_iterator)
1412 return *detail::parent_from_member<sg_multiset_impl, tree_type>
1413 ( &tree_type::container_from_end_iterator(end_iterator)
1414 , &sg_multiset_impl::tree_);
1417 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1418 //! of sg_multiset.
1419 //!
1420 //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1421 //!
1422 //! <b>Throws</b>: Nothing.
1423 //!
1424 //! <b>Complexity</b>: Constant.
1425 static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator)
1427 return *detail::parent_from_member<sg_multiset_impl, tree_type>
1428 ( &tree_type::container_from_end_iterator(end_iterator)
1429 , &sg_multiset_impl::tree_);
1432 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1433 //!
1434 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1435 //!
1436 //! <b>Throws</b>: Nothing.
1437 //!
1438 //! <b>Complexity</b>: Constant.
1439 static sg_multiset_impl &container_from_iterator(iterator it)
1441 return *detail::parent_from_member<sg_multiset_impl, tree_type>
1442 ( &tree_type::container_from_iterator(it)
1443 , &sg_multiset_impl::tree_);
1446 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1447 //!
1448 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1449 //!
1450 //! <b>Throws</b>: Nothing.
1451 //!
1452 //! <b>Complexity</b>: Constant.
1453 static const sg_multiset_impl &container_from_iterator(const_iterator it)
1455 return *detail::parent_from_member<sg_multiset_impl, tree_type>
1456 ( &tree_type::container_from_iterator(it)
1457 , &sg_multiset_impl::tree_);
1460 //! <b>Effects</b>: Returns the key_compare object used by the sg_multiset.
1461 //!
1462 //! <b>Complexity</b>: Constant.
1463 //!
1464 //! <b>Throws</b>: If key_compare copy-constructor throws.
1465 key_compare key_comp() const
1466 { return tree_.value_comp(); }
1468 //! <b>Effects</b>: Returns the value_compare object used by the sg_multiset.
1469 //!
1470 //! <b>Complexity</b>: Constant.
1471 //!
1472 //! <b>Throws</b>: If value_compare copy-constructor throws.
1473 value_compare value_comp() const
1474 { return tree_.value_comp(); }
1476 //! <b>Effects</b>: Returns true if the container is empty.
1477 //!
1478 //! <b>Complexity</b>: Constant.
1479 //!
1480 //! <b>Throws</b>: Nothing.
1481 bool empty() const
1482 { return tree_.empty(); }
1484 //! <b>Effects</b>: Returns the number of elements stored in the sg_multiset.
1485 //!
1486 //! <b>Complexity</b>: Linear to elements contained in *this if,
1487 //! constant-time size option is enabled. Constant-time otherwise.
1488 //!
1489 //! <b>Throws</b>: Nothing.
1490 size_type size() const
1491 { return tree_.size(); }
1493 //! <b>Effects</b>: Swaps the contents of two sg_multisets.
1494 //!
1495 //! <b>Complexity</b>: Constant.
1496 //!
1497 //! <b>Throws</b>: If the swap() call for the comparison functor
1498 //! found using ADL throws. Strong guarantee.
1499 void swap(sg_multiset_impl& other)
1500 { tree_.swap(other.tree_); }
1502 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1503 //! Cloner should yield to nodes equivalent to the original nodes.
1505 //! <b>Effects</b>: Erases all the elements from *this
1506 //! calling Disposer::operator()(pointer), clones all the
1507 //! elements from src calling Cloner::operator()(const_reference )
1508 //! and inserts them on *this. Copies the predicate from the source container.
1510 //! If cloner throws, all cloned elements are unlinked and disposed
1511 //! calling Disposer::operator()(pointer).
1512 //!
1513 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1514 //!
1515 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1516 template <class Cloner, class Disposer>
1517 void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer)
1518 { tree_.clone_from(src.tree_, cloner, disposer); }
1520 //! <b>Requires</b>: value must be an lvalue
1521 //!
1522 //! <b>Effects</b>: Inserts value into the sg_multiset.
1523 //!
1524 //! <b>Returns</b>: An iterator that points to the position where the new
1525 //! element was inserted.
1526 //!
1527 //! <b>Complexity</b>: Average complexity for insert element is at
1528 //! most logarithmic.
1529 //!
1530 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1531 //!
1532 //! <b>Note</b>: Does not affect the validity of iterators and references.
1533 //! No copy-constructors are called.
1534 iterator insert(reference value)
1535 { return tree_.insert_equal(value); }
1537 //! <b>Requires</b>: value must be an lvalue
1538 //!
1539 //! <b>Effects</b>: Inserts x into the sg_multiset, using pos as a hint to
1540 //! where it will be inserted.
1541 //!
1542 //! <b>Returns</b>: An iterator that points to the position where the new
1543 //! element was inserted.
1544 //!
1545 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1546 //! constant time if t is inserted immediately before hint.
1547 //!
1548 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1549 //!
1550 //! <b>Note</b>: Does not affect the validity of iterators and references.
1551 //! No copy-constructors are called.
1552 iterator insert(const_iterator hint, reference value)
1553 { return tree_.insert_equal(hint, value); }
1555 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1556 //! of type value_type.
1557 //!
1558 //! <b>Effects</b>: Inserts a range into the sg_multiset.
1559 //!
1560 //! <b>Returns</b>: An iterator that points to the position where the new
1561 //! element was inserted.
1562 //!
1563 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1564 //! size of the range. However, it is linear in N if the range is already sorted
1565 //! by value_comp().
1566 //!
1567 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1568 //!
1569 //! <b>Note</b>: Does not affect the validity of iterators and references.
1570 //! No copy-constructors are called.
1571 template<class Iterator>
1572 void insert(Iterator b, Iterator e)
1573 { tree_.insert_equal(b, e); }
1575 //! <b>Effects</b>: Erases the element pointed to by pos.
1576 //!
1577 //! <b>Complexity</b>: Average complexity is constant time.
1578 //!
1579 //! <b>Returns</b>: An iterator to the element after the erased element.
1581 //! <b>Throws</b>: Nothing.
1582 //!
1583 //! <b>Note</b>: Invalidates the iterators (but not the references)
1584 //! to the erased elements. No destructors are called.
1585 iterator erase(const_iterator i)
1586 { return tree_.erase(i); }
1588 //! <b>Effects</b>: Erases the range pointed to by b end e.
1590 //! <b>Returns</b>: An iterator to the element after the erased elements.
1591 //!
1592 //! <b>Complexity</b>: Average complexity for erase range is at most
1593 //! O(log(size() + N)), where N is the number of elements in the range.
1594 //!
1595 //! <b>Throws</b>: Nothing.
1596 //!
1597 //! <b>Note</b>: Invalidates the iterators (but not the references)
1598 //! to the erased elements. No destructors are called.
1599 iterator erase(const_iterator b, const_iterator e)
1600 { return tree_.erase(b, e); }
1602 //! <b>Effects</b>: Erases all the elements with the given value.
1603 //!
1604 //! <b>Returns</b>: The number of erased elements.
1605 //!
1606 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1607 //!
1608 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1609 //!
1610 //! <b>Note</b>: Invalidates the iterators (but not the references)
1611 //! to the erased elements. No destructors are called.
1612 size_type erase(const_reference value)
1613 { return tree_.erase(value); }
1615 //! <b>Effects</b>: Erases all the elements that compare equal with
1616 //! the given key and the given comparison functor.
1617 //!
1618 //! <b>Returns</b>: The number of erased elements.
1619 //!
1620 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1621 //!
1622 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1623 //!
1624 //! <b>Note</b>: Invalidates the iterators (but not the references)
1625 //! to the erased elements. No destructors are called.
1626 template<class KeyType, class KeyValueCompare>
1627 size_type erase(const KeyType& key, KeyValueCompare comp
1628 /// @cond
1629 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1630 /// @endcond
1632 { return tree_.erase(key, comp); }
1634 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1636 //! <b>Returns</b>: An iterator to the element after the erased element.
1638 //! <b>Effects</b>: Erases the element pointed to by pos.
1639 //! Disposer::operator()(pointer) is called for the removed element.
1640 //!
1641 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1642 //!
1643 //! <b>Throws</b>: Nothing.
1644 //!
1645 //! <b>Note</b>: Invalidates the iterators
1646 //! to the erased elements.
1647 template<class Disposer>
1648 iterator erase_and_dispose(const_iterator i, Disposer disposer)
1649 { return tree_.erase_and_dispose(i, disposer); }
1651 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1652 template<class Disposer>
1653 iterator erase_and_dispose(iterator i, Disposer disposer)
1654 { return this->erase_and_dispose(const_iterator(i), disposer); }
1655 #endif
1657 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1659 //! <b>Returns</b>: An iterator to the element after the erased elements.
1661 //! <b>Effects</b>: Erases the range pointed to by b end e.
1662 //! Disposer::operator()(pointer) is called for the removed elements.
1663 //!
1664 //! <b>Complexity</b>: Average complexity for erase range is at most
1665 //! O(log(size() + N)), where N is the number of elements in the range.
1666 //!
1667 //! <b>Throws</b>: Nothing.
1668 //!
1669 //! <b>Note</b>: Invalidates the iterators
1670 //! to the erased elements.
1671 template<class Disposer>
1672 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
1673 { return tree_.erase_and_dispose(b, e, disposer); }
1675 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1677 //! <b>Effects</b>: Erases all the elements with the given value.
1678 //! Disposer::operator()(pointer) is called for the removed elements.
1679 //!
1680 //! <b>Returns</b>: The number of erased elements.
1681 //!
1682 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1683 //!
1684 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1685 //!
1686 //! <b>Note</b>: Invalidates the iterators (but not the references)
1687 //! to the erased elements. No destructors are called.
1688 template<class Disposer>
1689 size_type erase_and_dispose(const_reference value, Disposer disposer)
1690 { return tree_.erase_and_dispose(value, disposer); }
1692 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1694 //! <b>Effects</b>: Erases all the elements with the given key.
1695 //! according to the comparison functor "comp".
1696 //! Disposer::operator()(pointer) is called for the removed elements.
1698 //! <b>Returns</b>: The number of erased elements.
1699 //!
1700 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1701 //!
1702 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1703 //!
1704 //! <b>Note</b>: Invalidates the iterators
1705 //! to the erased elements.
1706 template<class KeyType, class KeyValueCompare, class Disposer>
1707 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
1708 /// @cond
1709 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1710 /// @endcond
1712 { return tree_.erase_and_dispose(key, comp, disposer); }
1714 //! <b>Effects</b>: Erases all the elements of the container.
1715 //!
1716 //! <b>Complexity</b>: Linear to the number of elements on the container.
1717 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1718 //!
1719 //! <b>Throws</b>: Nothing.
1720 //!
1721 //! <b>Note</b>: Invalidates the iterators (but not the references)
1722 //! to the erased elements. No destructors are called.
1723 void clear()
1724 { return tree_.clear(); }
1726 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1727 //!
1728 //! <b>Effects</b>: Erases all the elements of the container.
1729 //!
1730 //! <b>Complexity</b>: Linear to the number of elements on the container.
1731 //! Disposer::operator()(pointer) is called for the removed elements.
1732 //!
1733 //! <b>Throws</b>: Nothing.
1734 //!
1735 //! <b>Note</b>: Invalidates the iterators (but not the references)
1736 //! to the erased elements. No destructors are called.
1737 template<class Disposer>
1738 void clear_and_dispose(Disposer disposer)
1739 { return tree_.clear_and_dispose(disposer); }
1741 //! <b>Effects</b>: Returns the number of contained elements with the given key
1742 //!
1743 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1744 //! to number of objects with the given key.
1745 //!
1746 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1747 size_type count(const_reference value) const
1748 { return tree_.count(value); }
1750 //! <b>Effects</b>: Returns the number of contained elements with the same key
1751 //! compared with the given comparison functor.
1752 //!
1753 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1754 //! to number of objects with the given key.
1755 //!
1756 //! <b>Throws</b>: If comp ordering function throws.
1757 template<class KeyType, class KeyValueCompare>
1758 size_type count(const KeyType& key, KeyValueCompare comp) const
1759 { return tree_.count(key, comp); }
1761 //! <b>Effects</b>: Returns an iterator to the first element whose
1762 //! key is not less than k or end() if that element does not exist.
1763 //!
1764 //! <b>Complexity</b>: Logarithmic.
1765 //!
1766 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1767 iterator lower_bound(const_reference value)
1768 { return tree_.lower_bound(value); }
1770 //! <b>Requires</b>: comp must imply the same element order as
1771 //! value_compare. Usually key is the part of the value_type
1772 //! that is used in the ordering functor.
1774 //! <b>Effects</b>: Returns an iterator to the first element whose
1775 //! key according to the comparison functor is not less than k or
1776 //! end() if that element does not exist.
1777 //!
1778 //! <b>Complexity</b>: Logarithmic.
1779 //!
1780 //! <b>Throws</b>: If comp ordering function throws.
1781 //!
1782 //! <b>Note</b>: This function is used when constructing a value_type
1783 //! is expensive and the value_type can be compared with a cheaper
1784 //! key type. Usually this key is part of the value_type.
1785 template<class KeyType, class KeyValueCompare>
1786 iterator lower_bound(const KeyType& key, KeyValueCompare comp)
1787 { return tree_.lower_bound(key, comp); }
1789 //! <b>Effects</b>: Returns a const iterator to the first element whose
1790 //! key is not less than k or end() if that element does not exist.
1791 //!
1792 //! <b>Complexity</b>: Logarithmic.
1793 //!
1794 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1795 const_iterator lower_bound(const_reference value) const
1796 { return tree_.lower_bound(value); }
1798 //! <b>Requires</b>: comp must imply the same element order as
1799 //! value_compare. Usually key is the part of the value_type
1800 //! that is used in the ordering functor.
1802 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1803 //! key according to the comparison functor is not less than k or
1804 //! end() if that element does not exist.
1805 //!
1806 //! <b>Complexity</b>: Logarithmic.
1807 //!
1808 //! <b>Throws</b>: If comp ordering function throws.
1809 //!
1810 //! <b>Note</b>: This function is used when constructing a value_type
1811 //! is expensive and the value_type can be compared with a cheaper
1812 //! key type. Usually this key is part of the value_type.
1813 template<class KeyType, class KeyValueCompare>
1814 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const
1815 { return tree_.lower_bound(key, comp); }
1817 //! <b>Effects</b>: Returns an iterator to the first element whose
1818 //! key is greater than k or end() if that element does not exist.
1819 //!
1820 //! <b>Complexity</b>: Logarithmic.
1821 //!
1822 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1823 iterator upper_bound(const_reference value)
1824 { return tree_.upper_bound(value); }
1826 //! <b>Requires</b>: comp must imply the same element order as
1827 //! value_compare. Usually key is the part of the value_type
1828 //! that is used in the ordering functor.
1830 //! <b>Effects</b>: Returns an iterator to the first element whose
1831 //! key according to the comparison functor is greater than key or
1832 //! end() if that element does not exist.
1833 //!
1834 //! <b>Complexity</b>: Logarithmic.
1835 //!
1836 //! <b>Throws</b>: If comp ordering function throws.
1838 //! <b>Note</b>: This function is used when constructing a value_type
1839 //! is expensive and the value_type can be compared with a cheaper
1840 //! key type. Usually this key is part of the value_type.
1841 template<class KeyType, class KeyValueCompare>
1842 iterator upper_bound(const KeyType& key, KeyValueCompare comp)
1843 { return tree_.upper_bound(key, comp); }
1845 //! <b>Effects</b>: Returns an iterator to the first element whose
1846 //! key is greater than k or end() if that element does not exist.
1847 //!
1848 //! <b>Complexity</b>: Logarithmic.
1849 //!
1850 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1851 const_iterator upper_bound(const_reference value) const
1852 { return tree_.upper_bound(value); }
1854 //! <b>Requires</b>: comp must imply the same element order as
1855 //! value_compare. Usually key is the part of the value_type
1856 //! that is used in the ordering functor.
1858 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1859 //! key according to the comparison functor is greater than key or
1860 //! end() if that element does not exist.
1861 //!
1862 //! <b>Complexity</b>: Logarithmic.
1863 //!
1864 //! <b>Throws</b>: If comp ordering function throws.
1866 //! <b>Note</b>: This function is used when constructing a value_type
1867 //! is expensive and the value_type can be compared with a cheaper
1868 //! key type. Usually this key is part of the value_type.
1869 template<class KeyType, class KeyValueCompare>
1870 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const
1871 { return tree_.upper_bound(key, comp); }
1873 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1874 //! "value" or end() if that element does not exist.
1876 //! <b>Complexity</b>: Logarithmic.
1877 //!
1878 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1879 iterator find(const_reference value)
1880 { return tree_.find(value); }
1882 //! <b>Requires</b>: comp must imply the same element order as
1883 //! value_compare. Usually key is the part of the value_type
1884 //! that is used in the ordering functor.
1886 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1887 //! "key" according to the comparison functor or end() if that element
1888 //! does not exist.
1890 //! <b>Complexity</b>: Logarithmic.
1891 //!
1892 //! <b>Throws</b>: If comp ordering function throws.
1894 //! <b>Note</b>: This function is used when constructing a value_type
1895 //! is expensive and the value_type can be compared with a cheaper
1896 //! key type. Usually this key is part of the value_type.
1897 template<class KeyType, class KeyValueCompare>
1898 iterator find(const KeyType& key, KeyValueCompare comp)
1899 { return tree_.find(key, comp); }
1901 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1902 //! "value" or end() if that element does not exist.
1903 //!
1904 //! <b>Complexity</b>: Logarithmic.
1905 //!
1906 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1907 const_iterator find(const_reference value) const
1908 { return tree_.find(value); }
1910 //! <b>Requires</b>: comp must imply the same element order as
1911 //! value_compare. Usually key is the part of the value_type
1912 //! that is used in the ordering functor.
1914 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1915 //! "key" according to the comparison functor or end() if that element
1916 //! does not exist.
1917 //!
1918 //! <b>Complexity</b>: Logarithmic.
1919 //!
1920 //! <b>Throws</b>: If comp ordering function throws.
1922 //! <b>Note</b>: This function is used when constructing a value_type
1923 //! is expensive and the value_type can be compared with a cheaper
1924 //! key type. Usually this key is part of the value_type.
1925 template<class KeyType, class KeyValueCompare>
1926 const_iterator find(const KeyType& key, KeyValueCompare comp) const
1927 { return tree_.find(key, comp); }
1929 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1930 //! an empty range that indicates the position where those elements would be
1931 //! if they there is no elements with key k.
1932 //!
1933 //! <b>Complexity</b>: Logarithmic.
1934 //!
1935 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1936 std::pair<iterator,iterator> equal_range(const_reference value)
1937 { return tree_.equal_range(value); }
1939 //! <b>Requires</b>: comp must imply the same element order as
1940 //! value_compare. Usually key is the part of the value_type
1941 //! that is used in the ordering functor.
1943 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1944 //! according to the comparison functor or an empty range
1945 //! that indicates the position where those elements would be
1946 //! if they there is no elements with key k.
1947 //!
1948 //! <b>Complexity</b>: Logarithmic.
1949 //!
1950 //! <b>Throws</b>: If comp ordering function throws.
1952 //! <b>Note</b>: This function is used when constructing a value_type
1953 //! is expensive and the value_type can be compared with a cheaper
1954 //! key type. Usually this key is part of the value_type.
1955 template<class KeyType, class KeyValueCompare>
1956 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)
1957 { return tree_.equal_range(key, comp); }
1959 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1960 //! an empty range that indicates the position where those elements would be
1961 //! if they there is no elements with key k.
1962 //!
1963 //! <b>Complexity</b>: Logarithmic.
1964 //!
1965 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1966 std::pair<const_iterator, const_iterator>
1967 equal_range(const_reference value) const
1968 { return tree_.equal_range(value); }
1970 //! <b>Requires</b>: comp must imply the same element order as
1971 //! value_compare. Usually key is the part of the value_type
1972 //! that is used in the ordering functor.
1974 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1975 //! according to the comparison functor or an empty range
1976 //! that indicates the position where those elements would be
1977 //! if they there is no elements with key k.
1978 //!
1979 //! <b>Complexity</b>: Logarithmic.
1980 //!
1981 //! <b>Throws</b>: If comp ordering function throws.
1983 //! <b>Note</b>: This function is used when constructing a value_type
1984 //! is expensive and the value_type can be compared with a cheaper
1985 //! key type. Usually this key is part of the value_type.
1986 template<class KeyType, class KeyValueCompare>
1987 std::pair<const_iterator, const_iterator>
1988 equal_range(const KeyType& key, KeyValueCompare comp) const
1989 { return tree_.equal_range(key, comp); }
1991 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
1992 //! appropriate type. Otherwise the behavior is undefined.
1993 //!
1994 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
1995 //! that points to the value
1996 //!
1997 //! <b>Complexity</b>: Constant.
1998 //!
1999 //! <b>Throws</b>: Nothing.
2000 //!
2001 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2002 //! is stateless.
2003 static iterator s_iterator_to(reference value)
2004 { return tree_type::s_iterator_to(value); }
2006 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2007 //! appropriate type. Otherwise the behavior is undefined.
2008 //!
2009 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2010 //! sg_multiset that points to the value
2011 //!
2012 //! <b>Complexity</b>: Constant.
2013 //!
2014 //! <b>Throws</b>: Nothing.
2015 //!
2016 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2017 //! is stateless.
2018 static const_iterator s_iterator_to(const_reference value)
2019 { return tree_type::s_iterator_to(value); }
2021 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2022 //! appropriate type. Otherwise the behavior is undefined.
2023 //!
2024 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
2025 //! that points to the value
2026 //!
2027 //! <b>Complexity</b>: Constant.
2028 //!
2029 //! <b>Throws</b>: Nothing.
2030 iterator iterator_to(reference value)
2031 { return tree_.iterator_to(value); }
2033 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2034 //! appropriate type. Otherwise the behavior is undefined.
2035 //!
2036 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2037 //! sg_multiset that points to the value
2038 //!
2039 //! <b>Complexity</b>: Constant.
2040 //!
2041 //! <b>Throws</b>: Nothing.
2042 const_iterator iterator_to(const_reference value) const
2043 { return tree_.iterator_to(value); }
2045 //! <b>Requires</b>: value shall not be in a sg_multiset/sg_multiset.
2046 //!
2047 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2048 //! state.
2049 //!
2050 //! <b>Throws</b>: Nothing.
2051 //!
2052 //! <b>Complexity</b>: Constant time.
2053 //!
2054 //! <b>Note</b>: This function puts the hook in the well-known default state
2055 //! used by auto_unlink and safe hooks.
2056 static void init_node(reference value)
2057 { tree_type::init_node(value); }
2059 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2060 //!
2061 //! <b>Complexity</b>: Average complexity is constant time.
2062 //!
2063 //! <b>Throws</b>: Nothing.
2064 //!
2065 //! <b>Notes</b>: This function breaks the tree and the tree can
2066 //! only be used for more unlink_leftmost_without_rebalance calls.
2067 //! This function is normally used to achieve a step by step
2068 //! controlled destruction of the tree.
2069 pointer unlink_leftmost_without_rebalance()
2070 { return tree_.unlink_leftmost_without_rebalance(); }
2072 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2073 //! and with_this must not be inserted in any tree.
2074 //!
2075 //! <b>Effects</b>: Replaces replace_this in its position in the
2076 //! tree with with_this. The tree does not need to be rebalanced.
2077 //!
2078 //! <b>Complexity</b>: Constant.
2079 //!
2080 //! <b>Throws</b>: Nothing.
2081 //!
2082 //! <b>Note</b>: This function will break container ordering invariants if
2083 //! with_this is not equivalent to *replace_this according to the
2084 //! ordering rules. This function is faster than erasing and inserting
2085 //! the node, since no rebalancing or comparison is needed.
2086 void replace_node(iterator replace_this, reference with_this)
2087 { tree_.replace_node(replace_this, with_this); }
2089 //! <b>Effects</b>: Rebalances the tree.
2090 //!
2091 //! <b>Throws</b>: Nothing.
2092 //!
2093 //! <b>Complexity</b>: Linear.
2094 void rebalance()
2095 { tree_.rebalance(); }
2097 //! <b>Requires</b>: old_root is a node of a tree.
2098 //!
2099 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
2101 //! <b>Returns</b>: The new root of the subtree.
2103 //! <b>Throws</b>: Nothing.
2104 //!
2105 //! <b>Complexity</b>: Linear to the elements in the subtree.
2106 iterator rebalance_subtree(iterator root)
2107 { return tree_.rebalance_subtree(root); }
2109 //! <b>Returns</b>: The balance factor (alpha) used in this tree
2111 //! <b>Throws</b>: Nothing.
2112 //!
2113 //! <b>Complexity</b>: Constant.
2114 float balance_factor() const
2115 { return tree_.balance_factor(); }
2117 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
2118 //!
2119 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
2120 //! the tree if the new balance factor is stricter (less) than the old factor.
2122 //! <b>Throws</b>: Nothing.
2123 //!
2124 //! <b>Complexity</b>: Linear to the elements in the subtree.
2125 void balance_factor(float new_alpha)
2126 { tree_.balance_factor(new_alpha); }
2128 /// @cond
2129 friend bool operator==(const sg_multiset_impl &x, const sg_multiset_impl &y)
2130 { return x.tree_ == y.tree_; }
2132 friend bool operator<(const sg_multiset_impl &x, const sg_multiset_impl &y)
2133 { return x.tree_ < y.tree_; }
2134 /// @endcond
2137 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2138 template<class T, class ...Options>
2139 #else
2140 template<class Config>
2141 #endif
2142 inline bool operator!=
2143 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2144 (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2145 #else
2146 (const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2147 #endif
2148 { return !(x == y); }
2150 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2151 template<class T, class ...Options>
2152 #else
2153 template<class Config>
2154 #endif
2155 inline bool operator>
2156 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2157 (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2158 #else
2159 (const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2160 #endif
2161 { return y < x; }
2163 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2164 template<class T, class ...Options>
2165 #else
2166 template<class Config>
2167 #endif
2168 inline bool operator<=
2169 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2170 (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2171 #else
2172 (const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2173 #endif
2174 { return !(y < x); }
2176 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2177 template<class T, class ...Options>
2178 #else
2179 template<class Config>
2180 #endif
2181 inline bool operator>=
2182 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2183 (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
2184 #else
2185 (const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
2186 #endif
2187 { return !(x < y); }
2189 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2190 template<class T, class ...Options>
2191 #else
2192 template<class Config>
2193 #endif
2194 inline void swap
2195 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2196 (sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y)
2197 #else
2198 (sg_multiset_impl<Config> &x, sg_multiset_impl<Config> &y)
2199 #endif
2200 { x.swap(y); }
2202 //! Helper metafunction to define a \c sg_multiset that yields to the same type when the
2203 //! same options (either explicitly or implicitly) are used.
2204 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2205 template<class T, class ...Options>
2206 #else
2207 template<class T, class O1 = none, class O2 = none
2208 , class O3 = none, class O4 = none>
2209 #endif
2210 struct make_sg_multiset
2212 /// @cond
2213 typedef sg_multiset_impl
2214 < typename make_sgtree_opt<T,
2215 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2216 O1, O2, O3, O4
2217 #else
2218 Options...
2219 #endif
2220 >::type
2221 > implementation_defined;
2222 /// @endcond
2223 typedef implementation_defined type;
2226 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2228 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2229 template<class T, class O1, class O2, class O3, class O4>
2230 #else
2231 template<class T, class ...Options>
2232 #endif
2233 class sg_multiset
2234 : public make_sg_multiset<T,
2235 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2236 O1, O2, O3, O4
2237 #else
2238 Options...
2239 #endif
2240 >::type
2242 typedef typename make_sg_multiset
2243 <T,
2244 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2245 O1, O2, O3, O4
2246 #else
2247 Options...
2248 #endif
2249 >::type Base;
2251 public:
2252 typedef typename Base::value_compare value_compare;
2253 typedef typename Base::value_traits value_traits;
2254 typedef typename Base::iterator iterator;
2255 typedef typename Base::const_iterator const_iterator;
2257 //Assert if passed value traits are compatible with the type
2258 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
2260 sg_multiset( const value_compare &cmp = value_compare()
2261 , const value_traits &v_traits = value_traits())
2262 : Base(cmp, v_traits)
2265 template<class Iterator>
2266 sg_multiset( Iterator b, Iterator e
2267 , const value_compare &cmp = value_compare()
2268 , const value_traits &v_traits = value_traits())
2269 : Base(b, e, cmp, v_traits)
2272 static sg_multiset &container_from_end_iterator(iterator end_iterator)
2273 { return static_cast<sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
2275 static const sg_multiset &container_from_end_iterator(const_iterator end_iterator)
2276 { return static_cast<const sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
2278 static sg_multiset &container_from_iterator(iterator it)
2279 { return static_cast<sg_multiset &>(Base::container_from_iterator(it)); }
2281 static const sg_multiset &container_from_iterator(const_iterator it)
2282 { return static_cast<const sg_multiset &>(Base::container_from_iterator(it)); }
2285 #endif
2287 } //namespace intrusive
2288 } //namespace boost
2290 #include <boost/intrusive/detail/config_end.hpp>
2292 #endif //BOOST_INTRUSIVE_SG_SET_HPP