1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_LIST_HPP
11 #define BOOST_CONTAINER_LIST_HPP
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
21 #include <boost/container/detail/config_begin.hpp>
22 #include <boost/container/detail/workaround.hpp>
25 #include <boost/container/container_fwd.hpp>
26 #include <boost/container/new_allocator.hpp> //new_allocator
27 #include <boost/container/throw_exception.hpp>
29 #include <boost/container/detail/algorithm.hpp>
30 #include <boost/container/detail/compare_functors.hpp>
31 #include <boost/container/detail/iterator.hpp>
32 #include <boost/container/detail/iterators.hpp>
33 #include <boost/container/detail/mpl.hpp>
34 #include <boost/container/detail/node_alloc_holder.hpp>
35 #include <boost/container/detail/version_type.hpp>
36 #include <boost/container/detail/value_functors.hpp>
38 #include <boost/move/utility_core.hpp>
39 #include <boost/move/iterator.hpp>
40 #include <boost/move/traits.hpp>
42 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
43 # include <boost/move/detail/fwd_macros.hpp>
45 #include <boost/move/detail/move_helpers.hpp>
46 #include <boost/move/detail/force_ptr.hpp>
49 #include <boost/intrusive/pointer_traits.hpp>
50 #include <boost/intrusive/list.hpp>
52 #include <boost/assert.hpp>
54 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
55 #include <initializer_list>
61 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
64 template<class VoidPointer>
67 typedef typename dtl::bi::make_list_base_hook
68 <dtl::bi::void_pointer<VoidPointer>, dtl::bi::link_mode<dtl::bi::normal_link> >::type type;
71 template <class T, class VoidPointer>
72 struct iiterator_node_value_type< base_node<T, list_hook<VoidPointer> > >
77 template<class Allocator>
78 struct intrusive_list_type
80 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
81 typedef typename allocator_traits_type::value_type value_type;
82 typedef typename boost::intrusive::pointer_traits
83 <typename allocator_traits_type::pointer>::template
84 rebind_pointer<void>::type
86 typedef base_node<value_type, list_hook<void_pointer> > node_type;
87 typedef typename dtl::bi::make_list
89 , dtl::bi::base_hook<typename list_hook<void_pointer>::type>
90 , dtl::bi::constant_time_size<true>
92 <typename allocator_traits_type::size_type>
93 >::type container_type;
94 typedef container_type type ;
98 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
100 //! A list is a doubly linked list. That is, it is a Sequence that supports both
101 //! forward and backward traversal, and (amortized) constant time insertion and
102 //! removal of elements at the beginning or the end, or in the middle. Lists have
103 //! the important property that insertion and splicing do not invalidate iterators
104 //! to list elements, and that even removal invalidates only the iterators that point
105 //! to the elements that are removed. The ordering of iterators may be changed
106 //! (that is, list<T>::iterator might have a different predecessor or successor
107 //! after a list operation than it did before), but the iterators themselves will
108 //! not be invalidated or made to point to different elements unless that invalidation
109 //! or mutation is explicit.
111 //! \tparam T The type of object that is stored in the list
112 //! \tparam Allocator The allocator used for all internal memory management, use void
113 //! for the default allocator
114 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
115 template <class T, class Allocator = void >
117 template <class T, class Allocator>
120 : protected dtl::node_alloc_holder
121 < typename real_allocator<T, Allocator>::type
122 , typename dtl::intrusive_list_type<typename real_allocator<T, Allocator>::type>::type>
124 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
125 typedef typename real_allocator<T, Allocator>::type ValueAllocator;
127 dtl::intrusive_list_type<ValueAllocator>::type Icont;
128 typedef dtl::node_alloc_holder<ValueAllocator, Icont> AllocHolder;
129 typedef typename AllocHolder::NodePtr NodePtr;
130 typedef typename AllocHolder::NodeAlloc NodeAlloc;
131 typedef typename AllocHolder::ValAlloc ValAlloc;
132 typedef typename AllocHolder::Node Node;
133 typedef dtl::allocator_node_destroyer<NodeAlloc> Destroyer;
134 typedef typename AllocHolder::alloc_version alloc_version;
135 typedef boost::container::allocator_traits<ValueAllocator> allocator_traits_type;
136 typedef boost::container::equal_to_value
137 <typename allocator_traits_type::value_type> equal_to_value_type;
139 BOOST_COPYABLE_AND_MOVABLE(list)
141 typedef dtl::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl;
142 typedef dtl::iterator_from_iiterator<typename Icont::iterator, true> const_iterator_impl;
143 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
146 //////////////////////////////////////////////
150 //////////////////////////////////////////////
152 typedef T value_type;
153 typedef typename ::boost::container::allocator_traits<ValueAllocator>::pointer pointer;
154 typedef typename ::boost::container::allocator_traits<ValueAllocator>::const_pointer const_pointer;
155 typedef typename ::boost::container::allocator_traits<ValueAllocator>::reference reference;
156 typedef typename ::boost::container::allocator_traits<ValueAllocator>::const_reference const_reference;
157 typedef typename ::boost::container::allocator_traits<ValueAllocator>::size_type size_type;
158 typedef typename ::boost::container::allocator_traits<ValueAllocator>::difference_type difference_type;
159 typedef ValueAllocator allocator_type;
160 typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type;
161 typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
162 typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
163 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator;
164 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
166 //////////////////////////////////////////////
168 // construct/copy/destroy
170 //////////////////////////////////////////////
172 //! <b>Effects</b>: Default constructs a list.
174 //! <b>Throws</b>: If allocator_type's default constructor throws.
176 //! <b>Complexity</b>: Constant.
177 list() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<ValueAllocator>::value)
181 //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
183 //! <b>Throws</b>: Nothing
185 //! <b>Complexity</b>: Constant.
186 explicit list(const allocator_type &a) BOOST_NOEXCEPT_OR_NOTHROW
190 //! <b>Effects</b>: Constructs a list
191 //! and inserts n value-initialized value_types.
193 //! <b>Throws</b>: If allocator_type's default constructor
194 //! throws or T's default or copy constructor throws.
196 //! <b>Complexity</b>: Linear to n.
197 explicit list(size_type n)
198 : AllocHolder(ValueAllocator())
201 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
202 //! and inserts n copies of value.
204 //! <b>Throws</b>: If allocator_type's default constructor
205 //! throws or T's default or copy constructor throws.
207 //! <b>Complexity</b>: Linear to n.
208 list(size_type n, const allocator_type &a)
212 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
213 //! and inserts n copies of value.
215 //! <b>Throws</b>: If allocator_type's default constructor
216 //! throws or T's default or copy constructor throws.
218 //! <b>Complexity</b>: Linear to n.
219 list(size_type n, const T& value, const ValueAllocator& a = ValueAllocator())
221 { this->insert(this->cbegin(), n, value); }
223 //! <b>Effects</b>: Copy constructs a list.
225 //! <b>Postcondition</b>: x == *this.
227 //! <b>Throws</b>: If allocator_type's default constructor throws.
229 //! <b>Complexity</b>: Linear to the elements x contains.
232 { this->insert(this->cbegin(), x.begin(), x.end()); }
234 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
236 //! <b>Throws</b>: If allocator_type's copy constructor throws.
238 //! <b>Complexity</b>: Constant.
239 list(BOOST_RV_REF(list) x) BOOST_NOEXCEPT_OR_NOTHROW
240 : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x))
243 //! <b>Effects</b>: Copy constructs a list using the specified allocator.
245 //! <b>Postcondition</b>: x == *this.
247 //! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws.
249 //! <b>Complexity</b>: Linear to the elements x contains.
250 list(const list& x, const allocator_type &a)
252 { this->insert(this->cbegin(), x.begin(), x.end()); }
254 //! <b>Effects</b>: Move constructor sing the specified allocator.
255 //! Moves x's resources to *this.
257 //! <b>Throws</b>: If allocation or value_type's copy constructor throws.
259 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
260 list(BOOST_RV_REF(list) x, const allocator_type &a)
263 if(this->node_alloc() == x.node_alloc()){
264 this->icont().swap(x.icont());
267 this->insert(this->cbegin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end()));
271 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
272 //! and inserts a copy of the range [first, last) in the list.
274 //! <b>Throws</b>: If allocator_type's default constructor
275 //! throws or T's constructor taking a dereferenced InIt throws.
277 //! <b>Complexity</b>: Linear to the range [first, last).
278 template <class InpIt>
279 list(InpIt first, InpIt last, const ValueAllocator &a = ValueAllocator())
281 { this->insert(this->cbegin(), first, last); }
284 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
285 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
286 //! and inserts a copy of the range [il.begin(), il.end()) in the list.
288 //! <b>Throws</b>: If allocator_type's default constructor
289 //! throws or T's constructor taking a dereferenced
290 //! std::initializer_list iterator throws.
292 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
293 list(std::initializer_list<value_type> il, const ValueAllocator &a = ValueAllocator())
295 { this->insert(this->cbegin(), il.begin(), il.end()); }
298 //! <b>Effects</b>: Destroys the list. All stored values are destroyed
299 //! and used memory is deallocated.
301 //! <b>Throws</b>: Nothing.
303 //! <b>Complexity</b>: Linear to the number of elements.
304 BOOST_CONTAINER_FORCEINLINE ~list() BOOST_NOEXCEPT_OR_NOTHROW
305 {} //AllocHolder clears the list
307 //! <b>Effects</b>: Makes *this contain the same elements as x.
309 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
310 //! of each of x's elements.
312 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
314 //! <b>Complexity</b>: Linear to the number of elements in x.
315 list& operator=(BOOST_COPY_ASSIGN_REF(list) x)
317 if (BOOST_LIKELY(this != &x)) {
318 NodeAlloc &this_alloc = this->node_alloc();
319 const NodeAlloc &x_alloc = x.node_alloc();
320 dtl::bool_<allocator_traits_type::
321 propagate_on_container_copy_assignment::value> flag;
322 if(flag && this_alloc != x_alloc){
325 this->AllocHolder::copy_assign_alloc(x);
326 this->assign(x.begin(), x.end());
331 //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
333 //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
334 //! before the function.
336 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
337 //! is false and (allocation throws or value_type's move constructor throws)
339 //! <b>Complexity</b>: Constant if allocator_traits_type::
340 //! propagate_on_container_move_assignment is true or
341 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
342 list& operator=(BOOST_RV_REF(list) x)
343 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
344 || allocator_traits_type::is_always_equal::value)
346 if (BOOST_LIKELY(this != &x)) {
347 NodeAlloc &this_alloc = this->node_alloc();
348 NodeAlloc &x_alloc = x.node_alloc();
349 const bool propagate_alloc = allocator_traits_type::
350 propagate_on_container_move_assignment::value;
351 const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
352 //Resources can be transferred if both allocators are
353 //going to be equal after this function (either propagated or already equal)
354 if(propagate_alloc || allocators_equal){
357 //Move allocator if needed
358 this->AllocHolder::move_assign_alloc(x);
360 this->icont() = boost::move(x.icont());
362 //Else do a one by one move
364 this->assign( boost::make_move_iterator(x.begin())
365 , boost::make_move_iterator(x.end()));
371 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
372 //! <b>Effects</b>: Makes *this contain the same elements as il.
374 //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
375 //! of each of x's elements.
377 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
379 //! <b>Complexity</b>: Linear to the number of elements in x.
380 BOOST_CONTAINER_FORCEINLINE list& operator=(std::initializer_list<value_type> il)
382 this->assign(il.begin(), il.end());
387 //! <b>Effects</b>: Assigns the n copies of val to *this.
389 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
391 //! <b>Complexity</b>: Linear to n.
392 BOOST_CONTAINER_FORCEINLINE void assign(size_type n, const T& val)
394 typedef constant_iterator<value_type> cvalue_iterator;
395 return this->assign(cvalue_iterator(val, n), cvalue_iterator());
398 //! <b>Effects</b>: Assigns the range [first, last) to *this.
400 //! <b>Throws</b>: If memory allocation throws or
401 //! T's constructor from dereferencing InpIt throws.
403 //! <b>Complexity</b>: Linear to n.
404 template <class InpIt>
405 void assign(InpIt first, InpIt last
406 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
407 , typename dtl::disable_if_convertible<InpIt, size_type>::type * = 0
411 iterator first1 = this->begin();
412 const iterator last1 = this->end();
413 for ( ; first1 != last1 && first != last; ++first1, ++first)
416 this->erase(first1, last1);
418 this->insert(last1, first, last);
422 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
423 //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this.
425 //! <b>Throws</b>: If memory allocation throws or
426 //! T's constructor from dereferencing std::initializer_list iterator throws.
428 //! <b>Complexity</b>: Linear to n.
429 BOOST_CONTAINER_FORCEINLINE void assign(std::initializer_list<value_type> il)
430 { this->assign(il.begin(), il.end()); }
433 //! <b>Effects</b>: Returns a copy of the internal allocator.
435 //! <b>Throws</b>: If allocator's copy constructor throws.
437 //! <b>Complexity</b>: Constant.
438 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
439 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
440 { return allocator_type(this->node_alloc()); }
442 //! <b>Effects</b>: Returns a reference to the internal allocator.
444 //! <b>Throws</b>: Nothing
446 //! <b>Complexity</b>: Constant.
448 //! <b>Note</b>: Non-standard extension.
449 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
450 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
451 { return this->node_alloc(); }
453 //! <b>Effects</b>: Returns a reference to the internal allocator.
455 //! <b>Throws</b>: Nothing
457 //! <b>Complexity</b>: Constant.
459 //! <b>Note</b>: Non-standard extension.
460 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
461 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
462 { return this->node_alloc(); }
464 //////////////////////////////////////////////
468 //////////////////////////////////////////////
470 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
472 //! <b>Throws</b>: Nothing.
474 //! <b>Complexity</b>: Constant.
475 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
476 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
477 { return iterator(this->icont().begin()); }
479 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
481 //! <b>Throws</b>: Nothing.
483 //! <b>Complexity</b>: Constant.
484 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
485 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
486 { return this->cbegin(); }
488 //! <b>Effects</b>: Returns an iterator to the end of the list.
490 //! <b>Throws</b>: Nothing.
492 //! <b>Complexity</b>: Constant.
493 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
494 iterator end() BOOST_NOEXCEPT_OR_NOTHROW
495 { return iterator(this->icont().end()); }
497 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
499 //! <b>Throws</b>: Nothing.
501 //! <b>Complexity</b>: Constant.
502 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
503 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
504 { return this->cend(); }
506 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
507 //! of the reversed list.
509 //! <b>Throws</b>: Nothing.
511 //! <b>Complexity</b>: Constant.
512 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
513 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
514 { return reverse_iterator(end()); }
516 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
517 //! of the reversed list.
519 //! <b>Throws</b>: Nothing.
521 //! <b>Complexity</b>: Constant.
522 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
523 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
524 { return this->crbegin(); }
526 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
527 //! of the reversed list.
529 //! <b>Throws</b>: Nothing.
531 //! <b>Complexity</b>: Constant.
532 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
533 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
534 { return reverse_iterator(begin()); }
536 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
537 //! of the reversed list.
539 //! <b>Throws</b>: Nothing.
541 //! <b>Complexity</b>: Constant.
542 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
543 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
544 { return this->crend(); }
546 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
548 //! <b>Throws</b>: Nothing.
550 //! <b>Complexity</b>: Constant.
551 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
552 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
553 { return const_iterator(this->non_const_icont().begin()); }
555 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
557 //! <b>Throws</b>: Nothing.
559 //! <b>Complexity</b>: Constant.
560 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
561 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
562 { return const_iterator(this->non_const_icont().end()); }
564 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
565 //! of the reversed list.
567 //! <b>Throws</b>: Nothing.
569 //! <b>Complexity</b>: Constant.
570 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
571 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
572 { return const_reverse_iterator(this->cend()); }
574 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
575 //! of the reversed list.
577 //! <b>Throws</b>: Nothing.
579 //! <b>Complexity</b>: Constant.
580 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
581 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
582 { return const_reverse_iterator(this->cbegin()); }
584 //////////////////////////////////////////////
588 //////////////////////////////////////////////
590 //! <b>Effects</b>: Returns true if the list contains no elements.
592 //! <b>Throws</b>: Nothing.
594 //! <b>Complexity</b>: Constant.
595 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
596 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
597 { return !this->size(); }
599 //! <b>Effects</b>: Returns the number of the elements contained in the list.
601 //! <b>Throws</b>: Nothing.
603 //! <b>Complexity</b>: Constant.
604 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
605 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
606 { return this->icont().size(); }
608 //! <b>Effects</b>: Returns the largest possible size of the list.
610 //! <b>Throws</b>: Nothing.
612 //! <b>Complexity</b>: Constant.
613 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
614 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
615 { return AllocHolder::max_size(); }
617 //! <b>Effects</b>: Inserts or erases elements at the end such that
618 //! the size becomes n. New elements are value initialized.
620 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
622 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
623 void resize(size_type new_size)
625 if(!priv_try_shrink(new_size)){
626 typedef value_init_construct_iterator<value_type> value_init_iterator;
627 this->insert(this->cend(), value_init_iterator(new_size - this->size()), value_init_iterator());
631 //! <b>Effects</b>: Inserts or erases elements at the end such that
632 //! the size becomes n. New elements are copy constructed from x.
634 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
636 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
637 void resize(size_type new_size, const T& x)
639 if(!priv_try_shrink(new_size)){
640 this->insert(this->cend(), new_size - this->size(), x);
644 //////////////////////////////////////////////
648 //////////////////////////////////////////////
650 //! <b>Requires</b>: !empty()
652 //! <b>Effects</b>: Returns a reference to the first element
653 //! from the beginning of the container.
655 //! <b>Throws</b>: Nothing.
657 //! <b>Complexity</b>: Constant.
658 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
659 reference front() BOOST_NOEXCEPT_OR_NOTHROW
661 BOOST_ASSERT(!this->empty());
662 return *this->begin();
665 //! <b>Requires</b>: !empty()
667 //! <b>Effects</b>: Returns a const reference to the first element
668 //! from the beginning of the container.
670 //! <b>Throws</b>: Nothing.
672 //! <b>Complexity</b>: Constant.
673 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
674 const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW
676 BOOST_ASSERT(!this->empty());
677 return *this->begin();
680 //! <b>Requires</b>: !empty()
682 //! <b>Effects</b>: Returns a reference to the first element
683 //! from the beginning of the container.
685 //! <b>Throws</b>: Nothing.
687 //! <b>Complexity</b>: Constant.
688 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
689 reference back() BOOST_NOEXCEPT_OR_NOTHROW
691 BOOST_ASSERT(!this->empty());
692 return *(--this->end());
695 //! <b>Requires</b>: !empty()
697 //! <b>Effects</b>: Returns a const reference to the first element
698 //! from the beginning of the container.
700 //! <b>Throws</b>: Nothing.
702 //! <b>Complexity</b>: Constant.
703 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
704 const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW
706 BOOST_ASSERT(!this->empty());
707 return *(--this->end());
710 //////////////////////////////////////////////
714 //////////////////////////////////////////////
716 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
718 //! <b>Effects</b>: Inserts an object of type T constructed with
719 //! std::forward<Args>(args)... in the end of the list.
721 //! <b>Returns</b>: A reference to the created object.
723 //! <b>Throws</b>: If memory allocation throws or
724 //! T's in-place constructor throws.
726 //! <b>Complexity</b>: Constant
727 template <class... Args>
728 reference emplace_back(BOOST_FWD_REF(Args)... args)
729 { return *this->emplace(this->cend(), boost::forward<Args>(args)...); }
731 //! <b>Effects</b>: Inserts an object of type T constructed with
732 //! std::forward<Args>(args)... in the beginning of the list.
734 //! <b>Returns</b>: A reference to the created object.
736 //! <b>Throws</b>: If memory allocation throws or
737 //! T's in-place constructor throws.
739 //! <b>Complexity</b>: Constant
740 template <class... Args>
741 reference emplace_front(BOOST_FWD_REF(Args)... args)
742 { return *this->emplace(this->cbegin(), boost::forward<Args>(args)...); }
744 //! <b>Effects</b>: Inserts an object of type T constructed with
745 //! std::forward<Args>(args)... before p.
747 //! <b>Throws</b>: If memory allocation throws or
748 //! T's in-place constructor throws.
750 //! <b>Complexity</b>: Constant
751 template <class... Args>
752 iterator emplace(const_iterator position, BOOST_FWD_REF(Args)... args)
754 BOOST_ASSERT((priv_is_linked)(position));
755 NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...));
756 return iterator(this->icont().insert(position.get(), *pnode));
759 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
761 #define BOOST_CONTAINER_LIST_EMPLACE_CODE(N) \
762 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
763 reference emplace_back(BOOST_MOVE_UREF##N)\
764 { return *this->emplace(this->cend() BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
766 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
767 reference emplace_front(BOOST_MOVE_UREF##N)\
768 { return *this->emplace(this->cbegin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\
770 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
771 iterator emplace(const_iterator position BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
773 BOOST_ASSERT(position == this->cend() || (--(++position) == position) );\
774 NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\
775 return iterator(this->icont().insert(position.get(), *pnode));\
778 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_LIST_EMPLACE_CODE)
779 #undef BOOST_CONTAINER_LIST_EMPLACE_CODE
781 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
783 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
784 //! <b>Effects</b>: Inserts a copy of x at the beginning of the list.
786 //! <b>Throws</b>: If memory allocation throws or
787 //! T's copy constructor throws.
789 //! <b>Complexity</b>: Amortized constant time.
790 void push_front(const T &x);
792 //! <b>Effects</b>: Constructs a new element in the beginning of the list
793 //! and moves the resources of x to this new element.
795 //! <b>Throws</b>: If memory allocation throws.
797 //! <b>Complexity</b>: Amortized constant time.
798 void push_front(T &&x);
800 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
803 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
804 //! <b>Effects</b>: Inserts a copy of x at the end of the list.
806 //! <b>Throws</b>: If memory allocation throws or
807 //! T's copy constructor throws.
809 //! <b>Complexity</b>: Amortized constant time.
810 void push_back(const T &x);
812 //! <b>Effects</b>: Constructs a new element in the end of the list
813 //! and moves the resources of x to this new element.
815 //! <b>Throws</b>: If memory allocation throws.
817 //! <b>Complexity</b>: Amortized constant time.
818 void push_back(T &&x);
820 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
823 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
824 //! <b>Requires</b>: p must be a valid iterator of *this.
826 //! <b>Effects</b>: Insert a copy of x before p.
828 //! <b>Returns</b>: an iterator to the inserted element.
830 //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
832 //! <b>Complexity</b>: Amortized constant time.
833 iterator insert(const_iterator p, const T &x);
835 //! <b>Requires</b>: p must be a valid iterator of *this.
837 //! <b>Effects</b>: Insert a new element before p with x's resources.
839 //! <b>Returns</b>: an iterator to the inserted element.
841 //! <b>Throws</b>: If memory allocation throws.
843 //! <b>Complexity</b>: Amortized constant time.
844 iterator insert(const_iterator p, T &&x);
846 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
849 //! <b>Requires</b>: p must be a valid iterator of *this.
851 //! <b>Effects</b>: Inserts n copies of x before p.
853 //! <b>Returns</b>: an iterator to the first inserted element or p if n is 0.
855 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
857 //! <b>Complexity</b>: Linear to n.
858 iterator insert(const_iterator position, size_type n, const T& x)
860 //range check is done by insert
861 typedef constant_iterator<value_type> cvalue_iterator;
862 return this->insert(position, cvalue_iterator(x, n), cvalue_iterator());
865 //! <b>Requires</b>: p must be a valid iterator of *this.
867 //! <b>Effects</b>: Insert a copy of the [first, last) range before p.
869 //! <b>Returns</b>: an iterator to the first inserted element or p if first == last.
871 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
872 //! dereferenced InpIt throws.
874 //! <b>Complexity</b>: Linear to distance [first, last).
875 template <class InpIt>
876 iterator insert(const_iterator p, InpIt first, InpIt last
877 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
878 , typename dtl::enable_if_c
879 < !dtl::is_convertible<InpIt, size_type>::value
880 && (dtl::is_input_iterator<InpIt>::value
881 || dtl::is_same<alloc_version, version_1>::value
887 BOOST_ASSERT((priv_is_linked)(p));
888 const typename Icont::iterator ipos(p.get());
889 iterator ret_it(ipos);
891 ret_it = iterator(this->icont().insert(ipos, *this->create_node_from_it(first)));
894 for (; first != last; ++first){
895 this->icont().insert(ipos, *this->create_node_from_it(first));
900 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
901 template <class FwdIt>
902 iterator insert(const_iterator position, FwdIt first, FwdIt last
903 , typename dtl::enable_if_c
904 < !dtl::is_convertible<FwdIt, size_type>::value
905 && !(dtl::is_input_iterator<FwdIt>::value
906 || dtl::is_same<alloc_version, version_1>::value
911 BOOST_ASSERT((priv_is_linked)(position));
912 //Optimized allocation and construction
913 insertion_functor func(this->icont(), position.get());
914 iterator before_p(position.get());
916 this->allocate_many_and_construct(first, boost::container::iterator_udistance(first, last), func);
921 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
922 //! <b>Requires</b>: p must be a valid iterator of *this.
924 //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
926 //! <b>Returns</b>: an iterator to the first inserted element or p if if.begin() == il.end().
928 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
929 //! dereferenced std::initializer_list iterator throws.
931 //! <b>Complexity</b>: Linear to distance [il.begin(), il.end()).
932 iterator insert(const_iterator p, std::initializer_list<value_type> il)
934 //position range check is done by insert()
935 return insert(p, il.begin(), il.end());
939 //! <b>Effects</b>: Removes the first element from the list.
941 //! <b>Throws</b>: Nothing.
943 //! <b>Complexity</b>: Amortized constant time.
944 void pop_front() BOOST_NOEXCEPT_OR_NOTHROW
946 BOOST_ASSERT(!this->empty());
947 this->erase(this->cbegin());
950 //! <b>Effects</b>: Removes the last element from the list.
952 //! <b>Throws</b>: Nothing.
954 //! <b>Complexity</b>: Amortized constant time.
955 void pop_back() BOOST_NOEXCEPT_OR_NOTHROW
957 BOOST_ASSERT(!this->empty());
958 const_iterator tmp = this->cend();
962 //! <b>Requires</b>: p must be a valid iterator of *this.
964 //! <b>Effects</b>: Erases the element at p.
966 //! <b>Throws</b>: Nothing.
968 //! <b>Complexity</b>: Amortized constant time.
969 iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
971 BOOST_ASSERT(p != this->cend() && (priv_is_linked)(p));
972 return iterator(this->icont().erase_and_dispose(p.get(), Destroyer(this->node_alloc())));
975 //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
977 //! <b>Effects</b>: Erases the elements pointed by [first, last).
979 //! <b>Throws</b>: Nothing.
981 //! <b>Complexity</b>: Linear to the distance between first and last.
982 iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
984 BOOST_ASSERT(first == last || (first != this->cend() && (priv_is_linked)(first)));
985 BOOST_ASSERT(first == last || (priv_is_linked)(last));
986 return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version()));
989 //! <b>Effects</b>: Swaps the contents of *this and x.
991 //! <b>Throws</b>: Nothing.
993 //! <b>Complexity</b>: Constant.
995 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
996 || allocator_traits_type::is_always_equal::value)
998 BOOST_ASSERT(allocator_traits_type::propagate_on_container_swap::value ||
999 allocator_traits_type::is_always_equal::value ||
1000 this->get_stored_allocator() == x.get_stored_allocator());
1001 AllocHolder::swap(x);
1004 //! <b>Effects</b>: Erases all the elements of the list.
1006 //! <b>Throws</b>: Nothing.
1008 //! <b>Complexity</b>: Linear to the number of elements in the list.
1009 void clear() BOOST_NOEXCEPT_OR_NOTHROW
1010 { AllocHolder::clear(alloc_version()); }
1012 //////////////////////////////////////////////
1016 //////////////////////////////////////////////
1018 //! <b>Requires</b>: p must point to an element contained
1019 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
1021 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
1022 //! the element pointed by p. No destructors or copy constructors are called.
1024 //! <b>Throws</b>: Nothing
1026 //! <b>Complexity</b>: Constant.
1028 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
1029 //! this list. Iterators of this list and all the references are not invalidated.
1030 void splice(const_iterator p, list& x) BOOST_NOEXCEPT_OR_NOTHROW
1032 BOOST_ASSERT((priv_is_linked)(p));
1033 BOOST_ASSERT(this != &x);
1034 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1035 this->icont().splice(p.get(), x.icont());
1038 //! <b>Requires</b>: p must point to an element contained
1039 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
1041 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
1042 //! the element pointed by p. No destructors or copy constructors are called.
1044 //! <b>Throws</b>: Nothing
1046 //! <b>Complexity</b>: Constant.
1048 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
1049 //! this list. Iterators of this list and all the references are not invalidated.
1050 void splice(const_iterator p, BOOST_RV_REF(list) x) BOOST_NOEXCEPT_OR_NOTHROW
1052 //Checks done in splice
1053 this->splice(p, static_cast<list&>(x));
1056 //! <b>Requires</b>: p must point to an element contained
1057 //! by this list. i must point to an element contained in list x.
1058 //! this' allocator and x's allocator shall compare equal
1060 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1061 //! before the element pointed by p. No destructors or copy constructors are called.
1062 //! If p == i or p == ++i, this function is a null operation.
1064 //! <b>Throws</b>: Nothing
1066 //! <b>Complexity</b>: Constant.
1068 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1069 //! list. Iterators of this list and all the references are not invalidated.
1070 void splice(const_iterator p, list &x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
1072 BOOST_ASSERT((priv_is_linked)(p));
1073 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1074 this->icont().splice(p.get(), x.icont(), i.get());
1077 //! <b>Requires</b>: p must point to an element contained
1078 //! by this list. i must point to an element contained in list x.
1079 //! this' allocator and x's allocator shall compare equal.
1081 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1082 //! before the element pointed by p. No destructors or copy constructors are called.
1083 //! If p == i or p == ++i, this function is a null operation.
1085 //! <b>Throws</b>: Nothing
1087 //! <b>Complexity</b>: Constant.
1089 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1090 //! list. Iterators of this list and all the references are not invalidated.
1091 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
1093 BOOST_ASSERT(this != &x);
1094 //Additional checks done in splice()
1095 this->splice(p, static_cast<list&>(x), i);
1098 //! <b>Requires</b>: p must point to an element contained
1099 //! by this list. first and last must point to elements contained in list x.
1100 //! this' allocator and x's allocator shall compare equal
1102 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1103 //! before the element pointed by p. No destructors or copy constructors are called.
1105 //! <b>Throws</b>: Nothing
1107 //! <b>Complexity</b>: Linear to the number of elements transferred.
1109 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1110 //! list. Iterators of this list and all the references are not invalidated.
1111 void splice(const_iterator p, list &x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
1113 BOOST_ASSERT((priv_is_linked)(p));
1114 BOOST_ASSERT(first == last || (first != x.cend() && x.priv_is_linked(first)));
1115 BOOST_ASSERT(first == last || x.priv_is_linked(last));
1116 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1117 this->icont().splice(p.get(), x.icont(), first.get(), last.get());
1120 //! <b>Requires</b>: p must point to an element contained
1121 //! by this list. first and last must point to elements contained in list x.
1122 //! this' allocator and x's allocator shall compare equal.
1124 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1125 //! before the element pointed by p. No destructors or copy constructors are called.
1127 //! <b>Throws</b>: Nothing
1129 //! <b>Complexity</b>: Linear to the number of elements transferred.
1131 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1132 //! list. Iterators of this list and all the references are not invalidated.
1133 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
1135 BOOST_ASSERT(this != &x);
1136 //Additional checks done in splice()
1137 this->splice(p, static_cast<list&>(x), first, last);
1140 //! <b>Requires</b>: p must point to an element contained
1141 //! by this list. first and last must point to elements contained in list x.
1142 //! n == distance(first, last). this' allocator and x's allocator shall compare equal
1144 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1145 //! before the element pointed by p. No destructors or copy constructors are called.
1147 //! <b>Throws</b>: Nothing
1149 //! <b>Complexity</b>: Constant.
1151 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1152 //! list. Iterators of this list and all the references are not invalidated.
1154 //! <b>Note</b>: Non-standard extension
1155 void splice(const_iterator p, list &x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1157 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1158 this->icont().splice(p.get(), x.icont(), first.get(), last.get(), n);
1161 //! <b>Requires</b>: p must point to an element contained
1162 //! by this list. first and last must point to elements contained in list x.
1163 //! n == distance(first, last). this' allocator and x's allocator shall compare equal
1165 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1166 //! before the element pointed by p. No destructors or copy constructors are called.
1168 //! <b>Throws</b>: Nothing
1170 //! <b>Complexity</b>: Constant.
1172 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1173 //! list. Iterators of this list and all the references are not invalidated.
1175 //! <b>Note</b>: Non-standard extension
1176 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1177 { this->splice(p, static_cast<list&>(x), first, last, n); }
1179 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1181 //! <b>Throws</b>: If comparison throws.
1183 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1185 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1186 //! and iterators to elements that are not removed remain valid.
1187 void remove(const T& value)
1188 { this->remove_if(equal_to_value_type(value)); }
1190 //! <b>Effects</b>: Removes all the elements for which a specified
1191 //! predicate is satisfied.
1193 //! <b>Throws</b>: If pred throws.
1195 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1197 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1198 //! and iterators to elements that are not removed remain valid.
1199 template <class Pred>
1200 void remove_if(Pred pred)
1202 typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
1203 this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
1206 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1207 //! elements that are equal from the list.
1209 //! <b>Throws</b>: If comparison throws.
1211 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1213 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1214 //! and iterators to elements that are not removed remain valid.
1216 { this->unique(value_equal_t()); }
1218 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1219 //! elements that satisfy some binary predicate from the list.
1221 //! <b>Throws</b>: If pred throws.
1223 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1225 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1226 //! and iterators to elements that are not removed remain valid.
1227 template <class BinaryPredicate>
1228 void unique(BinaryPredicate binary_pred)
1230 typedef value_to_node_compare<Node, BinaryPredicate> value_to_node_compare_type;
1231 this->icont().unique_and_dispose(value_to_node_compare_type(binary_pred), Destroyer(this->node_alloc()));
1234 //! <b>Requires</b>: The lists x and *this must be distinct.
1236 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1237 //! in order into *this according to std::less<value_type>. The merge is stable;
1238 //! that is, if an element from *this is equivalent to one from x, then the element
1239 //! from *this will precede the one from x.
1241 //! <b>Throws</b>: If comparison throws.
1243 //! <b>Complexity</b>: This function is linear time: it performs at most
1244 //! size() + x.size() - 1 comparisons.
1246 { this->merge(x, value_less_t()); }
1248 //! <b>Requires</b>: The lists x and *this must be distinct.
1250 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1251 //! in order into *this according to std::less<value_type>. The merge is stable;
1252 //! that is, if an element from *this is equivalent to one from x, then the element
1253 //! from *this will precede the one from x.
1255 //! <b>Throws</b>: If comparison throws.
1257 //! <b>Complexity</b>: This function is linear time: it performs at most
1258 //! size() + x.size() - 1 comparisons.
1259 void merge(BOOST_RV_REF(list) x)
1260 { this->merge(static_cast<list&>(x)); }
1262 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1263 //! ordering and both *this and x must be sorted according to that ordering
1264 //! The lists x and *this must be distinct.
1266 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1267 //! in order into *this. The merge is stable; that is, if an element from *this is
1268 //! equivalent to one from x, then the element from *this will precede the one from x.
1270 //! <b>Throws</b>: If comp throws.
1272 //! <b>Complexity</b>: This function is linear time: it performs at most
1273 //! size() + x.size() - 1 comparisons.
1275 //! <b>Note</b>: Iterators and references to *this are not invalidated.
1276 template <class StrictWeakOrdering>
1277 void merge(list &x, const StrictWeakOrdering &comp)
1279 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1280 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
1281 this->icont().merge(x.icont(), value_to_node_compare_type(comp));
1284 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1285 //! ordering and both *this and x must be sorted according to that ordering
1286 //! The lists x and *this must be distinct.
1288 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1289 //! in order into *this. The merge is stable; that is, if an element from *this is
1290 //! equivalent to one from x, then the element from *this will precede the one from x.
1292 //! <b>Throws</b>: If comp throws.
1294 //! <b>Complexity</b>: This function is linear time: it performs at most
1295 //! size() + x.size() - 1 comparisons.
1297 //! <b>Note</b>: Iterators and references to *this are not invalidated.
1298 template <class StrictWeakOrdering>
1299 void merge(BOOST_RV_REF(list) x, StrictWeakOrdering comp)
1300 { this->merge(static_cast<list&>(x), comp); }
1302 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
1303 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
1305 //! <b>Throws</b>: If comparison throws.
1307 //! <b>Notes</b>: Iterators and references are not invalidated.
1309 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1310 //! is the list's size.
1312 { this->sort(value_less_t()); }
1314 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
1315 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
1317 //! <b>Throws</b>: If comp throws.
1319 //! <b>Notes</b>: Iterators and references are not invalidated.
1321 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1322 //! is the list's size.
1323 template <class StrictWeakOrdering>
1324 void sort(StrictWeakOrdering comp)
1326 // nothing if the list has length 0 or 1.
1327 if (this->size() < 2)
1329 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
1330 this->icont().sort(value_to_node_compare_type(comp));
1333 //! <b>Effects</b>: Reverses the order of elements in the list.
1335 //! <b>Throws</b>: Nothing.
1337 //! <b>Complexity</b>: This function is linear time.
1339 //! <b>Note</b>: Iterators and references are not invalidated
1340 void reverse() BOOST_NOEXCEPT_OR_NOTHROW
1341 { this->icont().reverse(); }
1343 //! <b>Effects</b>: Returns true if x and y are equal
1345 //! <b>Complexity</b>: Linear to the number of elements in the container.
1346 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1347 friend bool operator==(const list& x, const list& y)
1348 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
1350 //! <b>Effects</b>: Returns true if x and y are unequal
1352 //! <b>Complexity</b>: Linear to the number of elements in the container.
1353 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1354 friend bool operator!=(const list& x, const list& y)
1355 { return !(x == y); }
1357 //! <b>Effects</b>: Returns true if x is less than y
1359 //! <b>Complexity</b>: Linear to the number of elements in the container.
1360 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1361 friend bool operator<(const list& x, const list& y)
1362 { return boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1364 //! <b>Effects</b>: Returns true if x is greater than y
1366 //! <b>Complexity</b>: Linear to the number of elements in the container.
1367 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1368 friend bool operator>(const list& x, const list& y)
1371 //! <b>Effects</b>: Returns true if x is equal or less than y
1373 //! <b>Complexity</b>: Linear to the number of elements in the container.
1374 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1375 friend bool operator<=(const list& x, const list& y)
1376 { return !(y < x); }
1378 //! <b>Effects</b>: Returns true if x is equal or greater than y
1380 //! <b>Complexity</b>: Linear to the number of elements in the container.
1381 BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
1382 friend bool operator>=(const list& x, const list& y)
1383 { return !(x < y); }
1385 //! <b>Effects</b>: x.swap(y)
1387 //! <b>Complexity</b>: Constant.
1388 BOOST_CONTAINER_FORCEINLINE friend void swap(list& x, list& y)
1389 BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
1392 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1395 static bool priv_is_linked(const_iterator const position)
1397 const_iterator cur(position);
1398 //This list is circular including end nodes
1399 return (--(++cur)) == position && (++(--cur)) == position;
1402 bool priv_try_shrink(size_type new_size)
1404 const size_type len = this->size();
1406 const const_iterator iend = this->cend();
1407 size_type to_erase = len - new_size;
1408 const_iterator ifirst;
1409 if(to_erase < len/2u){
1416 ifirst = this->cbegin();
1417 size_type to_skip = len - to_erase;
1422 this->erase(ifirst, iend);
1430 iterator priv_insert(const_iterator p, const T &x)
1432 BOOST_ASSERT((priv_is_linked)(p));
1433 NodePtr tmp = AllocHolder::create_node(x);
1434 return iterator(this->icont().insert(p.get(), *tmp));
1437 iterator priv_insert(const_iterator p, BOOST_RV_REF(T) x)
1439 BOOST_ASSERT((priv_is_linked)(p));
1440 NodePtr tmp = AllocHolder::create_node(boost::move(x));
1441 return iterator(this->icont().insert(p.get(), *tmp));
1445 void priv_push_back(BOOST_FWD_REF(U) x)
1446 { this->icont().push_back(*this->create_node(::boost::forward<U>(x))); }
1449 void priv_push_front(BOOST_FWD_REF(U) x)
1450 { this->icont().push_front(*this->create_node(::boost::forward<U>(x))); }
1452 class insertion_functor;
1453 friend class insertion_functor;
1455 class insertion_functor
1458 typedef typename Icont::const_iterator iconst_iterator;
1459 const iconst_iterator pos_;
1462 insertion_functor(Icont &icont, typename Icont::const_iterator pos)
1463 : icont_(icont), pos_(pos)
1466 void operator()(Node &n)
1468 this->icont_.insert(pos_, n);
1472 typedef value_less<value_type> value_less_t;
1473 typedef value_equal<value_type> value_equal_t;
1474 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1478 #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
1479 template <typename InputIterator>
1480 list(InputIterator, InputIterator) ->
1481 list<typename iterator_traits<InputIterator>::value_type>;
1483 template <typename InputIterator, typename ValueAllocator>
1484 list(InputIterator, InputIterator, ValueAllocator const&) ->
1485 list<typename iterator_traits<InputIterator>::value_type, ValueAllocator>;
1488 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1490 } //namespace container {
1492 //!has_trivial_destructor_after_move<> == true_type
1493 //!specialization for optimizations
1494 template <class T, class Allocator>
1495 struct has_trivial_destructor_after_move<boost::container::list<T, Allocator> >
1497 typedef typename boost::container::list<T, Allocator>::allocator_type allocator_type;
1498 typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
1499 static const bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
1500 ::boost::has_trivial_destructor_after_move<pointer>::value;
1503 namespace container {
1505 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1509 #include <boost/container/detail/config_end.hpp>
1511 #endif // BOOST_CONTAINER_LIST_HPP