fix doc example typo
[boost.git] / boost / intrusive / slist.hpp
blobe430fb1e0179c8aca865190612dfcecab8037085
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_SLIST_HPP
15 #define BOOST_INTRUSIVE_SLIST_HPP
17 #include <boost/intrusive/detail/config_begin.hpp>
18 #include <boost/static_assert.hpp>
19 #include <boost/intrusive/detail/assert.hpp>
20 #include <boost/intrusive/intrusive_fwd.hpp>
21 #include <boost/intrusive/slist_hook.hpp>
22 #include <boost/intrusive/circular_slist_algorithms.hpp>
23 #include <boost/intrusive/linear_slist_algorithms.hpp>
24 #include <boost/intrusive/detail/pointer_to_other.hpp>
25 #include <boost/intrusive/detail/clear_on_destructor_base.hpp>
26 #include <boost/intrusive/link_mode.hpp>
27 #include <boost/intrusive/options.hpp>
28 #include <boost/intrusive/detail/utilities.hpp>
29 #include <iterator>
30 #include <functional>
31 #include <algorithm>
32 #include <cstddef> //std::size_t
33 #include <utility> //std::pair
35 namespace boost {
36 namespace intrusive {
38 /// @cond
40 template <class ValueTraits, class SizeType, bool ConstantTimeSize, bool Linear, bool CacheLast>
41 struct slistopt
43 typedef ValueTraits value_traits;
44 typedef SizeType size_type;
45 static const bool constant_time_size = ConstantTimeSize;
46 static const bool linear = Linear;
47 static const bool cache_last = CacheLast;
50 template<class Node, class NodePtr, bool>
51 struct root_plus_last
53 Node root_;
54 NodePtr last_;
57 template<class Node, class NodePtr>
58 struct root_plus_last<Node, NodePtr, false>
60 Node root_;
63 template <class T>
64 struct slist_defaults
65 : pack_options
66 < none
67 , base_hook<detail::default_slist_hook>
68 , constant_time_size<true>
69 , linear<false>
70 , size_type<std::size_t>
71 , cache_last<false>
72 >::type
73 {};
75 /// @endcond
77 //! The class template slist is an intrusive container, that encapsulates
78 //! a singly-linked list. You can use such a list to squeeze the last bit
79 //! of performance from your application. Unfortunately, the little gains
80 //! come with some huge drawbacks. A lot of member functions can't be
81 //! implemented as efficiently as for standard containers. To overcome
82 //! this limitation some other member functions with rather unusual semantics
83 //! have to be introduced.
84 //!
85 //! The template parameter \c T is the type to be managed by the container.
86 //! The user can specify additional options and if no options are provided
87 //! default options are used.
88 //!
89 //! The container supports the following options:
90 //! \c base_hook<>/member_hook<>/value_traits<>,
91 //! \c constant_time_size<>, \c size_type<>,
92 //! \c linear<> and \c cache_last<>.
93 //!
94 //! The iterators of slist are forward iterators. slist provides a static
95 //! function called "previous" to compute the previous iterator of a given iterator.
96 //! This function has linear complexity. To improve the usability esp. with
97 //! the '*_after' functions, ++end() == begin() and previous(begin()) == end()
98 //! are defined. An new special function "before_begin()" is defined, which returns
99 //! an iterator that points one less the beginning of the list: ++before_begin() == begin()
100 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
101 template<class T, class ...Options>
102 #else
103 template<class Config>
104 #endif
105 class slist_impl
106 : private detail::clear_on_destructor_base<slist_impl<Config> >
108 template<class C> friend class detail::clear_on_destructor_base;
109 //Public typedefs
110 public:
111 typedef typename Config::value_traits value_traits;
112 /// @cond
113 static const bool external_value_traits =
114 detail::external_value_traits_is_true<value_traits>::value;
115 typedef typename detail::eval_if_c
116 < external_value_traits
117 , detail::eval_value_traits<value_traits>
118 , detail::identity<value_traits>
119 >::type real_value_traits;
120 /// @endcond
121 typedef typename real_value_traits::pointer pointer;
122 typedef typename real_value_traits::const_pointer const_pointer;
123 typedef typename std::iterator_traits<pointer>::value_type value_type;
124 typedef typename std::iterator_traits<pointer>::reference reference;
125 typedef typename std::iterator_traits<const_pointer>::reference const_reference;
126 typedef typename std::iterator_traits<pointer>::difference_type difference_type;
127 typedef typename Config::size_type size_type;
128 typedef slist_iterator<slist_impl, false> iterator;
129 typedef slist_iterator<slist_impl, true> const_iterator;
130 typedef typename real_value_traits::node_traits node_traits;
131 typedef typename node_traits::node node;
132 typedef typename boost::pointer_to_other
133 <pointer, node>::type node_ptr;
134 typedef typename boost::pointer_to_other
135 <pointer, const node>::type const_node_ptr;
136 typedef typename detail::if_c
137 < Config::linear
138 , linear_slist_algorithms<node_traits>
139 , circular_slist_algorithms<node_traits>
140 >::type node_algorithms;
142 static const bool constant_time_size = Config::constant_time_size;
143 static const bool stateful_value_traits = detail::store_cont_ptr_on_it<slist_impl>::value;
144 static const bool linear = Config::linear;
145 static const bool cache_last = Config::cache_last;
147 /// @cond
148 private:
149 typedef detail::size_holder<constant_time_size, size_type> size_traits;
151 //! This class is
152 //! non-copyable
153 slist_impl (const slist_impl&);
155 //! This class is
156 //! non-asignable
157 slist_impl &operator =(const slist_impl&);
159 enum { safemode_or_autounlink =
160 (int)real_value_traits::link_mode == (int)auto_unlink ||
161 (int)real_value_traits::link_mode == (int)safe_link };
163 //Constant-time size is incompatible with auto-unlink hooks!
164 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
165 //Linear singly linked lists are incompatible with auto-unlink hooks!
166 BOOST_STATIC_ASSERT(!(linear && ((int)real_value_traits::link_mode == (int)auto_unlink)));
167 //A list with cached last node is incompatible with auto-unlink hooks!
168 BOOST_STATIC_ASSERT(!(cache_last && ((int)real_value_traits::link_mode == (int)auto_unlink)));
170 node_ptr get_end_node()
171 { return node_ptr(linear ? node_ptr(0) : this->get_root_node()); }
173 const_node_ptr get_end_node() const
175 return const_node_ptr
176 (linear ? const_node_ptr(0) : this->get_root_node()); }
178 node_ptr get_root_node()
179 { return node_ptr(&data_.root_plus_size_.root_); }
181 const_node_ptr get_root_node() const
182 { return const_node_ptr(&data_.root_plus_size_.root_); }
184 node_ptr get_last_node()
185 { return this->get_last_node(detail::bool_<cache_last>()); }
187 const_node_ptr get_last_node() const
188 { return this->get_last_node(detail::bool_<cache_last>()); }
190 void set_last_node(node_ptr n)
191 { return this->set_last_node(n, detail::bool_<cache_last>()); }
193 static node_ptr get_last_node(detail::bool_<false>)
194 { return node_ptr(0); }
196 static void set_last_node(node_ptr, detail::bool_<false>)
199 node_ptr get_last_node(detail::bool_<true>)
200 { return node_ptr(data_.root_plus_size_.last_); }
202 const_node_ptr get_last_node(detail::bool_<true>) const
203 { return const_node_ptr(data_.root_plus_size_.last_); }
205 void set_last_node(node_ptr n, detail::bool_<true>)
206 { data_.root_plus_size_.last_ = n; }
208 static node_ptr uncast(const_node_ptr ptr)
209 { return node_ptr(const_cast<node*>(detail::get_pointer(ptr))); }
211 void set_default_constructed_state()
213 node_algorithms::init_header(this->get_root_node());
214 this->priv_size_traits().set_size(size_type(0));
215 if(cache_last){
216 this->set_last_node(this->get_root_node());
220 struct root_plus_size
221 : public size_traits
222 , public root_plus_last<node, node_ptr, cache_last>
225 struct data_t
226 : public slist_impl::value_traits
228 typedef typename slist_impl::value_traits value_traits;
229 data_t(const value_traits &val_traits)
230 : value_traits(val_traits)
233 root_plus_size root_plus_size_;
234 } data_;
236 size_traits &priv_size_traits()
237 { return data_.root_plus_size_; }
239 const size_traits &priv_size_traits() const
240 { return data_.root_plus_size_; }
242 const real_value_traits &get_real_value_traits(detail::bool_<false>) const
243 { return data_; }
245 const real_value_traits &get_real_value_traits(detail::bool_<true>) const
246 { return data_.get_value_traits(*this); }
248 real_value_traits &get_real_value_traits(detail::bool_<false>)
249 { return data_; }
251 real_value_traits &get_real_value_traits(detail::bool_<true>)
252 { return data_.get_value_traits(*this); }
254 /// @endcond
256 public:
258 const real_value_traits &get_real_value_traits() const
259 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
261 real_value_traits &get_real_value_traits()
262 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
264 public:
265 //! <b>Effects</b>: constructs an empty list.
266 //!
267 //! <b>Complexity</b>: Constant
268 //!
269 //! <b>Throws</b>: If value_traits::node_traits::node
270 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
271 slist_impl(const value_traits &v_traits = value_traits())
272 : data_(v_traits)
273 { this->set_default_constructed_state(); }
275 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
276 //!
277 //! <b>Effects</b>: Constructs a list equal to [first,last).
278 //!
279 //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called.
280 //!
281 //! <b>Throws</b>: If value_traits::node_traits::node
282 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
283 template<class Iterator>
284 slist_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
285 : data_(v_traits)
287 this->set_default_constructed_state();
288 this->insert_after(this->cbefore_begin(), b, e);
291 //! <b>Effects</b>: If it's a safe-mode
292 //! or auto-unlink value, the destructor does nothing
293 //! (ie. no code is generated). Otherwise it detaches all elements from this.
294 //! In this case the objects in the list are not deleted (i.e. no destructors
295 //! are called), but the hooks according to the value_traits template parameter
296 //! are set to their default value.
297 //!
298 //! <b>Complexity</b>: Linear to the number of elements in the list, if
299 //! it's a safe-mode or auto-unlink value. Otherwise constant.
300 ~slist_impl()
303 //! <b>Effects</b>: Erases all the elements of the container.
304 //!
305 //! <b>Throws</b>: Nothing.
306 //!
307 //! <b>Complexity</b>: Linear to the number of elements of the list.
308 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
309 //!
310 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
311 void clear()
313 if(safemode_or_autounlink){
314 this->clear_and_dispose(detail::null_disposer());
316 else{
317 this->set_default_constructed_state();
321 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
323 //! <b>Effects</b>: Erases all the elements of the container
324 //! Disposer::operator()(pointer) is called for the removed elements.
325 //!
326 //! <b>Throws</b>: Nothing.
327 //!
328 //! <b>Complexity</b>: Linear to the number of elements of the list.
329 //!
330 //! <b>Note</b>: Invalidates the iterators to the erased elements.
331 template <class Disposer>
332 void clear_and_dispose(Disposer disposer)
334 const_iterator it(this->begin()), itend(this->end());
335 while(it != itend){
336 node_ptr to_erase(it.pointed_node());
337 ++it;
338 if(safemode_or_autounlink)
339 node_algorithms::init(to_erase);
340 disposer(get_real_value_traits().to_value_ptr(to_erase));
342 this->set_default_constructed_state();
345 //! <b>Requires</b>: value must be an lvalue.
346 //!
347 //! <b>Effects</b>: Inserts the value in the front of the list.
348 //! No copy constructors are called.
349 //!
350 //! <b>Throws</b>: Nothing.
351 //!
352 //! <b>Complexity</b>: Constant.
353 //!
354 //! <b>Note</b>: Does not affect the validity of iterators and references.
355 void push_front(reference value)
357 node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
358 if(safemode_or_autounlink)
359 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
360 if(cache_last){
361 if(this->empty()){
362 this->set_last_node(to_insert);
365 node_algorithms::link_after(this->get_root_node(), to_insert);
366 this->priv_size_traits().increment();
369 //! <b>Requires</b>: value must be an lvalue.
370 //!
371 //! <b>Effects</b>: Inserts the value in the back of the list.
372 //! No copy constructors are called.
373 //!
374 //! <b>Throws</b>: Nothing.
375 //!
376 //! <b>Complexity</b>: Constant.
377 //!
378 //! <b>Note</b>: Does not affect the validity of iterators and references.
379 //! This function is only available is cache_last<> is true.
380 void push_back(reference value)
382 BOOST_STATIC_ASSERT((cache_last != 0));
383 this->insert_after(const_iterator(this->get_last_node(), this), value);
386 //! <b>Effects</b>: Erases the first element of the list.
387 //! No destructors are called.
388 //!
389 //! <b>Throws</b>: Nothing.
390 //!
391 //! <b>Complexity</b>: Constant.
392 //!
393 //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
394 void pop_front()
395 { return this->pop_front_and_dispose(detail::null_disposer()); }
397 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
399 //! <b>Effects</b>: Erases the first element of the list.
400 //! Disposer::operator()(pointer) is called for the removed element.
401 //!
402 //! <b>Throws</b>: Nothing.
403 //!
404 //! <b>Complexity</b>: Constant.
405 //!
406 //! <b>Note</b>: Invalidates the iterators to the erased element.
407 template<class Disposer>
408 void pop_front_and_dispose(Disposer disposer)
410 node_ptr to_erase = node_traits::get_next(this->get_root_node());
411 node_algorithms::unlink_after(this->get_root_node());
412 this->priv_size_traits().decrement();
413 if(safemode_or_autounlink)
414 node_algorithms::init(to_erase);
415 disposer(get_real_value_traits().to_value_ptr(to_erase));
416 if(cache_last){
417 if(this->empty()){
418 this->set_last_node(this->get_root_node());
423 //! <b>Effects</b>: Returns a reference to the first element of the list.
424 //!
425 //! <b>Throws</b>: Nothing.
426 //!
427 //! <b>Complexity</b>: Constant.
428 reference front()
429 { return *this->get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
431 //! <b>Effects</b>: Returns a const_reference to the first element of the list.
432 //!
433 //! <b>Throws</b>: Nothing.
434 //!
435 //! <b>Complexity</b>: Constant.
436 const_reference front() const
437 { return *this->get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); }
439 //! <b>Effects</b>: Returns a reference to the last element of the list.
440 //!
441 //! <b>Throws</b>: Nothing.
443 //! <b>Complexity</b>: Constant.
445 //! <b>Note</b>: Does not affect the validity of iterators and references.
446 //! This function is only available is cache_last<> is true.
447 reference back()
449 BOOST_STATIC_ASSERT((cache_last != 0));
450 return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
453 //! <b>Effects</b>: Returns a const_reference to the last element of the list.
454 //!
455 //! <b>Throws</b>: Nothing.
456 //!
457 //! <b>Complexity</b>: Constant.
459 //! <b>Note</b>: Does not affect the validity of iterators and references.
460 //! This function is only available is cache_last<> is true.
461 const_reference back() const
463 BOOST_STATIC_ASSERT((cache_last != 0));
464 return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
467 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
468 //!
469 //! <b>Throws</b>: Nothing.
470 //!
471 //! <b>Complexity</b>: Constant.
472 iterator begin()
473 { return iterator (node_traits::get_next(this->get_root_node()), this); }
475 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
476 //!
477 //! <b>Throws</b>: Nothing.
478 //!
479 //! <b>Complexity</b>: Constant.
480 const_iterator begin() const
481 { return const_iterator (node_traits::get_next(this->get_root_node()), this); }
483 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
484 //!
485 //! <b>Throws</b>: Nothing.
486 //!
487 //! <b>Complexity</b>: Constant.
488 const_iterator cbegin() const
489 { return const_iterator(node_traits::get_next(this->get_root_node()), this); }
491 //! <b>Effects</b>: Returns an iterator to the end of the list.
492 //!
493 //! <b>Throws</b>: Nothing.
494 //!
495 //! <b>Complexity</b>: Constant.
496 iterator end()
497 { return iterator(this->get_end_node(), this); }
499 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
500 //!
501 //! <b>Throws</b>: Nothing.
502 //!
503 //! <b>Complexity</b>: Constant.
504 const_iterator end() const
505 { return const_iterator(uncast(this->get_end_node()), this); }
507 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
508 //!
509 //! <b>Throws</b>: Nothing.
510 //!
511 //! <b>Complexity</b>: Constant.
512 const_iterator cend() const
513 { return this->end(); }
515 //! <b>Effects</b>: Returns an iterator that points to a position
516 //! before the first element. Equivalent to "end()"
517 //!
518 //! <b>Throws</b>: Nothing.
519 //!
520 //! <b>Complexity</b>: Constant.
521 iterator before_begin()
522 { return iterator(this->get_root_node(), this); }
524 //! <b>Effects</b>: Returns an iterator that points to a position
525 //! before the first element. Equivalent to "end()"
526 //!
527 //! <b>Throws</b>: Nothing.
528 //!
529 //! <b>Complexity</b>: Constant.
530 const_iterator before_begin() const
531 { return const_iterator(uncast(this->get_root_node()), this); }
533 //! <b>Effects</b>: Returns an iterator that points to a position
534 //! before the first element. Equivalent to "end()"
535 //!
536 //! <b>Throws</b>: Nothing.
537 //!
538 //! <b>Complexity</b>: Constant.
539 const_iterator cbefore_begin() const
540 { return this->before_begin(); }
542 //! <b>Precondition</b>: end_iterator must be a valid end iterator
543 //! of slist.
544 //!
545 //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
546 //!
547 //! <b>Throws</b>: Nothing.
548 //!
549 //! <b>Complexity</b>: Constant.
550 static slist_impl &container_from_end_iterator(iterator end_iterator)
551 { return slist_impl::priv_container_from_end_iterator(end_iterator); }
553 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
554 //! of slist.
555 //!
556 //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
557 //!
558 //! <b>Throws</b>: Nothing.
559 //!
560 //! <b>Complexity</b>: Constant.
561 static const slist_impl &container_from_end_iterator(const_iterator end_iterator)
562 { return slist_impl::priv_container_from_end_iterator(end_iterator); }
564 //! <b>Effects</b>: Returns the number of the elements contained in the list.
565 //!
566 //! <b>Throws</b>: Nothing.
567 //!
568 //! <b>Complexity</b>: Linear to the number of elements contained in the list.
569 //! if constant_time_size is false. Constant time otherwise.
570 //!
571 //! <b>Note</b>: Does not affect the validity of iterators and references.
572 size_type size() const
574 if(constant_time_size)
575 return this->priv_size_traits().get_size();
576 else
577 return node_algorithms::count(this->get_root_node()) - 1;
580 //! <b>Effects</b>: Returns true if the list contains no elements.
581 //!
582 //! <b>Throws</b>: Nothing.
583 //!
584 //! <b>Complexity</b>: Constant.
585 //!
586 //! <b>Note</b>: Does not affect the validity of iterators and references.
587 bool empty() const
588 { return node_algorithms::unique(this->get_root_node()); }
590 //! <b>Effects</b>: Swaps the elements of x and *this.
591 //!
592 //! <b>Throws</b>: Nothing.
593 //!
594 //! <b>Complexity</b>: Linear to the number of elements of both lists.
595 //! Constant-time if linear<> and/or cache_last<> options are used.
596 //!
597 //! <b>Note</b>: Does not affect the validity of iterators and references.
598 void swap(slist_impl& other)
600 if(cache_last){
601 priv_swap_cache_last(this, &other);
603 else{
604 this->priv_swap_lists(this->get_root_node(), other.get_root_node(), detail::bool_<linear>());
606 if(constant_time_size){
607 size_type backup = this->priv_size_traits().get_size();
608 this->priv_size_traits().set_size(other.priv_size_traits().get_size());
609 other.priv_size_traits().set_size(backup);
613 //! <b>Effects</b>: Moves backwards all the elements, so that the first
614 //! element becomes the second, the second becomes the third...
615 //! the last element becomes the first one.
616 //!
617 //! <b>Throws</b>: Nothing.
618 //!
619 //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
620 //!
621 //! <b>Note</b>: Iterators Does not affect the validity of iterators and references.
622 void shift_backwards(size_type n = 1)
623 { this->priv_shift_backwards(n, detail::bool_<linear>()); }
625 //! <b>Effects</b>: Moves forward all the elements, so that the second
626 //! element becomes the first, the third becomes the second...
627 //! the first element becomes the last one.
628 //!
629 //! <b>Throws</b>: Nothing.
630 //!
631 //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
632 //!
633 //! <b>Note</b>: Does not affect the validity of iterators and references.
634 void shift_forward(size_type n = 1)
635 { this->priv_shift_forward(n, detail::bool_<linear>()); }
637 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
638 //! Cloner should yield to nodes equivalent to the original nodes.
640 //! <b>Effects</b>: Erases all the elements from *this
641 //! calling Disposer::operator()(pointer), clones all the
642 //! elements from src calling Cloner::operator()(const_reference )
643 //! and inserts them on *this.
645 //! If cloner throws, all cloned elements are unlinked and disposed
646 //! calling Disposer::operator()(pointer).
647 //!
648 //! <b>Complexity</b>: Linear to erased plus inserted elements.
649 //!
650 //! <b>Throws</b>: If cloner throws.
651 template <class Cloner, class Disposer>
652 void clone_from(const slist_impl &src, Cloner cloner, Disposer disposer)
654 this->clear_and_dispose(disposer);
655 detail::exception_disposer<slist_impl, Disposer>
656 rollback(*this, disposer);
657 const_iterator prev(this->cbefore_begin());
658 const_iterator b(src.begin()), e(src.end());
659 for(; b != e; ++b){
660 prev = this->insert_after(prev, *cloner(*b));
662 rollback.release();
665 //! <b>Requires</b>: value must be an lvalue and prev_p must point to an element
666 //! contained by the list or to end().
668 //! <b>Effects</b>: Inserts the value after the position pointed by prev_p.
669 //! No copy constructor is called.
671 //! <b>Returns</b>: An iterator to the inserted element.
672 //!
673 //! <b>Throws</b>: Nothing.
674 //!
675 //! <b>Complexity</b>: Constant.
676 //!
677 //! <b>Note</b>: Does not affect the validity of iterators and references.
678 iterator insert_after(const_iterator prev_p, reference value)
680 node_ptr n = get_real_value_traits().to_node_ptr(value);
681 if(safemode_or_autounlink)
682 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
683 node_ptr prev_n(prev_p.pointed_node());
684 node_algorithms::link_after(prev_n, n);
685 if(cache_last && (this->get_last_node() == prev_n)){
686 this->set_last_node(n);
688 this->priv_size_traits().increment();
689 return iterator (n, this);
692 //! <b>Requires</b>: Dereferencing iterator must yield
693 //! an lvalue of type value_type and prev_p must point to an element
694 //! contained by the list or to the end node.
695 //!
696 //! <b>Effects</b>: Inserts the [first, last)
697 //! after the position prev_p.
698 //!
699 //! <b>Throws</b>: Nothing.
700 //!
701 //! <b>Complexity</b>: Linear to the number of elements inserted.
702 //!
703 //! <b>Note</b>: Does not affect the validity of iterators and references.
704 template<class Iterator>
705 void insert_after(const_iterator prev_p, Iterator first, Iterator last)
707 for (; first != last; ++first)
708 prev_p = this->insert_after(prev_p, *first);
711 //! <b>Requires</b>: value must be an lvalue and p must point to an element
712 //! contained by the list or to end().
714 //! <b>Effects</b>: Inserts the value before the position pointed by p.
715 //! No copy constructor is called.
716 //!
717 //! <b>Throws</b>: Nothing.
718 //!
719 //! <b>Complexity</b>: Linear to the number of elements before p.
720 //! Constant-time if cache_last<> is true and p == end().
721 //!
722 //! <b>Note</b>: Does not affect the validity of iterators and references.
723 iterator insert(const_iterator p, reference value)
724 { return this->insert_after(this->previous(p), value); }
726 //! <b>Requires</b>: Dereferencing iterator must yield
727 //! an lvalue of type value_type and p must point to an element
728 //! contained by the list or to the end node.
729 //!
730 //! <b>Effects</b>: Inserts the pointed by b and e
731 //! before the position p. No copy constructors are called.
732 //!
733 //! <b>Throws</b>: Nothing.
734 //!
735 //! <b>Complexity</b>: Linear to the number of elements inserted plus linear
736 //! to the elements before b.
737 //! Linear to the number of elements to insert if cache_last<> option is true and p == end().
738 //!
739 //! <b>Note</b>: Does not affect the validity of iterators and references.
740 template<class Iterator>
741 void insert(const_iterator p, Iterator b, Iterator e)
742 { return this->insert_after(this->previous(p), b, e); }
744 //! <b>Effects</b>: Erases the element after the element pointed by prev of
745 //! the list. No destructors are called.
747 //! <b>Returns</b>: the first element remaining beyond the removed elements,
748 //! or end() if no such element exists.
749 //!
750 //! <b>Throws</b>: Nothing.
751 //!
752 //! <b>Complexity</b>: Constant.
753 //!
754 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
755 //! erased element.
756 iterator erase_after(const_iterator prev)
757 { return this->erase_after_and_dispose(prev, detail::null_disposer()); }
759 //! <b>Effects</b>: Erases the range (before_first, last) from
760 //! the list. No destructors are called.
762 //! <b>Returns</b>: the first element remaining beyond the removed elements,
763 //! or end() if no such element exists.
764 //!
765 //! <b>Throws</b>: Nothing.
766 //!
767 //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
768 //! , auto-unlink value or constant-time size is activated. Constant time otherwise.
769 //!
770 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
771 //! erased element.
772 iterator erase_after(const_iterator before_first, const_iterator last)
774 if(safemode_or_autounlink || constant_time_size){
775 return this->erase_after_and_dispose(before_first, last, detail::null_disposer());
777 else{
778 node_ptr bfp = before_first.pointed_node();
779 node_ptr lp = last.pointed_node();
780 if(cache_last){
781 if((lp == this->get_end_node())){
782 this->set_last_node(bfp);
785 node_algorithms::unlink_after(bfp, lp);
786 return last.unconst();
790 //! <b>Effects</b>: Erases the range (before_first, last) from
791 //! the list. n must be std::distance(before_first, last) - 1.
792 //! No destructors are called.
794 //! <b>Returns</b>: the first element remaining beyond the removed elements,
795 //! or end() if no such element exists.
796 //!
797 //! <b>Throws</b>: Nothing.
798 //!
799 //! <b>Complexity</b>: constant-time if link_mode is normal_link.
800 //! Linear to the elements (last - before_first) otherwise.
801 //!
802 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
803 //! erased element.
804 iterator erase_after(const_iterator before_first, const_iterator last, difference_type n)
806 BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_first), last) == difference_type(n));
807 if(safemode_or_autounlink){
808 return this->erase_after(before_first, last);
810 else{
811 node_ptr bfp = before_first.pointed_node();
812 node_ptr lp = last.pointed_node();
813 if(cache_last){
814 if((lp == this->get_end_node())){
815 this->set_last_node(bfp);
818 node_algorithms::unlink_after(bfp, lp);
819 if(constant_time_size){
820 this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
822 return last.unconst();
826 //! <b>Effects</b>: Erases the element pointed by i of the list.
827 //! No destructors are called.
829 //! <b>Returns</b>: the first element remaining beyond the removed element,
830 //! or end() if no such element exists.
831 //!
832 //! <b>Throws</b>: Nothing.
833 //!
834 //! <b>Complexity</b>: Linear to the elements before i.
835 //!
836 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
837 //! erased element.
838 iterator erase(const_iterator i)
839 { return this->erase_after(this->previous(i)); }
841 //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
842 //!
843 //! <b>Effects</b>: Erases the range pointed by b and e.
844 //! No destructors are called.
846 //! <b>Returns</b>: the first element remaining beyond the removed elements,
847 //! or end() if no such element exists.
848 //!
849 //! <b>Throws</b>: Nothing.
850 //!
851 //! <b>Complexity</b>: Linear to the elements before last.
852 //!
853 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
854 //! erased elements.
855 iterator erase(const_iterator first, const_iterator last)
856 { return this->erase_after(this->previous(first), last); }
858 //! <b>Effects</b>: Erases the range [first, last) from
859 //! the list. n must be std::distance(first, last).
860 //! No destructors are called.
862 //! <b>Returns</b>: the first element remaining beyond the removed elements,
863 //! or end() if no such element exists.
864 //!
865 //! <b>Throws</b>: Nothing.
866 //!
867 //! <b>Complexity</b>: linear to the elements before first if link_mode is normal_link
868 //! and constant_time_size is activated. Linear to the elements before last otherwise.
869 //!
870 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
871 //! erased element.
872 iterator erase(const_iterator first, const_iterator last, difference_type n)
873 { return this->erase_after(this->previous(first), last, n); }
875 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
877 //! <b>Effects</b>: Erases the element after the element pointed by prev of
878 //! the list.
879 //! Disposer::operator()(pointer) is called for the removed element.
881 //! <b>Returns</b>: the first element remaining beyond the removed elements,
882 //! or end() if no such element exists.
883 //!
884 //! <b>Throws</b>: Nothing.
885 //!
886 //! <b>Complexity</b>: Constant.
887 //!
888 //! <b>Note</b>: Invalidates the iterators to the erased element.
889 template<class Disposer>
890 iterator erase_after_and_dispose(const_iterator prev, Disposer disposer)
892 const_iterator it(prev);
893 ++it;
894 node_ptr to_erase(it.pointed_node());
895 ++it;
896 node_ptr prev_n(prev.pointed_node());
897 node_algorithms::unlink_after(prev_n);
898 if(cache_last && (to_erase == this->get_last_node())){
899 this->set_last_node(prev_n);
901 if(safemode_or_autounlink)
902 node_algorithms::init(to_erase);
903 disposer(get_real_value_traits().to_value_ptr(to_erase));
904 this->priv_size_traits().decrement();
905 return it.unconst();
908 /// @cond
910 template<class Disposer>
911 static iterator s_erase_after_and_dispose(const_iterator prev, Disposer disposer)
913 BOOST_STATIC_ASSERT(((!cache_last)&&(!constant_time_size)&&(!stateful_value_traits)));
914 const_iterator it(prev);
915 ++it;
916 node_ptr to_erase(it.pointed_node());
917 ++it;
918 node_ptr prev_n(prev.pointed_node());
919 node_algorithms::unlink_after(prev_n);
920 if(safemode_or_autounlink)
921 node_algorithms::init(to_erase);
922 disposer(real_value_traits::to_value_ptr(to_erase));
923 return it.unconst();
926 static iterator s_erase_after(const_iterator prev)
927 { return s_erase_after_and_dispose(prev, detail::null_disposer()); }
929 /// @endcond
931 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
933 //! <b>Effects</b>: Erases the range (before_first, last) from
934 //! the list.
935 //! Disposer::operator()(pointer) is called for the removed elements.
937 //! <b>Returns</b>: the first element remaining beyond the removed elements,
938 //! or end() if no such element exists.
939 //!
940 //! <b>Throws</b>: Nothing.
941 //!
942 //! <b>Complexity</b>: Lineal to the elements (last - before_first + 1).
943 //!
944 //! <b>Note</b>: Invalidates the iterators to the erased element.
945 template<class Disposer>
946 iterator erase_after_and_dispose(const_iterator before_first, const_iterator last, Disposer disposer)
948 node_ptr bfp(before_first.pointed_node()), lp(last.pointed_node());
949 node_ptr fp(node_traits::get_next(bfp));
950 node_algorithms::unlink_after(bfp, lp);
951 while(fp != lp){
952 node_ptr to_erase(fp);
953 fp = node_traits::get_next(fp);
954 if(safemode_or_autounlink)
955 node_algorithms::init(to_erase);
956 disposer(get_real_value_traits().to_value_ptr(to_erase));
957 this->priv_size_traits().decrement();
959 if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){
960 this->set_last_node(bfp);
962 return last.unconst();
965 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
967 //! <b>Effects</b>: Erases the element pointed by i of the list.
968 //! No destructors are called.
969 //! Disposer::operator()(pointer) is called for the removed element.
971 //! <b>Returns</b>: the first element remaining beyond the removed element,
972 //! or end() if no such element exists.
973 //!
974 //! <b>Throws</b>: Nothing.
975 //!
976 //! <b>Complexity</b>: Linear to the elements before i.
977 //!
978 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
979 //! erased element.
980 template<class Disposer>
981 iterator erase_and_dispose(const_iterator i, Disposer disposer)
982 { return this->erase_after_and_dispose(this->previous(i), disposer); }
984 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
985 template<class Disposer>
986 iterator erase_and_dispose(iterator i, Disposer disposer)
987 { return this->erase_and_dispose(const_iterator(i), disposer); }
988 #endif
990 //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
991 //! Disposer::operator()(pointer) shouldn't throw.
992 //!
993 //! <b>Effects</b>: Erases the range pointed by b and e.
994 //! No destructors are called.
995 //! Disposer::operator()(pointer) is called for the removed elements.
997 //! <b>Returns</b>: the first element remaining beyond the removed elements,
998 //! or end() if no such element exists.
999 //!
1000 //! <b>Throws</b>: Nothing.
1001 //!
1002 //! <b>Complexity</b>: Linear to the number of erased elements plus linear
1003 //! to the elements before first.
1004 //!
1005 //! <b>Note</b>: Invalidates the iterators (but not the references) to the
1006 //! erased elements.
1007 template<class Disposer>
1008 iterator erase_and_dispose(const_iterator first, const_iterator last, Disposer disposer)
1009 { return this->erase_after_and_dispose(this->previous(first), last, disposer); }
1011 //! <b>Requires</b>: Dereferencing iterator must yield
1012 //! an lvalue of type value_type.
1013 //!
1014 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
1015 //! No destructors or copy constructors are called.
1016 //!
1017 //! <b>Throws</b>: Nothing.
1018 //!
1019 //! <b>Complexity</b>: Linear to the number of elements inserted plus
1020 //! linear to the elements contained in the list if it's a safe-mode
1021 //! or auto-unlink value.
1022 //! Linear to the number of elements inserted in the list otherwise.
1023 //!
1024 //! <b>Note</b>: Invalidates the iterators (but not the references)
1025 //! to the erased elements.
1026 template<class Iterator>
1027 void assign(Iterator b, Iterator e)
1029 this->clear();
1030 this->insert_after(this->cbefore_begin(), b, e);
1033 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1035 //! <b>Requires</b>: Dereferencing iterator must yield
1036 //! an lvalue of type value_type.
1037 //!
1038 //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
1039 //! No destructors or copy constructors are called.
1040 //! Disposer::operator()(pointer) is called for the removed elements.
1041 //!
1042 //! <b>Throws</b>: Nothing.
1043 //!
1044 //! <b>Complexity</b>: Linear to the number of elements inserted plus
1045 //! linear to the elements contained in the list.
1046 //!
1047 //! <b>Note</b>: Invalidates the iterators (but not the references)
1048 //! to the erased elements.
1049 template<class Iterator, class Disposer>
1050 void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
1052 this->clear_and_dispose(disposer);
1053 this->insert_after(this->cbefore_begin(), b, e, disposer);
1056 //! <b>Requires</b>: prev is an iterator to an element or x.end()/x.before_begin() in x.
1057 //!
1058 //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
1059 //! the element pointed by prev. No destructors or copy constructors are called.
1060 //!
1061 //! <b>Returns</b>: The last element inserted of x or prev if x is empty.
1062 //! This iterator can be used as new "prev" iterator for a new splice_after call.
1063 //! that will splice new values after the previously spliced values.
1064 //!
1065 //! <b>Throws</b>: Nothing.
1067 //! <b>Complexity</b>: Linear to the elements contained in x.
1068 //! Constant-time if cache_last<> option is true.
1069 //!
1070 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1071 //! list. Iterators of this list and all the references are not invalidated.
1072 iterator splice_after(const_iterator prev, slist_impl &x)
1074 if (!x.empty()){
1075 const_iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active
1076 node_ptr prev_n(prev.pointed_node());
1077 node_ptr last_x_n(last_x.pointed_node());
1078 if(cache_last){
1079 x.set_last_node(x.get_root_node());
1080 if(node_traits::get_next(prev_n) == this->get_end_node()){
1081 this->set_last_node(last_x_n);
1084 node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
1085 this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size());
1086 x.priv_size_traits().set_size(size_type(0));
1087 return last_x.unconst();
1089 else{
1090 return prev.unconst();
1094 //! <b>Requires</b>: prev must point to an element contained by this list or
1095 //! to the before_begin() element. prev_ele must point to an element contained in list
1096 //! x or must be x.before_begin().
1097 //!
1098 //! <b>Effects</b>: Transfers the element after prev_ele, from list x to this list,
1099 //! after the element pointed by prev. No destructors or copy constructors are called.
1100 //!
1101 //! <b>Throws</b>: Nothing.
1102 //!
1103 //! <b>Complexity</b>: Constant.
1104 //!
1105 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1106 //! list. Iterators of this list and all the references are not invalidated.
1107 void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator prev_ele)
1109 const_iterator elem = prev_ele;
1110 this->splice_after(prev_pos, x, prev_ele, ++elem, 1);
1113 //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
1114 //! before_begin(), and before_first and before_last belong to x and
1115 //! ++before_first != x.end() && before_last != x.end().
1116 //!
1117 //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this
1118 //! list, after the element pointed by prev_pos.
1119 //! No destructors or copy constructors are called.
1120 //!
1121 //! <b>Throws</b>: Nothing.
1122 //!
1123 //! <b>Complexity</b>: Linear to the number of elements transferred
1124 //! if constant_time_size is true. Constant-time otherwise.
1125 //!
1126 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1127 //! list. Iterators of this list and all the references are not invalidated.
1128 void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last)
1130 if(constant_time_size)
1131 this->splice_after(prev_pos, x, before_first, before_last, std::distance(before_first, before_last));
1132 else
1133 this->priv_splice_after
1134 (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node());
1137 //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
1138 //! before_begin(), and before_first and before_last belong to x and
1139 //! ++before_first != x.end() && before_last != x.end() and
1140 //! n == std::distance(before_first, before_last).
1141 //!
1142 //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this
1143 //! list, after the element pointed by p. No destructors or copy constructors are called.
1144 //!
1145 //! <b>Throws</b>: Nothing.
1146 //!
1147 //! <b>Complexity</b>: Constant time.
1148 //!
1149 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1150 //! list. Iterators of this list and all the references are not invalidated.
1151 void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last, difference_type n)
1153 if(n){
1154 BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_first, before_last) == n);
1155 this->priv_splice_after
1156 (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node());
1157 if(constant_time_size){
1158 this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
1159 x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n);
1164 //! <b>Requires</b>: it is an iterator to an element in x.
1165 //!
1166 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
1167 //! the element pointed by it. No destructors or copy constructors are called.
1168 //!
1169 //! <b>Returns</b>: The last element inserted of x or the previous element
1170 //! of it if x is empty.
1171 //! This iterator can be used as new "prev" iterator for a new splice call.
1172 //! that will splice new values after the previously spliced values.
1173 //!
1174 //! <b>Throws</b>: Nothing.
1176 //! <b>Complexity</b>: Linear to the elements contained in x plus linear to
1177 //! the elements before it.
1178 //! Linear to the elements before it if cache_last<> option is true.
1179 //! Constant-time if cache_last<> option is true and it == end().
1180 //!
1181 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1182 //! list. Iterators of this list and all the references are not invalidated.
1183 iterator splice(const_iterator it, slist_impl &x)
1184 { return this->splice_after(this->previous(it), x); }
1186 //! <b>Requires</b>: it p must be a valid iterator of *this.
1187 //! elem must point to an element contained in list
1188 //! x.
1189 //!
1190 //! <b>Effects</b>: Transfers the element elem, from list x to this list,
1191 //! before the element pointed by pos. No destructors or copy constructors are called.
1192 //!
1193 //! <b>Throws</b>: Nothing.
1194 //!
1195 //! <b>Complexity</b>: Linear to the elements before pos and before elem.
1196 //! Linear to the elements before elem if cache_last<> option is true and pos == end().
1197 //!
1198 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1199 //! list. Iterators of this list and all the references are not invalidated.
1200 void splice(const_iterator pos, slist_impl &x, const_iterator elem)
1201 { return this->splice_after(this->previous(pos), x, x.previous(elem)); }
1203 //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
1204 //! and first and last belong to x and first and last a valid range on x.
1205 //!
1206 //! <b>Effects</b>: Transfers the range [first, last) from list x to this
1207 //! list, before the element pointed by pos.
1208 //! No destructors or copy constructors are called.
1209 //!
1210 //! <b>Throws</b>: Nothing.
1211 //!
1212 //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last
1213 //! plus linear to the number of elements transferred if constant_time_size is true.
1214 //! Linear to the sum of elements before first, and last
1215 //! plus linear to the number of elements transferred if constant_time_size is true
1216 //! if cache_last<> is true and pos == end()
1217 //!
1218 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1219 //! list. Iterators of this list and all the references are not invalidated.
1220 void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last)
1221 { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last)); }
1223 //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
1224 //! and first and last belong to x and first and last a valid range on x.
1225 //! n == std::distance(first, last).
1226 //!
1227 //! <b>Effects</b>: Transfers the range [first, last) from list x to this
1228 //! list, before the element pointed by pos.
1229 //! No destructors or copy constructors are called.
1230 //!
1231 //! <b>Throws</b>: Nothing.
1232 //!
1233 //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last.
1234 //! Linear to the sum of elements before first and last
1235 //! if cache_last<> is true and pos == end().
1236 //!
1237 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1238 //! list. Iterators of this list and all the references are not invalidated.
1239 void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last, difference_type n)
1240 { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last), n); }
1242 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
1243 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
1244 //!
1245 //! <b>Throws</b>: If value_traits::node_traits::node
1246 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1247 //! or the predicate throws. Basic guarantee.
1248 //!
1249 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1250 //! is the list's size.
1252 //! <b>Note</b>: Iterators and references are not invalidated
1253 template<class Predicate>
1254 void sort(Predicate p)
1256 if (node_traits::get_next(node_traits::get_next(this->get_root_node()))
1257 != this->get_root_node()) {
1258 slist_impl carry;
1259 slist_impl counter[64];
1260 int fill = 0;
1261 const_iterator last_inserted;
1262 while(!this->empty()){
1263 last_inserted = this->cbegin();
1264 carry.splice_after(carry.cbefore_begin(), *this, this->cbefore_begin());
1265 int i = 0;
1266 while(i < fill && !counter[i].empty()) {
1267 carry.swap(counter[i]);
1268 last_inserted = carry.merge(counter[i++], p);
1270 BOOST_INTRUSIVE_INVARIANT_ASSERT(counter[i].empty());
1272 node_ptr p = node_algorithms::get_previous_node
1273 (last_inserted.pointed_node(), carry.cend().pointed_node());
1274 const_iterator last_element(p, this);
1275 if(constant_time_size){
1276 counter[i].splice_after( counter[i].cbefore_begin(), carry
1277 , carry.cbefore_begin(), last_element
1278 , carry.size());
1280 else{
1281 counter[i].splice_after( counter[i].cbefore_begin(), carry
1282 , carry.cbefore_begin(), last_element);
1284 if(i == fill)
1285 ++fill;
1288 for (int i = 1; i < fill; ++i)
1289 last_inserted = counter[i].merge(counter[i-1], p);
1290 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->empty());
1292 node_ptr p = node_algorithms::get_previous_node
1293 (last_inserted.pointed_node(), counter[--fill].end().pointed_node());
1294 const_iterator last_element(p, this);
1295 if(constant_time_size){
1296 this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
1297 , last_element, counter[fill].size());
1299 else{
1300 this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
1301 , last_element);
1306 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1307 //! ordering and both *this and x must be sorted according to that ordering
1308 //! The lists x and *this must be distinct.
1309 //!
1310 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1311 //! in order into *this. The merge is stable; that is, if an element from *this is
1312 //! equivalent to one from x, then the element from *this will precede the one from x.
1313 //!
1314 //! <b>Throws</b>: If value_traits::node_traits::node
1315 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1316 //! or std::less<value_type> throws. Basic guarantee.
1317 //!
1318 //! <b>Complexity</b>: This function is linear time: it performs at most
1319 //! size() + x.size() - 1 comparisons.
1320 //!
1321 //! <b>Note</b>: Iterators and references are not invalidated.
1322 void sort()
1323 { this->sort(std::less<value_type>()); }
1325 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1326 //! ordering and both *this and x must be sorted according to that ordering
1327 //! The lists x and *this must be distinct.
1328 //!
1329 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1330 //! in order into *this. The merge is stable; that is, if an element from *this is
1331 //! equivalent to one from x, then the element from *this will precede the one from x.
1332 //!
1333 //! <b>Returns</b>: An iterator to the last transferred value, end() is x is empty.
1334 //!
1335 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1336 //!
1337 //! <b>Complexity</b>: This function is linear time: it performs at most
1338 //! size() + x.size() - 1 comparisons.
1339 //!
1340 //! <b>Note</b>: Iterators and references are not invalidated.
1341 template<class Predicate>
1342 iterator merge(slist_impl& x, Predicate p)
1344 const_iterator e(this->cend()), ex(x.cend()), bb(this->cbefore_begin()),
1345 bb_next, last_inserted(e);
1346 while(!x.empty()){
1347 const_iterator ibx_next(x.cbefore_begin()), ibx(ibx_next++);
1348 while (++(bb_next = bb) != e && !p(*ibx_next, *bb_next)){
1349 bb = bb_next;
1351 if(bb_next == e){
1352 //Now transfer the rest to the end of the container
1353 last_inserted = this->splice_after(bb, x);
1354 break;
1356 else{
1357 size_type n(0);
1359 ibx = ibx_next; ++n;
1360 } while(++(ibx_next = ibx) != ex && p(*ibx_next, *bb_next));
1361 this->splice_after(bb, x, x.before_begin(), ibx, n);
1362 last_inserted = ibx;
1365 return last_inserted.unconst();
1368 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1369 //! in order into *this according to std::less<value_type>. The merge is stable;
1370 //! that is, if an element from *this is equivalent to one from x, then the element
1371 //! from *this will precede the one from x.
1372 //!
1373 //! <b>Throws</b>: if std::less<value_type> throws. Basic guarantee.
1374 //!
1375 //! <b>Complexity</b>: This function is linear time: it performs at most
1376 //! size() + x.size() - 1 comparisons.
1377 //!
1378 //! <b>Note</b>: Iterators and references are not invalidated
1379 void merge(slist_impl& x)
1380 { this->merge(x, std::less<value_type>()); }
1382 //! <b>Effects</b>: Reverses the order of elements in the list.
1383 //!
1384 //! <b>Throws</b>: Nothing.
1385 //!
1386 //! <b>Complexity</b>: This function is linear to the contained elements.
1387 //!
1388 //! <b>Note</b>: Iterators and references are not invalidated
1389 void reverse()
1391 if(cache_last && !this->empty()){
1392 this->set_last_node(node_traits::get_next(this->get_root_node()));
1394 this->priv_reverse(detail::bool_<linear>());
1397 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1398 //! No destructors are called.
1399 //!
1400 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1401 //!
1402 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1403 //!
1404 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1405 //! and iterators to elements that are not removed remain valid. This function is
1406 //! linear time: it performs exactly size() comparisons for equality.
1407 void remove(const_reference value)
1408 { this->remove_if(detail::equal_to_value<const_reference>(value)); }
1410 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1412 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1413 //! Disposer::operator()(pointer) is called for every removed element.
1415 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1416 //!
1417 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1418 //!
1419 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1420 //! and iterators to elements that are not removed remain valid.
1421 template<class Disposer>
1422 void remove_and_dispose(const_reference value, Disposer disposer)
1423 { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
1425 //! <b>Effects</b>: Removes all the elements for which a specified
1426 //! predicate is satisfied. No destructors are called.
1427 //!
1428 //! <b>Throws</b>: If pred throws. Basic guarantee.
1429 //!
1430 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1431 //!
1432 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1433 //! and iterators to elements that are not removed remain valid.
1434 template<class Pred>
1435 void remove_if(Pred pred)
1436 { this->remove_and_dispose_if(pred, detail::null_disposer()); }
1438 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1440 //! <b>Effects</b>: Removes all the elements for which a specified
1441 //! predicate is satisfied.
1442 //! Disposer::operator()(pointer) is called for every removed element.
1444 //! <b>Throws</b>: If pred throws. Basic guarantee.
1445 //!
1446 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1448 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1449 //! and iterators to elements that are not removed remain valid.
1450 template<class Pred, class Disposer>
1451 void remove_and_dispose_if(Pred pred, Disposer disposer)
1453 const_iterator bcur(this->before_begin()), cur(this->begin()), e(this->end());
1455 while(cur != e){
1456 if (pred(*cur)){
1457 cur = this->erase_after_and_dispose(bcur, disposer);
1459 else{
1460 bcur = cur;
1461 ++cur;
1464 if(cache_last){
1465 this->set_last_node(bcur.pointed_node());
1469 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1470 //! elements that are equal from the list. No destructors are called.
1471 //!
1472 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1473 //!
1474 //! <b>Complexity</b>: Linear time (size()-1) comparisons calls to pred()).
1475 //!
1476 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1477 //! and iterators to elements that are not removed remain valid.
1478 void unique()
1479 { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
1481 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1482 //! elements that satisfy some binary predicate from the list.
1483 //! No destructors are called.
1484 //!
1485 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1486 //!
1487 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1488 //!
1489 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1490 //! and iterators to elements that are not removed remain valid.
1491 template<class BinaryPredicate>
1492 void unique(BinaryPredicate pred)
1493 { this->unique_and_dispose(pred, detail::null_disposer()); }
1495 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1497 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1498 //! elements that satisfy some binary predicate from the list.
1499 //! Disposer::operator()(pointer) is called for every removed element.
1500 //!
1501 //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
1502 //!
1503 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1504 //!
1505 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1506 //! and iterators to elements that are not removed remain valid.
1507 template<class Disposer>
1508 void unique_and_dispose(Disposer disposer)
1509 { this->unique(std::equal_to<value_type>(), disposer); }
1511 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1513 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1514 //! elements that satisfy some binary predicate from the list.
1515 //! Disposer::operator()(pointer) is called for every removed element.
1516 //!
1517 //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1518 //!
1519 //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1520 //!
1521 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1522 //! and iterators to elements that are not removed remain valid.
1523 template<class BinaryPredicate, class Disposer>
1524 void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
1526 const_iterator end_n(this->cend());
1527 const_iterator bcur(this->cbegin());
1528 if(bcur != end_n){
1529 const_iterator cur(bcur);
1530 ++cur;
1531 while(cur != end_n) {
1532 if (pred(*bcur, *cur)){
1533 cur = this->erase_after_and_dispose(bcur, disposer);
1535 else{
1536 bcur = cur;
1537 ++cur;
1540 if(cache_last){
1541 this->set_last_node(bcur.pointed_node());
1546 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1547 //!
1548 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1549 //!
1550 //! <b>Throws</b>: Nothing.
1551 //!
1552 //! <b>Complexity</b>: Constant time.
1553 //!
1554 //! <b>Note</b>: Iterators and references are not invalidated.
1555 //! This static function is available only if the <i>value traits</i>
1556 //! is stateless.
1557 static iterator s_iterator_to(reference value)
1559 BOOST_STATIC_ASSERT((!stateful_value_traits));
1560 //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
1561 return iterator (value_traits::to_node_ptr(value), 0);
1564 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1565 //!
1566 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1567 //!
1568 //! <b>Throws</b>: Nothing.
1569 //!
1570 //! <b>Complexity</b>: Constant time.
1571 //!
1572 //! <b>Note</b>: Iterators and references are not invalidated.
1573 //! This static function is available only if the <i>value traits</i>
1574 //! is stateless.
1575 static const_iterator s_iterator_to(const_reference value)
1577 BOOST_STATIC_ASSERT((!stateful_value_traits));
1578 //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
1579 return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0);
1582 //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1583 //!
1584 //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1585 //!
1586 //! <b>Throws</b>: Nothing.
1587 //!
1588 //! <b>Complexity</b>: Constant time.
1589 //!
1590 //! <b>Note</b>: Iterators and references are not invalidated.
1591 iterator iterator_to(reference value)
1593 //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
1594 return iterator (value_traits::to_node_ptr(value), this);
1597 //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1598 //!
1599 //! <b>Effects</b>: This function returns an iterator pointing to the element.
1600 //!
1601 //! <b>Throws</b>: Nothing.
1602 //!
1603 //! <b>Complexity</b>: Constant time.
1604 //!
1605 //! <b>Note</b>: Iterators and references are not invalidated.
1606 const_iterator iterator_to(const_reference value) const
1608 //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
1609 return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this);
1612 //! <b>Returns</b>: The iterator to the element before i in the list.
1613 //! Returns the end-iterator, if either i is the begin-iterator or the
1614 //! list is empty.
1615 //!
1616 //! <b>Throws</b>: Nothing.
1617 //!
1618 //! <b>Complexity</b>: Linear to the number of elements before i.
1619 //! Constant if cache_last<> is true and i == end().
1620 iterator previous(iterator i)
1622 if(cache_last && (i.pointed_node() == this->get_end_node())){
1623 return iterator(this->get_last_node(), this);
1625 return iterator
1626 (node_algorithms::get_previous_node
1627 (this->before_begin().pointed_node(), i.pointed_node()), this);
1630 //! <b>Returns</b>: The const_iterator to the element before i in the list.
1631 //! Returns the end-const_iterator, if either i is the begin-const_iterator or
1632 //! the list is empty.
1633 //!
1634 //! <b>Throws</b>: Nothing.
1635 //!
1636 //! <b>Complexity</b>: Linear to the number of elements before i.
1637 //! Constant if cache_last<> is true and i == end().
1638 const_iterator previous(const_iterator i) const
1640 if(cache_last && (i.pointed_node() == this->get_end_node())){
1641 return const_iterator(uncast(this->get_last_node()), this);
1643 return const_iterator
1644 (node_algorithms::get_previous_node
1645 (this->before_begin().pointed_node(), i.pointed_node()), this);
1648 private:
1649 void priv_splice_after(node_ptr prev_pos_n, slist_impl &x, node_ptr before_first_n, node_ptr before_last_n)
1651 if (before_first_n != before_last_n && prev_pos_n != before_first_n && prev_pos_n != before_last_n)
1653 if(cache_last){
1654 if(node_traits::get_next(prev_pos_n) == this->get_end_node()){
1655 this->set_last_node(before_last_n);
1657 if(node_traits::get_next(before_last_n) == x.get_end_node()){
1658 x.set_last_node(before_first_n);
1661 node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n);
1665 void priv_reverse(detail::bool_<false>)
1666 { node_algorithms::reverse(this->get_root_node()); }
1668 void priv_reverse(detail::bool_<true>)
1670 node_ptr new_first = node_algorithms::reverse
1671 (node_traits::get_next(this->get_root_node()));
1672 node_traits::set_next(this->get_root_node(), new_first);
1675 void priv_shift_backwards(size_type n, detail::bool_<false>)
1677 node_ptr last = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n);
1678 if(cache_last && last){
1679 this->set_last_node(last);
1683 void priv_shift_backwards(size_type n, detail::bool_<true>)
1685 std::pair<node_ptr, node_ptr> ret(
1686 node_algorithms::move_first_n_forward
1687 (node_traits::get_next(this->get_root_node()), (std::size_t)n));
1688 if(ret.first){
1689 node_traits::set_next(this->get_root_node(), ret.first);
1690 if(cache_last){
1691 this->set_last_node(ret.second);
1696 void priv_shift_forward(size_type n, detail::bool_<false>)
1698 node_ptr last = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n);
1699 if(cache_last && last){
1700 this->set_last_node(last);
1704 void priv_shift_forward(size_type n, detail::bool_<true>)
1706 std::pair<node_ptr, node_ptr> ret(
1707 node_algorithms::move_first_n_backwards
1708 (node_traits::get_next(this->get_root_node()), (std::size_t)n));
1709 if(ret.first){
1710 node_traits::set_next(this->get_root_node(), ret.first);
1711 if(cache_last){
1712 this->set_last_node(ret.second);
1717 static void priv_swap_cache_last(slist_impl *this_impl, slist_impl *other_impl)
1719 bool other_was_empty = false;
1720 if(this_impl->empty()){
1721 //Check if both are empty or
1722 if(other_impl->empty())
1723 return;
1724 //If this is empty swap pointers
1725 slist_impl *tmp = this_impl;
1726 this_impl = other_impl;
1727 other_impl = tmp;
1728 other_was_empty = true;
1730 else{
1731 other_was_empty = other_impl->empty();
1734 //Precondition: this is not empty
1735 node_ptr other_old_last(other_impl->get_last_node());
1736 node_ptr other_bfirst(other_impl->get_root_node());
1737 node_ptr this_bfirst(this_impl->get_root_node());
1738 node_ptr this_old_last(this_impl->get_last_node());
1740 //Move all nodes from this to other's beginning
1741 node_algorithms::transfer_after(other_bfirst, this_bfirst, this_old_last);
1742 other_impl->set_last_node(this_old_last);
1744 if(other_was_empty){
1745 this_impl->set_last_node(this_bfirst);
1747 else{
1748 //Move trailing nodes from other to this
1749 node_algorithms::transfer_after(this_bfirst, this_old_last, other_old_last);
1750 this_impl->set_last_node(other_old_last);
1754 //circular version
1755 static void priv_swap_lists(node_ptr this_node, node_ptr other_node, detail::bool_<false>)
1756 { node_algorithms::swap_nodes(this_node, other_node); }
1758 //linear version
1759 static void priv_swap_lists(node_ptr this_node, node_ptr other_node, detail::bool_<true>)
1760 { node_algorithms::swap_trailing_nodes(this_node, other_node); }
1762 static slist_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
1764 //Obtaining the container from the end iterator is not possible with linear
1765 //singly linked lists (because "end" is represented by the null pointer)
1766 BOOST_STATIC_ASSERT(!linear);
1767 root_plus_size *r = detail::parent_from_member<root_plus_size, node>
1768 ( detail::get_pointer(end_iterator.pointed_node()), (&root_plus_size::root_));
1769 data_t *d = detail::parent_from_member<data_t, root_plus_size>
1770 ( r, &data_t::root_plus_size_);
1771 slist_impl *s = detail::parent_from_member<slist_impl, data_t>(d, &slist_impl::data_);
1772 return *s;
1776 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1777 template<class T, class ...Options>
1778 #else
1779 template<class Config>
1780 #endif
1781 inline bool operator<
1782 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1783 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1784 #else
1785 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1786 #endif
1787 { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1789 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1790 template<class T, class ...Options>
1791 #else
1792 template<class Config>
1793 #endif
1794 bool operator==
1795 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1796 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1797 #else
1798 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1799 #endif
1801 typedef slist_impl<Config> slist_type;
1802 typedef typename slist_type::const_iterator const_iterator;
1803 const bool C = slist_type::constant_time_size;
1804 if(C && x.size() != y.size()){
1805 return false;
1807 const_iterator end1 = x.end();
1809 const_iterator i1 = x.begin();
1810 const_iterator i2 = y.begin();
1811 if(C){
1812 while (i1 != end1 && *i1 == *i2) {
1813 ++i1;
1814 ++i2;
1816 return i1 == end1;
1818 else{
1819 const_iterator end2 = y.end();
1820 while (i1 != end1 && i2 != end2 && *i1 == *i2) {
1821 ++i1;
1822 ++i2;
1824 return i1 == end1 && i2 == end2;
1828 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1829 template<class T, class ...Options>
1830 #else
1831 template<class Config>
1832 #endif
1833 inline bool operator!=
1834 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1835 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1836 #else
1837 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1838 #endif
1839 { return !(x == y); }
1841 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1842 template<class T, class ...Options>
1843 #else
1844 template<class Config>
1845 #endif
1846 inline bool operator>
1847 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1848 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1849 #else
1850 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1851 #endif
1852 { return y < x; }
1854 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1855 template<class T, class ...Options>
1856 #else
1857 template<class Config>
1858 #endif
1859 inline bool operator<=
1860 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1861 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1862 #else
1863 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1864 #endif
1865 { return !(y < x); }
1867 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1868 template<class T, class ...Options>
1869 #else
1870 template<class Config>
1871 #endif
1872 inline bool operator>=
1873 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1874 (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
1875 #else
1876 (const slist_impl<Config> &x, const slist_impl<Config> &y)
1877 #endif
1878 { return !(x < y); }
1880 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1881 template<class T, class ...Options>
1882 #else
1883 template<class Config>
1884 #endif
1885 inline void swap
1886 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1887 (slist_impl<T, Options...> &x, slist_impl<T, Options...> &y)
1888 #else
1889 (slist_impl<Config> &x, slist_impl<Config> &y)
1890 #endif
1891 { x.swap(y); }
1893 //! Helper metafunction to define a \c slist that yields to the same type when the
1894 //! same options (either explicitly or implicitly) are used.
1895 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1896 template<class T, class ...Options>
1897 #else
1898 template<class T, class O1 = none, class O2 = none, class O3 = none, class O4 = none, class O5 = none>
1899 #endif
1900 struct make_slist
1902 /// @cond
1903 typedef typename pack_options
1904 < slist_defaults<T>,
1905 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1906 O1, O2, O3, O4, O5
1907 #else
1908 Options...
1909 #endif
1910 >::type packed_options;
1911 typedef typename detail::get_value_traits
1912 <T, typename packed_options::value_traits>::type value_traits;
1913 typedef slist_impl
1915 slistopt
1916 < value_traits
1917 , typename packed_options::size_type
1918 , packed_options::constant_time_size
1919 , packed_options::linear
1920 , packed_options::cache_last
1922 > implementation_defined;
1923 /// @endcond
1924 typedef implementation_defined type;
1928 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1930 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1931 template<class T, class O1, class O2, class O3, class O4, class O5>
1932 #else
1933 template<class T, class ...Options>
1934 #endif
1935 class slist
1936 : public make_slist<T,
1937 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1938 O1, O2, O3, O4, O5
1939 #else
1940 Options...
1941 #endif
1942 >::type
1944 typedef typename make_slist
1945 <T,
1946 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1947 O1, O2, O3, O4, O5
1948 #else
1949 Options...
1950 #endif
1951 >::type Base;
1952 typedef typename Base::real_value_traits real_value_traits;
1953 //Assert if passed value traits are compatible with the type
1954 BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
1955 public:
1956 typedef typename Base::value_traits value_traits;
1957 typedef typename Base::iterator iterator;
1958 typedef typename Base::const_iterator const_iterator;
1960 slist(const value_traits &v_traits = value_traits())
1961 : Base(v_traits)
1964 template<class Iterator>
1965 slist(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
1966 : Base(b, e, v_traits)
1969 static slist &container_from_end_iterator(iterator end_iterator)
1970 { return static_cast<slist &>(Base::container_from_end_iterator(end_iterator)); }
1972 static const slist &container_from_end_iterator(const_iterator end_iterator)
1973 { return static_cast<const slist &>(Base::container_from_end_iterator(end_iterator)); }
1976 #endif
1978 } //namespace intrusive
1979 } //namespace boost
1981 #include <boost/intrusive/detail/config_end.hpp>
1983 #endif //BOOST_INTRUSIVE_SLIST_HPP