1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2014
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)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_LIST_HPP
15 #define BOOST_INTRUSIVE_LIST_HPP
17 #include <boost/intrusive/detail/config_begin.hpp>
18 #include <boost/intrusive/intrusive_fwd.hpp>
19 #include <boost/intrusive/detail/assert.hpp>
20 #include <boost/intrusive/list_hook.hpp>
21 #include <boost/intrusive/circular_list_algorithms.hpp>
22 #include <boost/intrusive/pointer_traits.hpp>
23 #include <boost/intrusive/detail/mpl.hpp>
24 #include <boost/intrusive/link_mode.hpp>
25 #include <boost/intrusive/detail/get_value_traits.hpp>
26 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
27 #include <boost/intrusive/detail/default_header_holder.hpp>
28 #include <boost/intrusive/detail/reverse_iterator.hpp>
29 #include <boost/intrusive/detail/uncast.hpp>
30 #include <boost/intrusive/detail/list_iterator.hpp>
31 #include <boost/intrusive/detail/array_initializer.hpp>
32 #include <boost/intrusive/detail/exception_disposer.hpp>
33 #include <boost/intrusive/detail/equal_to_value.hpp>
34 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
35 #include <boost/intrusive/detail/simple_disposers.hpp>
36 #include <boost/intrusive/detail/size_holder.hpp>
37 #include <boost/intrusive/detail/algorithm.hpp>
39 #include <boost/move/utility_core.hpp>
40 #include <boost/static_assert.hpp>
42 #include <boost/intrusive/detail/value_functors.hpp>
43 #include <cstddef> //std::size_t, etc.
45 #if defined(BOOST_HAS_PRAGMA_ONCE)
54 struct default_list_hook_applier
55 { template <class T> struct apply{ typedef typename T::default_list_hook type; }; };
58 struct is_default_hook_tag<default_list_hook_applier>
59 { static const bool value = true; };
63 typedef default_list_hook_applier proto_value_traits;
64 static const bool constant_time_size = true;
65 typedef std::size_t size_type;
66 typedef void header_holder_type;
71 //! The class template list is an intrusive container that mimics most of the
72 //! interface of std::list as described in the C++ standard.
74 //! The template parameter \c T is the type to be managed by the container.
75 //! The user can specify additional options and if no options are provided
76 //! default options are used.
78 //! The container supports the following options:
79 //! \c base_hook<>/member_hook<>/value_traits<>,
80 //! \c constant_time_size<> and \c size_type<>.
81 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
82 template<class T, class ...Options>
84 template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
90 typedef ValueTraits value_traits;
91 typedef typename value_traits::pointer pointer;
92 typedef typename value_traits::const_pointer const_pointer;
93 typedef typename pointer_traits<pointer>::element_type value_type;
94 typedef typename pointer_traits<pointer>::reference reference;
95 typedef typename pointer_traits<const_pointer>::reference const_reference;
96 typedef typename pointer_traits<pointer>::difference_type difference_type;
97 typedef SizeType size_type;
98 typedef list_iterator<value_traits, false> iterator;
99 typedef list_iterator<value_traits, true> const_iterator;
100 typedef boost::intrusive::reverse_iterator<iterator> reverse_iterator;
101 typedef boost::intrusive::reverse_iterator<const_iterator> const_reverse_iterator;
102 typedef typename value_traits::node_traits node_traits;
103 typedef typename node_traits::node node;
104 typedef typename node_traits::node_ptr node_ptr;
105 typedef typename node_traits::const_node_ptr const_node_ptr;
106 typedef circular_list_algorithms<node_traits> node_algorithms;
107 typedef typename detail::get_header_holder_type
108 < value_traits, HeaderHolder >::type header_holder_type;
110 static const bool constant_time_size = ConstantTimeSize;
111 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
112 static const bool has_container_from_iterator =
113 detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value;
118 typedef detail::size_holder<constant_time_size, size_type> size_traits;
121 BOOST_MOVABLE_BUT_NOT_COPYABLE(list_impl)
123 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
125 //Constant-time size is incompatible with auto-unlink hooks!
126 BOOST_STATIC_ASSERT(!(constant_time_size &&
127 ((int)value_traits::link_mode == (int)auto_unlink)
130 node_ptr get_root_node()
131 { return data_.root_plus_size_.m_header.get_node(); }
133 const_node_ptr get_root_node() const
134 { return data_.root_plus_size_.m_header.get_node(); }
136 struct root_plus_size : public size_traits
138 header_holder_type m_header;
141 struct data_t : public value_traits
143 typedef typename list_impl::value_traits value_traits;
144 explicit data_t(const value_traits &val_traits)
145 : value_traits(val_traits)
148 root_plus_size root_plus_size_;
151 BOOST_INTRUSIVE_FORCEINLINE size_traits &priv_size_traits() BOOST_NOEXCEPT
152 { return data_.root_plus_size_; }
154 BOOST_INTRUSIVE_FORCEINLINE const size_traits &priv_size_traits() const BOOST_NOEXCEPT
155 { return data_.root_plus_size_; }
157 BOOST_INTRUSIVE_FORCEINLINE const value_traits &priv_value_traits() const BOOST_NOEXCEPT
160 BOOST_INTRUSIVE_FORCEINLINE value_traits &priv_value_traits() BOOST_NOEXCEPT
163 typedef typename boost::intrusive::value_traits_pointers
164 <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
166 BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr priv_value_traits_ptr() const BOOST_NOEXCEPT
167 { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); }
173 //! <b>Effects</b>: constructs an empty list.
175 //! <b>Complexity</b>: Constant
177 //! <b>Throws</b>: If value_traits::node_traits::node
178 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
180 : data_(value_traits())
182 this->priv_size_traits().set_size(size_type(0));
183 node_algorithms::init_header(this->get_root_node());
186 //! <b>Effects</b>: constructs an empty list.
188 //! <b>Complexity</b>: Constant
190 //! <b>Throws</b>: If value_traits::node_traits::node
191 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
192 explicit list_impl(const value_traits &v_traits)
195 this->priv_size_traits().set_size(size_type(0));
196 node_algorithms::init_header(this->get_root_node());
199 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
201 //! <b>Effects</b>: Constructs a list equal to the range [first,last).
203 //! <b>Complexity</b>: Linear in distance(b, e). No copy constructors are called.
205 //! <b>Throws</b>: If value_traits::node_traits::node
206 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
207 template<class Iterator>
208 list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
211 //nothrow, no need to rollback to release elements on exception
212 this->priv_size_traits().set_size(size_type(0));
213 node_algorithms::init_header(this->get_root_node());
214 //nothrow, no need to rollback to release elements on exception
215 this->insert(this->cend(), b, e);
218 //! <b>Effects</b>: Constructs a container moving resources from another container.
219 //! Internal value traits are move constructed and
220 //! nodes belonging to x (except the node representing the "end") are linked to *this.
222 //! <b>Complexity</b>: Constant.
224 //! <b>Throws</b>: If value_traits::node_traits::node's
225 //! move constructor throws (this does not happen with predefined Boost.Intrusive hooks)
226 //! or the move constructor of value traits throws.
227 list_impl(BOOST_RV_REF(list_impl) x)
228 : data_(::boost::move(x.priv_value_traits()))
230 this->priv_size_traits().set_size(size_type(0));
231 node_algorithms::init_header(this->get_root_node());
232 //nothrow, no need to rollback to release elements on exception
236 //! <b>Effects</b>: Equivalent to swap
238 list_impl& operator=(BOOST_RV_REF(list_impl) x)
239 { this->swap(x); return *this; }
241 //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type
242 //! the destructor does nothing
243 //! (ie. no code is generated). Otherwise it detaches all elements from this.
244 //! In this case the objects in the list are not deleted (i.e. no destructors
245 //! are called), but the hooks according to the ValueTraits template parameter
246 //! are set to their default value.
248 //! <b>Throws</b>: Nothing.
250 //! <b>Complexity</b>: Linear to the number of elements in the list, if
251 //! it's a safe-mode or auto-unlink value . Otherwise constant.
254 BOOST_IF_CONSTEXPR(is_safe_autounlink<ValueTraits::link_mode>::value){
256 node_algorithms::init(this->get_root_node());
260 //! <b>Requires</b>: value must be an lvalue.
262 //! <b>Effects</b>: Inserts the value in the back of the list.
263 //! No copy constructors are called.
265 //! <b>Throws</b>: Nothing.
267 //! <b>Complexity</b>: Constant.
269 //! <b>Note</b>: Does not affect the validity of iterators and references.
270 void push_back(reference value) BOOST_NOEXCEPT
272 node_ptr to_insert = priv_value_traits().to_node_ptr(value);
273 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
274 node_algorithms::link_before(this->get_root_node(), to_insert);
275 this->priv_size_traits().increment();
278 //! <b>Requires</b>: value must be an lvalue.
280 //! <b>Effects</b>: Inserts the value in the front of the list.
281 //! No copy constructors are called.
283 //! <b>Throws</b>: Nothing.
285 //! <b>Complexity</b>: Constant.
287 //! <b>Note</b>: Does not affect the validity of iterators and references.
288 void push_front(reference value) BOOST_NOEXCEPT
290 node_ptr to_insert = priv_value_traits().to_node_ptr(value);
291 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
292 node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
293 this->priv_size_traits().increment();
296 //! <b>Effects</b>: Erases the last element of the list.
297 //! No destructors are called.
299 //! <b>Throws</b>: Nothing.
301 //! <b>Complexity</b>: Constant.
303 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
304 void pop_back() BOOST_NOEXCEPT
305 { return this->pop_back_and_dispose(detail::null_disposer()); }
307 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
309 //! <b>Effects</b>: Erases the last element of the list.
310 //! No destructors are called.
311 //! Disposer::operator()(pointer) is called for the removed element.
313 //! <b>Throws</b>: Nothing.
315 //! <b>Complexity</b>: Constant.
317 //! <b>Note</b>: Invalidates the iterators to the erased element.
318 template<class Disposer>
319 void pop_back_and_dispose(Disposer disposer) BOOST_NOEXCEPT
321 node_ptr to_erase = node_traits::get_previous(this->get_root_node());
322 node_algorithms::unlink(to_erase);
323 this->priv_size_traits().decrement();
324 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
325 node_algorithms::init(to_erase);
326 disposer(priv_value_traits().to_value_ptr(to_erase));
329 //! <b>Effects</b>: Erases the first element of the list.
330 //! No destructors are called.
332 //! <b>Throws</b>: Nothing.
334 //! <b>Complexity</b>: Constant.
336 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
337 void pop_front() BOOST_NOEXCEPT
338 { return this->pop_front_and_dispose(detail::null_disposer()); }
340 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
342 //! <b>Effects</b>: Erases the first element of the list.
343 //! No destructors are called.
344 //! Disposer::operator()(pointer) is called for the removed element.
346 //! <b>Throws</b>: Nothing.
348 //! <b>Complexity</b>: Constant.
350 //! <b>Note</b>: Invalidates the iterators to the erased element.
351 template<class Disposer>
352 void pop_front_and_dispose(Disposer disposer) BOOST_NOEXCEPT
354 node_ptr to_erase = node_traits::get_next(this->get_root_node());
355 node_algorithms::unlink(to_erase);
356 this->priv_size_traits().decrement();
357 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
358 node_algorithms::init(to_erase);
359 disposer(priv_value_traits().to_value_ptr(to_erase));
362 //! <b>Effects</b>: Returns a reference to the first element of the list.
364 //! <b>Throws</b>: Nothing.
366 //! <b>Complexity</b>: Constant.
367 BOOST_INTRUSIVE_FORCEINLINE reference front() BOOST_NOEXCEPT
368 { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
370 //! <b>Effects</b>: Returns a const_reference to the first element of the list.
372 //! <b>Throws</b>: Nothing.
374 //! <b>Complexity</b>: Constant.
375 BOOST_INTRUSIVE_FORCEINLINE const_reference front() const BOOST_NOEXCEPT
376 { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
378 //! <b>Effects</b>: Returns a reference to the last element of the list.
380 //! <b>Throws</b>: Nothing.
382 //! <b>Complexity</b>: Constant.
383 BOOST_INTRUSIVE_FORCEINLINE reference back() BOOST_NOEXCEPT
384 { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
386 //! <b>Effects</b>: Returns a const_reference to the last element of the list.
388 //! <b>Throws</b>: Nothing.
390 //! <b>Complexity</b>: Constant.
391 BOOST_INTRUSIVE_FORCEINLINE const_reference back() const BOOST_NOEXCEPT
392 { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); }
394 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
396 //! <b>Throws</b>: Nothing.
398 //! <b>Complexity</b>: Constant.
399 BOOST_INTRUSIVE_FORCEINLINE iterator begin() BOOST_NOEXCEPT
400 { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
402 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
404 //! <b>Throws</b>: Nothing.
406 //! <b>Complexity</b>: Constant.
407 BOOST_INTRUSIVE_FORCEINLINE const_iterator begin() const BOOST_NOEXCEPT
408 { return this->cbegin(); }
410 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
412 //! <b>Throws</b>: Nothing.
414 //! <b>Complexity</b>: Constant.
415 BOOST_INTRUSIVE_FORCEINLINE const_iterator cbegin() const BOOST_NOEXCEPT
416 { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
418 //! <b>Effects</b>: Returns an iterator to the end of the list.
420 //! <b>Throws</b>: Nothing.
422 //! <b>Complexity</b>: Constant.
423 BOOST_INTRUSIVE_FORCEINLINE iterator end() BOOST_NOEXCEPT
424 { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); }
426 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
428 //! <b>Throws</b>: Nothing.
430 //! <b>Complexity</b>: Constant.
431 BOOST_INTRUSIVE_FORCEINLINE const_iterator end() const BOOST_NOEXCEPT
432 { return this->cend(); }
434 //! <b>Effects</b>: Returns a constant iterator to the end of the list.
436 //! <b>Throws</b>: Nothing.
438 //! <b>Complexity</b>: Constant.
439 BOOST_INTRUSIVE_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT
440 { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); }
442 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
443 //! of the reversed list.
445 //! <b>Throws</b>: Nothing.
447 //! <b>Complexity</b>: Constant.
448 BOOST_INTRUSIVE_FORCEINLINE reverse_iterator rbegin() BOOST_NOEXCEPT
449 { return reverse_iterator(this->end()); }
451 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
452 //! of the reversed list.
454 //! <b>Throws</b>: Nothing.
456 //! <b>Complexity</b>: Constant.
457 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator rbegin() const BOOST_NOEXCEPT
458 { return this->crbegin(); }
460 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
461 //! of the reversed list.
463 //! <b>Throws</b>: Nothing.
465 //! <b>Complexity</b>: Constant.
466 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator crbegin() const BOOST_NOEXCEPT
467 { return const_reverse_iterator(end()); }
469 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
470 //! of the reversed list.
472 //! <b>Throws</b>: Nothing.
474 //! <b>Complexity</b>: Constant.
475 BOOST_INTRUSIVE_FORCEINLINE reverse_iterator rend() BOOST_NOEXCEPT
476 { return reverse_iterator(begin()); }
478 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
479 //! of the reversed list.
481 //! <b>Throws</b>: Nothing.
483 //! <b>Complexity</b>: Constant.
484 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator rend() const BOOST_NOEXCEPT
485 { return this->crend(); }
487 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
488 //! of the reversed list.
490 //! <b>Throws</b>: Nothing.
492 //! <b>Complexity</b>: Constant.
493 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator crend() const BOOST_NOEXCEPT
494 { return const_reverse_iterator(this->begin()); }
496 //! <b>Precondition</b>: end_iterator must be a valid end iterator
499 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
501 //! <b>Throws</b>: Nothing.
503 //! <b>Complexity</b>: Constant.
504 BOOST_INTRUSIVE_FORCEINLINE static list_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
505 { return list_impl::priv_container_from_end_iterator(end_iterator); }
507 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
510 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
512 //! <b>Throws</b>: Nothing.
514 //! <b>Complexity</b>: Constant.
515 BOOST_INTRUSIVE_FORCEINLINE static const list_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
516 { return list_impl::priv_container_from_end_iterator(end_iterator); }
518 //! <b>Effects</b>: Returns the number of the elements contained in the list.
520 //! <b>Throws</b>: Nothing.
522 //! <b>Complexity</b>: Linear to the number of elements contained in the list.
523 //! if constant-time size option is disabled. Constant time otherwise.
525 //! <b>Note</b>: Does not affect the validity of iterators and references.
526 BOOST_INTRUSIVE_FORCEINLINE size_type size() const BOOST_NOEXCEPT
528 BOOST_IF_CONSTEXPR(constant_time_size)
529 return this->priv_size_traits().get_size();
531 return node_algorithms::count(this->get_root_node()) - 1;
534 //! <b>Effects</b>: Returns true if the list contains no elements.
536 //! <b>Throws</b>: Nothing.
538 //! <b>Complexity</b>: Constant.
540 //! <b>Note</b>: Does not affect the validity of iterators and references.
541 BOOST_INTRUSIVE_FORCEINLINE bool empty() const BOOST_NOEXCEPT
542 { return node_algorithms::unique(this->get_root_node()); }
544 //! <b>Effects</b>: Swaps the elements of x and *this.
546 //! <b>Throws</b>: Nothing.
548 //! <b>Complexity</b>: Constant.
550 //! <b>Note</b>: Does not affect the validity of iterators and references.
551 void swap(list_impl& other) BOOST_NOEXCEPT
553 node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
554 this->priv_size_traits().swap(other.priv_size_traits());
557 //! <b>Effects</b>: Moves backwards all the elements, so that the first
558 //! element becomes the second, the second becomes the third...
559 //! the last element becomes the first one.
561 //! <b>Throws</b>: Nothing.
563 //! <b>Complexity</b>: Linear to the number of shifts.
565 //! <b>Note</b>: Does not affect the validity of iterators and references.
566 BOOST_INTRUSIVE_FORCEINLINE void shift_backwards(size_type n = 1) BOOST_NOEXCEPT
567 { node_algorithms::move_forward(this->get_root_node(), n); }
569 //! <b>Effects</b>: Moves forward all the elements, so that the second
570 //! element becomes the first, the third becomes the second...
571 //! the first element becomes the last one.
573 //! <b>Throws</b>: Nothing.
575 //! <b>Complexity</b>: Linear to the number of shifts.
577 //! <b>Note</b>: Does not affect the validity of iterators and references.
578 BOOST_INTRUSIVE_FORCEINLINE void shift_forward(size_type n = 1) BOOST_NOEXCEPT
579 { node_algorithms::move_backwards(this->get_root_node(), n); }
581 //! <b>Effects</b>: Erases the element pointed by i of the list.
582 //! No destructors are called.
584 //! <b>Returns</b>: the first element remaining beyond the removed element,
585 //! or end() if no such element exists.
587 //! <b>Throws</b>: Nothing.
589 //! <b>Complexity</b>: Constant.
591 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
593 BOOST_INTRUSIVE_FORCEINLINE iterator erase(const_iterator i) BOOST_NOEXCEPT
594 { return this->erase_and_dispose(i, detail::null_disposer()); }
596 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
598 //! <b>Effects</b>: Erases the element range pointed by b and e
599 //! No destructors are called.
601 //! <b>Returns</b>: the first element remaining beyond the removed elements,
602 //! or end() if no such element exists.
604 //! <b>Throws</b>: Nothing.
606 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
607 //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise.
609 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
611 BOOST_INTRUSIVE_FORCEINLINE iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT
613 BOOST_IF_CONSTEXPR(safemode_or_autounlink || constant_time_size){
614 return this->erase_and_dispose(b, e, detail::null_disposer());
617 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
622 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
623 //! n must be distance(b, e).
625 //! <b>Effects</b>: Erases the element range pointed by b and e
626 //! No destructors are called.
628 //! <b>Returns</b>: the first element remaining beyond the removed elements,
629 //! or end() if no such element exists.
631 //! <b>Throws</b>: Nothing.
633 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
634 //! or auto-unlink value is enabled. Constant-time otherwise.
636 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
638 iterator erase(const_iterator b, const_iterator e, size_type n) BOOST_NOEXCEPT
640 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n);
642 BOOST_IF_CONSTEXPR(safemode_or_autounlink){
643 return this->erase_and_dispose(b, e, detail::null_disposer());
646 BOOST_IF_CONSTEXPR(constant_time_size){
647 this->priv_size_traits().decrease(n);
649 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
654 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
656 //! <b>Effects</b>: Erases the element pointed by i of the list.
657 //! No destructors are called.
658 //! Disposer::operator()(pointer) is called for the removed element.
660 //! <b>Returns</b>: the first element remaining beyond the removed element,
661 //! or end() if no such element exists.
663 //! <b>Throws</b>: Nothing.
665 //! <b>Complexity</b>: Constant.
667 //! <b>Note</b>: Invalidates the iterators to the erased element.
668 template <class Disposer>
669 iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT
671 node_ptr to_erase(i.pointed_node());
673 node_algorithms::unlink(to_erase);
674 this->priv_size_traits().decrement();
675 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
676 node_algorithms::init(to_erase);
677 disposer(this->priv_value_traits().to_value_ptr(to_erase));
681 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
682 template<class Disposer>
683 iterator erase_and_dispose(iterator i, Disposer disposer) BOOST_NOEXCEPT
684 { return this->erase_and_dispose(const_iterator(i), disposer); }
687 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
689 //! <b>Effects</b>: Erases the element range pointed by b and e
690 //! No destructors are called.
691 //! Disposer::operator()(pointer) is called for the removed elements.
693 //! <b>Returns</b>: the first element remaining beyond the removed elements,
694 //! or end() if no such element exists.
696 //! <b>Throws</b>: Nothing.
698 //! <b>Complexity</b>: Linear to the number of elements erased.
700 //! <b>Note</b>: Invalidates the iterators to the erased elements.
701 template <class Disposer>
702 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT
704 node_ptr bp(b.pointed_node()), ep(e.pointed_node());
705 node_algorithms::unlink(bp, ep);
707 node_ptr to_erase(bp);
708 bp = node_traits::get_next(bp);
709 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
710 node_algorithms::init(to_erase);
711 disposer(priv_value_traits().to_value_ptr(to_erase));
712 this->priv_size_traits().decrement();
717 //! <b>Effects</b>: Erases all the elements of the container.
718 //! No destructors are called.
720 //! <b>Throws</b>: Nothing.
722 //! <b>Complexity</b>: Linear to the number of elements of the list.
723 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
725 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
726 void clear() BOOST_NOEXCEPT
728 BOOST_IF_CONSTEXPR(safemode_or_autounlink){
729 this->clear_and_dispose(detail::null_disposer());
732 node_algorithms::init_header(this->get_root_node());
733 this->priv_size_traits().set_size(size_type(0));
737 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
739 //! <b>Effects</b>: Erases all the elements of the container.
740 //! No destructors are called.
741 //! Disposer::operator()(pointer) is called for the removed elements.
743 //! <b>Throws</b>: Nothing.
745 //! <b>Complexity</b>: Linear to the number of elements of the list.
747 //! <b>Note</b>: Invalidates the iterators to the erased elements.
748 template <class Disposer>
749 void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT
751 const_iterator it(this->begin()), itend(this->end());
753 node_ptr to_erase(it.pointed_node());
755 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
756 node_algorithms::init(to_erase);
757 disposer(priv_value_traits().to_value_ptr(to_erase));
759 node_algorithms::init_header(this->get_root_node());
760 this->priv_size_traits().set_size(0);
763 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
764 //! Cloner should yield to nodes equivalent to the original nodes.
766 //! <b>Effects</b>: Erases all the elements from *this
767 //! calling Disposer::operator()(pointer), clones all the
768 //! elements from src calling Cloner::operator()(const_reference )
769 //! and inserts them on *this.
771 //! If cloner throws, all cloned elements are unlinked and disposed
772 //! calling Disposer::operator()(pointer).
774 //! <b>Complexity</b>: Linear to erased plus inserted elements.
776 //! <b>Throws</b>: If cloner throws. Basic guarantee.
777 template <class Cloner, class Disposer>
778 void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
780 this->clear_and_dispose(disposer);
781 detail::exception_disposer<list_impl, Disposer>
782 rollback(*this, disposer);
783 const_iterator b(src.begin()), e(src.end());
785 this->push_back(*cloner(*b));
790 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
791 //! Cloner should yield to nodes equivalent to the original nodes.
793 //! <b>Effects</b>: Erases all the elements from *this
794 //! calling Disposer::operator()(pointer), clones all the
795 //! elements from src calling Cloner::operator()(reference)
796 //! and inserts them on *this.
798 //! If cloner throws, all cloned elements are unlinked and disposed
799 //! calling Disposer::operator()(pointer).
801 //! <b>Complexity</b>: Linear to erased plus inserted elements.
803 //! <b>Throws</b>: If cloner throws. Basic guarantee.
804 template <class Cloner, class Disposer>
805 void clone_from(BOOST_RV_REF(list_impl) src, Cloner cloner, Disposer disposer)
807 this->clear_and_dispose(disposer);
808 detail::exception_disposer<list_impl, Disposer>
809 rollback(*this, disposer);
810 iterator b(src.begin()), e(src.end());
812 this->push_back(*cloner(*b));
817 //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this.
819 //! <b>Effects</b>: Inserts the value before the position pointed by p.
821 //! <b>Returns</b>: An iterator to the inserted element.
823 //! <b>Throws</b>: Nothing.
825 //! <b>Complexity</b>: Constant time. No copy constructors are called.
827 //! <b>Note</b>: Does not affect the validity of iterators and references.
828 iterator insert(const_iterator p, reference value) BOOST_NOEXCEPT
830 node_ptr to_insert = this->priv_value_traits().to_node_ptr(value);
831 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
832 node_algorithms::link_before(p.pointed_node(), to_insert);
833 this->priv_size_traits().increment();
834 return iterator(to_insert, this->priv_value_traits_ptr());
837 //! <b>Requires</b>: Dereferencing iterator must yield
838 //! an lvalue of type value_type and p must be a valid iterator of *this.
840 //! <b>Effects</b>: Inserts the range pointed by b and e before the position p.
841 //! No copy constructors are called.
843 //! <b>Throws</b>: Nothing.
845 //! <b>Complexity</b>: Linear to the number of elements inserted.
847 //! <b>Note</b>: Does not affect the validity of iterators and references.
848 template<class Iterator>
849 void insert(const_iterator p, Iterator b, Iterator e) BOOST_NOEXCEPT
855 //! <b>Requires</b>: Dereferencing iterator must yield
856 //! an lvalue of type value_type.
858 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
859 //! No destructors or copy constructors are called.
861 //! <b>Throws</b>: Nothing.
863 //! <b>Complexity</b>: Linear to the number of elements inserted plus
864 //! linear to the elements contained in the list if it's a safe-mode
865 //! or auto-unlink value.
866 //! Linear to the number of elements inserted in the list otherwise.
868 //! <b>Note</b>: Invalidates the iterators (but not the references)
869 //! to the erased elements.
870 template<class Iterator>
871 void assign(Iterator b, Iterator e) BOOST_NOEXCEPT
874 this->insert(this->cend(), b, e);
877 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
879 //! <b>Requires</b>: Dereferencing iterator must yield
880 //! an lvalue of type value_type.
882 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
883 //! No destructors or copy constructors are called.
884 //! Disposer::operator()(pointer) is called for the removed elements.
886 //! <b>Throws</b>: Nothing.
888 //! <b>Complexity</b>: Linear to the number of elements inserted plus
889 //! linear to the elements contained in the list.
891 //! <b>Note</b>: Invalidates the iterators (but not the references)
892 //! to the erased elements.
893 template<class Iterator, class Disposer>
894 void dispose_and_assign(Disposer disposer, Iterator b, Iterator e) BOOST_NOEXCEPT
896 this->clear_and_dispose(disposer);
897 this->insert(this->cend(), b, e);
900 //! <b>Requires</b>: p must be a valid iterator of *this.
902 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
903 //! the element pointed by p. No destructors or copy constructors are called.
905 //! <b>Throws</b>: Nothing.
907 //! <b>Complexity</b>: Constant.
909 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
910 //! this list. Iterators of this list and all the references are not invalidated.
911 void splice(const_iterator p, list_impl& x) BOOST_NOEXCEPT
914 node_algorithms::transfer
915 (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
916 size_traits &thist = this->priv_size_traits();
917 size_traits &xt = x.priv_size_traits();
918 thist.increase(xt.get_size());
919 xt.set_size(size_type(0));
923 //! <b>Requires</b>: p must be a valid iterator of *this.
924 //! new_ele must point to an element contained in list x.
926 //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list,
927 //! before the element pointed by p. No destructors or copy constructors are called.
928 //! If p == new_ele or p == ++new_ele, this function is a null operation.
930 //! <b>Throws</b>: Nothing.
932 //! <b>Complexity</b>: Constant.
934 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
935 //! list. Iterators of this list and all the references are not invalidated.
936 void splice(const_iterator p, list_impl&x, const_iterator new_ele) BOOST_NOEXCEPT
938 node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
939 x.priv_size_traits().decrement();
940 this->priv_size_traits().increment();
943 //! <b>Requires</b>: p must be a valid iterator of *this.
944 //! f and e must point to elements contained in list x.
946 //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
947 //! before the element pointed by p. No destructors or copy constructors are called.
949 //! <b>Throws</b>: Nothing.
951 //! <b>Complexity</b>: Linear to the number of elements transferred
952 //! if constant-time size option is enabled. Constant-time otherwise.
954 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
955 //! list. Iterators of this list and all the references are not invalidated.
956 void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) BOOST_NOEXCEPT
958 BOOST_IF_CONSTEXPR(constant_time_size)
959 this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node()));
961 this->splice(p, x, f, e, 1);//intrusive::iterator_distance is a dummy value
964 //! <b>Requires</b>: p must be a valid iterator of *this.
965 //! f and e must point to elements contained in list x.
966 //! n == distance(f, e)
968 //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
969 //! before the element pointed by p. No destructors or copy constructors are called.
971 //! <b>Throws</b>: Nothing.
973 //! <b>Complexity</b>: Constant.
975 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
976 //! list. Iterators of this list and all the references are not invalidated.
977 void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n) BOOST_NOEXCEPT
980 BOOST_IF_CONSTEXPR(constant_time_size){
981 BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node()));
982 node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
983 size_traits &thist = this->priv_size_traits();
984 size_traits &xt = x.priv_size_traits();
989 node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
994 //! <b>Effects</b>: This function sorts the list *this according to operator <.
995 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
997 //! <b>Throws</b>: If value_traits::node_traits::node
998 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
999 //! or operator < throws. Basic guarantee.
1001 //! <b>Notes</b>: Iterators and references are not invalidated.
1003 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1004 //! is the list's size.
1006 { this->sort(value_less<value_type>()); }
1008 //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering
1010 //! <b>Effects</b>: This function sorts the list *this according to p. The sort is
1011 //! stable, that is, the relative order of equivalent elements is preserved.
1013 //! <b>Throws</b>: If value_traits::node_traits::node
1014 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1015 //! or the predicate throws. Basic guarantee.
1017 //! <b>Notes</b>: This won't throw if list_base_hook<> or
1018 //! list_member_hook are used.
1019 //! Iterators and references are not invalidated.
1021 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1022 //! is the list's size.
1023 template<class Predicate>
1024 void sort(Predicate p)
1026 if(node_traits::get_next(this->get_root_node())
1027 != node_traits::get_previous(this->get_root_node())){
1028 list_impl carry(this->priv_value_traits());
1029 detail::array_initializer<list_impl, 64> counter(this->priv_value_traits());
1031 while(!this->empty()){
1032 carry.splice(carry.cbegin(), *this, this->cbegin());
1034 while(i < fill && !counter[i].empty()) {
1035 counter[i].merge(carry, p);
1036 carry.swap(counter[i++]);
1038 carry.swap(counter[i]);
1042 for (int i = 1; i < fill; ++i)
1043 counter[i].merge(counter[i-1], p);
1044 this->swap(counter[fill-1]);
1048 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1049 //! in order into *this according to operator <. The merge is stable;
1050 //! that is, if an element from *this is equivalent to one from x, then the element
1051 //! from *this will precede the one from x.
1053 //! <b>Throws</b>: If operator < throws. Basic guarantee.
1055 //! <b>Complexity</b>: This function is linear time: it performs at most
1056 //! size() + x.size() - 1 comparisons.
1058 //! <b>Note</b>: Iterators and references are not invalidated
1059 void merge(list_impl& x)
1060 { this->merge(x, value_less<value_type>()); }
1062 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1063 //! ordering and both *this and x must be sorted according to that ordering
1064 //! The lists x and *this must be distinct.
1066 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1067 //! in order into *this. The merge is stable; that is, if an element from *this is
1068 //! equivalent to one from x, then the element from *this will precede the one from x.
1070 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1072 //! <b>Complexity</b>: This function is linear time: it performs at most
1073 //! size() + x.size() - 1 comparisons.
1075 //! <b>Note</b>: Iterators and references are not invalidated.
1076 template<class Predicate>
1077 void merge(list_impl& x, Predicate p)
1079 const_iterator e(this->cend()), ex(x.cend());
1080 const_iterator b(this->cbegin());
1082 const_iterator ix(x.cbegin());
1083 while (b != e && !p(*ix, *b)){
1087 //Now transfer the rest to the end of the container
1095 } while(ix != ex && p(*ix, *b));
1096 this->splice(b, x, x.begin(), ix, n);
1101 //! <b>Effects</b>: Reverses the order of elements in the list.
1103 //! <b>Throws</b>: Nothing.
1105 //! <b>Complexity</b>: This function is linear time.
1107 //! <b>Note</b>: Iterators and references are not invalidated
1108 void reverse() BOOST_NOEXCEPT
1109 { node_algorithms::reverse(this->get_root_node()); }
1111 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1112 //! No destructors are called.
1114 //! <b>Throws</b>: If operator == throws. Basic guarantee.
1116 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1118 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1119 //! and iterators to elements that are not removed remain valid.
1120 void remove(const_reference value) BOOST_NOEXCEPT
1121 { this->remove_if(detail::equal_to_value<const_reference>(value)); }
1123 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1125 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1126 //! Disposer::operator()(pointer) is called for every removed element.
1128 //! <b>Throws</b>: If operator == throws. Basic guarantee.
1130 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1132 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1133 //! and iterators to elements that are not removed remain valid.
1134 template<class Disposer>
1135 void remove_and_dispose(const_reference value, Disposer disposer) BOOST_NOEXCEPT
1136 { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
1138 //! <b>Effects</b>: Removes all the elements for which a specified
1139 //! predicate is satisfied. No destructors are called.
1141 //! <b>Throws</b>: If pred throws. Basic guarantee.
1143 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1145 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1146 //! and iterators to elements that are not removed remain valid.
1147 template<class Pred>
1148 void remove_if(Pred pred)
1150 const node_ptr root_node = this->get_root_node();
1151 typename node_algorithms::stable_partition_info info;
1152 node_algorithms::stable_partition
1153 (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1154 //Invariants preserved by stable_partition so erase can be safely called
1155 //The first element might have changed so calculate it again
1156 this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1157 , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1158 , info.num_1st_partition);
1161 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1163 //! <b>Effects</b>: Removes all the elements for which a specified
1164 //! predicate is satisfied.
1165 //! Disposer::operator()(pointer) is called for every removed element.
1167 //! <b>Throws</b>: If pred throws. Basic guarantee.
1169 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1171 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1172 //! and iterators to elements that are not removed remain valid.
1173 template<class Pred, class Disposer>
1174 void remove_and_dispose_if(Pred pred, Disposer disposer)
1176 const node_ptr root_node = this->get_root_node();
1177 typename node_algorithms::stable_partition_info info;
1178 node_algorithms::stable_partition
1179 (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1180 //Invariants preserved by stable_partition so erase can be safely called
1181 //The first element might have changed so calculate it again
1182 this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1183 , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1187 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1188 //! elements that are equal from the list. No destructors are called.
1190 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1192 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1194 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1195 //! and iterators to elements that are not removed remain valid.
1197 { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
1199 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1200 //! elements that satisfy some binary predicate from the list.
1201 //! No destructors are called.
1203 //! <b>Throws</b>: If pred throws. Basic guarantee.
1205 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1207 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1208 //! and iterators to elements that are not removed remain valid.
1209 template<class BinaryPredicate>
1210 void unique(BinaryPredicate pred)
1211 { this->unique_and_dispose(pred, detail::null_disposer()); }
1213 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1215 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1216 //! elements that are equal from the list.
1217 //! Disposer::operator()(pointer) is called for every removed element.
1219 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1221 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1223 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1224 //! and iterators to elements that are not removed remain valid.
1225 template<class Disposer>
1226 void unique_and_dispose(Disposer disposer)
1227 { this->unique_and_dispose(std::equal_to<value_type>(), disposer); }
1229 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1231 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1232 //! elements that satisfy some binary predicate from the list.
1233 //! Disposer::operator()(pointer) is called for every removed element.
1235 //! <b>Throws</b>: If pred throws. Basic guarantee.
1237 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1239 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1240 //! and iterators to elements that are not removed remain valid.
1241 template<class BinaryPredicate, class Disposer>
1242 void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
1244 const_iterator itend(this->cend());
1245 const_iterator cur(this->cbegin());
1248 const_iterator after(cur);
1250 while(after != itend){
1251 if(pred(*cur, *after)){
1252 after = this->erase_and_dispose(after, disposer);
1262 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1264 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1266 //! <b>Throws</b>: Nothing.
1268 //! <b>Complexity</b>: Constant time.
1270 //! <b>Note</b>: Iterators and references are not invalidated.
1271 //! This static function is available only if the <i>value traits</i>
1273 static iterator s_iterator_to(reference value) BOOST_NOEXCEPT
1275 BOOST_STATIC_ASSERT((!stateful_value_traits));
1276 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
1277 return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr());
1280 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1282 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1284 //! <b>Throws</b>: Nothing.
1286 //! <b>Complexity</b>: Constant time.
1288 //! <b>Note</b>: Iterators and references are not invalidated.
1289 //! This static function is available only if the <i>value traits</i>
1291 static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT
1293 BOOST_STATIC_ASSERT((!stateful_value_traits));
1294 reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1295 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r)));
1296 return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr());
1299 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1301 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1303 //! <b>Throws</b>: Nothing.
1305 //! <b>Complexity</b>: Constant time.
1307 //! <b>Note</b>: Iterators and references are not invalidated.
1308 iterator iterator_to(reference value) BOOST_NOEXCEPT
1310 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
1311 return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr());
1314 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1316 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1318 //! <b>Throws</b>: Nothing.
1320 //! <b>Complexity</b>: Constant time.
1322 //! <b>Note</b>: Iterators and references are not invalidated.
1323 const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT
1325 reference r = *detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1326 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r)));
1327 return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr());
1330 //! <b>Effects</b>: Asserts the integrity of the container.
1332 //! <b>Complexity</b>: Linear time.
1334 //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG).
1335 //! Experimental function, interface might change in future versions.
1338 const_node_ptr header_ptr = get_root_node();
1339 // header's next and prev are never null
1340 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr));
1341 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr));
1342 // header's next and prev either both point to header (empty list) or neither does
1343 BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr)
1344 == (node_traits::get_previous(header_ptr) == header_ptr));
1345 if (node_traits::get_next(header_ptr) == header_ptr)
1347 BOOST_IF_CONSTEXPR(constant_time_size)
1348 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0);
1351 size_t node_count = 0;
1352 const_node_ptr p = header_ptr;
1355 const_node_ptr next_p = node_traits::get_next(p);
1356 BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p);
1357 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p);
1359 if (p == header_ptr) break;
1362 BOOST_IF_CONSTEXPR(constant_time_size)
1363 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count);
1366 friend bool operator==(const list_impl &x, const list_impl &y)
1368 if(constant_time_size && x.size() != y.size()){
1371 return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
1374 BOOST_INTRUSIVE_FORCEINLINE friend bool operator!=(const list_impl &x, const list_impl &y)
1375 { return !(x == y); }
1377 BOOST_INTRUSIVE_FORCEINLINE friend bool operator<(const list_impl &x, const list_impl &y)
1378 { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1380 BOOST_INTRUSIVE_FORCEINLINE friend bool operator>(const list_impl &x, const list_impl &y)
1383 BOOST_INTRUSIVE_FORCEINLINE friend bool operator<=(const list_impl &x, const list_impl &y)
1384 { return !(y < x); }
1386 BOOST_INTRUSIVE_FORCEINLINE friend bool operator>=(const list_impl &x, const list_impl &y)
1387 { return !(x < y); }
1389 BOOST_INTRUSIVE_FORCEINLINE friend void swap(list_impl &x, list_impl &y) BOOST_NOEXCEPT
1395 static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) BOOST_NOEXCEPT
1397 BOOST_STATIC_ASSERT((has_container_from_iterator));
1398 node_ptr p = end_iterator.pointed_node();
1399 header_holder_type* h = header_holder_type::get_holder(p);
1400 root_plus_size* r = detail::parent_from_member
1401 < root_plus_size, header_holder_type>(h, &root_plus_size::m_header);
1402 data_t *d = detail::parent_from_member<data_t, root_plus_size>
1403 ( r, &data_t::root_plus_size_);
1404 list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
1411 //! Helper metafunction to define a \c list that yields to the same type when the
1412 //! same options (either explicitly or implicitly) are used.
1413 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1414 template<class T, class ...Options>
1416 template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void>
1421 typedef typename pack_options
1423 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1428 >::type packed_options;
1430 typedef typename detail::get_value_traits
1431 <T, typename packed_options::proto_value_traits>::type value_traits;
1435 typename packed_options::size_type,
1436 packed_options::constant_time_size,
1437 typename packed_options::header_holder_type
1438 > implementation_defined;
1440 typedef implementation_defined type;
1444 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1446 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1447 template<class T, class O1, class O2, class O3, class O4>
1449 template<class T, class ...Options>
1452 : public make_list<T,
1453 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1460 typedef typename make_list
1462 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1468 //Assert if passed value traits are compatible with the type
1469 BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
1470 BOOST_MOVABLE_BUT_NOT_COPYABLE(list)
1473 typedef typename Base::value_traits value_traits;
1474 typedef typename Base::iterator iterator;
1475 typedef typename Base::const_iterator const_iterator;
1477 BOOST_INTRUSIVE_FORCEINLINE list()
1481 BOOST_INTRUSIVE_FORCEINLINE explicit list(const value_traits &v_traits)
1485 template<class Iterator>
1486 BOOST_INTRUSIVE_FORCEINLINE list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
1487 : Base(b, e, v_traits)
1490 BOOST_INTRUSIVE_FORCEINLINE list(BOOST_RV_REF(list) x)
1491 : Base(BOOST_MOVE_BASE(Base, x))
1494 BOOST_INTRUSIVE_FORCEINLINE list& operator=(BOOST_RV_REF(list) x)
1495 { return static_cast<list &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
1497 template <class Cloner, class Disposer>
1498 BOOST_INTRUSIVE_FORCEINLINE void clone_from(const list &src, Cloner cloner, Disposer disposer)
1499 { Base::clone_from(src, cloner, disposer); }
1501 template <class Cloner, class Disposer>
1502 BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(list) src, Cloner cloner, Disposer disposer)
1503 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
1505 BOOST_INTRUSIVE_FORCEINLINE static list &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
1506 { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); }
1508 BOOST_INTRUSIVE_FORCEINLINE static const list &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
1509 { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); }
1514 } //namespace intrusive
1517 #include <boost/intrusive/detail/config_end.hpp>
1519 #endif //BOOST_INTRUSIVE_LIST_HPP