]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
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) | |
6 | // | |
7 | // See http://www.boost.org/libs/container for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | #ifndef BOOST_CONTAINER_LIST_HPP | |
11 | #define BOOST_CONTAINER_LIST_HPP | |
12 | ||
13 | #ifndef BOOST_CONFIG_HPP | |
14 | # include <boost/config.hpp> | |
15 | #endif | |
16 | ||
17 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
18 | # pragma once | |
19 | #endif | |
20 | ||
21 | #include <boost/container/detail/config_begin.hpp> | |
22 | #include <boost/container/detail/workaround.hpp> | |
23 | ||
24 | // container | |
25 | #include <boost/container/container_fwd.hpp> | |
26 | #include <boost/container/new_allocator.hpp> //new_allocator | |
27 | #include <boost/container/throw_exception.hpp> | |
28 | // container/detail | |
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> | |
11fdf7f2 | 36 | #include <boost/container/detail/value_functors.hpp> |
7c673cae FG |
37 | // move |
38 | #include <boost/move/utility_core.hpp> | |
39 | #include <boost/move/iterator.hpp> | |
40 | #include <boost/move/traits.hpp> | |
41 | // move/detail | |
42 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
43 | # include <boost/move/detail/fwd_macros.hpp> | |
44 | #endif | |
45 | #include <boost/move/detail/move_helpers.hpp> | |
1e59de90 | 46 | #include <boost/move/detail/force_ptr.hpp> |
7c673cae FG |
47 | |
48 | // intrusive | |
49 | #include <boost/intrusive/pointer_traits.hpp> | |
50 | #include <boost/intrusive/list.hpp> | |
51 | // other | |
52 | #include <boost/assert.hpp> | |
53 | // std | |
54 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
55 | #include <initializer_list> | |
56 | #endif | |
57 | ||
58 | namespace boost { | |
59 | namespace container { | |
60 | ||
61 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
11fdf7f2 | 62 | namespace dtl { |
7c673cae FG |
63 | |
64 | template<class VoidPointer> | |
65 | struct list_hook | |
66 | { | |
11fdf7f2 TL |
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; | |
7c673cae FG |
69 | }; |
70 | ||
71 | template <class T, class VoidPointer> | |
1e59de90 | 72 | struct iiterator_node_value_type< base_node<T, list_hook<VoidPointer> > > |
7c673cae | 73 | { |
7c673cae FG |
74 | typedef T type; |
75 | }; | |
76 | ||
77 | template<class Allocator> | |
78 | struct intrusive_list_type | |
79 | { | |
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 | |
85 | void_pointer; | |
1e59de90 | 86 | typedef base_node<value_type, list_hook<void_pointer> > node_type; |
11fdf7f2 | 87 | typedef typename dtl::bi::make_list |
7c673cae | 88 | < node_type |
11fdf7f2 TL |
89 | , dtl::bi::base_hook<typename list_hook<void_pointer>::type> |
90 | , dtl::bi::constant_time_size<true> | |
91 | , dtl::bi::size_type | |
7c673cae FG |
92 | <typename allocator_traits_type::size_type> |
93 | >::type container_type; | |
94 | typedef container_type type ; | |
95 | }; | |
96 | ||
11fdf7f2 | 97 | } //namespace dtl { |
7c673cae FG |
98 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED |
99 | ||
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. | |
110 | //! | |
111 | //! \tparam T The type of object that is stored in the list | |
92f5a8d4 TL |
112 | //! \tparam Allocator The allocator used for all internal memory management, use void |
113 | //! for the default allocator | |
7c673cae | 114 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED |
92f5a8d4 | 115 | template <class T, class Allocator = void > |
7c673cae FG |
116 | #else |
117 | template <class T, class Allocator> | |
118 | #endif | |
119 | class list | |
11fdf7f2 | 120 | : protected dtl::node_alloc_holder |
92f5a8d4 TL |
121 | < typename real_allocator<T, Allocator>::type |
122 | , typename dtl::intrusive_list_type<typename real_allocator<T, Allocator>::type>::type> | |
7c673cae FG |
123 | { |
124 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
92f5a8d4 | 125 | typedef typename real_allocator<T, Allocator>::type ValueAllocator; |
7c673cae | 126 | typedef typename |
92f5a8d4 TL |
127 | dtl::intrusive_list_type<ValueAllocator>::type Icont; |
128 | typedef dtl::node_alloc_holder<ValueAllocator, Icont> AllocHolder; | |
7c673cae FG |
129 | typedef typename AllocHolder::NodePtr NodePtr; |
130 | typedef typename AllocHolder::NodeAlloc NodeAlloc; | |
131 | typedef typename AllocHolder::ValAlloc ValAlloc; | |
132 | typedef typename AllocHolder::Node Node; | |
1e59de90 | 133 | typedef dtl::allocator_node_destroyer<NodeAlloc> Destroyer; |
7c673cae | 134 | typedef typename AllocHolder::alloc_version alloc_version; |
92f5a8d4 TL |
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; | |
7c673cae FG |
138 | |
139 | BOOST_COPYABLE_AND_MOVABLE(list) | |
140 | ||
11fdf7f2 TL |
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; | |
7c673cae FG |
143 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED |
144 | ||
145 | public: | |
146 | ////////////////////////////////////////////// | |
147 | // | |
148 | // types | |
149 | // | |
150 | ////////////////////////////////////////////// | |
151 | ||
92f5a8d4 TL |
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; | |
7c673cae FG |
165 | |
166 | ////////////////////////////////////////////// | |
167 | // | |
168 | // construct/copy/destroy | |
169 | // | |
170 | ////////////////////////////////////////////// | |
171 | ||
172 | //! <b>Effects</b>: Default constructs a list. | |
173 | //! | |
174 | //! <b>Throws</b>: If allocator_type's default constructor throws. | |
175 | //! | |
176 | //! <b>Complexity</b>: Constant. | |
92f5a8d4 | 177 | list() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<ValueAllocator>::value) |
7c673cae FG |
178 | : AllocHolder() |
179 | {} | |
180 | ||
181 | //! <b>Effects</b>: Constructs a list taking the allocator as parameter. | |
182 | //! | |
183 | //! <b>Throws</b>: Nothing | |
184 | //! | |
185 | //! <b>Complexity</b>: Constant. | |
186 | explicit list(const allocator_type &a) BOOST_NOEXCEPT_OR_NOTHROW | |
187 | : AllocHolder(a) | |
188 | {} | |
189 | ||
190 | //! <b>Effects</b>: Constructs a list | |
191 | //! and inserts n value-initialized value_types. | |
192 | //! | |
193 | //! <b>Throws</b>: If allocator_type's default constructor | |
194 | //! throws or T's default or copy constructor throws. | |
195 | //! | |
196 | //! <b>Complexity</b>: Linear to n. | |
197 | explicit list(size_type n) | |
92f5a8d4 | 198 | : AllocHolder(ValueAllocator()) |
7c673cae FG |
199 | { this->resize(n); } |
200 | ||
201 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
202 | //! and inserts n copies of value. | |
203 | //! | |
204 | //! <b>Throws</b>: If allocator_type's default constructor | |
205 | //! throws or T's default or copy constructor throws. | |
206 | //! | |
207 | //! <b>Complexity</b>: Linear to n. | |
208 | list(size_type n, const allocator_type &a) | |
209 | : AllocHolder(a) | |
210 | { this->resize(n); } | |
211 | ||
212 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
213 | //! and inserts n copies of value. | |
214 | //! | |
215 | //! <b>Throws</b>: If allocator_type's default constructor | |
216 | //! throws or T's default or copy constructor throws. | |
217 | //! | |
218 | //! <b>Complexity</b>: Linear to n. | |
92f5a8d4 | 219 | list(size_type n, const T& value, const ValueAllocator& a = ValueAllocator()) |
7c673cae FG |
220 | : AllocHolder(a) |
221 | { this->insert(this->cbegin(), n, value); } | |
222 | ||
223 | //! <b>Effects</b>: Copy constructs a list. | |
224 | //! | |
225 | //! <b>Postcondition</b>: x == *this. | |
226 | //! | |
227 | //! <b>Throws</b>: If allocator_type's default constructor throws. | |
228 | //! | |
229 | //! <b>Complexity</b>: Linear to the elements x contains. | |
230 | list(const list& x) | |
231 | : AllocHolder(x) | |
232 | { this->insert(this->cbegin(), x.begin(), x.end()); } | |
233 | ||
234 | //! <b>Effects</b>: Move constructor. Moves x's resources to *this. | |
235 | //! | |
236 | //! <b>Throws</b>: If allocator_type's copy constructor throws. | |
237 | //! | |
238 | //! <b>Complexity</b>: Constant. | |
239 | list(BOOST_RV_REF(list) x) BOOST_NOEXCEPT_OR_NOTHROW | |
240 | : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x)) | |
241 | {} | |
242 | ||
243 | //! <b>Effects</b>: Copy constructs a list using the specified allocator. | |
244 | //! | |
245 | //! <b>Postcondition</b>: x == *this. | |
246 | //! | |
247 | //! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws. | |
248 | //! | |
249 | //! <b>Complexity</b>: Linear to the elements x contains. | |
250 | list(const list& x, const allocator_type &a) | |
251 | : AllocHolder(a) | |
252 | { this->insert(this->cbegin(), x.begin(), x.end()); } | |
253 | ||
254 | //! <b>Effects</b>: Move constructor sing the specified allocator. | |
255 | //! Moves x's resources to *this. | |
256 | //! | |
257 | //! <b>Throws</b>: If allocation or value_type's copy constructor throws. | |
258 | //! | |
259 | //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise. | |
260 | list(BOOST_RV_REF(list) x, const allocator_type &a) | |
261 | : AllocHolder(a) | |
262 | { | |
263 | if(this->node_alloc() == x.node_alloc()){ | |
264 | this->icont().swap(x.icont()); | |
265 | } | |
266 | else{ | |
267 | this->insert(this->cbegin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); | |
268 | } | |
269 | } | |
270 | ||
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. | |
273 | //! | |
274 | //! <b>Throws</b>: If allocator_type's default constructor | |
275 | //! throws or T's constructor taking a dereferenced InIt throws. | |
276 | //! | |
277 | //! <b>Complexity</b>: Linear to the range [first, last). | |
278 | template <class InpIt> | |
92f5a8d4 | 279 | list(InpIt first, InpIt last, const ValueAllocator &a = ValueAllocator()) |
7c673cae FG |
280 | : AllocHolder(a) |
281 | { this->insert(this->cbegin(), first, last); } | |
282 | ||
283 | ||
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. | |
287 | //! | |
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. | |
291 | //! | |
292 | //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()). | |
92f5a8d4 | 293 | list(std::initializer_list<value_type> il, const ValueAllocator &a = ValueAllocator()) |
7c673cae FG |
294 | : AllocHolder(a) |
295 | { this->insert(this->cbegin(), il.begin(), il.end()); } | |
296 | #endif | |
297 | ||
298 | //! <b>Effects</b>: Destroys the list. All stored values are destroyed | |
299 | //! and used memory is deallocated. | |
300 | //! | |
301 | //! <b>Throws</b>: Nothing. | |
302 | //! | |
303 | //! <b>Complexity</b>: Linear to the number of elements. | |
20effc67 | 304 | BOOST_CONTAINER_FORCEINLINE ~list() BOOST_NOEXCEPT_OR_NOTHROW |
7c673cae FG |
305 | {} //AllocHolder clears the list |
306 | ||
307 | //! <b>Effects</b>: Makes *this contain the same elements as x. | |
308 | //! | |
309 | //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy | |
310 | //! of each of x's elements. | |
311 | //! | |
312 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
313 | //! | |
314 | //! <b>Complexity</b>: Linear to the number of elements in x. | |
315 | list& operator=(BOOST_COPY_ASSIGN_REF(list) x) | |
316 | { | |
92f5a8d4 | 317 | if (BOOST_LIKELY(this != &x)) { |
7c673cae FG |
318 | NodeAlloc &this_alloc = this->node_alloc(); |
319 | const NodeAlloc &x_alloc = x.node_alloc(); | |
11fdf7f2 | 320 | dtl::bool_<allocator_traits_type:: |
7c673cae FG |
321 | propagate_on_container_copy_assignment::value> flag; |
322 | if(flag && this_alloc != x_alloc){ | |
323 | this->clear(); | |
324 | } | |
325 | this->AllocHolder::copy_assign_alloc(x); | |
326 | this->assign(x.begin(), x.end()); | |
327 | } | |
328 | return *this; | |
329 | } | |
330 | ||
331 | //! <b>Effects</b>: Move assignment. All x's values are transferred to *this. | |
332 | //! | |
333 | //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had | |
334 | //! before the function. | |
335 | //! | |
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) | |
338 | //! | |
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) | |
345 | { | |
92f5a8d4 TL |
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){ | |
355 | //Destroy | |
356 | this->clear(); | |
357 | //Move allocator if needed | |
358 | this->AllocHolder::move_assign_alloc(x); | |
359 | //Obtain resources | |
360 | this->icont() = boost::move(x.icont()); | |
361 | } | |
362 | //Else do a one by one move | |
363 | else{ | |
364 | this->assign( boost::make_move_iterator(x.begin()) | |
365 | , boost::make_move_iterator(x.end())); | |
366 | } | |
7c673cae FG |
367 | } |
368 | return *this; | |
369 | } | |
370 | ||
371 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
372 | //! <b>Effects</b>: Makes *this contain the same elements as il. | |
373 | //! | |
374 | //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy | |
375 | //! of each of x's elements. | |
376 | //! | |
377 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
378 | //! | |
379 | //! <b>Complexity</b>: Linear to the number of elements in x. | |
20effc67 | 380 | BOOST_CONTAINER_FORCEINLINE list& operator=(std::initializer_list<value_type> il) |
7c673cae | 381 | { |
20effc67 | 382 | this->assign(il.begin(), il.end()); |
7c673cae FG |
383 | return *this; |
384 | } | |
385 | #endif | |
386 | ||
387 | //! <b>Effects</b>: Assigns the n copies of val to *this. | |
388 | //! | |
389 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
390 | //! | |
391 | //! <b>Complexity</b>: Linear to n. | |
20effc67 | 392 | BOOST_CONTAINER_FORCEINLINE void assign(size_type n, const T& val) |
7c673cae | 393 | { |
1e59de90 | 394 | typedef constant_iterator<value_type> cvalue_iterator; |
7c673cae FG |
395 | return this->assign(cvalue_iterator(val, n), cvalue_iterator()); |
396 | } | |
397 | ||
398 | //! <b>Effects</b>: Assigns the range [first, last) to *this. | |
399 | //! | |
400 | //! <b>Throws</b>: If memory allocation throws or | |
401 | //! T's constructor from dereferencing InpIt throws. | |
402 | //! | |
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) | |
11fdf7f2 | 407 | , typename dtl::disable_if_convertible<InpIt, size_type>::type * = 0 |
7c673cae FG |
408 | #endif |
409 | ) | |
410 | { | |
411 | iterator first1 = this->begin(); | |
412 | const iterator last1 = this->end(); | |
413 | for ( ; first1 != last1 && first != last; ++first1, ++first) | |
414 | *first1 = *first; | |
415 | if (first == last) | |
416 | this->erase(first1, last1); | |
417 | else{ | |
418 | this->insert(last1, first, last); | |
419 | } | |
420 | } | |
421 | ||
422 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
423 | //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this. | |
424 | //! | |
425 | //! <b>Throws</b>: If memory allocation throws or | |
426 | //! T's constructor from dereferencing std::initializer_list iterator throws. | |
427 | //! | |
428 | //! <b>Complexity</b>: Linear to n. | |
20effc67 TL |
429 | BOOST_CONTAINER_FORCEINLINE void assign(std::initializer_list<value_type> il) |
430 | { this->assign(il.begin(), il.end()); } | |
7c673cae FG |
431 | #endif |
432 | ||
433 | //! <b>Effects</b>: Returns a copy of the internal allocator. | |
434 | //! | |
435 | //! <b>Throws</b>: If allocator's copy constructor throws. | |
436 | //! | |
437 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
438 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
439 | allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
440 | { return allocator_type(this->node_alloc()); } |
441 | ||
442 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
443 | //! | |
444 | //! <b>Throws</b>: Nothing | |
445 | //! | |
446 | //! <b>Complexity</b>: Constant. | |
447 | //! | |
448 | //! <b>Note</b>: Non-standard extension. | |
1e59de90 TL |
449 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
450 | stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
451 | { return this->node_alloc(); } |
452 | ||
453 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
454 | //! | |
455 | //! <b>Throws</b>: Nothing | |
456 | //! | |
457 | //! <b>Complexity</b>: Constant. | |
458 | //! | |
459 | //! <b>Note</b>: Non-standard extension. | |
1e59de90 TL |
460 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
461 | const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
462 | { return this->node_alloc(); } |
463 | ||
464 | ////////////////////////////////////////////// | |
465 | // | |
466 | // iterators | |
467 | // | |
468 | ////////////////////////////////////////////// | |
469 | ||
470 | //! <b>Effects</b>: Returns an iterator to the first element contained in the list. | |
471 | //! | |
472 | //! <b>Throws</b>: Nothing. | |
473 | //! | |
474 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
475 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
476 | iterator begin() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
477 | { return iterator(this->icont().begin()); } |
478 | ||
479 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. | |
480 | //! | |
481 | //! <b>Throws</b>: Nothing. | |
482 | //! | |
483 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
484 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
485 | const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
486 | { return this->cbegin(); } |
487 | ||
488 | //! <b>Effects</b>: Returns an iterator to the end of the list. | |
489 | //! | |
490 | //! <b>Throws</b>: Nothing. | |
491 | //! | |
492 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
493 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
494 | iterator end() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
495 | { return iterator(this->icont().end()); } |
496 | ||
497 | //! <b>Effects</b>: Returns a const_iterator to the end of the list. | |
498 | //! | |
499 | //! <b>Throws</b>: Nothing. | |
500 | //! | |
501 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
502 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
503 | const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
504 | { return this->cend(); } |
505 | ||
506 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning | |
507 | //! of the reversed list. | |
508 | //! | |
509 | //! <b>Throws</b>: Nothing. | |
510 | //! | |
511 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
512 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
513 | reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
514 | { return reverse_iterator(end()); } |
515 | ||
516 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning | |
517 | //! of the reversed list. | |
518 | //! | |
519 | //! <b>Throws</b>: Nothing. | |
520 | //! | |
521 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
522 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
523 | const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
524 | { return this->crbegin(); } |
525 | ||
526 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the end | |
527 | //! of the reversed list. | |
528 | //! | |
529 | //! <b>Throws</b>: Nothing. | |
530 | //! | |
531 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
532 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
533 | reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
534 | { return reverse_iterator(begin()); } |
535 | ||
536 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end | |
537 | //! of the reversed list. | |
538 | //! | |
539 | //! <b>Throws</b>: Nothing. | |
540 | //! | |
541 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
542 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
543 | const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
544 | { return this->crend(); } |
545 | ||
546 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. | |
547 | //! | |
548 | //! <b>Throws</b>: Nothing. | |
549 | //! | |
550 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
551 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
552 | const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
553 | { return const_iterator(this->non_const_icont().begin()); } |
554 | ||
555 | //! <b>Effects</b>: Returns a const_iterator to the end of the list. | |
556 | //! | |
557 | //! <b>Throws</b>: Nothing. | |
558 | //! | |
559 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
560 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
561 | const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
562 | { return const_iterator(this->non_const_icont().end()); } |
563 | ||
564 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning | |
565 | //! of the reversed list. | |
566 | //! | |
567 | //! <b>Throws</b>: Nothing. | |
568 | //! | |
569 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
570 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
571 | const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
572 | { return const_reverse_iterator(this->cend()); } |
573 | ||
574 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end | |
575 | //! of the reversed list. | |
576 | //! | |
577 | //! <b>Throws</b>: Nothing. | |
578 | //! | |
579 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
580 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
581 | const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
582 | { return const_reverse_iterator(this->cbegin()); } |
583 | ||
584 | ////////////////////////////////////////////// | |
585 | // | |
586 | // capacity | |
587 | // | |
588 | ////////////////////////////////////////////// | |
589 | ||
590 | //! <b>Effects</b>: Returns true if the list contains no elements. | |
591 | //! | |
592 | //! <b>Throws</b>: Nothing. | |
593 | //! | |
594 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
595 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
596 | bool empty() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
597 | { return !this->size(); } |
598 | ||
599 | //! <b>Effects</b>: Returns the number of the elements contained in the list. | |
600 | //! | |
601 | //! <b>Throws</b>: Nothing. | |
602 | //! | |
603 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
604 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
605 | size_type size() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
606 | { return this->icont().size(); } |
607 | ||
608 | //! <b>Effects</b>: Returns the largest possible size of the list. | |
609 | //! | |
610 | //! <b>Throws</b>: Nothing. | |
611 | //! | |
612 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
613 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
614 | size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
615 | { return AllocHolder::max_size(); } |
616 | ||
617 | //! <b>Effects</b>: Inserts or erases elements at the end such that | |
618 | //! the size becomes n. New elements are value initialized. | |
619 | //! | |
620 | //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws. | |
621 | //! | |
622 | //! <b>Complexity</b>: Linear to the difference between size() and new_size. | |
623 | void resize(size_type new_size) | |
624 | { | |
625 | if(!priv_try_shrink(new_size)){ | |
1e59de90 | 626 | typedef value_init_construct_iterator<value_type> value_init_iterator; |
7c673cae FG |
627 | this->insert(this->cend(), value_init_iterator(new_size - this->size()), value_init_iterator()); |
628 | } | |
629 | } | |
630 | ||
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. | |
633 | //! | |
634 | //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws. | |
635 | //! | |
636 | //! <b>Complexity</b>: Linear to the difference between size() and new_size. | |
637 | void resize(size_type new_size, const T& x) | |
638 | { | |
639 | if(!priv_try_shrink(new_size)){ | |
640 | this->insert(this->cend(), new_size - this->size(), x); | |
641 | } | |
642 | } | |
643 | ||
644 | ////////////////////////////////////////////// | |
645 | // | |
646 | // element access | |
647 | // | |
648 | ////////////////////////////////////////////// | |
649 | ||
650 | //! <b>Requires</b>: !empty() | |
651 | //! | |
652 | //! <b>Effects</b>: Returns a reference to the first element | |
653 | //! from the beginning of the container. | |
654 | //! | |
655 | //! <b>Throws</b>: Nothing. | |
656 | //! | |
657 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
658 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
659 | reference front() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
660 | { |
661 | BOOST_ASSERT(!this->empty()); | |
662 | return *this->begin(); | |
663 | } | |
664 | ||
665 | //! <b>Requires</b>: !empty() | |
666 | //! | |
667 | //! <b>Effects</b>: Returns a const reference to the first element | |
668 | //! from the beginning of the container. | |
669 | //! | |
670 | //! <b>Throws</b>: Nothing. | |
671 | //! | |
672 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
673 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
674 | const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
675 | { |
676 | BOOST_ASSERT(!this->empty()); | |
677 | return *this->begin(); | |
678 | } | |
679 | ||
680 | //! <b>Requires</b>: !empty() | |
681 | //! | |
682 | //! <b>Effects</b>: Returns a reference to the first element | |
683 | //! from the beginning of the container. | |
684 | //! | |
685 | //! <b>Throws</b>: Nothing. | |
686 | //! | |
687 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
688 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
689 | reference back() BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
690 | { |
691 | BOOST_ASSERT(!this->empty()); | |
692 | return *(--this->end()); | |
693 | } | |
694 | ||
695 | //! <b>Requires</b>: !empty() | |
696 | //! | |
697 | //! <b>Effects</b>: Returns a const reference to the first element | |
698 | //! from the beginning of the container. | |
699 | //! | |
700 | //! <b>Throws</b>: Nothing. | |
701 | //! | |
702 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
703 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
704 | const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW | |
7c673cae FG |
705 | { |
706 | BOOST_ASSERT(!this->empty()); | |
707 | return *(--this->end()); | |
708 | } | |
709 | ||
710 | ////////////////////////////////////////////// | |
711 | // | |
712 | // modifiers | |
713 | // | |
714 | ////////////////////////////////////////////// | |
715 | ||
716 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
717 | ||
718 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
719 | //! std::forward<Args>(args)... in the end of the list. | |
720 | //! | |
721 | //! <b>Returns</b>: A reference to the created object. | |
722 | //! | |
723 | //! <b>Throws</b>: If memory allocation throws or | |
724 | //! T's in-place constructor throws. | |
725 | //! | |
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)...); } | |
730 | ||
731 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
732 | //! std::forward<Args>(args)... in the beginning of the list. | |
733 | //! | |
734 | //! <b>Returns</b>: A reference to the created object. | |
735 | //! | |
736 | //! <b>Throws</b>: If memory allocation throws or | |
737 | //! T's in-place constructor throws. | |
738 | //! | |
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)...); } | |
743 | ||
744 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
745 | //! std::forward<Args>(args)... before p. | |
746 | //! | |
747 | //! <b>Throws</b>: If memory allocation throws or | |
748 | //! T's in-place constructor throws. | |
749 | //! | |
750 | //! <b>Complexity</b>: Constant | |
751 | template <class... Args> | |
752 | iterator emplace(const_iterator position, BOOST_FWD_REF(Args)... args) | |
753 | { | |
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)); | |
757 | } | |
758 | ||
759 | #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
760 | ||
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); }\ | |
765 | \ | |
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);}\ | |
769 | \ | |
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)\ | |
772 | {\ | |
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));\ | |
776 | }\ | |
777 | // | |
778 | BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_LIST_EMPLACE_CODE) | |
779 | #undef BOOST_CONTAINER_LIST_EMPLACE_CODE | |
780 | ||
781 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
782 | ||
783 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
784 | //! <b>Effects</b>: Inserts a copy of x at the beginning of the list. | |
785 | //! | |
786 | //! <b>Throws</b>: If memory allocation throws or | |
787 | //! T's copy constructor throws. | |
788 | //! | |
789 | //! <b>Complexity</b>: Amortized constant time. | |
790 | void push_front(const T &x); | |
791 | ||
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. | |
794 | //! | |
795 | //! <b>Throws</b>: If memory allocation throws. | |
796 | //! | |
797 | //! <b>Complexity</b>: Amortized constant time. | |
798 | void push_front(T &&x); | |
799 | #else | |
800 | BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front) | |
801 | #endif | |
802 | ||
803 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
804 | //! <b>Effects</b>: Inserts a copy of x at the end of the list. | |
805 | //! | |
806 | //! <b>Throws</b>: If memory allocation throws or | |
807 | //! T's copy constructor throws. | |
808 | //! | |
809 | //! <b>Complexity</b>: Amortized constant time. | |
810 | void push_back(const T &x); | |
811 | ||
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. | |
814 | //! | |
815 | //! <b>Throws</b>: If memory allocation throws. | |
816 | //! | |
817 | //! <b>Complexity</b>: Amortized constant time. | |
818 | void push_back(T &&x); | |
819 | #else | |
820 | BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back) | |
821 | #endif | |
822 | ||
823 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
824 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
825 | //! | |
826 | //! <b>Effects</b>: Insert a copy of x before p. | |
827 | //! | |
828 | //! <b>Returns</b>: an iterator to the inserted element. | |
829 | //! | |
830 | //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws. | |
831 | //! | |
832 | //! <b>Complexity</b>: Amortized constant time. | |
833 | iterator insert(const_iterator p, const T &x); | |
834 | ||
835 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
836 | //! | |
837 | //! <b>Effects</b>: Insert a new element before p with x's resources. | |
838 | //! | |
839 | //! <b>Returns</b>: an iterator to the inserted element. | |
840 | //! | |
841 | //! <b>Throws</b>: If memory allocation throws. | |
842 | //! | |
843 | //! <b>Complexity</b>: Amortized constant time. | |
844 | iterator insert(const_iterator p, T &&x); | |
845 | #else | |
846 | BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator) | |
847 | #endif | |
848 | ||
849 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
850 | //! | |
851 | //! <b>Effects</b>: Inserts n copies of x before p. | |
852 | //! | |
853 | //! <b>Returns</b>: an iterator to the first inserted element or p if n is 0. | |
854 | //! | |
855 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
856 | //! | |
857 | //! <b>Complexity</b>: Linear to n. | |
858 | iterator insert(const_iterator position, size_type n, const T& x) | |
859 | { | |
860 | //range check is done by insert | |
1e59de90 | 861 | typedef constant_iterator<value_type> cvalue_iterator; |
7c673cae FG |
862 | return this->insert(position, cvalue_iterator(x, n), cvalue_iterator()); |
863 | } | |
864 | ||
865 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
866 | //! | |
867 | //! <b>Effects</b>: Insert a copy of the [first, last) range before p. | |
868 | //! | |
869 | //! <b>Returns</b>: an iterator to the first inserted element or p if first == last. | |
870 | //! | |
871 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
872 | //! dereferenced InpIt throws. | |
873 | //! | |
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) | |
11fdf7f2 TL |
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 | |
7c673cae FG |
882 | ) |
883 | >::type * = 0 | |
884 | #endif | |
885 | ) | |
886 | { | |
887 | BOOST_ASSERT((priv_is_linked)(p)); | |
888 | const typename Icont::iterator ipos(p.get()); | |
889 | iterator ret_it(ipos); | |
890 | if(first != last){ | |
891 | ret_it = iterator(this->icont().insert(ipos, *this->create_node_from_it(first))); | |
892 | ++first; | |
893 | } | |
894 | for (; first != last; ++first){ | |
895 | this->icont().insert(ipos, *this->create_node_from_it(first)); | |
896 | } | |
897 | return ret_it; | |
898 | } | |
899 | ||
900 | #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
901 | template <class FwdIt> | |
902 | iterator insert(const_iterator position, FwdIt first, FwdIt last | |
11fdf7f2 TL |
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 | |
7c673cae FG |
907 | ) |
908 | >::type * = 0 | |
909 | ) | |
910 | { | |
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()); | |
915 | --before_p; | |
1e59de90 | 916 | this->allocate_many_and_construct(first, boost::container::iterator_udistance(first, last), func); |
7c673cae FG |
917 | return ++before_p; |
918 | } | |
919 | #endif | |
920 | ||
921 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
922 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
923 | //! | |
924 | //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p. | |
925 | //! | |
926 | //! <b>Returns</b>: an iterator to the first inserted element or p if if.begin() == il.end(). | |
927 | //! | |
928 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
929 | //! dereferenced std::initializer_list iterator throws. | |
930 | //! | |
931 | //! <b>Complexity</b>: Linear to distance [il.begin(), il.end()). | |
932 | iterator insert(const_iterator p, std::initializer_list<value_type> il) | |
933 | { | |
934 | //position range check is done by insert() | |
935 | return insert(p, il.begin(), il.end()); | |
936 | } | |
937 | #endif | |
938 | ||
939 | //! <b>Effects</b>: Removes the first element from the list. | |
940 | //! | |
941 | //! <b>Throws</b>: Nothing. | |
942 | //! | |
943 | //! <b>Complexity</b>: Amortized constant time. | |
944 | void pop_front() BOOST_NOEXCEPT_OR_NOTHROW | |
945 | { | |
946 | BOOST_ASSERT(!this->empty()); | |
947 | this->erase(this->cbegin()); | |
948 | } | |
949 | ||
950 | //! <b>Effects</b>: Removes the last element from the list. | |
951 | //! | |
952 | //! <b>Throws</b>: Nothing. | |
953 | //! | |
954 | //! <b>Complexity</b>: Amortized constant time. | |
955 | void pop_back() BOOST_NOEXCEPT_OR_NOTHROW | |
956 | { | |
957 | BOOST_ASSERT(!this->empty()); | |
958 | const_iterator tmp = this->cend(); | |
959 | this->erase(--tmp); | |
960 | } | |
961 | ||
962 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
963 | //! | |
964 | //! <b>Effects</b>: Erases the element at p. | |
965 | //! | |
966 | //! <b>Throws</b>: Nothing. | |
967 | //! | |
968 | //! <b>Complexity</b>: Amortized constant time. | |
969 | iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW | |
970 | { | |
971 | BOOST_ASSERT(p != this->cend() && (priv_is_linked)(p)); | |
972 | return iterator(this->icont().erase_and_dispose(p.get(), Destroyer(this->node_alloc()))); | |
973 | } | |
974 | ||
975 | //! <b>Requires</b>: first and last must be valid iterator to elements in *this. | |
976 | //! | |
977 | //! <b>Effects</b>: Erases the elements pointed by [first, last). | |
978 | //! | |
979 | //! <b>Throws</b>: Nothing. | |
980 | //! | |
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 | |
983 | { | |
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())); | |
987 | } | |
988 | ||
989 | //! <b>Effects</b>: Swaps the contents of *this and x. | |
990 | //! | |
991 | //! <b>Throws</b>: Nothing. | |
992 | //! | |
993 | //! <b>Complexity</b>: Constant. | |
994 | void swap(list& x) | |
995 | BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value | |
996 | || allocator_traits_type::is_always_equal::value) | |
997 | { | |
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); | |
1002 | } | |
1003 | ||
1004 | //! <b>Effects</b>: Erases all the elements of the list. | |
1005 | //! | |
1006 | //! <b>Throws</b>: Nothing. | |
1007 | //! | |
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()); } | |
1011 | ||
1012 | ////////////////////////////////////////////// | |
1013 | // | |
1014 | // slist operations | |
1015 | // | |
1016 | ////////////////////////////////////////////// | |
1017 | ||
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 | |
1020 | //! | |
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. | |
1023 | //! | |
1024 | //! <b>Throws</b>: Nothing | |
1025 | //! | |
1026 | //! <b>Complexity</b>: Constant. | |
1027 | //! | |
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 | |
1031 | { | |
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()); | |
1036 | } | |
1037 | ||
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 | |
1040 | //! | |
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. | |
1043 | //! | |
1044 | //! <b>Throws</b>: Nothing | |
1045 | //! | |
1046 | //! <b>Complexity</b>: Constant. | |
1047 | //! | |
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 | |
1051 | { | |
1052 | //Checks done in splice | |
1053 | this->splice(p, static_cast<list&>(x)); | |
1054 | } | |
1055 | ||
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 | |
1059 | //! | |
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. | |
1063 | //! | |
1064 | //! <b>Throws</b>: Nothing | |
1065 | //! | |
1066 | //! <b>Complexity</b>: Constant. | |
1067 | //! | |
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 | |
1071 | { | |
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()); | |
1075 | } | |
1076 | ||
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. | |
1080 | //! | |
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. | |
1084 | //! | |
1085 | //! <b>Throws</b>: Nothing | |
1086 | //! | |
1087 | //! <b>Complexity</b>: Constant. | |
1088 | //! | |
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 | |
1092 | { | |
1093 | BOOST_ASSERT(this != &x); | |
1094 | //Additional checks done in splice() | |
1095 | this->splice(p, static_cast<list&>(x), i); | |
1096 | } | |
1097 | ||
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 | |
1101 | //! | |
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. | |
1104 | //! | |
1105 | //! <b>Throws</b>: Nothing | |
1106 | //! | |
1107 | //! <b>Complexity</b>: Linear to the number of elements transferred. | |
1108 | //! | |
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 | |
1112 | { | |
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()); | |
1118 | } | |
1119 | ||
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. | |
1123 | //! | |
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. | |
1126 | //! | |
1127 | //! <b>Throws</b>: Nothing | |
1128 | //! | |
1129 | //! <b>Complexity</b>: Linear to the number of elements transferred. | |
1130 | //! | |
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 | |
1134 | { | |
1135 | BOOST_ASSERT(this != &x); | |
1136 | //Additional checks done in splice() | |
1137 | this->splice(p, static_cast<list&>(x), first, last); | |
1138 | } | |
1139 | ||
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 | |
1143 | //! | |
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. | |
1146 | //! | |
1147 | //! <b>Throws</b>: Nothing | |
1148 | //! | |
1149 | //! <b>Complexity</b>: Constant. | |
1150 | //! | |
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. | |
1153 | //! | |
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 | |
1156 | { | |
1157 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
1158 | this->icont().splice(p.get(), x.icont(), first.get(), last.get(), n); | |
1159 | } | |
1160 | ||
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 | |
1164 | //! | |
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. | |
1167 | //! | |
1168 | //! <b>Throws</b>: Nothing | |
1169 | //! | |
1170 | //! <b>Complexity</b>: Constant. | |
1171 | //! | |
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. | |
1174 | //! | |
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); } | |
1178 | ||
1179 | //! <b>Effects</b>: Removes all the elements that compare equal to value. | |
1180 | //! | |
1181 | //! <b>Throws</b>: If comparison throws. | |
1182 | //! | |
1183 | //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality. | |
1184 | //! | |
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)); } | |
1189 | ||
1190 | //! <b>Effects</b>: Removes all the elements for which a specified | |
1191 | //! predicate is satisfied. | |
1192 | //! | |
1193 | //! <b>Throws</b>: If pred throws. | |
1194 | //! | |
1195 | //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate. | |
1196 | //! | |
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) | |
1201 | { | |
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())); | |
1204 | } | |
1205 | ||
1206 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent | |
1207 | //! elements that are equal from the list. | |
1208 | //! | |
1209 | //! <b>Throws</b>: If comparison throws. | |
1210 | //! | |
1211 | //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons). | |
1212 | //! | |
1213 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, | |
1214 | //! and iterators to elements that are not removed remain valid. | |
1215 | void unique() | |
11fdf7f2 | 1216 | { this->unique(value_equal_t()); } |
7c673cae FG |
1217 | |
1218 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent | |
1219 | //! elements that satisfy some binary predicate from the list. | |
1220 | //! | |
1221 | //! <b>Throws</b>: If pred throws. | |
1222 | //! | |
1223 | //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()). | |
1224 | //! | |
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) | |
1229 | { | |
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())); | |
1232 | } | |
1233 | ||
1234 | //! <b>Requires</b>: The lists x and *this must be distinct. | |
1235 | //! | |
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. | |
1240 | //! | |
1241 | //! <b>Throws</b>: If comparison throws. | |
1242 | //! | |
1243 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1244 | //! size() + x.size() - 1 comparisons. | |
1245 | void merge(list &x) | |
11fdf7f2 | 1246 | { this->merge(x, value_less_t()); } |
7c673cae FG |
1247 | |
1248 | //! <b>Requires</b>: The lists x and *this must be distinct. | |
1249 | //! | |
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. | |
1254 | //! | |
1255 | //! <b>Throws</b>: If comparison throws. | |
1256 | //! | |
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)); } | |
1261 | ||
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. | |
1265 | //! | |
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. | |
1269 | //! | |
1270 | //! <b>Throws</b>: If comp throws. | |
1271 | //! | |
1272 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1273 | //! size() + x.size() - 1 comparisons. | |
1274 | //! | |
1275 | //! <b>Note</b>: Iterators and references to *this are not invalidated. | |
1276 | template <class StrictWeakOrdering> | |
1277 | void merge(list &x, const StrictWeakOrdering &comp) | |
1278 | { | |
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)); | |
1282 | } | |
1283 | ||
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. | |
1287 | //! | |
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. | |
1291 | //! | |
1292 | //! <b>Throws</b>: If comp throws. | |
1293 | //! | |
1294 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1295 | //! size() + x.size() - 1 comparisons. | |
1296 | //! | |
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); } | |
1301 | ||
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. | |
1304 | //! | |
1305 | //! <b>Throws</b>: If comparison throws. | |
1306 | //! | |
1307 | //! <b>Notes</b>: Iterators and references are not invalidated. | |
1308 | //! | |
1309 | //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N | |
1310 | //! is the list's size. | |
1311 | void sort() | |
11fdf7f2 | 1312 | { this->sort(value_less_t()); } |
7c673cae FG |
1313 | |
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. | |
1316 | //! | |
1317 | //! <b>Throws</b>: If comp throws. | |
1318 | //! | |
1319 | //! <b>Notes</b>: Iterators and references are not invalidated. | |
1320 | //! | |
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) | |
1325 | { | |
1326 | // nothing if the list has length 0 or 1. | |
1327 | if (this->size() < 2) | |
1328 | return; | |
1329 | typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type; | |
1330 | this->icont().sort(value_to_node_compare_type(comp)); | |
1331 | } | |
1332 | ||
1333 | //! <b>Effects</b>: Reverses the order of elements in the list. | |
1334 | //! | |
1335 | //! <b>Throws</b>: Nothing. | |
1336 | //! | |
1337 | //! <b>Complexity</b>: This function is linear time. | |
1338 | //! | |
1339 | //! <b>Note</b>: Iterators and references are not invalidated | |
1340 | void reverse() BOOST_NOEXCEPT_OR_NOTHROW | |
1341 | { this->icont().reverse(); } | |
1342 | ||
1343 | //! <b>Effects</b>: Returns true if x and y are equal | |
1344 | //! | |
1345 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1346 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1347 | friend bool operator==(const list& x, const list& y) | |
7c673cae FG |
1348 | { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } |
1349 | ||
1350 | //! <b>Effects</b>: Returns true if x and y are unequal | |
1351 | //! | |
1352 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1353 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1354 | friend bool operator!=(const list& x, const list& y) | |
7c673cae FG |
1355 | { return !(x == y); } |
1356 | ||
1357 | //! <b>Effects</b>: Returns true if x is less than y | |
1358 | //! | |
1359 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1360 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1361 | friend bool operator<(const list& x, const list& y) | |
7c673cae FG |
1362 | { return boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } |
1363 | ||
1364 | //! <b>Effects</b>: Returns true if x is greater than y | |
1365 | //! | |
1366 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1367 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1368 | friend bool operator>(const list& x, const list& y) | |
7c673cae FG |
1369 | { return y < x; } |
1370 | ||
1371 | //! <b>Effects</b>: Returns true if x is equal or less than y | |
1372 | //! | |
1373 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1374 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1375 | friend bool operator<=(const list& x, const list& y) | |
7c673cae FG |
1376 | { return !(y < x); } |
1377 | ||
1378 | //! <b>Effects</b>: Returns true if x is equal or greater than y | |
1379 | //! | |
1380 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1e59de90 TL |
1381 | BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE |
1382 | friend bool operator>=(const list& x, const list& y) | |
7c673cae FG |
1383 | { return !(x < y); } |
1384 | ||
1385 | //! <b>Effects</b>: x.swap(y) | |
1386 | //! | |
1387 | //! <b>Complexity</b>: Constant. | |
1e59de90 TL |
1388 | BOOST_CONTAINER_FORCEINLINE friend void swap(list& x, list& y) |
1389 | BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y))) | |
7c673cae FG |
1390 | { x.swap(y); } |
1391 | ||
1392 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1393 | private: | |
1394 | ||
1395 | static bool priv_is_linked(const_iterator const position) | |
1396 | { | |
1397 | const_iterator cur(position); | |
1398 | //This list is circular including end nodes | |
1399 | return (--(++cur)) == position && (++(--cur)) == position; | |
1400 | } | |
1401 | ||
1402 | bool priv_try_shrink(size_type new_size) | |
1403 | { | |
1404 | const size_type len = this->size(); | |
1405 | if(len > new_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){ | |
1410 | ifirst = iend; | |
1411 | while(to_erase--){ | |
1412 | --ifirst; | |
1413 | } | |
1414 | } | |
1415 | else{ | |
1416 | ifirst = this->cbegin(); | |
1417 | size_type to_skip = len - to_erase; | |
1418 | while(to_skip--){ | |
1419 | ++ifirst; | |
1420 | } | |
1421 | } | |
1422 | this->erase(ifirst, iend); | |
1423 | return true; | |
1424 | } | |
1425 | else{ | |
1426 | return false; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | iterator priv_insert(const_iterator p, const T &x) | |
1431 | { | |
1432 | BOOST_ASSERT((priv_is_linked)(p)); | |
1433 | NodePtr tmp = AllocHolder::create_node(x); | |
1434 | return iterator(this->icont().insert(p.get(), *tmp)); | |
1435 | } | |
1436 | ||
1437 | iterator priv_insert(const_iterator p, BOOST_RV_REF(T) x) | |
1438 | { | |
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)); | |
1442 | } | |
1443 | ||
1e59de90 TL |
1444 | template<class U> |
1445 | void priv_push_back(BOOST_FWD_REF(U) x) | |
1446 | { this->icont().push_back(*this->create_node(::boost::forward<U>(x))); } | |
7c673cae | 1447 | |
1e59de90 TL |
1448 | template<class U> |
1449 | void priv_push_front(BOOST_FWD_REF(U) x) | |
1450 | { this->icont().push_front(*this->create_node(::boost::forward<U>(x))); } | |
7c673cae FG |
1451 | |
1452 | class insertion_functor; | |
1453 | friend class insertion_functor; | |
1454 | ||
1455 | class insertion_functor | |
1456 | { | |
1457 | Icont &icont_; | |
1458 | typedef typename Icont::const_iterator iconst_iterator; | |
1459 | const iconst_iterator pos_; | |
1460 | ||
1461 | public: | |
1462 | insertion_functor(Icont &icont, typename Icont::const_iterator pos) | |
1463 | : icont_(icont), pos_(pos) | |
1464 | {} | |
1465 | ||
1466 | void operator()(Node &n) | |
1467 | { | |
1468 | this->icont_.insert(pos_, n); | |
1469 | } | |
1470 | }; | |
1471 | ||
11fdf7f2 TL |
1472 | typedef value_less<value_type> value_less_t; |
1473 | typedef value_equal<value_type> value_equal_t; | |
7c673cae FG |
1474 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED |
1475 | ||
1476 | }; | |
1477 | ||
92f5a8d4 TL |
1478 | #ifndef BOOST_CONTAINER_NO_CXX17_CTAD |
1479 | template <typename InputIterator> | |
1480 | list(InputIterator, InputIterator) -> | |
1481 | list<typename iterator_traits<InputIterator>::value_type>; | |
1482 | ||
1483 | template <typename InputIterator, typename ValueAllocator> | |
1484 | list(InputIterator, InputIterator, ValueAllocator const&) -> | |
1485 | list<typename iterator_traits<InputIterator>::value_type, ValueAllocator>; | |
1486 | #endif | |
1487 | ||
7c673cae FG |
1488 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED |
1489 | ||
1490 | } //namespace container { | |
1491 | ||
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> > | |
1496 | { | |
92f5a8d4 TL |
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 && | |
7c673cae FG |
1500 | ::boost::has_trivial_destructor_after_move<pointer>::value; |
1501 | }; | |
1502 | ||
1503 | namespace container { | |
1504 | ||
1505 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1506 | ||
1507 | }} | |
1508 | ||
1509 | #include <boost/container/detail/config_end.hpp> | |
1510 | ||
1511 | #endif // BOOST_CONTAINER_LIST_HPP |