fix doc example typo
[boost.git] / boost / intrusive / list.hpp
blobd38d960947bec7dd37de6f6f26ccd9bb9a4d6a6e
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2008
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_LIST_HPP
15 #define BOOST_INTRUSIVE_LIST_HPP
17 #include <boost/intrusive/detail/config_begin.hpp>
18 #include <boost/intrusive/detail/assert.hpp>
19 #include <boost/intrusive/intrusive_fwd.hpp>
20 #include <boost/intrusive/list_hook.hpp>
21 #include <boost/intrusive/circular_list_algorithms.hpp>
22 #include <boost/intrusive/detail/pointer_to_other.hpp>
23 #include <boost/intrusive/detail/clear_on_destructor_base.hpp>
24 #include <boost/intrusive/detail/mpl.hpp>
25 #include <boost/intrusive/link_mode.hpp>
26 #include <boost/static_assert.hpp>
27 #include <boost/intrusive/options.hpp>
28 #include <boost/intrusive/detail/utilities.hpp>
29 #include <iterator>
30 #include <algorithm>
31 #include <functional>
32 #include <cstddef>
34 namespace boost {
35 namespace intrusive {
37 /// @cond
39 template <class ValueTraits, class SizeType, bool ConstantTimeSize>
40 struct listopt
42 typedef ValueTraits value_traits;
43 typedef SizeType size_type;
44 static const bool constant_time_size = ConstantTimeSize;
48 template <class T>
49 struct list_defaults
50 : pack_options
51 < none
52 , base_hook<detail::default_list_hook>
53 , constant_time_size<true>
54 , size_type<std::size_t>
55 >::type
56 {};
58 /// @endcond
60 //! The class template list is an intrusive container that mimics most of the
61 //! interface of std::list as described in the C++ standard.
62 //!
63 //! The template parameter \c T is the type to be managed by the container.
64 //! The user can specify additional options and if no options are provided
65 //! default options are used.
66 //!
67 //! The container supports the following options:
68 //! \c base_hook<>/member_hook<>/value_traits<>,
69 //! \c constant_time_size<> and \c size_type<>.
70 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
71 template<class T, class ...Options>
72 #else
73 template<class Config>
74 #endif
75 class list_impl
76 : private detail::clear_on_destructor_base< list_impl<Config> >
78 template<class C> friend class detail::clear_on_destructor_base;
79 //Public typedefs
80 public:
81 typedef typename Config::value_traits value_traits;
82 /// @cond
83 static const bool external_value_traits =
84 detail::external_value_traits_is_true<value_traits>::value;
85 typedef typename detail::eval_if_c
86 < external_value_traits
87 , detail::eval_value_traits<value_traits>
88 , detail::identity<value_traits>
89 >::type real_value_traits;
90 /// @endcond
91 typedef typename real_value_traits::pointer pointer;
92 typedef typename real_value_traits::const_pointer const_pointer;
93 typedef typename std::iterator_traits<pointer>::value_type value_type;
94 typedef typename std::iterator_traits<pointer>::reference reference;
95 typedef typename std::iterator_traits<const_pointer>::reference const_reference;
96 typedef typename std::iterator_traits<pointer>::difference_type difference_type;
97 typedef typename Config::size_type size_type;
98 typedef list_iterator<list_impl, false> iterator;
99 typedef list_iterator<list_impl, true> const_iterator;
100 typedef std::reverse_iterator<iterator> reverse_iterator;
101 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
102 typedef typename real_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;
108 static const bool constant_time_size = Config::constant_time_size;
109 static const bool stateful_value_traits = detail::store_cont_ptr_on_it<list_impl>::value;
111 /// @cond
113 private:
114 typedef detail::size_holder<constant_time_size, size_type> size_traits;
116 //Non-copyable and non-moveable
117 list_impl (const list_impl&);
118 list_impl &operator =(const list_impl&);
120 enum { safemode_or_autounlink =
121 (int)real_value_traits::link_mode == (int)auto_unlink ||
122 (int)real_value_traits::link_mode == (int)safe_link };
124 //Constant-time size is incompatible with auto-unlink hooks!
125 BOOST_STATIC_ASSERT(!(constant_time_size &&
126 ((int)real_value_traits::link_mode == (int)auto_unlink)
129 //Const cast emulation for smart pointers
130 static node_ptr uncast(const_node_ptr ptr)
132 //return node_ptr(detail::get_pointer(ptr)));
133 return const_cast<node*>(detail::get_pointer(ptr));
136 node_ptr get_root_node()
137 { return node_ptr(&data_.root_plus_size_.root_); }
139 const_node_ptr get_root_node() const
140 { return const_node_ptr(&data_.root_plus_size_.root_); }
142 struct root_plus_size : public size_traits
144 node root_;
147 struct data_t : public value_traits
149 typedef typename list_impl::value_traits value_traits;
150 data_t(const value_traits &val_traits)
151 : value_traits(val_traits)
154 root_plus_size root_plus_size_;
155 } data_;
157 size_traits &priv_size_traits()
158 { return data_.root_plus_size_; }
160 const size_traits &priv_size_traits() const
161 { return data_.root_plus_size_; }
163 const real_value_traits &get_real_value_traits(detail::bool_<false>) const
164 { return data_; }
166 const real_value_traits &get_real_value_traits(detail::bool_<true>) const
167 { return data_.get_value_traits(*this); }
169 real_value_traits &get_real_value_traits(detail::bool_<false>)
170 { return data_; }
172 real_value_traits &get_real_value_traits(detail::bool_<true>)
173 { return data_.get_value_traits(*this); }
175 /// @endcond
177 public:
179 const real_value_traits &get_real_value_traits() const
180 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
182 real_value_traits &get_real_value_traits()
183 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
185 //! <b>Effects</b>: constructs an empty list.
186 //!
187 //! <b>Complexity</b>: Constant
188 //!
189 //! <b>Throws</b>: If real_value_traits::node_traits::node
190 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
191 list_impl(const value_traits &v_traits = value_traits())
192 : data_(v_traits)
194 this->priv_size_traits().set_size(size_type(0));
195 node_algorithms::init_header(this->get_root_node());
198 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
199 //!
200 //! <b>Effects</b>: Constructs a list equal to the range [first,last).
201 //!
202 //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called.
203 //!
204 //! <b>Throws</b>: If real_value_traits::node_traits::node
205 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
206 template<class Iterator>
207 list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
208 : data_(v_traits)
210 this->priv_size_traits().set_size(size_type(0));
211 node_algorithms::init_header(this->get_root_node());
212 this->insert(this->cend(), b, e);
215 //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type
216 //! the destructor does nothing
217 //! (ie. no code is generated). Otherwise it detaches all elements from this.
218 //! In this case the objects in the list are not deleted (i.e. no destructors
219 //! are called), but the hooks according to the ValueTraits template parameter
220 //! are set to their default value.
221 //!
222 //! <b>Complexity</b>: Linear to the number of elements in the list, if
223 //! it's a safe-mode or auto-unlink value . Otherwise constant.
224 ~list_impl()
227 //! <b>Requires</b>: value must be an lvalue.
228 //!
229 //! <b>Effects</b>: Inserts the value in the back of the list.
230 //! No copy constructors are called.
231 //!
232 //! <b>Throws</b>: Nothing.
233 //!
234 //! <b>Complexity</b>: Constant.
235 //!
236 //! <b>Note</b>: Does not affect the validity of iterators and references.
237 void push_back(reference value)
239 node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
240 if(safemode_or_autounlink)
241 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
242 node_algorithms::link_before(this->get_root_node(), to_insert);
243 this->priv_size_traits().increment();
246 //! <b>Requires</b>: value must be an lvalue.
247 //!
248 //! <b>Effects</b>: Inserts the value in the front of the list.
249 //! No copy constructors are called.
250 //!
251 //! <b>Throws</b>: Nothing.
252 //!
253 //! <b>Complexity</b>: Constant.
254 //!
255 //! <b>Note</b>: Does not affect the validity of iterators and references.
256 void push_front(reference value)
258 node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
259 if(safemode_or_autounlink)
260 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
261 node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
262 this->priv_size_traits().increment();
265 //! <b>Effects</b>: Erases the last element of the list.
266 //! No destructors are called.
267 //!
268 //! <b>Throws</b>: Nothing.
269 //!
270 //! <b>Complexity</b>: Constant.
271 //!
272 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
273 void pop_back()
274 { return this->pop_back_and_dispose(detail::null_disposer()); }
276 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
278 //! <b>Effects</b>: Erases the last element of the list.
279 //! No destructors are called.
280 //! Disposer::operator()(pointer) is called for the removed element.
281 //!
282 //! <b>Throws</b>: Nothing.
283 //!
284 //! <b>Complexity</b>: Constant.
285 //!
286 //! <b>Note</b>: Invalidates the iterators to the erased element.
287 template<class Disposer>
288 void pop_back_and_dispose(Disposer disposer)
290 node_ptr to_erase = node_traits::get_previous(this->get_root_node());
291 node_algorithms::unlink(to_erase);
292 this->priv_size_traits().decrement();
293 if(safemode_or_autounlink)
294 node_algorithms::init(to_erase);
295 disposer(get_real_value_traits().to_value_ptr(to_erase));
298 //! <b>Effects</b>: Erases the first element of the list.
299 //! No destructors are called.
300 //!
301 //! <b>Throws</b>: Nothing.
302 //!
303 //! <b>Complexity</b>: Constant.
304 //!
305 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
306 void pop_front()
307 { return this->pop_front_and_dispose(detail::null_disposer()); }
309 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
311 //! <b>Effects</b>: Erases the first element of the list.
312 //! No destructors are called.
313 //! Disposer::operator()(pointer) is called for the removed element.
314 //!
315 //! <b>Throws</b>: Nothing.
316 //!
317 //! <b>Complexity</b>: Constant.
318 //!
319 //! <b>Note</b>: Invalidates the iterators to the erased element.
320 template<class Disposer>
321 void pop_front_and_dispose(Disposer disposer)
323 node_ptr to_erase = node_traits::get_next(this->get_root_node());
324 node_algorithms::unlink(to_erase);
325 this->priv_size_traits().decrement();
326 if(safemode_or_autounlink)
327 node_algorithms::init(to_erase);
328 disposer(get_real_value_traits().to_value_ptr(to_erase));
331 //! <b>Effects</b>: Returns a reference to the first element of the list.
332 //!
333 //! <b>Throws</b>: Nothing.
334 //!
335 //! <b>Complexity</b>: Constant.
336 reference front()
337 { return *get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
339 //! <b>Effects</b>: Returns a const_reference to the first element of the list.
340 //!
341 //! <b>Throws</b>: Nothing.
342 //!
343 //! <b>Complexity</b>: Constant.
344 const_reference front() const
345 { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); }
347 //! <b>Effects</b>: Returns a reference to the last element of the list.
348 //!
349 //! <b>Throws</b>: Nothing.
350 //!
351 //! <b>Complexity</b>: Constant.
352 reference back()
353 { return *get_real_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
355 //! <b>Effects</b>: Returns a const_reference to the last element of the list.
356 //!
357 //! <b>Throws</b>: Nothing.
358 //!
359 //! <b>Complexity</b>: Constant.
360 const_reference back() const
361 { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_previous(this->get_root_node()))); }
363 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
364 //!
365 //! <b>Throws</b>: Nothing.
366 //!
367 //! <b>Complexity</b>: Constant.
368 iterator begin()
369 { return iterator(node_traits::get_next(this->get_root_node()), this); }
371 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
372 //!
373 //! <b>Throws</b>: Nothing.
374 //!
375 //! <b>Complexity</b>: Constant.
376 const_iterator begin() const
377 { return this->cbegin(); }
379 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
380 //!
381 //! <b>Throws</b>: Nothing.
382 //!
383 //! <b>Complexity</b>: Constant.
384 const_iterator cbegin() const
385 { return const_iterator(node_traits::get_next(this->get_root_node()), this); }
387 //! <b>Effects</b>: Returns an iterator to the end of the list.
388 //!
389 //! <b>Throws</b>: Nothing.
390 //!
391 //! <b>Complexity</b>: Constant.
392 iterator end()
393 { return iterator(this->get_root_node(), this); }
395 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
396 //!
397 //! <b>Throws</b>: Nothing.
398 //!
399 //! <b>Complexity</b>: Constant.
400 const_iterator end() const
401 { return this->cend(); }
403 //! <b>Effects</b>: Returns a constant iterator to the end of the list.
404 //!
405 //! <b>Throws</b>: Nothing.
406 //!
407 //! <b>Complexity</b>: Constant.
408 const_iterator cend() const
409 { return const_iterator(uncast(this->get_root_node()), this); }
411 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
412 //! of the reversed list.
413 //!
414 //! <b>Throws</b>: Nothing.
415 //!
416 //! <b>Complexity</b>: Constant.
417 reverse_iterator rbegin()
418 { return reverse_iterator(this->end()); }
420 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
421 //! of the reversed list.
422 //!
423 //! <b>Throws</b>: Nothing.
424 //!
425 //! <b>Complexity</b>: Constant.
426 const_reverse_iterator rbegin() const
427 { return this->crbegin(); }
429 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
430 //! of the reversed list.
431 //!
432 //! <b>Throws</b>: Nothing.
433 //!
434 //! <b>Complexity</b>: Constant.
435 const_reverse_iterator crbegin() const
436 { return const_reverse_iterator(end()); }
438 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
439 //! of the reversed list.
440 //!
441 //! <b>Throws</b>: Nothing.
442 //!
443 //! <b>Complexity</b>: Constant.
444 reverse_iterator rend()
445 { return reverse_iterator(begin()); }
447 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
448 //! of the reversed list.
449 //!
450 //! <b>Throws</b>: Nothing.
451 //!
452 //! <b>Complexity</b>: Constant.
453 const_reverse_iterator rend() const
454 { return this->crend(); }
456 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
457 //! of the reversed list.
458 //!
459 //! <b>Throws</b>: Nothing.
460 //!
461 //! <b>Complexity</b>: Constant.
462 const_reverse_iterator crend() const
463 { return const_reverse_iterator(this->begin()); }
465 //! <b>Precondition</b>: end_iterator must be a valid end iterator
466 //! of list.
467 //!
468 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
469 //!
470 //! <b>Throws</b>: Nothing.
471 //!
472 //! <b>Complexity</b>: Constant.
473 static list_impl &container_from_end_iterator(iterator end_iterator)
474 { return list_impl::priv_container_from_end_iterator(end_iterator); }
476 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
477 //! of list.
478 //!
479 //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
480 //!
481 //! <b>Throws</b>: Nothing.
482 //!
483 //! <b>Complexity</b>: Constant.
484 static const list_impl &container_from_end_iterator(const_iterator end_iterator)
485 { return list_impl::priv_container_from_end_iterator(end_iterator); }
487 //! <b>Effects</b>: Returns the number of the elements contained in the list.
488 //!
489 //! <b>Throws</b>: Nothing.
490 //!
491 //! <b>Complexity</b>: Linear to the number of elements contained in the list.
492 //! if constant-time size option is disabled. Constant time otherwise.
493 //!
494 //! <b>Note</b>: Does not affect the validity of iterators and references.
495 size_type size() const
497 if(constant_time_size)
498 return this->priv_size_traits().get_size();
499 else
500 return node_algorithms::count(this->get_root_node()) - 1;
503 //! <b>Effects</b>: Returns true if the list contains no elements.
504 //!
505 //! <b>Throws</b>: Nothing.
506 //!
507 //! <b>Complexity</b>: Constant.
508 //!
509 //! <b>Note</b>: Does not affect the validity of iterators and references.
510 bool empty() const
511 { return node_algorithms::unique(this->get_root_node()); }
513 //! <b>Effects</b>: Swaps the elements of x and *this.
514 //!
515 //! <b>Throws</b>: Nothing.
516 //!
517 //! <b>Complexity</b>: Constant.
518 //!
519 //! <b>Note</b>: Does not affect the validity of iterators and references.
520 void swap(list_impl& other)
522 node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
523 if(constant_time_size){
524 size_type backup = this->priv_size_traits().get_size();
525 this->priv_size_traits().set_size(other.priv_size_traits().get_size());
526 other.priv_size_traits().set_size(backup);
530 //! <b>Effects</b>: Moves backwards all the elements, so that the first
531 //! element becomes the second, the second becomes the third...
532 //! the last element becomes the first one.
533 //!
534 //! <b>Throws</b>: Nothing.
535 //!
536 //! <b>Complexity</b>: Linear to the number of shifts.
537 //!
538 //! <b>Note</b>: Does not affect the validity of iterators and references.
539 void shift_backwards(size_type n = 1)
540 { node_algorithms::move_forward(this->get_root_node(), n); }
542 //! <b>Effects</b>: Moves forward all the elements, so that the second
543 //! element becomes the first, the third becomes the second...
544 //! the first element becomes the last one.
545 //!
546 //! <b>Throws</b>: Nothing.
547 //!
548 //! <b>Complexity</b>: Linear to the number of shifts.
549 //!
550 //! <b>Note</b>: Does not affect the validity of iterators and references.
551 void shift_forward(size_type n = 1)
552 { node_algorithms::move_backwards(this->get_root_node(), n); }
554 //! <b>Effects</b>: Erases the element pointed by i of the list.
555 //! No destructors are called.
557 //! <b>Returns</b>: the first element remaining beyond the removed element,
558 //! or end() if no such element exists.
560 //! <b>Throws</b>: Nothing.
561 //!
562 //! <b>Complexity</b>: Constant.
563 //!
564 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
565 //! erased element.
566 iterator erase(const_iterator i)
567 { return this->erase_and_dispose(i, detail::null_disposer()); }
569 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
571 //! <b>Effects</b>: Erases the element range pointed by b and e
572 //! No destructors are called.
574 //! <b>Returns</b>: the first element remaining beyond the removed elements,
575 //! or end() if no such element exists.
576 //!
577 //! <b>Throws</b>: Nothing.
578 //!
579 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
580 //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise.
581 //!
582 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
583 //! erased elements.
584 iterator erase(const_iterator b, const_iterator e)
586 if(safemode_or_autounlink || constant_time_size){
587 return this->erase_and_dispose(b, e, detail::null_disposer());
589 else{
590 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
591 return e.unconst();
595 //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
596 //! n must be std::distance(b, e).
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.
603 //!
604 //! <b>Throws</b>: Nothing.
605 //!
606 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
607 //! or auto-unlink value is enabled. Constant-time otherwise.
608 //!
609 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
610 //! erased elements.
611 iterator erase(const_iterator b, const_iterator e, difference_type n)
613 BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(b, e) == difference_type(n));
614 if(safemode_or_autounlink || constant_time_size){
615 return this->erase_and_dispose(b, e, detail::null_disposer());
617 else{
618 if(constant_time_size){
619 this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
621 node_algorithms::unlink(b.pointed_node(), e.pointed_node());
622 return e.unconst();
626 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
628 //! <b>Effects</b>: Erases the element pointed by i of the list.
629 //! No destructors are called.
630 //! Disposer::operator()(pointer) is called for the removed element.
632 //! <b>Returns</b>: the first element remaining beyond the removed element,
633 //! or end() if no such element exists.
635 //! <b>Throws</b>: Nothing.
636 //!
637 //! <b>Complexity</b>: Constant.
638 //!
639 //! <b>Note</b>: Invalidates the iterators to the erased element.
640 template <class Disposer>
641 iterator erase_and_dispose(const_iterator i, Disposer disposer)
643 node_ptr to_erase(i.pointed_node());
644 ++i;
645 node_algorithms::unlink(to_erase);
646 this->priv_size_traits().decrement();
647 if(safemode_or_autounlink)
648 node_algorithms::init(to_erase);
649 disposer(this->get_real_value_traits().to_value_ptr(to_erase));
650 return i.unconst();
653 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
654 template<class Disposer>
655 iterator erase_and_dispose(iterator i, Disposer disposer)
656 { return this->erase_and_dispose(const_iterator(i), disposer); }
657 #endif
659 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
661 //! <b>Effects</b>: Erases the element range pointed by b and e
662 //! No destructors are called.
663 //! Disposer::operator()(pointer) is called for the removed elements.
665 //! <b>Returns</b>: the first element remaining beyond the removed elements,
666 //! or end() if no such element exists.
667 //!
668 //! <b>Throws</b>: Nothing.
669 //!
670 //! <b>Complexity</b>: Linear to the number of elements erased.
671 //!
672 //! <b>Note</b>: Invalidates the iterators to the erased elements.
673 template <class Disposer>
674 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
676 node_ptr bp(b.pointed_node()), ep(e.pointed_node());
677 node_algorithms::unlink(bp, ep);
678 while(bp != ep){
679 node_ptr to_erase(bp);
680 bp = node_traits::get_next(bp);
681 if(safemode_or_autounlink)
682 node_algorithms::init(to_erase);
683 disposer(get_real_value_traits().to_value_ptr(to_erase));
684 this->priv_size_traits().decrement();
686 return e.unconst();
689 //! <b>Effects</b>: Erases all the elements of the container.
690 //! No destructors are called.
691 //!
692 //! <b>Throws</b>: Nothing.
693 //!
694 //! <b>Complexity</b>: Linear to the number of elements of the list.
695 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
696 //!
697 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
698 void clear()
700 if(safemode_or_autounlink){
701 this->clear_and_dispose(detail::null_disposer());
703 else{
704 node_algorithms::init_header(this->get_root_node());
705 this->priv_size_traits().set_size(size_type(0));
709 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
711 //! <b>Effects</b>: Erases all the elements of the container.
712 //! No destructors are called.
713 //! Disposer::operator()(pointer) is called for the removed elements.
714 //!
715 //! <b>Throws</b>: Nothing.
716 //!
717 //! <b>Complexity</b>: Linear to the number of elements of the list.
718 //!
719 //! <b>Note</b>: Invalidates the iterators to the erased elements.
720 template <class Disposer>
721 void clear_and_dispose(Disposer disposer)
723 const_iterator it(this->begin()), itend(this->end());
724 while(it != itend){
725 node_ptr to_erase(it.pointed_node());
726 ++it;
727 if(safemode_or_autounlink)
728 node_algorithms::init(to_erase);
729 disposer(get_real_value_traits().to_value_ptr(to_erase));
731 node_algorithms::init_header(this->get_root_node());
732 this->priv_size_traits().set_size(0);
735 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
736 //! Cloner should yield to nodes equivalent to the original nodes.
738 //! <b>Effects</b>: Erases all the elements from *this
739 //! calling Disposer::operator()(pointer), clones all the
740 //! elements from src calling Cloner::operator()(const_reference )
741 //! and inserts them on *this.
743 //! If cloner throws, all cloned elements are unlinked and disposed
744 //! calling Disposer::operator()(pointer).
745 //!
746 //! <b>Complexity</b>: Linear to erased plus inserted elements.
747 //!
748 //! <b>Throws</b>: If cloner throws. Basic guarantee.
749 template <class Cloner, class Disposer>
750 void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
752 this->clear_and_dispose(disposer);
753 detail::exception_disposer<list_impl, Disposer>
754 rollback(*this, disposer);
755 const_iterator b(src.begin()), e(src.end());
756 for(; b != e; ++b){
757 this->push_back(*cloner(*b));
759 rollback.release();
762 //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this.
764 //! <b>Effects</b>: Inserts the value before the position pointed by p.
766 //! <b>Returns</b>: An iterator to the inserted element.
767 //!
768 //! <b>Throws</b>: Nothing.
769 //!
770 //! <b>Complexity</b>: Constant time. No copy constructors are called.
771 //!
772 //! <b>Note</b>: Does not affect the validity of iterators and references.
773 iterator insert(const_iterator p, reference value)
775 node_ptr to_insert = this->get_real_value_traits().to_node_ptr(value);
776 if(safemode_or_autounlink)
777 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
778 node_algorithms::link_before(p.pointed_node(), to_insert);
779 this->priv_size_traits().increment();
780 return iterator(to_insert, this);
783 //! <b>Requires</b>: Dereferencing iterator must yield
784 //! an lvalue of type value_type and p must be a valid iterator of *this.
785 //!
786 //! <b>Effects</b>: Inserts the range pointed by b and e before the position p.
787 //! No copy constructors are called.
788 //!
789 //! <b>Throws</b>: Nothing.
790 //!
791 //! <b>Complexity</b>: Linear to the number of elements inserted.
792 //!
793 //! <b>Note</b>: Does not affect the validity of iterators and references.
794 template<class Iterator>
795 void insert(const_iterator p, Iterator b, Iterator e)
797 for (; b != e; ++b)
798 this->insert(p, *b);
801 //! <b>Requires</b>: Dereferencing iterator must yield
802 //! an lvalue of type value_type.
803 //!
804 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
805 //! No destructors or copy constructors are called.
806 //!
807 //! <b>Throws</b>: Nothing.
808 //!
809 //! <b>Complexity</b>: Linear to the number of elements inserted plus
810 //! linear to the elements contained in the list if it's a safe-mode
811 //! or auto-unlink value.
812 //! Linear to the number of elements inserted in the list otherwise.
813 //!
814 //! <b>Note</b>: Invalidates the iterators (but not the references)
815 //! to the erased elements.
816 template<class Iterator>
817 void assign(Iterator b, Iterator e)
819 this->clear();
820 this->insert(this->cend(), b, e);
823 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
825 //! <b>Requires</b>: Dereferencing iterator must yield
826 //! an lvalue of type value_type.
827 //!
828 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
829 //! No destructors or copy constructors are called.
830 //! Disposer::operator()(pointer) is called for the removed elements.
831 //!
832 //! <b>Throws</b>: Nothing.
833 //!
834 //! <b>Complexity</b>: Linear to the number of elements inserted plus
835 //! linear to the elements contained in the list.
836 //!
837 //! <b>Note</b>: Invalidates the iterators (but not the references)
838 //! to the erased elements.
839 template<class Iterator, class Disposer>
840 void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
842 this->clear_and_dispose(disposer);
843 this->insert(this->cend(), b, e);
846 //! <b>Requires</b>: p must be a valid iterator of *this.
848 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
849 //! the element pointed by p. No destructors or copy constructors are called.
851 //! <b>Throws</b>: Nothing.
853 //! <b>Complexity</b>: Constant.
854 //!
855 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
856 //! this list. Iterators of this list and all the references are not invalidated.
857 void splice(const_iterator p, list_impl& x)
859 if(!x.empty()){
860 size_traits &thist = this->priv_size_traits();
861 size_traits &xt = x.priv_size_traits();
862 node_algorithms::transfer
863 (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
864 thist.set_size(thist.get_size() + xt.get_size());
865 xt.set_size(size_type(0));
869 //! <b>Requires</b>: p must be a valid iterator of *this.
870 //! new_ele must point to an element contained in list x.
871 //!
872 //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list,
873 //! before the the element pointed by p. No destructors or copy constructors are called.
874 //! If p == new_ele or p == ++new_ele, this function is a null operation.
875 //!
876 //! <b>Throws</b>: Nothing.
877 //!
878 //! <b>Complexity</b>: Constant.
879 //!
880 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
881 //! list. Iterators of this list and all the references are not invalidated.
882 void splice(const_iterator p, list_impl&x, const_iterator new_ele)
884 node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
885 x.priv_size_traits().decrement();
886 this->priv_size_traits().increment();
889 //! <b>Requires</b>: p must be a valid iterator of *this.
890 //! start and end must point to elements contained in list x.
891 //!
892 //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list,
893 //! before the the element pointed by p. No destructors or copy constructors are called.
894 //!
895 //! <b>Throws</b>: Nothing.
896 //!
897 //! <b>Complexity</b>: Linear to the number of elements transferred
898 //! if constant-time size option is enabled. Constant-time otherwise.
899 //!
900 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
901 //! list. Iterators of this list and all the references are not invalidated.
902 void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end)
904 if(constant_time_size)
905 this->splice(p, x, start, end, std::distance(start, end));
906 else
907 this->splice(p, x, start, end, 1);//distance is a dummy value
910 //! <b>Requires</b>: p must be a valid iterator of *this.
911 //! start and end must point to elements contained in list x.
912 //! n == std::distance(start, end)
913 //!
914 //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list,
915 //! before the the element pointed by p. No destructors or copy constructors are called.
916 //!
917 //! <b>Throws</b>: Nothing.
918 //!
919 //! <b>Complexity</b>: Constant.
920 //!
921 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
922 //! list. Iterators of this list and all the references are not invalidated.
923 void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end, difference_type n)
925 if(n){
926 if(constant_time_size){
927 size_traits &thist = this->priv_size_traits();
928 size_traits &xt = x.priv_size_traits();
929 BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(start, end));
930 node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node());
931 thist.set_size(thist.get_size() + n);
932 xt.set_size(xt.get_size() - n);
934 else{
935 node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node());
940 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
941 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
942 //!
943 //! <b>Throws</b>: If real_value_traits::node_traits::node
944 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
945 //! or std::less<value_type> throws. Basic guarantee.
947 //! <b>Notes</b>: Iterators and references are not invalidated.
948 //!
949 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
950 //! is the list's size.
951 void sort()
952 { this->sort(std::less<value_type>()); }
954 //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering
955 //!
956 //! <b>Effects</b>: This function sorts the list *this according to p. The sort is
957 //! stable, that is, the relative order of equivalent elements is preserved.
958 //!
959 //! <b>Throws</b>: If real_value_traits::node_traits::node
960 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
961 //! or the predicate throws. Basic guarantee.
963 //! <b>Notes</b>: This won't throw if list_base_hook<> or
964 //! list_member_hook are used.
965 //! Iterators and references are not invalidated.
966 //!
967 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
968 //! is the list's size.
969 template<class Predicate>
970 void sort(Predicate p)
972 if(node_traits::get_next(this->get_root_node())
973 != node_traits::get_previous(this->get_root_node())){
974 list_impl carry;
975 list_impl counter[64];
976 int fill = 0;
977 while(!this->empty()){
978 carry.splice(carry.cbegin(), *this, this->cbegin());
979 int i = 0;
980 while(i < fill && !counter[i].empty()) {
981 counter[i].merge(carry, p);
982 carry.swap(counter[i++]);
984 carry.swap(counter[i]);
985 if(i == fill)
986 ++fill;
988 for (int i = 1; i < fill; ++i)
989 counter[i].merge(counter[i-1], p);
990 this->swap(counter[fill-1]);
994 //! <b>Effects</b>: This function removes all of x's elements and inserts them
995 //! in order into *this according to std::less<value_type>. The merge is stable;
996 //! that is, if an element from *this is equivalent to one from x, then the element
997 //! from *this will precede the one from x.
998 //!
999 //! <b>Throws</b>: If std::less<value_type> throws. Basic guarantee.
1000 //!
1001 //! <b>Complexity</b>: This function is linear time: it performs at most
1002 //! size() + x.size() - 1 comparisons.
1003 //!
1004 //! <b>Note</b>: Iterators and references are not invalidated
1005 void merge(list_impl& x)
1006 { this->merge(x, std::less<value_type>()); }
1008 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1009 //! ordering and both *this and x must be sorted according to that ordering
1010 //! The lists x and *this must be distinct.
1011 //!
1012 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1013 //! in order into *this. The merge is stable; that is, if an element from *this is
1014 //! equivalent to one from x, then the element from *this will precede the one from x.
1015 //!
1016 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1017 //!
1018 //! <b>Complexity</b>: This function is linear time: it performs at most
1019 //! size() + x.size() - 1 comparisons.
1020 //!
1021 //! <b>Note</b>: Iterators and references are not invalidated.
1022 template<class Predicate>
1023 void merge(list_impl& x, Predicate p)
1025 const_iterator e(this->cend()), ex(x.cend());
1026 const_iterator b(this->cbegin());
1027 while(!x.empty()){
1028 const_iterator ix(x.cbegin());
1029 while (b != e && !p(*ix, *b)){
1030 ++b;
1032 if(b == e){
1033 //Now transfer the rest to the end of the container
1034 this->splice(e, x);
1035 break;
1037 else{
1038 size_type n(0);
1040 ++ix; ++n;
1041 } while(ix != ex && p(*ix, *b));
1042 this->splice(b, x, x.begin(), ix, n);
1047 //! <b>Effects</b>: Reverses the order of elements in the list.
1048 //!
1049 //! <b>Throws</b>: Nothing.
1050 //!
1051 //! <b>Complexity</b>: This function is linear time.
1052 //!
1053 //! <b>Note</b>: Iterators and references are not invalidated
1054 void reverse()
1055 { node_algorithms::reverse(this->get_root_node()); }
1057 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1058 //! No destructors are called.
1059 //!
1060 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1061 //!
1062 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1063 //!
1064 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1065 //! and iterators to elements that are not removed remain valid.
1066 void remove(const_reference value)
1067 { this->remove_if(detail::equal_to_value<const_reference>(value)); }
1069 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1071 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1072 //! Disposer::operator()(pointer) is called for every removed element.
1074 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1075 //!
1076 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1077 //!
1078 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1079 //! and iterators to elements that are not removed remain valid.
1080 template<class Disposer>
1081 void remove_and_dispose(const_reference value, Disposer disposer)
1082 { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
1084 //! <b>Effects</b>: Removes all the elements for which a specified
1085 //! predicate is satisfied. No destructors are called.
1086 //!
1087 //! <b>Throws</b>: If pred throws. Basic guarantee.
1088 //!
1089 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1090 //!
1091 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1092 //! and iterators to elements that are not removed remain valid.
1093 template<class Pred>
1094 void remove_if(Pred pred)
1095 { this->remove_and_dispose_if(pred, detail::null_disposer()); }
1097 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1099 //! <b>Effects</b>: Removes all the elements for which a specified
1100 //! predicate is satisfied.
1101 //! Disposer::operator()(pointer) is called for every removed element.
1103 //! <b>Throws</b>: If pred throws. Basic guarantee.
1104 //!
1105 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1107 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1108 //! and iterators to elements that are not removed remain valid.
1109 template<class Pred, class Disposer>
1110 void remove_and_dispose_if(Pred pred, Disposer disposer)
1112 const_iterator cur(this->cbegin());
1113 const_iterator last(this->cend());
1114 while(cur != last) {
1115 if(pred(*cur)){
1116 cur = this->erase_and_dispose(cur, disposer);
1118 else{
1119 ++cur;
1124 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1125 //! elements that are equal from the list. No destructors are called.
1126 //!
1127 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1128 //!
1129 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1130 //!
1131 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1132 //! and iterators to elements that are not removed remain valid.
1133 void unique()
1134 { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
1136 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1137 //! elements that satisfy some binary predicate from the list.
1138 //! No destructors are called.
1139 //!
1140 //! <b>Throws</b>: If pred throws. Basic guarantee.
1141 //!
1142 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1143 //!
1144 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1145 //! and iterators to elements that are not removed remain valid.
1146 template<class BinaryPredicate>
1147 void unique(BinaryPredicate pred)
1148 { this->unique_and_dispose(pred, detail::null_disposer()); }
1150 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1152 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1153 //! elements that are equal from the list.
1154 //! Disposer::operator()(pointer) is called for every removed element.
1155 //!
1156 //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
1157 //!
1158 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1159 //!
1160 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1161 //! and iterators to elements that are not removed remain valid.
1162 template<class Disposer>
1163 void unique_and_dispose(Disposer disposer)
1164 { this->unique_and_dispose(std::equal_to<value_type>(), disposer); }
1166 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1168 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1169 //! elements that satisfy some binary predicate from the list.
1170 //! Disposer::operator()(pointer) is called for every removed element.
1171 //!
1172 //! <b>Throws</b>: If pred throws. Basic guarantee.
1173 //!
1174 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1175 //!
1176 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1177 //! and iterators to elements that are not removed remain valid.
1178 template<class BinaryPredicate, class Disposer>
1179 void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
1181 const_iterator itend(this->cend());
1182 const_iterator cur(this->cbegin());
1184 if(cur != itend){
1185 const_iterator after(cur);
1186 ++after;
1187 while(after != itend){
1188 if(pred(*cur, *after)){
1189 after = this->erase_and_dispose(after, disposer);
1191 else{
1192 cur = after;
1193 ++after;
1199 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1200 //!
1201 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1202 //!
1203 //! <b>Throws</b>: Nothing.
1204 //!
1205 //! <b>Complexity</b>: Constant time.
1206 //!
1207 //! <b>Note</b>: Iterators and references are not invalidated.
1208 //! This static function is available only if the <i>value traits</i>
1209 //! is stateless.
1210 static iterator s_iterator_to(reference value)
1212 BOOST_STATIC_ASSERT((!stateful_value_traits));
1213 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value)));
1214 return iterator(real_value_traits::to_node_ptr(value), 0);
1217 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1218 //!
1219 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1220 //!
1221 //! <b>Throws</b>: Nothing.
1222 //!
1223 //! <b>Complexity</b>: Constant time.
1224 //!
1225 //! <b>Note</b>: Iterators and references are not invalidated.
1226 //! This static function is available only if the <i>value traits</i>
1227 //! is stateless.
1228 static const_iterator s_iterator_to(const_reference value)
1230 BOOST_STATIC_ASSERT((!stateful_value_traits));
1231 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value))));
1232 return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), 0);
1235 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1236 //!
1237 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1238 //!
1239 //! <b>Throws</b>: Nothing.
1240 //!
1241 //! <b>Complexity</b>: Constant time.
1242 //!
1243 //! <b>Note</b>: Iterators and references are not invalidated.
1244 iterator iterator_to(reference value)
1246 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value)));
1247 return iterator(real_value_traits::to_node_ptr(value), this);
1250 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1251 //!
1252 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1253 //!
1254 //! <b>Throws</b>: Nothing.
1255 //!
1256 //! <b>Complexity</b>: Constant time.
1257 //!
1258 //! <b>Note</b>: Iterators and references are not invalidated.
1259 const_iterator iterator_to(const_reference value) const
1261 BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value))));
1262 return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), this);
1265 /// @cond
1267 private:
1268 static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
1270 root_plus_size *r = detail::parent_from_member<root_plus_size, node>
1271 ( detail::get_pointer(end_iterator.pointed_node()), &root_plus_size::root_);
1272 data_t *d = detail::parent_from_member<data_t, root_plus_size>
1273 ( r, &data_t::root_plus_size_);
1274 list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
1275 return *s;
1277 /// @endcond
1280 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1281 template<class T, class ...Options>
1282 #else
1283 template<class Config>
1284 #endif
1285 inline bool operator<
1286 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1287 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1288 #else
1289 (const list_impl<Config> &x, const list_impl<Config> &y)
1290 #endif
1291 { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1293 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1294 template<class T, class ...Options>
1295 #else
1296 template<class Config>
1297 #endif
1298 bool operator==
1299 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1300 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1301 #else
1302 (const list_impl<Config> &x, const list_impl<Config> &y)
1303 #endif
1305 typedef list_impl<Config> list_type;
1306 typedef typename list_type::const_iterator const_iterator;
1307 const bool C = list_type::constant_time_size;
1308 if(C && x.size() != y.size()){
1309 return false;
1311 const_iterator end1 = x.end();
1313 const_iterator i1 = x.begin();
1314 const_iterator i2 = y.begin();
1315 if(C){
1316 while (i1 != end1 && *i1 == *i2) {
1317 ++i1;
1318 ++i2;
1320 return i1 == end1;
1322 else{
1323 const_iterator end2 = y.end();
1324 while (i1 != end1 && i2 != end2 && *i1 == *i2) {
1325 ++i1;
1326 ++i2;
1328 return i1 == end1 && i2 == end2;
1332 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1333 template<class T, class ...Options>
1334 #else
1335 template<class Config>
1336 #endif
1337 inline bool operator!=
1338 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1339 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1340 #else
1341 (const list_impl<Config> &x, const list_impl<Config> &y)
1342 #endif
1343 { return !(x == y); }
1345 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1346 template<class T, class ...Options>
1347 #else
1348 template<class Config>
1349 #endif
1350 inline bool operator>
1351 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1352 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1353 #else
1354 (const list_impl<Config> &x, const list_impl<Config> &y)
1355 #endif
1356 { return y < x; }
1358 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1359 template<class T, class ...Options>
1360 #else
1361 template<class Config>
1362 #endif
1363 inline bool operator<=
1364 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1365 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1366 #else
1367 (const list_impl<Config> &x, const list_impl<Config> &y)
1368 #endif
1369 { return !(y < x); }
1371 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1372 template<class T, class ...Options>
1373 #else
1374 template<class Config>
1375 #endif
1376 inline bool operator>=
1377 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1378 (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
1379 #else
1380 (const list_impl<Config> &x, const list_impl<Config> &y)
1381 #endif
1382 { return !(x < y); }
1384 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1385 template<class T, class ...Options>
1386 #else
1387 template<class Config>
1388 #endif
1389 inline void swap
1390 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1391 (list_impl<T, Options...> &x, list_impl<T, Options...> &y)
1392 #else
1393 (list_impl<Config> &x, list_impl<Config> &y)
1394 #endif
1395 { x.swap(y); }
1397 //! Helper metafunction to define a \c list that yields to the same type when the
1398 //! same options (either explicitly or implicitly) are used.
1399 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1400 template<class T, class ...Options>
1401 #else
1402 template<class T, class O1 = none, class O2 = none, class O3 = none>
1403 #endif
1404 struct make_list
1406 /// @cond
1407 typedef typename pack_options
1408 < list_defaults<T>,
1409 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1410 O1, O2, O3
1411 #else
1412 Options...
1413 #endif
1414 >::type packed_options;
1416 typedef typename detail::get_value_traits
1417 <T, typename packed_options::value_traits>::type value_traits;
1419 typedef list_impl
1421 listopt
1422 < value_traits
1423 , typename packed_options::size_type
1424 , packed_options::constant_time_size
1426 > implementation_defined;
1427 /// @endcond
1428 typedef implementation_defined type;
1432 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1434 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1435 template<class T, class O1, class O2, class O3>
1436 #else
1437 template<class T, class ...Options>
1438 #endif
1439 class list
1440 : public make_list<T,
1441 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1442 O1, O2, O3
1443 #else
1444 Options...
1445 #endif
1446 >::type
1448 typedef typename make_list
1449 <T,
1450 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1451 O1, O2, O3
1452 #else
1453 Options...
1454 #endif
1455 >::type Base;
1456 typedef typename Base::real_value_traits real_value_traits;
1457 //Assert if passed value traits are compatible with the type
1458 BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
1459 public:
1460 typedef typename Base::value_traits value_traits;
1461 typedef typename Base::iterator iterator;
1462 typedef typename Base::const_iterator const_iterator;
1464 list(const value_traits &v_traits = value_traits())
1465 : Base(v_traits)
1468 template<class Iterator>
1469 list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
1470 : Base(b, e, v_traits)
1473 static list &container_from_end_iterator(iterator end_iterator)
1474 { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); }
1476 static const list &container_from_end_iterator(const_iterator end_iterator)
1477 { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); }
1480 #endif
1482 } //namespace intrusive
1483 } //namespace boost
1485 #include <boost/intrusive/detail/config_end.hpp>
1487 #endif //BOOST_INTRUSIVE_LIST_HPP