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/minimal_less_equal_header.hpp>//std::less
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 size_traits &priv_size_traits()
152 { return data_.root_plus_size_; }
154 const size_traits &priv_size_traits() const
155 { return data_.root_plus_size_; }
157 const value_traits &priv_value_traits() const
160 value_traits &priv_value_traits()
163 typedef typename boost::intrusive::value_traits_pointers
164 <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
166 const_value_traits_ptr priv_value_traits_ptr() const
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>: to-do
220 list_impl(BOOST_RV_REF(list_impl) x)
221 : data_(::boost::move(x.priv_value_traits()))
223 this->priv_size_traits().set_size(size_type(0));
224 node_algorithms::init_header(this->get_root_node());
225 //nothrow, no need to rollback to release elements on exception
229 //! <b>Effects</b>: to-do
231 list_impl& operator=(BOOST_RV_REF(list_impl) x)
232 { this->swap(x); return *this; }
234 //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type
235 //! the destructor does nothing
236 //! (ie. no code is generated). Otherwise it detaches all elements from this.
237 //! In this case the objects in the list are not deleted (i.e. no destructors
238 //! are called), but the hooks according to the ValueTraits template parameter
239 //! are set to their default value.
241 //! <b>Complexity</b>: Linear to the number of elements in the list, if
242 //! it's a safe-mode or auto-unlink value . Otherwise constant.
245 if(is_safe_autounlink<ValueTraits::link_mode>::value){
247 node_algorithms::init(this->get_root_node());
251 //! <b>Requires</b>: value must be an lvalue.
253 //! <b>Effects</b>: Inserts the value in the back of the list.
254 //! No copy constructors are called.
256 //! <b>Throws</b>: Nothing.
258 //! <b>Complexity</b>: Constant.
260 //! <b>Note</b>: Does not affect the validity of iterators and references.
261 void push_back(reference value)
263 node_ptr to_insert = priv_value_traits().to_node_ptr(value);
264 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
265 node_algorithms::link_before(this->get_root_node(), to_insert);
266 this->priv_size_traits().increment();
269 //! <b>Requires</b>: value must be an lvalue.
271 //! <b>Effects</b>: Inserts the value in the front of the list.
272 //! No copy constructors are called.
274 //! <b>Throws</b>: Nothing.
276 //! <b>Complexity</b>: Constant.
278 //! <b>Note</b>: Does not affect the validity of iterators and references.
279 void push_front(reference value)
281 node_ptr to_insert = priv_value_traits().to_node_ptr(value);
282 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
283 node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
284 this->priv_size_traits().increment();
287 //! <b>Effects</b>: Erases the last element of the list.
288 //! No destructors are called.
290 //! <b>Throws</b>: Nothing.
292 //! <b>Complexity</b>: Constant.
294 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
296 { return this->pop_back_and_dispose(detail::null_disposer()); }
298 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
300 //! <b>Effects</b>: Erases the last element of the list.
301 //! No destructors are called.
302 //! Disposer::operator()(pointer) is called for the removed element.
304 //! <b>Throws</b>: Nothing.
306 //! <b>Complexity</b>: Constant.
308 //! <b>Note</b>: Invalidates the iterators to the erased element.
309 template<class Disposer>
310 void pop_back_and_dispose(Disposer disposer)
312 node_ptr to_erase = node_traits::get_previous(this->get_root_node());
313 node_algorithms::unlink(to_erase);
314 this->priv_size_traits().decrement();
315 if(safemode_or_autounlink)
316 node_algorithms::init(to_erase);
317 disposer(priv_value_traits().to_value_ptr(to_erase));
320 //! <b>Effects</b>: Erases the first element of the list.
321 //! No destructors are called.
323 //! <b>Throws</b>: Nothing.
325 //! <b>Complexity</b>: Constant.
327 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
329 { return this->pop_front_and_dispose(detail::null_disposer()); }
331 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
333 //! <b>Effects</b>: Erases the first element of the list.
334 //! No destructors are called.
335 //! Disposer::operator()(pointer) is called for the removed element.
337 //! <b>Throws</b>: Nothing.
339 //! <b>Complexity</b>: Constant.
341 //! <b>Note</b>: Invalidates the iterators to the erased element.
342 template<class Disposer>
343 void pop_front_and_dispose(Disposer disposer)
345 node_ptr to_erase = node_traits::get_next(this->get_root_node());
346 node_algorithms::unlink(to_erase);
347 this->priv_size_traits().decrement();
348 if(safemode_or_autounlink)
349 node_algorithms::init(to_erase);
350 disposer(priv_value_traits().to_value_ptr(to_erase));
353 //! <b>Effects</b>: Returns a reference to the first element of the list.
355 //! <b>Throws</b>: Nothing.
357 //! <b>Complexity</b>: Constant.
359 { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
361 //! <b>Effects</b>: Returns a const_reference to the first element of the list.
363 //! <b>Throws</b>: Nothing.
365 //! <b>Complexity</b>: Constant.
366 const_reference front() const
367 { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
369 //! <b>Effects</b>: Returns a reference to the last element of the list.
371 //! <b>Throws</b>: Nothing.
373 //! <b>Complexity</b>: Constant.
375 { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
377 //! <b>Effects</b>: Returns a const_reference to the last element of the list.
379 //! <b>Throws</b>: Nothing.
381 //! <b>Complexity</b>: Constant.
382 const_reference back() const
383 { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); }
385 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
387 //! <b>Throws</b>: Nothing.
389 //! <b>Complexity</b>: Constant.
391 { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
393 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
395 //! <b>Throws</b>: Nothing.
397 //! <b>Complexity</b>: Constant.
398 const_iterator begin() const
399 { return this->cbegin(); }
401 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
403 //! <b>Throws</b>: Nothing.
405 //! <b>Complexity</b>: Constant.
406 const_iterator cbegin() const
407 { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
409 //! <b>Effects</b>: Returns an iterator to the end of the list.
411 //! <b>Throws</b>: Nothing.
413 //! <b>Complexity</b>: Constant.
415 { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); }
417 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
419 //! <b>Throws</b>: Nothing.
421 //! <b>Complexity</b>: Constant.
422 const_iterator end() const
423 { return this->cend(); }
425 //! <b>Effects</b>: Returns a constant iterator to the end of the list.
427 //! <b>Throws</b>: Nothing.
429 //! <b>Complexity</b>: Constant.
430 const_iterator cend() const
431 { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); }
433 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
434 //! of the reversed list.
436 //! <b>Throws</b>: Nothing.
438 //! <b>Complexity</b>: Constant.
439 reverse_iterator rbegin()
440 { return reverse_iterator(this->end()); }
442 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
443 //! of the reversed list.
445 //! <b>Throws</b>: Nothing.
447 //! <b>Complexity</b>: Constant.
448 const_reverse_iterator rbegin() const
449 { return this->crbegin(); }
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 const_reverse_iterator crbegin() const
458 { return const_reverse_iterator(end()); }
460 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
461 //! of the reversed list.
463 //! <b>Throws</b>: Nothing.
465 //! <b>Complexity</b>: Constant.
466 reverse_iterator rend()
467 { return reverse_iterator(begin()); }
469 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
470 //! of the reversed list.
472 //! <b>Throws</b>: Nothing.
474 //! <b>Complexity</b>: Constant.
475 const_reverse_iterator rend() const
476 { return this->crend(); }
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 const_reverse_iterator crend() const
485 { return const_reverse_iterator(this->begin()); }
487 //! <b>Precondition</b>: end_iterator must be a valid end iterator
490 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
492 //! <b>Throws</b>: Nothing.
494 //! <b>Complexity</b>: Constant.
495 static list_impl &container_from_end_iterator(iterator end_iterator)
496 { return list_impl::priv_container_from_end_iterator(end_iterator); }
498 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
501 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
503 //! <b>Throws</b>: Nothing.
505 //! <b>Complexity</b>: Constant.
506 static const list_impl &container_from_end_iterator(const_iterator end_iterator)
507 { return list_impl::priv_container_from_end_iterator(end_iterator); }
509 //! <b>Effects</b>: Returns the number of the elements contained in the list.
511 //! <b>Throws</b>: Nothing.
513 //! <b>Complexity</b>: Linear to the number of elements contained in the list.
514 //! if constant-time size option is disabled. Constant time otherwise.
516 //! <b>Note</b>: Does not affect the validity of iterators and references.
517 size_type size() const
519 if(constant_time_size)
520 return this->priv_size_traits().get_size();
522 return node_algorithms::count(this->get_root_node()) - 1;
525 //! <b>Effects</b>: Returns true if the list contains no elements.
527 //! <b>Throws</b>: Nothing.
529 //! <b>Complexity</b>: Constant.
531 //! <b>Note</b>: Does not affect the validity of iterators and references.
533 { return node_algorithms::unique(this->get_root_node()); }
535 //! <b>Effects</b>: Swaps the elements of x and *this.
537 //! <b>Throws</b>: Nothing.
539 //! <b>Complexity</b>: Constant.
541 //! <b>Note</b>: Does not affect the validity of iterators and references.
542 void swap(list_impl& other)
544 node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
545 this->priv_size_traits().swap(other.priv_size_traits());
548 //! <b>Effects</b>: Moves backwards all the elements, so that the first
549 //! element becomes the second, the second becomes the third...
550 //! the last element becomes the first one.
552 //! <b>Throws</b>: Nothing.
554 //! <b>Complexity</b>: Linear to the number of shifts.
556 //! <b>Note</b>: Does not affect the validity of iterators and references.
557 void shift_backwards(size_type n = 1)
558 { node_algorithms::move_forward(this->get_root_node(), n); }
560 //! <b>Effects</b>: Moves forward all the elements, so that the second
561 //! element becomes the first, the third becomes the second...
562 //! the first element becomes the last one.
564 //! <b>Throws</b>: Nothing.
566 //! <b>Complexity</b>: Linear to the number of shifts.
568 //! <b>Note</b>: Does not affect the validity of iterators and references.
569 void shift_forward(size_type n = 1)
570 { node_algorithms::move_backwards(this->get_root_node(), n); }
572 //! <b>Effects</b>: Erases the element pointed by i of the list.
573 //! No destructors are called.
575 //! <b>Returns</b>: the first element remaining beyond the removed element,
576 //! or end() if no such element exists.
578 //! <b>Throws</b>: Nothing.
580 //! <b>Complexity</b>: Constant.
582 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
584 iterator erase(const_iterator i)
585 { return this->erase_and_dispose(i, detail::null_disposer()); }
587 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
589 //! <b>Effects</b>: Erases the element range pointed by b and e
590 //! No destructors are called.
592 //! <b>Returns</b>: the first element remaining beyond the removed elements,
593 //! or end() if no such element exists.
595 //! <b>Throws</b>: Nothing.
597 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
598 //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise.
600 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
602 iterator erase(const_iterator b, const_iterator e)
604 if(safemode_or_autounlink || constant_time_size){
605 return this->erase_and_dispose(b, e, detail::null_disposer());
608 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
613 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
614 //! n must be distance(b, e).
616 //! <b>Effects</b>: Erases the element range pointed by b and e
617 //! No destructors are called.
619 //! <b>Returns</b>: the first element remaining beyond the removed elements,
620 //! or end() if no such element exists.
622 //! <b>Throws</b>: Nothing.
624 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
625 //! or auto-unlink value is enabled. Constant-time otherwise.
627 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
629 iterator erase(const_iterator b, const_iterator e, size_type n)
631 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n);
632 if(safemode_or_autounlink || constant_time_size){
633 return this->erase_and_dispose(b, e, detail::null_disposer());
636 if(constant_time_size){
637 this->priv_size_traits().decrease(n);
639 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
644 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
646 //! <b>Effects</b>: Erases the element pointed by i of the list.
647 //! No destructors are called.
648 //! Disposer::operator()(pointer) is called for the removed element.
650 //! <b>Returns</b>: the first element remaining beyond the removed element,
651 //! or end() if no such element exists.
653 //! <b>Throws</b>: Nothing.
655 //! <b>Complexity</b>: Constant.
657 //! <b>Note</b>: Invalidates the iterators to the erased element.
658 template <class Disposer>
659 iterator erase_and_dispose(const_iterator i, Disposer disposer)
661 node_ptr to_erase(i.pointed_node());
663 node_algorithms::unlink(to_erase);
664 this->priv_size_traits().decrement();
665 if(safemode_or_autounlink)
666 node_algorithms::init(to_erase);
667 disposer(this->priv_value_traits().to_value_ptr(to_erase));
671 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
672 template<class Disposer>
673 iterator erase_and_dispose(iterator i, Disposer disposer)
674 { return this->erase_and_dispose(const_iterator(i), disposer); }
677 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
679 //! <b>Effects</b>: Erases the element range pointed by b and e
680 //! No destructors are called.
681 //! Disposer::operator()(pointer) is called for the removed elements.
683 //! <b>Returns</b>: the first element remaining beyond the removed elements,
684 //! or end() if no such element exists.
686 //! <b>Throws</b>: Nothing.
688 //! <b>Complexity</b>: Linear to the number of elements erased.
690 //! <b>Note</b>: Invalidates the iterators to the erased elements.
691 template <class Disposer>
692 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
694 node_ptr bp(b.pointed_node()), ep(e.pointed_node());
695 node_algorithms::unlink(bp, ep);
697 node_ptr to_erase(bp);
698 bp = node_traits::get_next(bp);
699 if(safemode_or_autounlink)
700 node_algorithms::init(to_erase);
701 disposer(priv_value_traits().to_value_ptr(to_erase));
702 this->priv_size_traits().decrement();
707 //! <b>Effects</b>: Erases all the elements of the container.
708 //! No destructors are called.
710 //! <b>Throws</b>: Nothing.
712 //! <b>Complexity</b>: Linear to the number of elements of the list.
713 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
715 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
718 if(safemode_or_autounlink){
719 this->clear_and_dispose(detail::null_disposer());
722 node_algorithms::init_header(this->get_root_node());
723 this->priv_size_traits().set_size(size_type(0));
727 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
729 //! <b>Effects</b>: Erases all the elements of the container.
730 //! No destructors are called.
731 //! Disposer::operator()(pointer) is called for the removed elements.
733 //! <b>Throws</b>: Nothing.
735 //! <b>Complexity</b>: Linear to the number of elements of the list.
737 //! <b>Note</b>: Invalidates the iterators to the erased elements.
738 template <class Disposer>
739 void clear_and_dispose(Disposer disposer)
741 const_iterator it(this->begin()), itend(this->end());
743 node_ptr to_erase(it.pointed_node());
745 if(safemode_or_autounlink)
746 node_algorithms::init(to_erase);
747 disposer(priv_value_traits().to_value_ptr(to_erase));
749 node_algorithms::init_header(this->get_root_node());
750 this->priv_size_traits().set_size(0);
753 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
754 //! Cloner should yield to nodes equivalent to the original nodes.
756 //! <b>Effects</b>: Erases all the elements from *this
757 //! calling Disposer::operator()(pointer), clones all the
758 //! elements from src calling Cloner::operator()(const_reference )
759 //! and inserts them on *this.
761 //! If cloner throws, all cloned elements are unlinked and disposed
762 //! calling Disposer::operator()(pointer).
764 //! <b>Complexity</b>: Linear to erased plus inserted elements.
766 //! <b>Throws</b>: If cloner throws. Basic guarantee.
767 template <class Cloner, class Disposer>
768 void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
770 this->clear_and_dispose(disposer);
771 detail::exception_disposer<list_impl, Disposer>
772 rollback(*this, disposer);
773 const_iterator b(src.begin()), e(src.end());
775 this->push_back(*cloner(*b));
780 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
781 //! Cloner should yield to nodes equivalent to the original nodes.
783 //! <b>Effects</b>: Erases all the elements from *this
784 //! calling Disposer::operator()(pointer), clones all the
785 //! elements from src calling Cloner::operator()(reference)
786 //! and inserts them on *this.
788 //! If cloner throws, all cloned elements are unlinked and disposed
789 //! calling Disposer::operator()(pointer).
791 //! <b>Complexity</b>: Linear to erased plus inserted elements.
793 //! <b>Throws</b>: If cloner throws. Basic guarantee.
794 template <class Cloner, class Disposer>
795 void clone_from(BOOST_RV_REF(list_impl) src, Cloner cloner, Disposer disposer)
797 this->clear_and_dispose(disposer);
798 detail::exception_disposer<list_impl, Disposer>
799 rollback(*this, disposer);
800 iterator b(src.begin()), e(src.end());
802 this->push_back(*cloner(*b));
807 //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this.
809 //! <b>Effects</b>: Inserts the value before the position pointed by p.
811 //! <b>Returns</b>: An iterator to the inserted element.
813 //! <b>Throws</b>: Nothing.
815 //! <b>Complexity</b>: Constant time. No copy constructors are called.
817 //! <b>Note</b>: Does not affect the validity of iterators and references.
818 iterator insert(const_iterator p, reference value)
820 node_ptr to_insert = this->priv_value_traits().to_node_ptr(value);
821 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
822 node_algorithms::link_before(p.pointed_node(), to_insert);
823 this->priv_size_traits().increment();
824 return iterator(to_insert, this->priv_value_traits_ptr());
827 //! <b>Requires</b>: Dereferencing iterator must yield
828 //! an lvalue of type value_type and p must be a valid iterator of *this.
830 //! <b>Effects</b>: Inserts the range pointed by b and e before the position p.
831 //! No copy constructors are called.
833 //! <b>Throws</b>: Nothing.
835 //! <b>Complexity</b>: Linear to the number of elements inserted.
837 //! <b>Note</b>: Does not affect the validity of iterators and references.
838 template<class Iterator>
839 void insert(const_iterator p, Iterator b, Iterator e)
845 //! <b>Requires</b>: Dereferencing iterator must yield
846 //! an lvalue of type value_type.
848 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
849 //! No destructors or copy constructors are called.
851 //! <b>Throws</b>: Nothing.
853 //! <b>Complexity</b>: Linear to the number of elements inserted plus
854 //! linear to the elements contained in the list if it's a safe-mode
855 //! or auto-unlink value.
856 //! Linear to the number of elements inserted in the list otherwise.
858 //! <b>Note</b>: Invalidates the iterators (but not the references)
859 //! to the erased elements.
860 template<class Iterator>
861 void assign(Iterator b, Iterator e)
864 this->insert(this->cend(), b, e);
867 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
869 //! <b>Requires</b>: Dereferencing iterator must yield
870 //! an lvalue of type value_type.
872 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
873 //! No destructors or copy constructors are called.
874 //! Disposer::operator()(pointer) is called for the removed elements.
876 //! <b>Throws</b>: Nothing.
878 //! <b>Complexity</b>: Linear to the number of elements inserted plus
879 //! linear to the elements contained in the list.
881 //! <b>Note</b>: Invalidates the iterators (but not the references)
882 //! to the erased elements.
883 template<class Iterator, class Disposer>
884 void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
886 this->clear_and_dispose(disposer);
887 this->insert(this->cend(), b, e);
890 //! <b>Requires</b>: p must be a valid iterator of *this.
892 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
893 //! the element pointed by p. No destructors or copy constructors are called.
895 //! <b>Throws</b>: Nothing.
897 //! <b>Complexity</b>: Constant.
899 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
900 //! this list. Iterators of this list and all the references are not invalidated.
901 void splice(const_iterator p, list_impl& x)
904 node_algorithms::transfer
905 (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
906 size_traits &thist = this->priv_size_traits();
907 size_traits &xt = x.priv_size_traits();
908 thist.increase(xt.get_size());
909 xt.set_size(size_type(0));
913 //! <b>Requires</b>: p must be a valid iterator of *this.
914 //! new_ele must point to an element contained in list x.
916 //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list,
917 //! before the element pointed by p. No destructors or copy constructors are called.
918 //! If p == new_ele or p == ++new_ele, this function is a null operation.
920 //! <b>Throws</b>: Nothing.
922 //! <b>Complexity</b>: Constant.
924 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
925 //! list. Iterators of this list and all the references are not invalidated.
926 void splice(const_iterator p, list_impl&x, const_iterator new_ele)
928 node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
929 x.priv_size_traits().decrement();
930 this->priv_size_traits().increment();
933 //! <b>Requires</b>: p must be a valid iterator of *this.
934 //! f and e must point to elements contained in list x.
936 //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
937 //! before the element pointed by p. No destructors or copy constructors are called.
939 //! <b>Throws</b>: Nothing.
941 //! <b>Complexity</b>: Linear to the number of elements transferred
942 //! if constant-time size option is enabled. Constant-time otherwise.
944 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
945 //! list. Iterators of this list and all the references are not invalidated.
946 void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e)
948 if(constant_time_size)
949 this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node()));
951 this->splice(p, x, f, e, 1);//intrusive::iterator_distance is a dummy value
954 //! <b>Requires</b>: p must be a valid iterator of *this.
955 //! f and e must point to elements contained in list x.
956 //! n == distance(f, e)
958 //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
959 //! before the element pointed by p. No destructors or copy constructors are called.
961 //! <b>Throws</b>: Nothing.
963 //! <b>Complexity</b>: Constant.
965 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
966 //! list. Iterators of this list and all the references are not invalidated.
967 void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n)
970 if(constant_time_size){
971 BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node()));
972 node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
973 size_traits &thist = this->priv_size_traits();
974 size_traits &xt = x.priv_size_traits();
979 node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
984 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
985 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
987 //! <b>Throws</b>: If value_traits::node_traits::node
988 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
989 //! or std::less<value_type> throws. Basic guarantee.
991 //! <b>Notes</b>: Iterators and references are not invalidated.
993 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
994 //! is the list's size.
996 { this->sort(std::less<value_type>()); }
998 //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering
1000 //! <b>Effects</b>: This function sorts the list *this according to p. The sort is
1001 //! stable, that is, the relative order of equivalent elements is preserved.
1003 //! <b>Throws</b>: If value_traits::node_traits::node
1004 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1005 //! or the predicate throws. Basic guarantee.
1007 //! <b>Notes</b>: This won't throw if list_base_hook<> or
1008 //! list_member_hook are used.
1009 //! Iterators and references are not invalidated.
1011 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1012 //! is the list's size.
1013 template<class Predicate>
1014 void sort(Predicate p)
1016 if(node_traits::get_next(this->get_root_node())
1017 != node_traits::get_previous(this->get_root_node())){
1018 list_impl carry(this->priv_value_traits());
1019 detail::array_initializer<list_impl, 64> counter(this->priv_value_traits());
1021 while(!this->empty()){
1022 carry.splice(carry.cbegin(), *this, this->cbegin());
1024 while(i < fill && !counter[i].empty()) {
1025 counter[i].merge(carry, p);
1026 carry.swap(counter[i++]);
1028 carry.swap(counter[i]);
1032 for (int i = 1; i < fill; ++i)
1033 counter[i].merge(counter[i-1], p);
1034 this->swap(counter[fill-1]);
1038 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1039 //! in order into *this according to std::less<value_type>. The merge is stable;
1040 //! that is, if an element from *this is equivalent to one from x, then the element
1041 //! from *this will precede the one from x.
1043 //! <b>Throws</b>: If std::less<value_type> throws. Basic guarantee.
1045 //! <b>Complexity</b>: This function is linear time: it performs at most
1046 //! size() + x.size() - 1 comparisons.
1048 //! <b>Note</b>: Iterators and references are not invalidated
1049 void merge(list_impl& x)
1050 { this->merge(x, std::less<value_type>()); }
1052 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1053 //! ordering and both *this and x must be sorted according to that ordering
1054 //! The lists x and *this must be distinct.
1056 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1057 //! in order into *this. The merge is stable; that is, if an element from *this is
1058 //! equivalent to one from x, then the element from *this will precede the one from x.
1060 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1062 //! <b>Complexity</b>: This function is linear time: it performs at most
1063 //! size() + x.size() - 1 comparisons.
1065 //! <b>Note</b>: Iterators and references are not invalidated.
1066 template<class Predicate>
1067 void merge(list_impl& x, Predicate p)
1069 const_iterator e(this->cend()), ex(x.cend());
1070 const_iterator b(this->cbegin());
1072 const_iterator ix(x.cbegin());
1073 while (b != e && !p(*ix, *b)){
1077 //Now transfer the rest to the end of the container
1085 } while(ix != ex && p(*ix, *b));
1086 this->splice(b, x, x.begin(), ix, n);
1091 //! <b>Effects</b>: Reverses the order of elements in the list.
1093 //! <b>Throws</b>: Nothing.
1095 //! <b>Complexity</b>: This function is linear time.
1097 //! <b>Note</b>: Iterators and references are not invalidated
1099 { node_algorithms::reverse(this->get_root_node()); }
1101 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1102 //! No destructors are called.
1104 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1106 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1108 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1109 //! and iterators to elements that are not removed remain valid.
1110 void remove(const_reference value)
1111 { this->remove_if(detail::equal_to_value<const_reference>(value)); }
1113 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1115 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1116 //! Disposer::operator()(pointer) is called for every removed element.
1118 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1120 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1122 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1123 //! and iterators to elements that are not removed remain valid.
1124 template<class Disposer>
1125 void remove_and_dispose(const_reference value, Disposer disposer)
1126 { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
1128 //! <b>Effects</b>: Removes all the elements for which a specified
1129 //! predicate is satisfied. No destructors are called.
1131 //! <b>Throws</b>: If pred throws. Basic guarantee.
1133 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1135 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1136 //! and iterators to elements that are not removed remain valid.
1137 template<class Pred>
1138 void remove_if(Pred pred)
1140 const node_ptr root_node = this->get_root_node();
1141 typename node_algorithms::stable_partition_info info;
1142 node_algorithms::stable_partition
1143 (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1144 //Invariants preserved by stable_partition so erase can be safely called
1145 //The first element might have changed so calculate it again
1146 this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1147 , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1148 , info.num_1st_partition);
1151 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1153 //! <b>Effects</b>: Removes all the elements for which a specified
1154 //! predicate is satisfied.
1155 //! Disposer::operator()(pointer) is called for every removed element.
1157 //! <b>Throws</b>: If pred throws. Basic guarantee.
1159 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1161 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1162 //! and iterators to elements that are not removed remain valid.
1163 template<class Pred, class Disposer>
1164 void remove_and_dispose_if(Pred pred, Disposer disposer)
1166 const node_ptr root_node = this->get_root_node();
1167 typename node_algorithms::stable_partition_info info;
1168 node_algorithms::stable_partition
1169 (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1170 //Invariants preserved by stable_partition so erase can be safely called
1171 //The first element might have changed so calculate it again
1172 this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1173 , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1177 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1178 //! elements that are equal from the list. No destructors are called.
1180 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1182 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1184 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1185 //! and iterators to elements that are not removed remain valid.
1187 { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
1189 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1190 //! elements that satisfy some binary predicate from the list.
1191 //! No destructors are called.
1193 //! <b>Throws</b>: If pred throws. Basic guarantee.
1195 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1197 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1198 //! and iterators to elements that are not removed remain valid.
1199 template<class BinaryPredicate>
1200 void unique(BinaryPredicate pred)
1201 { this->unique_and_dispose(pred, detail::null_disposer()); }
1203 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1205 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1206 //! elements that are equal from the list.
1207 //! Disposer::operator()(pointer) is called for every removed element.
1209 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1211 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1213 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1214 //! and iterators to elements that are not removed remain valid.
1215 template<class Disposer>
1216 void unique_and_dispose(Disposer disposer)
1217 { this->unique_and_dispose(std::equal_to<value_type>(), disposer); }
1219 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1221 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1222 //! elements that satisfy some binary predicate from the list.
1223 //! Disposer::operator()(pointer) is called for every removed element.
1225 //! <b>Throws</b>: If pred throws. Basic guarantee.
1227 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1229 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1230 //! and iterators to elements that are not removed remain valid.
1231 template<class BinaryPredicate, class Disposer>
1232 void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
1234 const_iterator itend(this->cend());
1235 const_iterator cur(this->cbegin());
1238 const_iterator after(cur);
1240 while(after != itend){
1241 if(pred(*cur, *after)){
1242 after = this->erase_and_dispose(after, disposer);
1252 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1254 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1256 //! <b>Throws</b>: Nothing.
1258 //! <b>Complexity</b>: Constant time.
1260 //! <b>Note</b>: Iterators and references are not invalidated.
1261 //! This static function is available only if the <i>value traits</i>
1263 static iterator s_iterator_to(reference value)
1265 BOOST_STATIC_ASSERT((!stateful_value_traits));
1266 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
1267 return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr());
1270 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1272 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1274 //! <b>Throws</b>: Nothing.
1276 //! <b>Complexity</b>: Constant time.
1278 //! <b>Note</b>: Iterators and references are not invalidated.
1279 //! This static function is available only if the <i>value traits</i>
1281 static const_iterator s_iterator_to(const_reference value)
1283 BOOST_STATIC_ASSERT((!stateful_value_traits));
1284 reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1285 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r)));
1286 return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr());
1289 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1291 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1293 //! <b>Throws</b>: Nothing.
1295 //! <b>Complexity</b>: Constant time.
1297 //! <b>Note</b>: Iterators and references are not invalidated.
1298 iterator iterator_to(reference value)
1300 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
1301 return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr());
1304 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1306 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1308 //! <b>Throws</b>: Nothing.
1310 //! <b>Complexity</b>: Constant time.
1312 //! <b>Note</b>: Iterators and references are not invalidated.
1313 const_iterator iterator_to(const_reference value) const
1315 reference r = *detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1316 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r)));
1317 return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr());
1320 //! <b>Effects</b>: Asserts the integrity of the container.
1322 //! <b>Complexity</b>: Linear time.
1324 //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG).
1325 //! Experimental function, interface might change in future versions.
1328 const_node_ptr header_ptr = get_root_node();
1329 // header's next and prev are never null
1330 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr));
1331 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr));
1332 // header's next and prev either both point to header (empty list) or neither does
1333 BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr)
1334 == (node_traits::get_previous(header_ptr) == header_ptr));
1335 if (node_traits::get_next(header_ptr) == header_ptr)
1337 if (constant_time_size)
1338 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0);
1341 size_t node_count = 0;
1342 const_node_ptr p = header_ptr;
1345 const_node_ptr next_p = node_traits::get_next(p);
1346 BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p);
1347 BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p);
1349 if (p == header_ptr) break;
1352 if (constant_time_size)
1353 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count);
1356 friend bool operator==(const list_impl &x, const list_impl &y)
1358 if(constant_time_size && x.size() != y.size()){
1361 return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
1364 friend bool operator!=(const list_impl &x, const list_impl &y)
1365 { return !(x == y); }
1367 friend bool operator<(const list_impl &x, const list_impl &y)
1368 { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1370 friend bool operator>(const list_impl &x, const list_impl &y)
1373 friend bool operator<=(const list_impl &x, const list_impl &y)
1374 { return !(y < x); }
1376 friend bool operator>=(const list_impl &x, const list_impl &y)
1377 { return !(x < y); }
1379 friend void swap(list_impl &x, list_impl &y)
1385 static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
1387 BOOST_STATIC_ASSERT((has_container_from_iterator));
1388 node_ptr p = end_iterator.pointed_node();
1389 header_holder_type* h = header_holder_type::get_holder(p);
1390 root_plus_size* r = detail::parent_from_member
1391 < root_plus_size, header_holder_type>(h, &root_plus_size::m_header);
1392 data_t *d = detail::parent_from_member<data_t, root_plus_size>
1393 ( r, &data_t::root_plus_size_);
1394 list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
1401 //! Helper metafunction to define a \c list that yields to the same type when the
1402 //! same options (either explicitly or implicitly) are used.
1403 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1404 template<class T, class ...Options>
1406 template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void>
1411 typedef typename pack_options
1413 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1418 >::type packed_options;
1420 typedef typename detail::get_value_traits
1421 <T, typename packed_options::proto_value_traits>::type value_traits;
1425 typename packed_options::size_type,
1426 packed_options::constant_time_size,
1427 typename packed_options::header_holder_type
1428 > implementation_defined;
1430 typedef implementation_defined type;
1434 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1436 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1437 template<class T, class O1, class O2, class O3, class O4>
1439 template<class T, class ...Options>
1442 : public make_list<T,
1443 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1450 typedef typename make_list
1452 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1458 //Assert if passed value traits are compatible with the type
1459 BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
1460 BOOST_MOVABLE_BUT_NOT_COPYABLE(list)
1463 typedef typename Base::value_traits value_traits;
1464 typedef typename Base::iterator iterator;
1465 typedef typename Base::const_iterator const_iterator;
1471 explicit list(const value_traits &v_traits)
1475 template<class Iterator>
1476 list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
1477 : Base(b, e, v_traits)
1480 list(BOOST_RV_REF(list) x)
1481 : Base(BOOST_MOVE_BASE(Base, x))
1484 list& operator=(BOOST_RV_REF(list) x)
1485 { return static_cast<list &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
1487 template <class Cloner, class Disposer>
1488 void clone_from(const list &src, Cloner cloner, Disposer disposer)
1489 { Base::clone_from(src, cloner, disposer); }
1491 template <class Cloner, class Disposer>
1492 void clone_from(BOOST_RV_REF(list) src, Cloner cloner, Disposer disposer)
1493 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
1495 static list &container_from_end_iterator(iterator end_iterator)
1496 { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); }
1498 static const list &container_from_end_iterator(const_iterator end_iterator)
1499 { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); }
1504 } //namespace intrusive
1507 #include <boost/intrusive/detail/config_end.hpp>
1509 #endif //BOOST_INTRUSIVE_LIST_HPP