]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2004-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 | ||
11 | #ifndef BOOST_CONTAINER_SLIST_HPP | |
12 | #define BOOST_CONTAINER_SLIST_HPP | |
13 | ||
14 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | ||
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
22 | #include <boost/container/detail/config_begin.hpp> | |
23 | #include <boost/container/detail/workaround.hpp> | |
24 | ||
25 | // container | |
26 | #include <boost/container/container_fwd.hpp> | |
27 | #include <boost/container/new_allocator.hpp> //new_allocator | |
28 | #include <boost/container/throw_exception.hpp> | |
29 | // container/detail | |
30 | #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare | |
31 | #include <boost/container/detail/compare_functors.hpp> | |
32 | #include <boost/container/detail/iterator.hpp> | |
33 | #include <boost/container/detail/iterators.hpp> | |
34 | #include <boost/container/detail/mpl.hpp> | |
35 | #include <boost/container/detail/node_alloc_holder.hpp> | |
36 | #include <boost/container/detail/type_traits.hpp> | |
37 | // intrusive | |
38 | #include <boost/intrusive/pointer_traits.hpp> | |
39 | #include <boost/intrusive/slist.hpp> | |
40 | // move | |
41 | #include <boost/move/iterator.hpp> | |
42 | #include <boost/move/traits.hpp> | |
43 | #include <boost/move/utility_core.hpp> | |
44 | // move/detail | |
45 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
46 | #include <boost/move/detail/fwd_macros.hpp> | |
47 | #endif | |
48 | #include <boost/move/detail/move_helpers.hpp> | |
49 | // other | |
50 | #include <boost/core/no_exceptions_support.hpp> | |
51 | // std | |
52 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
53 | #include <initializer_list> | |
54 | #endif | |
55 | ||
56 | namespace boost { | |
57 | namespace container { | |
58 | ||
59 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
60 | ||
61 | template <class T, class Allocator> | |
62 | class slist; | |
63 | ||
64 | namespace container_detail { | |
65 | ||
66 | template<class VoidPointer> | |
67 | struct slist_hook | |
68 | { | |
69 | typedef typename container_detail::bi::make_slist_base_hook | |
70 | <container_detail::bi::void_pointer<VoidPointer>, container_detail::bi::link_mode<container_detail::bi::normal_link> >::type type; | |
71 | }; | |
72 | ||
73 | template <class T, class VoidPointer> | |
74 | struct slist_node | |
75 | : public slist_hook<VoidPointer>::type | |
76 | { | |
77 | private: | |
78 | slist_node(); | |
79 | ||
80 | public: | |
81 | typedef T value_type; | |
82 | typedef typename slist_hook<VoidPointer>::type hook_type; | |
83 | ||
84 | T m_data; | |
85 | ||
86 | T &get_data() | |
87 | { return this->m_data; } | |
88 | ||
89 | const T &get_data() const | |
90 | { return this->m_data; } | |
91 | }; | |
92 | ||
93 | template <class T, class VoidPointer> | |
94 | struct iiterator_node_value_type< slist_node<T,VoidPointer> > { | |
95 | typedef T type; | |
96 | }; | |
97 | ||
98 | template<class Allocator> | |
99 | struct intrusive_slist_type | |
100 | { | |
101 | typedef boost::container::allocator_traits<Allocator> allocator_traits_type; | |
102 | typedef typename allocator_traits_type::value_type value_type; | |
103 | typedef typename boost::intrusive::pointer_traits | |
104 | <typename allocator_traits_type::pointer>::template | |
105 | rebind_pointer<void>::type | |
106 | void_pointer; | |
107 | typedef typename container_detail::slist_node | |
108 | <value_type, void_pointer> node_type; | |
109 | ||
110 | typedef typename container_detail::bi::make_slist | |
111 | <node_type | |
112 | ,container_detail::bi::base_hook<typename slist_hook<void_pointer>::type> | |
113 | ,container_detail::bi::constant_time_size<true> | |
114 | , container_detail::bi::size_type | |
115 | <typename allocator_traits_type::size_type> | |
116 | >::type container_type; | |
117 | typedef container_type type ; | |
118 | }; | |
119 | ||
120 | } //namespace container_detail { | |
121 | ||
122 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
123 | ||
124 | //! An slist is a singly linked list: a list where each element is linked to the next | |
125 | //! element, but not to the previous element. That is, it is a Sequence that | |
126 | //! supports forward but not backward traversal, and (amortized) constant time | |
127 | //! insertion and removal of elements. Slists, like lists, have the important | |
128 | //! property that insertion and splicing do not invalidate iterators to list elements, | |
129 | //! and that even removal invalidates only the iterators that point to the elements | |
130 | //! that are removed. The ordering of iterators may be changed (that is, | |
131 | //! slist<T>::iterator might have a different predecessor or successor after a list | |
132 | //! operation than it did before), but the iterators themselves will not be invalidated | |
133 | //! or made to point to different elements unless that invalidation or mutation is explicit. | |
134 | //! | |
135 | //! The main difference between slist and list is that list's iterators are bidirectional | |
136 | //! iterators, while slist's iterators are forward iterators. This means that slist is | |
137 | //! less versatile than list; frequently, however, bidirectional iterators are | |
138 | //! unnecessary. You should usually use slist unless you actually need the extra | |
139 | //! functionality of list, because singly linked lists are smaller and faster than double | |
140 | //! linked lists. | |
141 | //! | |
142 | //! Important performance note: like every other Sequence, slist defines the member | |
143 | //! functions insert and erase. Using these member functions carelessly, however, can | |
144 | //! result in disastrously slow programs. The problem is that insert's first argument is | |
145 | //! an iterator p, and that it inserts the new element(s) before p. This means that | |
146 | //! insert must find the iterator just before p; this is a constant-time operation | |
147 | //! for list, since list has bidirectional iterators, but for slist it must find that | |
148 | //! iterator by traversing the list from the beginning up to p. In other words: | |
149 | //! insert and erase are slow operations anywhere but near the beginning of the slist. | |
150 | //! | |
151 | //! Slist provides the member functions insert_after and erase_after, which are constant | |
152 | //! time operations: you should always use insert_after and erase_after whenever | |
153 | //! possible. If you find that insert_after and erase_after aren't adequate for your | |
154 | //! needs, and that you often need to use insert and erase in the middle of the list, | |
155 | //! then you should probably use list instead of slist. | |
156 | //! | |
157 | //! \tparam T The type of object that is stored in the list | |
158 | //! \tparam Allocator The allocator used for all internal memory management | |
159 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED | |
160 | template <class T, class Allocator = new_allocator<T> > | |
161 | #else | |
162 | template <class T, class Allocator> | |
163 | #endif | |
164 | class slist | |
165 | : protected container_detail::node_alloc_holder | |
166 | <Allocator, typename container_detail::intrusive_slist_type<Allocator>::type> | |
167 | { | |
168 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
169 | typedef typename | |
170 | container_detail::intrusive_slist_type<Allocator>::type Icont; | |
171 | typedef container_detail::node_alloc_holder<Allocator, Icont> AllocHolder; | |
172 | typedef typename AllocHolder::NodePtr NodePtr; | |
173 | typedef typename AllocHolder::NodeAlloc NodeAlloc; | |
174 | typedef typename AllocHolder::ValAlloc ValAlloc; | |
175 | typedef typename AllocHolder::Node Node; | |
176 | typedef container_detail::allocator_destroyer<NodeAlloc> Destroyer; | |
177 | typedef typename AllocHolder::alloc_version alloc_version; | |
178 | typedef boost::container:: | |
179 | allocator_traits<Allocator> allocator_traits_type; | |
180 | typedef boost::container::equal_to_value<Allocator> equal_to_value_type; | |
181 | ||
182 | BOOST_COPYABLE_AND_MOVABLE(slist) | |
183 | typedef container_detail::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl; | |
184 | typedef container_detail::iterator_from_iiterator<typename Icont::iterator, true > const_iterator_impl; | |
185 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
186 | ||
187 | public: | |
188 | ////////////////////////////////////////////// | |
189 | // | |
190 | // types | |
191 | // | |
192 | ////////////////////////////////////////////// | |
193 | ||
194 | typedef T value_type; | |
195 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
196 | typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer; | |
197 | typedef typename ::boost::container::allocator_traits<Allocator>::reference reference; | |
198 | typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference; | |
199 | typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type; | |
200 | typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type; | |
201 | typedef Allocator allocator_type; | |
202 | typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type; | |
203 | typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; | |
204 | typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; | |
205 | ||
206 | public: | |
207 | ||
208 | ////////////////////////////////////////////// | |
209 | // | |
210 | // construct/copy/destroy | |
211 | // | |
212 | ////////////////////////////////////////////// | |
213 | ||
214 | //! <b>Effects</b>: Constructs a list taking the allocator as parameter. | |
215 | //! | |
216 | //! <b>Throws</b>: If allocator_type's copy constructor throws. | |
217 | //! | |
218 | //! <b>Complexity</b>: Constant. | |
219 | slist() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value) | |
220 | : AllocHolder() | |
221 | {} | |
222 | ||
223 | //! <b>Effects</b>: Constructs a list taking the allocator as parameter. | |
224 | //! | |
225 | //! <b>Throws</b>: Nothing | |
226 | //! | |
227 | //! <b>Complexity</b>: Constant. | |
228 | explicit slist(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW | |
229 | : AllocHolder(a) | |
230 | {} | |
231 | ||
232 | //! <b>Effects</b>: Constructs a list | |
233 | //! and inserts n value-initialized value_types. | |
234 | //! | |
235 | //! <b>Throws</b>: If allocator_type's default constructor | |
236 | //! throws or T's default or copy constructor throws. | |
237 | //! | |
238 | //! <b>Complexity</b>: Linear to n. | |
239 | explicit slist(size_type n) | |
240 | : AllocHolder(allocator_type()) | |
241 | { this->resize(n); } | |
242 | ||
243 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
244 | //! and inserts n copies of value. | |
245 | //! | |
246 | //! <b>Throws</b>: If allocator_type's default constructor | |
247 | //! throws or T's default or copy constructor throws. | |
248 | //! | |
249 | //! <b>Complexity</b>: Linear to n. | |
250 | slist(size_type n, const allocator_type &a) | |
251 | : AllocHolder(a) | |
252 | { this->resize(n); } | |
253 | ||
254 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
255 | //! and inserts n copies of value. | |
256 | //! | |
257 | //! <b>Throws</b>: If allocator_type's default constructor | |
258 | //! throws or T's default or copy constructor throws. | |
259 | //! | |
260 | //! <b>Complexity</b>: Linear to n. | |
261 | explicit slist(size_type n, const value_type& x, const allocator_type& a = allocator_type()) | |
262 | : AllocHolder(a) | |
263 | { this->insert_after(this->cbefore_begin(), n, x); } | |
264 | ||
265 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
266 | //! and inserts a copy of the range [first, last) in the list. | |
267 | //! | |
268 | //! <b>Throws</b>: If allocator_type's default constructor | |
269 | //! throws or T's constructor taking a dereferenced InIt throws. | |
270 | //! | |
271 | //! <b>Complexity</b>: Linear to the range [first, last). | |
272 | template <class InpIt> | |
273 | slist(InpIt first, InpIt last, const allocator_type& a = allocator_type()) | |
274 | : AllocHolder(a) | |
275 | { this->insert_after(this->cbefore_begin(), first, last); } | |
276 | ||
277 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
278 | //! <b>Effects</b>: Constructs a list that will use a copy of allocator a | |
279 | //! and inserts a copy of the range [il.begin(), il.end()) in the list. | |
280 | //! | |
281 | //! <b>Throws</b>: If allocator_type's default constructor | |
282 | //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws. | |
283 | //! | |
284 | //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()). | |
285 | slist(std::initializer_list<value_type> il, const allocator_type& a = allocator_type()) | |
286 | : AllocHolder(a) | |
287 | { this->insert_after(this->cbefore_begin(), il.begin(), il.end()); } | |
288 | #endif | |
289 | ||
290 | //! <b>Effects</b>: Copy constructs a list. | |
291 | //! | |
292 | //! <b>Postcondition</b>: x == *this. | |
293 | //! | |
294 | //! <b>Throws</b>: If allocator_type's default constructor | |
295 | //! | |
296 | //! <b>Complexity</b>: Linear to the elements x contains. | |
297 | slist(const slist& x) | |
298 | : AllocHolder(x) | |
299 | { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); } | |
300 | ||
301 | //! <b>Effects</b>: Move constructor. Moves x's resources to *this. | |
302 | //! | |
303 | //! <b>Throws</b>: If allocator_type's copy constructor throws. | |
304 | //! | |
305 | //! <b>Complexity</b>: Constant. | |
306 | slist(BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW | |
307 | : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x)) | |
308 | {} | |
309 | ||
310 | //! <b>Effects</b>: Copy constructs a list using the specified allocator. | |
311 | //! | |
312 | //! <b>Postcondition</b>: x == *this. | |
313 | //! | |
314 | //! <b>Throws</b>: If allocator_type's default constructor | |
315 | //! | |
316 | //! <b>Complexity</b>: Linear to the elements x contains. | |
317 | slist(const slist& x, const allocator_type &a) | |
318 | : AllocHolder(a) | |
319 | { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); } | |
320 | ||
321 | //! <b>Effects</b>: Move constructor using the specified allocator. | |
322 | //! Moves x's resources to *this. | |
323 | //! | |
324 | //! <b>Throws</b>: If allocation or value_type's copy constructor throws. | |
325 | //! | |
326 | //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise. | |
327 | slist(BOOST_RV_REF(slist) x, const allocator_type &a) | |
328 | : AllocHolder(a) | |
329 | { | |
330 | if(this->node_alloc() == x.node_alloc()){ | |
331 | this->icont().swap(x.icont()); | |
332 | } | |
333 | else{ | |
334 | this->insert_after(this->cbefore_begin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); | |
335 | } | |
336 | } | |
337 | ||
338 | //! <b>Effects</b>: Destroys the list. All stored values are destroyed | |
339 | //! and used memory is deallocated. | |
340 | //! | |
341 | //! <b>Throws</b>: Nothing. | |
342 | //! | |
343 | //! <b>Complexity</b>: Linear to the number of elements. | |
344 | ~slist() BOOST_NOEXCEPT_OR_NOTHROW | |
345 | {} //AllocHolder clears the slist | |
346 | ||
347 | //! <b>Effects</b>: Makes *this contain the same elements as x. | |
348 | //! | |
349 | //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy | |
350 | //! of each of x's elements. | |
351 | //! | |
352 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
353 | //! | |
354 | //! <b>Complexity</b>: Linear to the number of elements in x. | |
355 | slist& operator= (BOOST_COPY_ASSIGN_REF(slist) x) | |
356 | { | |
357 | if (&x != this){ | |
358 | NodeAlloc &this_alloc = this->node_alloc(); | |
359 | const NodeAlloc &x_alloc = x.node_alloc(); | |
360 | container_detail::bool_<allocator_traits_type:: | |
361 | propagate_on_container_copy_assignment::value> flag; | |
362 | if(flag && this_alloc != x_alloc){ | |
363 | this->clear(); | |
364 | } | |
365 | this->AllocHolder::copy_assign_alloc(x); | |
366 | this->assign(x.begin(), x.end()); | |
367 | } | |
368 | return *this; | |
369 | } | |
370 | ||
371 | //! <b>Effects</b>: Makes *this contain the same elements as x. | |
372 | //! | |
373 | //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy | |
374 | //! of each of x's elements. | |
375 | //! | |
376 | //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment | |
377 | //! is false and (allocation throws or value_type's move constructor throws) | |
378 | //! | |
379 | //! <b>Complexity</b>: Constant if allocator_traits_type:: | |
380 | //! propagate_on_container_move_assignment is true or | |
381 | //! this->get>allocator() == x.get_allocator(). Linear otherwise. | |
382 | slist& operator=(BOOST_RV_REF(slist) x) | |
383 | BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value | |
384 | || allocator_traits_type::is_always_equal::value) | |
385 | { | |
386 | BOOST_ASSERT(this != &x); | |
387 | NodeAlloc &this_alloc = this->node_alloc(); | |
388 | NodeAlloc &x_alloc = x.node_alloc(); | |
389 | const bool propagate_alloc = allocator_traits_type:: | |
390 | propagate_on_container_move_assignment::value; | |
391 | const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal; | |
392 | //Resources can be transferred if both allocators are | |
393 | //going to be equal after this function (either propagated or already equal) | |
394 | if(propagate_alloc || allocators_equal){ | |
395 | //Destroy | |
396 | this->clear(); | |
397 | //Move allocator if needed | |
398 | this->AllocHolder::move_assign_alloc(x); | |
399 | //Obtain resources | |
400 | this->icont() = boost::move(x.icont()); | |
401 | } | |
402 | //Else do a one by one move | |
403 | else{ | |
404 | this->assign( boost::make_move_iterator(x.begin()) | |
405 | , boost::make_move_iterator(x.end())); | |
406 | } | |
407 | return *this; | |
408 | } | |
409 | ||
410 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
411 | //! <b>Effects</b>: Makes *this contain the same elements as in il. | |
412 | //! | |
413 | //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy | |
414 | //! of each of il's elements. | |
415 | //! | |
416 | //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment | |
417 | //! is false and (allocation throws or value_type's move constructor throws) | |
418 | slist& operator=(std::initializer_list<value_type> il) | |
419 | { | |
420 | assign(il.begin(), il.end()); | |
421 | return *this; | |
422 | } | |
423 | #endif | |
424 | ||
425 | //! <b>Effects</b>: Assigns the n copies of val to *this. | |
426 | //! | |
427 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
428 | //! | |
429 | //! <b>Complexity</b>: Linear to n. | |
430 | void assign(size_type n, const T& val) | |
431 | { | |
432 | typedef constant_iterator<value_type, difference_type> cvalue_iterator; | |
433 | return this->assign(cvalue_iterator(val, n), cvalue_iterator()); | |
434 | } | |
435 | ||
436 | //! <b>Effects</b>: Assigns the range [first, last) to *this. | |
437 | //! | |
438 | //! <b>Throws</b>: If memory allocation throws or | |
439 | //! T's constructor from dereferencing InpIt throws. | |
440 | //! | |
441 | //! <b>Complexity</b>: Linear to n. | |
442 | template <class InpIt> | |
443 | void assign(InpIt first, InpIt last | |
444 | #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
445 | , typename container_detail::disable_if_convertible<InpIt, size_type>::type * = 0 | |
446 | #endif | |
447 | ) | |
448 | { | |
449 | iterator end_n(this->end()); | |
450 | iterator prev(this->before_begin()); | |
451 | iterator node(this->begin()); | |
452 | while (node != end_n && first != last){ | |
453 | *node = *first; | |
454 | prev = node; | |
455 | ++node; | |
456 | ++first; | |
457 | } | |
458 | if (first != last) | |
459 | this->insert_after(prev, first, last); | |
460 | else | |
461 | this->erase_after(prev, end_n); | |
462 | } | |
463 | ||
464 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
465 | //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this. | |
466 | //! | |
467 | //! <b>Throws</b>: If memory allocation throws or | |
468 | //! T's constructor from dereferencing std::initializer_list iterator throws. | |
469 | //! | |
470 | //! <b>Complexity</b>: Linear to range [il.begin(), il.end()). | |
471 | ||
472 | void assign(std::initializer_list<value_type> il) | |
473 | { | |
474 | assign(il.begin(), il.end()); | |
475 | } | |
476 | #endif | |
477 | //! <b>Effects</b>: Returns a copy of the internal allocator. | |
478 | //! | |
479 | //! <b>Throws</b>: If allocator's copy constructor throws. | |
480 | //! | |
481 | //! <b>Complexity</b>: Constant. | |
482 | allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW | |
483 | { return allocator_type(this->node_alloc()); } | |
484 | ||
485 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
486 | //! | |
487 | //! <b>Throws</b>: Nothing | |
488 | //! | |
489 | //! <b>Complexity</b>: Constant. | |
490 | //! | |
491 | //! <b>Note</b>: Non-standard extension. | |
492 | stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW | |
493 | { return this->node_alloc(); } | |
494 | ||
495 | //! <b>Effects</b>: Returns a reference to the internal allocator. | |
496 | //! | |
497 | //! <b>Throws</b>: Nothing | |
498 | //! | |
499 | //! <b>Complexity</b>: Constant. | |
500 | //! | |
501 | //! <b>Note</b>: Non-standard extension. | |
502 | const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW | |
503 | { return this->node_alloc(); } | |
504 | ||
505 | ////////////////////////////////////////////// | |
506 | // | |
507 | // iterators | |
508 | // | |
509 | ////////////////////////////////////////////// | |
510 | ||
511 | //! <b>Effects</b>: Returns a non-dereferenceable iterator that, | |
512 | //! when incremented, yields begin(). This iterator may be used | |
513 | //! as the argument to insert_after, erase_after, etc. | |
514 | //! | |
515 | //! <b>Throws</b>: Nothing. | |
516 | //! | |
517 | //! <b>Complexity</b>: Constant. | |
518 | iterator before_begin() BOOST_NOEXCEPT_OR_NOTHROW | |
519 | { return iterator(end()); } | |
520 | ||
521 | //! <b>Effects</b>: Returns a non-dereferenceable const_iterator | |
522 | //! that, when incremented, yields begin(). This iterator may be used | |
523 | //! as the argument to insert_after, erase_after, etc. | |
524 | //! | |
525 | //! <b>Throws</b>: Nothing. | |
526 | //! | |
527 | //! <b>Complexity</b>: Constant. | |
528 | const_iterator before_begin() const BOOST_NOEXCEPT_OR_NOTHROW | |
529 | { return this->cbefore_begin(); } | |
530 | ||
531 | //! <b>Effects</b>: Returns an iterator to the first element contained in the list. | |
532 | //! | |
533 | //! <b>Throws</b>: Nothing. | |
534 | //! | |
535 | //! <b>Complexity</b>: Constant. | |
536 | iterator begin() BOOST_NOEXCEPT_OR_NOTHROW | |
537 | { return iterator(this->icont().begin()); } | |
538 | ||
539 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. | |
540 | //! | |
541 | //! <b>Throws</b>: Nothing. | |
542 | //! | |
543 | //! <b>Complexity</b>: Constant. | |
544 | const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW | |
545 | { return this->cbegin(); } | |
546 | ||
547 | //! <b>Effects</b>: Returns an iterator to the end of the list. | |
548 | //! | |
549 | //! <b>Throws</b>: Nothing. | |
550 | //! | |
551 | //! <b>Complexity</b>: Constant. | |
552 | iterator end() BOOST_NOEXCEPT_OR_NOTHROW | |
553 | { return iterator(this->icont().end()); } | |
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. | |
560 | const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW | |
561 | { return this->cend(); } | |
562 | ||
563 | //! <b>Effects</b>: Returns a non-dereferenceable const_iterator | |
564 | //! that, when incremented, yields begin(). This iterator may be used | |
565 | //! as the argument to insert_after, erase_after, etc. | |
566 | //! | |
567 | //! <b>Throws</b>: Nothing. | |
568 | //! | |
569 | //! <b>Complexity</b>: Constant. | |
570 | const_iterator cbefore_begin() const BOOST_NOEXCEPT_OR_NOTHROW | |
571 | { return const_iterator(end()); } | |
572 | ||
573 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. | |
574 | //! | |
575 | //! <b>Throws</b>: Nothing. | |
576 | //! | |
577 | //! <b>Complexity</b>: Constant. | |
578 | const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW | |
579 | { return const_iterator(this->non_const_icont().begin()); } | |
580 | ||
581 | //! <b>Effects</b>: Returns a const_iterator to the end of the list. | |
582 | //! | |
583 | //! <b>Throws</b>: Nothing. | |
584 | //! | |
585 | //! <b>Complexity</b>: Constant. | |
586 | const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW | |
587 | { return const_iterator(this->non_const_icont().end()); } | |
588 | ||
589 | //! <b>Returns</b>: The iterator to the element before i in the sequence. | |
590 | //! Returns the end-iterator, if either i is the begin-iterator or the | |
591 | //! sequence is empty. | |
592 | //! | |
593 | //! <b>Throws</b>: Nothing. | |
594 | //! | |
595 | //! <b>Complexity</b>: Linear to the number of elements before i. | |
596 | //! | |
597 | //! <b>Note</b>: Non-standard extension. | |
598 | iterator previous(iterator p) BOOST_NOEXCEPT_OR_NOTHROW | |
599 | { return iterator(this->icont().previous(p.get())); } | |
600 | ||
601 | //! <b>Returns</b>: The const_iterator to the element before i in the sequence. | |
602 | //! Returns the end-const_iterator, if either i is the begin-const_iterator or | |
603 | //! the sequence is empty. | |
604 | //! | |
605 | //! <b>Throws</b>: Nothing. | |
606 | //! | |
607 | //! <b>Complexity</b>: Linear to the number of elements before i. | |
608 | //! | |
609 | //! <b>Note</b>: Non-standard extension. | |
610 | const_iterator previous(const_iterator p) | |
611 | { return const_iterator(this->icont().previous(p.get())); } | |
612 | ||
613 | ////////////////////////////////////////////// | |
614 | // | |
615 | // capacity | |
616 | // | |
617 | ////////////////////////////////////////////// | |
618 | ||
619 | //! <b>Effects</b>: Returns true if the list contains no elements. | |
620 | //! | |
621 | //! <b>Throws</b>: Nothing. | |
622 | //! | |
623 | //! <b>Complexity</b>: Constant. | |
624 | bool empty() const | |
625 | { return !this->size(); } | |
626 | ||
627 | //! <b>Effects</b>: Returns the number of the elements contained in the list. | |
628 | //! | |
629 | //! <b>Throws</b>: Nothing. | |
630 | //! | |
631 | //! <b>Complexity</b>: Constant. | |
632 | size_type size() const | |
633 | { return this->icont().size(); } | |
634 | ||
635 | //! <b>Effects</b>: Returns the largest possible size of the list. | |
636 | //! | |
637 | //! <b>Throws</b>: Nothing. | |
638 | //! | |
639 | //! <b>Complexity</b>: Constant. | |
640 | size_type max_size() const | |
641 | { return AllocHolder::max_size(); } | |
642 | ||
643 | //! <b>Effects</b>: Inserts or erases elements at the end such that | |
644 | //! the size becomes n. New elements are value initialized. | |
645 | //! | |
646 | //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws. | |
647 | //! | |
648 | //! <b>Complexity</b>: Linear to the difference between size() and new_size. | |
649 | void resize(size_type new_size) | |
650 | { | |
651 | const_iterator last_pos; | |
652 | if(!priv_try_shrink(new_size, last_pos)){ | |
653 | typedef value_init_construct_iterator<value_type, difference_type> value_init_iterator; | |
654 | this->insert_after(last_pos, value_init_iterator(new_size - this->size()), value_init_iterator()); | |
655 | } | |
656 | } | |
657 | ||
658 | //! <b>Effects</b>: Inserts or erases elements at the end such that | |
659 | //! the size becomes n. New elements are copy constructed from x. | |
660 | //! | |
661 | //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws. | |
662 | //! | |
663 | //! <b>Complexity</b>: Linear to the difference between size() and new_size. | |
664 | void resize(size_type new_size, const T& x) | |
665 | { | |
666 | const_iterator last_pos; | |
667 | if(!priv_try_shrink(new_size, last_pos)){ | |
668 | this->insert_after(last_pos, new_size, x); | |
669 | } | |
670 | } | |
671 | ||
672 | ////////////////////////////////////////////// | |
673 | // | |
674 | // element access | |
675 | // | |
676 | ////////////////////////////////////////////// | |
677 | ||
678 | //! <b>Requires</b>: !empty() | |
679 | //! | |
680 | //! <b>Effects</b>: Returns a reference to the first element | |
681 | //! from the beginning of the container. | |
682 | //! | |
683 | //! <b>Throws</b>: Nothing. | |
684 | //! | |
685 | //! <b>Complexity</b>: Constant. | |
686 | reference front() | |
687 | { | |
688 | BOOST_ASSERT(!this->empty()); | |
689 | return *this->begin(); | |
690 | } | |
691 | ||
692 | //! <b>Requires</b>: !empty() | |
693 | //! | |
694 | //! <b>Effects</b>: Returns a const reference to the first element | |
695 | //! from the beginning of the container. | |
696 | //! | |
697 | //! <b>Throws</b>: Nothing. | |
698 | //! | |
699 | //! <b>Complexity</b>: Constant. | |
700 | const_reference front() const | |
701 | { | |
702 | BOOST_ASSERT(!this->empty()); | |
703 | return *this->begin(); | |
704 | } | |
705 | ||
706 | ////////////////////////////////////////////// | |
707 | // | |
708 | // modifiers | |
709 | // | |
710 | ////////////////////////////////////////////// | |
711 | ||
712 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
713 | ||
714 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
715 | //! std::forward<Args>(args)... in the front of the list | |
716 | //! | |
717 | //! <b>Returns</b>: A reference to the created object. | |
718 | //! | |
719 | //! <b>Throws</b>: If memory allocation throws or | |
720 | //! T's copy constructor throws. | |
721 | //! | |
722 | //! <b>Complexity</b>: Amortized constant time. | |
723 | template <class... Args> | |
724 | reference emplace_front(BOOST_FWD_REF(Args)... args) | |
725 | { return *this->emplace_after(this->cbefore_begin(), boost::forward<Args>(args)...); } | |
726 | ||
727 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
728 | //! std::forward<Args>(args)... after prev | |
729 | //! | |
730 | //! <b>Throws</b>: If memory allocation throws or | |
731 | //! T's in-place constructor throws. | |
732 | //! | |
733 | //! <b>Complexity</b>: Constant | |
734 | template <class... Args> | |
735 | iterator emplace_after(const_iterator prev, BOOST_FWD_REF(Args)... args) | |
736 | { | |
737 | NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...)); | |
738 | return iterator(this->icont().insert_after(prev.get(), *pnode)); | |
739 | } | |
740 | ||
741 | #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
742 | ||
743 | #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \ | |
744 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
745 | reference emplace_front(BOOST_MOVE_UREF##N)\ | |
746 | { return *this->emplace_after(this->cbefore_begin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\ | |
747 | \ | |
748 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
749 | iterator emplace_after(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ | |
750 | {\ | |
751 | NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\ | |
752 | return iterator(this->icont().insert_after(p.get(), *pnode));\ | |
753 | }\ | |
754 | // | |
755 | BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE) | |
756 | #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE | |
757 | ||
758 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
759 | ||
760 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
761 | //! <b>Effects</b>: Inserts a copy of x at the beginning of the list. | |
762 | //! | |
763 | //! <b>Throws</b>: If memory allocation throws or | |
764 | //! T's copy constructor throws. | |
765 | //! | |
766 | //! <b>Complexity</b>: Amortized constant time. | |
767 | void push_front(const T &x); | |
768 | ||
769 | //! <b>Effects</b>: Constructs a new element in the beginning of the list | |
770 | //! and moves the resources of x to this new element. | |
771 | //! | |
772 | //! <b>Throws</b>: If memory allocation throws. | |
773 | //! | |
774 | //! <b>Complexity</b>: Amortized constant time. | |
775 | void push_front(T &&x); | |
776 | #else | |
777 | BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front) | |
778 | #endif | |
779 | ||
780 | ||
781 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
782 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
783 | //! | |
784 | //! <b>Effects</b>: Inserts a copy of the value after prev_p. | |
785 | //! | |
786 | //! <b>Returns</b>: An iterator to the inserted element. | |
787 | //! | |
788 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
789 | //! | |
790 | //! <b>Complexity</b>: Amortized constant time. | |
791 | //! | |
792 | //! <b>Note</b>: Does not affect the validity of iterators and references of | |
793 | //! previous values. | |
794 | iterator insert_after(const_iterator prev_p, const T &x); | |
795 | ||
796 | //! <b>Requires</b>: prev_p must be a valid iterator of *this. | |
797 | //! | |
798 | //! <b>Effects</b>: Inserts a move constructed copy object from the value after the | |
799 | //! element pointed by prev_p. | |
800 | //! | |
801 | //! <b>Returns</b>: An iterator to the inserted element. | |
802 | //! | |
803 | //! <b>Throws</b>: If memory allocation throws. | |
804 | //! | |
805 | //! <b>Complexity</b>: Amortized constant time. | |
806 | //! | |
807 | //! <b>Note</b>: Does not affect the validity of iterators and references of | |
808 | //! previous values. | |
809 | iterator insert_after(const_iterator prev_p, T &&x); | |
810 | #else | |
811 | BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_after, T, iterator, priv_insert_after, const_iterator, const_iterator) | |
812 | #endif | |
813 | ||
814 | //! <b>Requires</b>: prev_p must be a valid iterator of *this. | |
815 | //! | |
816 | //! <b>Effects</b>: Inserts n copies of x after prev_p. | |
817 | //! | |
818 | //! <b>Returns</b>: an iterator to the last inserted element or prev_p if n is 0. | |
819 | //! | |
820 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
821 | //! | |
822 | //! | |
823 | //! <b>Complexity</b>: Linear to n. | |
824 | //! | |
825 | //! <b>Note</b>: Does not affect the validity of iterators and references of | |
826 | //! previous values. | |
827 | iterator insert_after(const_iterator prev_p, size_type n, const value_type& x) | |
828 | { | |
829 | typedef constant_iterator<value_type, difference_type> cvalue_iterator; | |
830 | return this->insert_after(prev_p, cvalue_iterator(x, n), cvalue_iterator()); | |
831 | } | |
832 | ||
833 | //! <b>Requires</b>: prev_p must be a valid iterator of *this. | |
834 | //! | |
835 | //! <b>Effects</b>: Inserts the range pointed by [first, last) after prev_p. | |
836 | //! | |
837 | //! <b>Returns</b>: an iterator to the last inserted element or prev_p if first == last. | |
838 | //! | |
839 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
840 | //! dereferenced InpIt throws. | |
841 | //! | |
842 | //! <b>Complexity</b>: Linear to the number of elements inserted. | |
843 | //! | |
844 | //! <b>Note</b>: Does not affect the validity of iterators and references of | |
845 | //! previous values. | |
846 | template <class InpIt> | |
847 | iterator insert_after(const_iterator prev_p, InpIt first, InpIt last | |
848 | #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
849 | , typename container_detail::enable_if_c | |
850 | < !container_detail::is_convertible<InpIt, size_type>::value | |
851 | && (container_detail::is_input_iterator<InpIt>::value | |
852 | || container_detail::is_same<alloc_version, version_1>::value | |
853 | ) | |
854 | >::type * = 0 | |
855 | #endif | |
856 | ) | |
857 | { | |
858 | iterator ret_it(prev_p.get()); | |
859 | for (; first != last; ++first){ | |
860 | ret_it = iterator(this->icont().insert_after(ret_it.get(), *this->create_node_from_it(first))); | |
861 | } | |
862 | return ret_it; | |
863 | } | |
864 | ||
865 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
866 | //! <b>Requires</b>: prev_p must be a valid iterator of *this. | |
867 | //! | |
868 | //! <b>Effects</b>: Inserts the range pointed by [il.begin(), il.end()) after prev_p. | |
869 | //! | |
870 | //! <b>Returns</b>: an iterator to the last inserted element or prev_p if il.begin() == il.end(). | |
871 | //! | |
872 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
873 | //! dereferenced std::initializer_list iterator throws. | |
874 | //! | |
875 | //! <b>Complexity</b>: Linear to the number of elements inserted. | |
876 | //! | |
877 | //! <b>Note</b>: Does not affect the validity of iterators and references of | |
878 | //! previous values. | |
879 | iterator insert_after(const_iterator prev_p, std::initializer_list<value_type> il) | |
880 | { | |
881 | return insert_after(prev_p, il.begin(), il.end()); | |
882 | } | |
883 | #endif | |
884 | #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
885 | template <class FwdIt> | |
886 | iterator insert_after(const_iterator prev, FwdIt first, FwdIt last | |
887 | , typename container_detail::enable_if_c | |
888 | < !container_detail::is_convertible<FwdIt, size_type>::value | |
889 | && !(container_detail::is_input_iterator<FwdIt>::value | |
890 | || container_detail::is_same<alloc_version, version_1>::value | |
891 | ) | |
892 | >::type * = 0 | |
893 | ) | |
894 | { | |
895 | //Optimized allocation and construction | |
896 | insertion_functor func(this->icont(), prev.get()); | |
897 | this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func); | |
898 | return iterator(func.inserted_first()); | |
899 | } | |
900 | #endif | |
901 | ||
902 | //! <b>Effects</b>: Removes the first element from the list. | |
903 | //! | |
904 | //! <b>Throws</b>: Nothing. | |
905 | //! | |
906 | //! <b>Complexity</b>: Amortized constant time. | |
907 | void pop_front() | |
908 | { | |
909 | BOOST_ASSERT(!this->empty()); | |
910 | this->icont().pop_front_and_dispose(Destroyer(this->node_alloc())); | |
911 | } | |
912 | ||
913 | //! <b>Effects</b>: Erases the element after the element pointed by prev_p | |
914 | //! of the list. | |
915 | //! | |
916 | //! <b>Returns</b>: the first element remaining beyond the removed elements, | |
917 | //! or end() if no such element exists. | |
918 | //! | |
919 | //! <b>Throws</b>: Nothing. | |
920 | //! | |
921 | //! <b>Complexity</b>: Constant. | |
922 | //! | |
923 | //! <b>Note</b>: Does not invalidate iterators or references to non erased elements. | |
924 | iterator erase_after(const_iterator prev_p) | |
925 | { | |
926 | return iterator(this->icont().erase_after_and_dispose(prev_p.get(), Destroyer(this->node_alloc()))); | |
927 | } | |
928 | ||
929 | //! <b>Effects</b>: Erases the range (before_first, last) from | |
930 | //! the list. | |
931 | //! | |
932 | //! <b>Returns</b>: the first element remaining beyond the removed elements, | |
933 | //! or end() if no such element exists. | |
934 | //! | |
935 | //! <b>Throws</b>: Nothing. | |
936 | //! | |
937 | //! <b>Complexity</b>: Linear to the number of erased elements. | |
938 | //! | |
939 | //! <b>Note</b>: Does not invalidate iterators or references to non erased elements. | |
940 | iterator erase_after(const_iterator before_first, const_iterator last) | |
941 | { | |
942 | return iterator(this->icont().erase_after_and_dispose(before_first.get(), last.get(), Destroyer(this->node_alloc()))); | |
943 | } | |
944 | ||
945 | //! <b>Effects</b>: Swaps the contents of *this and x. | |
946 | //! | |
947 | //! <b>Throws</b>: Nothing. | |
948 | //! | |
949 | //! <b>Complexity</b>: Linear to the number of elements on *this and x. | |
950 | void swap(slist& x) | |
951 | BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value | |
952 | || allocator_traits_type::is_always_equal::value) | |
953 | { | |
954 | BOOST_ASSERT(allocator_traits_type::propagate_on_container_swap::value || | |
955 | allocator_traits_type::is_always_equal::value || | |
956 | this->get_stored_allocator() == x.get_stored_allocator()); | |
957 | AllocHolder::swap(x); | |
958 | } | |
959 | ||
960 | //! <b>Effects</b>: Erases all the elements of the list. | |
961 | //! | |
962 | //! <b>Throws</b>: Nothing. | |
963 | //! | |
964 | //! <b>Complexity</b>: Linear to the number of elements in the list. | |
965 | void clear() | |
966 | { this->icont().clear_and_dispose(Destroyer(this->node_alloc())); } | |
967 | ||
968 | ////////////////////////////////////////////// | |
969 | // | |
970 | // slist operations | |
971 | // | |
972 | ////////////////////////////////////////////// | |
973 | ||
974 | //! <b>Requires</b>: p must point to an element contained | |
975 | //! by the list. x != *this | |
976 | //! | |
977 | //! <b>Effects</b>: Transfers all the elements of list x to this list, after the | |
978 | //! the element pointed by p. No destructors or copy constructors are called. | |
979 | //! | |
980 | //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator | |
981 | //! are not equal. | |
982 | //! | |
983 | //! <b>Complexity</b>: Linear to the elements in x. | |
984 | //! | |
985 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of | |
986 | //! this list. Iterators of this list and all the references are not invalidated. | |
987 | void splice_after(const_iterator prev_p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW | |
988 | { | |
989 | BOOST_ASSERT(this != &x); | |
990 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
991 | this->icont().splice_after(prev_p.get(), x.icont()); | |
992 | } | |
993 | ||
994 | //! <b>Requires</b>: p must point to an element contained | |
995 | //! by the list. x != *this | |
996 | //! | |
997 | //! <b>Effects</b>: Transfers all the elements of list x to this list, after the | |
998 | //! the element pointed by p. No destructors or copy constructors are called. | |
999 | //! | |
1000 | //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator | |
1001 | //! are not equal. | |
1002 | //! | |
1003 | //! <b>Complexity</b>: Linear to the elements in x. | |
1004 | //! | |
1005 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of | |
1006 | //! this list. Iterators of this list and all the references are not invalidated. | |
1007 | void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW | |
1008 | { this->splice_after(prev_p, static_cast<slist&>(x)); } | |
1009 | ||
1010 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1011 | //! i must point to an element contained in list x. | |
1012 | //! this' allocator and x's allocator shall compare equal. | |
1013 | //! | |
1014 | //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list, | |
1015 | //! after the element pointed by prev_p. | |
1016 | //! If prev_p == prev or prev_p == ++prev, this function is a null operation. | |
1017 | //! | |
1018 | //! <b>Throws</b>: Nothing | |
1019 | //! | |
1020 | //! <b>Complexity</b>: Constant. | |
1021 | //! | |
1022 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1023 | //! list. Iterators of this list and all the references are not invalidated. | |
1024 | void splice_after(const_iterator prev_p, slist& x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW | |
1025 | { | |
1026 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
1027 | this->icont().splice_after(prev_p.get(), x.icont(), prev.get()); | |
1028 | } | |
1029 | ||
1030 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1031 | //! i must point to an element contained in list x. | |
1032 | //! this' allocator and x's allocator shall compare equal. | |
1033 | //! | |
1034 | //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list, | |
1035 | //! after the element pointed by prev_p. | |
1036 | //! If prev_p == prev or prev_p == ++prev, this function is a null operation. | |
1037 | //! | |
1038 | //! <b>Throws</b>: Nothing | |
1039 | //! | |
1040 | //! <b>Complexity</b>: Constant. | |
1041 | //! | |
1042 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1043 | //! list. Iterators of this list and all the references are not invalidated. | |
1044 | void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW | |
1045 | { this->splice_after(prev_p, static_cast<slist&>(x), prev); } | |
1046 | ||
1047 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1048 | //! before_first and before_last must be valid iterators of x. | |
1049 | //! prev_p must not be contained in [before_first, before_last) range. | |
1050 | //! this' allocator and x's allocator shall compare equal. | |
1051 | //! | |
1052 | //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1) | |
1053 | //! from list x to this list, after the element pointed by prev_p. | |
1054 | //! | |
1055 | //! <b>Throws</b>: Nothing | |
1056 | //! | |
1057 | //! <b>Complexity</b>: Linear to the number of transferred elements. | |
1058 | //! | |
1059 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1060 | //! list. Iterators of this list and all the references are not invalidated. | |
1061 | void splice_after(const_iterator prev_p, slist& x, | |
1062 | const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW | |
1063 | { | |
1064 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
1065 | this->icont().splice_after | |
1066 | (prev_p.get(), x.icont(), before_first.get(), before_last.get()); | |
1067 | } | |
1068 | ||
1069 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1070 | //! before_first and before_last must be valid iterators of x. | |
1071 | //! prev_p must not be contained in [before_first, before_last) range. | |
1072 | //! this' allocator and x's allocator shall compare equal. | |
1073 | //! | |
1074 | //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1) | |
1075 | //! from list x to this list, after the element pointed by prev_p. | |
1076 | //! | |
1077 | //! <b>Throws</b>: Nothing | |
1078 | //! | |
1079 | //! <b>Complexity</b>: Linear to the number of transferred elements. | |
1080 | //! | |
1081 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1082 | //! list. Iterators of this list and all the references are not invalidated. | |
1083 | void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, | |
1084 | const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW | |
1085 | { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last); } | |
1086 | ||
1087 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1088 | //! before_first and before_last must be valid iterators of x. | |
1089 | //! prev_p must not be contained in [before_first, before_last) range. | |
1090 | //! n == distance(before_first, before_last). | |
1091 | //! this' allocator and x's allocator shall compare equal. | |
1092 | //! | |
1093 | //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1) | |
1094 | //! from list x to this list, after the element pointed by prev_p. | |
1095 | //! | |
1096 | //! <b>Throws</b>: Nothing | |
1097 | //! | |
1098 | //! <b>Complexity</b>: Constant. | |
1099 | //! | |
1100 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1101 | //! list. Iterators of this list and all the references are not invalidated. | |
1102 | void splice_after(const_iterator prev_p, slist& x, | |
1103 | const_iterator before_first, const_iterator before_last, | |
1104 | size_type n) BOOST_NOEXCEPT_OR_NOTHROW | |
1105 | { | |
1106 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
1107 | this->icont().splice_after | |
1108 | (prev_p.get(), x.icont(), before_first.get(), before_last.get(), n); | |
1109 | } | |
1110 | ||
1111 | //! <b>Requires</b>: prev_p must be a valid iterator of this. | |
1112 | //! before_first and before_last must be valid iterators of x. | |
1113 | //! prev_p must not be contained in [before_first, before_last) range. | |
1114 | //! n == distance(before_first, before_last). | |
1115 | //! this' allocator and x's allocator shall compare equal. | |
1116 | //! | |
1117 | //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1) | |
1118 | //! from list x to this list, after the element pointed by prev_p. | |
1119 | //! | |
1120 | //! <b>Throws</b>: Nothing | |
1121 | //! | |
1122 | //! <b>Complexity</b>: Constant. | |
1123 | //! | |
1124 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1125 | //! list. Iterators of this list and all the references are not invalidated. | |
1126 | void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, | |
1127 | const_iterator before_first, const_iterator before_last, | |
1128 | size_type n) BOOST_NOEXCEPT_OR_NOTHROW | |
1129 | { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last, n); } | |
1130 | ||
1131 | //! <b>Effects</b>: Removes all the elements that compare equal to value. | |
1132 | //! | |
1133 | //! <b>Throws</b>: Nothing. | |
1134 | //! | |
1135 | //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality. | |
1136 | //! | |
1137 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, | |
1138 | //! and iterators to elements that are not removed remain valid. | |
1139 | void remove(const T& value) | |
1140 | { this->remove_if(equal_to_value_type(value)); } | |
1141 | ||
1142 | //! <b>Effects</b>: Removes all the elements for which a specified | |
1143 | //! predicate is satisfied. | |
1144 | //! | |
1145 | //! <b>Throws</b>: If pred throws. | |
1146 | //! | |
1147 | //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate. | |
1148 | //! | |
1149 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, | |
1150 | //! and iterators to elements that are not removed remain valid. | |
1151 | template <class Pred> | |
1152 | void remove_if(Pred pred) | |
1153 | { | |
1154 | typedef value_to_node_compare<Node, Pred> value_to_node_compare_type; | |
1155 | this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc())); | |
1156 | } | |
1157 | ||
1158 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent | |
1159 | //! elements that are equal from the list. | |
1160 | //! | |
1161 | //! <b>Throws</b>: If comparison throws. | |
1162 | //! | |
1163 | //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons). | |
1164 | //! | |
1165 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, | |
1166 | //! and iterators to elements that are not removed remain valid. | |
1167 | void unique() | |
1168 | { this->unique(value_equal()); } | |
1169 | ||
1170 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent | |
1171 | //! elements that satisfy some binary predicate from the list. | |
1172 | //! | |
1173 | //! <b>Throws</b>: If pred throws. | |
1174 | //! | |
1175 | //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()). | |
1176 | //! | |
1177 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, | |
1178 | //! and iterators to elements that are not removed remain valid. | |
1179 | template <class Pred> | |
1180 | void unique(Pred pred) | |
1181 | { | |
1182 | typedef value_to_node_compare<Node, Pred> value_to_node_compare_type; | |
1183 | this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc())); | |
1184 | } | |
1185 | ||
1186 | //! <b>Requires</b>: The lists x and *this must be distinct. | |
1187 | //! | |
1188 | //! <b>Effects</b>: This function removes all of x's elements and inserts them | |
1189 | //! in order into *this according to std::less<value_type>. The merge is stable; | |
1190 | //! that is, if an element from *this is equivalent to one from x, then the element | |
1191 | //! from *this will precede the one from x. | |
1192 | //! | |
1193 | //! <b>Throws</b>: If comparison throws. | |
1194 | //! | |
1195 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1196 | //! size() + x.size() - 1 comparisons. | |
1197 | void merge(slist & x) | |
1198 | { this->merge(x, value_less()); } | |
1199 | ||
1200 | //! <b>Requires</b>: The lists x and *this must be distinct. | |
1201 | //! | |
1202 | //! <b>Effects</b>: This function removes all of x's elements and inserts them | |
1203 | //! in order into *this according to std::less<value_type>. The merge is stable; | |
1204 | //! that is, if an element from *this is equivalent to one from x, then the element | |
1205 | //! from *this will precede the one from x. | |
1206 | //! | |
1207 | //! <b>Throws</b>: If comparison throws. | |
1208 | //! | |
1209 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1210 | //! size() + x.size() - 1 comparisons. | |
1211 | void merge(BOOST_RV_REF(slist) x) | |
1212 | { this->merge(static_cast<slist&>(x)); } | |
1213 | ||
1214 | //! <b>Requires</b>: p must be a comparison function that induces a strict weak | |
1215 | //! ordering and both *this and x must be sorted according to that ordering | |
1216 | //! The lists x and *this must be distinct. | |
1217 | //! | |
1218 | //! <b>Effects</b>: This function removes all of x's elements and inserts them | |
1219 | //! in order into *this. The merge is stable; that is, if an element from *this is | |
1220 | //! equivalent to one from x, then the element from *this will precede the one from x. | |
1221 | //! | |
1222 | //! <b>Throws</b>: If comp throws. | |
1223 | //! | |
1224 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1225 | //! size() + x.size() - 1 comparisons. | |
1226 | //! | |
1227 | //! <b>Note</b>: Iterators and references to *this are not invalidated. | |
1228 | template <class StrictWeakOrdering> | |
1229 | void merge(slist& x, StrictWeakOrdering comp) | |
1230 | { | |
1231 | typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type; | |
1232 | BOOST_ASSERT(this->node_alloc() == x.node_alloc()); | |
1233 | this->icont().merge(x.icont(), value_to_node_compare_type(comp)); | |
1234 | } | |
1235 | ||
1236 | //! <b>Requires</b>: p must be a comparison function that induces a strict weak | |
1237 | //! ordering and both *this and x must be sorted according to that ordering | |
1238 | //! The lists x and *this must be distinct. | |
1239 | //! | |
1240 | //! <b>Effects</b>: This function removes all of x's elements and inserts them | |
1241 | //! in order into *this. The merge is stable; that is, if an element from *this is | |
1242 | //! equivalent to one from x, then the element from *this will precede the one from x. | |
1243 | //! | |
1244 | //! <b>Throws</b>: If comp throws. | |
1245 | //! | |
1246 | //! <b>Complexity</b>: This function is linear time: it performs at most | |
1247 | //! size() + x.size() - 1 comparisons. | |
1248 | //! | |
1249 | //! <b>Note</b>: Iterators and references to *this are not invalidated. | |
1250 | template <class StrictWeakOrdering> | |
1251 | void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp) | |
1252 | { this->merge(static_cast<slist&>(x), comp); } | |
1253 | ||
1254 | //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>. | |
1255 | //! The sort is stable, that is, the relative order of equivalent elements is preserved. | |
1256 | //! | |
1257 | //! <b>Throws</b>: If comparison throws. | |
1258 | //! | |
1259 | //! <b>Notes</b>: Iterators and references are not invalidated. | |
1260 | //! | |
1261 | //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N | |
1262 | //! is the list's size. | |
1263 | void sort() | |
1264 | { this->sort(value_less()); } | |
1265 | ||
1266 | //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>. | |
1267 | //! The sort is stable, that is, the relative order of equivalent elements is preserved. | |
1268 | //! | |
1269 | //! <b>Throws</b>: If comp throws. | |
1270 | //! | |
1271 | //! <b>Notes</b>: Iterators and references are not invalidated. | |
1272 | //! | |
1273 | //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N | |
1274 | //! is the list's size. | |
1275 | template <class StrictWeakOrdering> | |
1276 | void sort(StrictWeakOrdering comp) | |
1277 | { | |
1278 | typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type; | |
1279 | // nothing if the slist has length 0 or 1. | |
1280 | if (this->size() < 2) | |
1281 | return; | |
1282 | this->icont().sort(value_to_node_compare_type(comp)); | |
1283 | } | |
1284 | ||
1285 | //! <b>Effects</b>: Reverses the order of elements in the list. | |
1286 | //! | |
1287 | //! <b>Throws</b>: Nothing. | |
1288 | //! | |
1289 | //! <b>Complexity</b>: This function is linear time. | |
1290 | //! | |
1291 | //! <b>Note</b>: Iterators and references are not invalidated | |
1292 | void reverse() BOOST_NOEXCEPT_OR_NOTHROW | |
1293 | { this->icont().reverse(); } | |
1294 | ||
1295 | ////////////////////////////////////////////// | |
1296 | // | |
1297 | // list compatibility interface | |
1298 | // | |
1299 | ////////////////////////////////////////////// | |
1300 | ||
1301 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1302 | ||
1303 | //! <b>Effects</b>: Inserts an object of type T constructed with | |
1304 | //! std::forward<Args>(args)... before p | |
1305 | //! | |
1306 | //! <b>Throws</b>: If memory allocation throws or | |
1307 | //! T's in-place constructor throws. | |
1308 | //! | |
1309 | //! <b>Complexity</b>: Linear to the elements before p | |
1310 | template <class... Args> | |
1311 | iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args) | |
1312 | { return this->emplace_after(this->previous(p), boost::forward<Args>(args)...); } | |
1313 | ||
1314 | #else | |
1315 | ||
1316 | #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \ | |
1317 | BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ | |
1318 | iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ | |
1319 | {\ | |
1320 | return this->emplace_after(this->previous(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ | |
1321 | }\ | |
1322 | // | |
1323 | BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE) | |
1324 | #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE | |
1325 | ||
1326 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) | |
1327 | ||
1328 | #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) | |
1329 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1330 | //! | |
1331 | //! <b>Effects</b>: Insert a copy of x before p. | |
1332 | //! | |
1333 | //! <b>Returns</b>: an iterator to the inserted element. | |
1334 | //! | |
1335 | //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws. | |
1336 | //! | |
1337 | //! <b>Complexity</b>: Linear to the elements before p. | |
1338 | iterator insert(const_iterator p, const T &x); | |
1339 | ||
1340 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1341 | //! | |
1342 | //! <b>Effects</b>: Insert a new element before p with x's resources. | |
1343 | //! | |
1344 | //! <b>Returns</b>: an iterator to the inserted element. | |
1345 | //! | |
1346 | //! <b>Throws</b>: If memory allocation throws. | |
1347 | //! | |
1348 | //! <b>Complexity</b>: Linear to the elements before p. | |
1349 | iterator insert(const_iterator prev_p, T &&x); | |
1350 | #else | |
1351 | BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator) | |
1352 | #endif | |
1353 | ||
1354 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1355 | //! | |
1356 | //! <b>Effects</b>: Inserts n copies of x before p. | |
1357 | //! | |
1358 | //! <b>Returns</b>: an iterator to the first inserted element or p if n == 0. | |
1359 | //! | |
1360 | //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws. | |
1361 | //! | |
1362 | //! <b>Complexity</b>: Linear to n plus linear to the elements before p. | |
1363 | iterator insert(const_iterator p, size_type n, const value_type& x) | |
1364 | { | |
1365 | const_iterator prev(this->previous(p)); | |
1366 | this->insert_after(prev, n, x); | |
1367 | return ++iterator(prev.get()); | |
1368 | } | |
1369 | ||
1370 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1371 | //! | |
1372 | //! <b>Effects</b>: Insert a copy of the [first, last) range before p. | |
1373 | //! | |
1374 | //! <b>Returns</b>: an iterator to the first inserted element or p if first == last. | |
1375 | //! | |
1376 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
1377 | //! dereferenced InpIt throws. | |
1378 | //! | |
1379 | //! <b>Complexity</b>: Linear to distance [first, last) plus | |
1380 | //! linear to the elements before p. | |
1381 | template <class InIter> | |
1382 | iterator insert(const_iterator p, InIter first, InIter last) | |
1383 | { | |
1384 | const_iterator prev(this->previous(p)); | |
1385 | this->insert_after(prev, first, last); | |
1386 | return ++iterator(prev.get()); | |
1387 | } | |
1388 | ||
1389 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
1390 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1391 | //! | |
1392 | //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p. | |
1393 | //! | |
1394 | //! <b>Returns</b>: an iterator to the first inserted element or p if il.begin() == il.end(). | |
1395 | //! | |
1396 | //! <b>Throws</b>: If memory allocation throws, T's constructor from a | |
1397 | //! dereferenced std::initializer_list iterator throws. | |
1398 | //! | |
1399 | //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()) plus | |
1400 | //! linear to the elements before p. | |
1401 | iterator insert(const_iterator p, std::initializer_list<value_type> il) | |
1402 | { | |
1403 | return insert(p, il.begin(), il.end()); | |
1404 | } | |
1405 | #endif | |
1406 | ||
1407 | //! <b>Requires</b>: p must be a valid iterator of *this. | |
1408 | //! | |
1409 | //! <b>Effects</b>: Erases the element at p. | |
1410 | //! | |
1411 | //! <b>Throws</b>: Nothing. | |
1412 | //! | |
1413 | //! <b>Complexity</b>: Linear to the number of elements before p. | |
1414 | iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW | |
1415 | { return iterator(this->erase_after(previous(p))); } | |
1416 | ||
1417 | //! <b>Requires</b>: first and last must be valid iterator to elements in *this. | |
1418 | //! | |
1419 | //! <b>Effects</b>: Erases the elements pointed by [first, last). | |
1420 | //! | |
1421 | //! <b>Throws</b>: Nothing. | |
1422 | //! | |
1423 | //! <b>Complexity</b>: Linear to the distance between first and last plus | |
1424 | //! linear to the elements before first. | |
1425 | iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW | |
1426 | { return iterator(this->erase_after(previous(first), last)); } | |
1427 | ||
1428 | //! <b>Requires</b>: p must point to an element contained | |
1429 | //! by the list. x != *this. this' allocator and x's allocator shall compare equal | |
1430 | //! | |
1431 | //! <b>Effects</b>: Transfers all the elements of list x to this list, before the | |
1432 | //! the element pointed by p. No destructors or copy constructors are called. | |
1433 | //! | |
1434 | //! <b>Throws</b>: Nothing | |
1435 | //! | |
1436 | //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size(). | |
1437 | //! | |
1438 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of | |
1439 | //! this list. Iterators of this list and all the references are not invalidated. | |
1440 | void splice(const_iterator p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW | |
1441 | { this->splice_after(this->previous(p), x); } | |
1442 | ||
1443 | //! <b>Requires</b>: p must point to an element contained | |
1444 | //! by the list. x != *this. this' allocator and x's allocator shall compare equal | |
1445 | //! | |
1446 | //! <b>Effects</b>: Transfers all the elements of list x to this list, before the | |
1447 | //! the element pointed by p. No destructors or copy constructors are called. | |
1448 | //! | |
1449 | //! <b>Throws</b>: Nothing | |
1450 | //! | |
1451 | //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size(). | |
1452 | //! | |
1453 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of | |
1454 | //! this list. Iterators of this list and all the references are not invalidated. | |
1455 | void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW | |
1456 | { this->splice(p, static_cast<slist&>(x)); } | |
1457 | ||
1458 | //! <b>Requires</b>: p must point to an element contained | |
1459 | //! by this list. i must point to an element contained in list x. | |
1460 | //! this' allocator and x's allocator shall compare equal | |
1461 | //! | |
1462 | //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list, | |
1463 | //! before the element pointed by p. No destructors or copy constructors are called. | |
1464 | //! If p == i or p == ++i, this function is a null operation. | |
1465 | //! | |
1466 | //! <b>Throws</b>: Nothing | |
1467 | //! | |
1468 | //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i). | |
1469 | //! | |
1470 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1471 | //! list. Iterators of this list and all the references are not invalidated. | |
1472 | void splice(const_iterator p, slist& x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW | |
1473 | { this->splice_after(this->previous(p), x, this->previous(i)); } | |
1474 | ||
1475 | //! <b>Requires</b>: p must point to an element contained | |
1476 | //! by this list. i must point to an element contained in list x. | |
1477 | //! this' allocator and x's allocator shall compare equal. | |
1478 | //! | |
1479 | //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list, | |
1480 | //! before the element pointed by p. No destructors or copy constructors are called. | |
1481 | //! If p == i or p == ++i, this function is a null operation. | |
1482 | //! | |
1483 | //! <b>Throws</b>: Nothing | |
1484 | //! | |
1485 | //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i). | |
1486 | //! | |
1487 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1488 | //! list. Iterators of this list and all the references are not invalidated. | |
1489 | void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW | |
1490 | { this->splice(p, static_cast<slist&>(x), i); } | |
1491 | ||
1492 | //! <b>Requires</b>: p must point to an element contained | |
1493 | //! by this list. first and last must point to elements contained in list x. | |
1494 | //! | |
1495 | //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list, | |
1496 | //! before the element pointed by p. No destructors or copy constructors are called. | |
1497 | //! this' allocator and x's allocator shall compare equal. | |
1498 | //! | |
1499 | //! <b>Throws</b>: Nothing | |
1500 | //! | |
1501 | //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first), | |
1502 | //! and in distance(first, last). | |
1503 | //! | |
1504 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1505 | //! list. Iterators of this list and all the references are not invalidated. | |
1506 | void splice(const_iterator p, slist& x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW | |
1507 | { this->splice_after(this->previous(p), x, this->previous(first), this->previous(last)); } | |
1508 | ||
1509 | //! <b>Requires</b>: p must point to an element contained | |
1510 | //! by this list. first and last must point to elements contained in list x. | |
1511 | //! this' allocator and x's allocator shall compare equal | |
1512 | //! | |
1513 | //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list, | |
1514 | //! before the element pointed by p. No destructors or copy constructors are called. | |
1515 | //! | |
1516 | //! <b>Throws</b>: Nothing | |
1517 | //! | |
1518 | //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first), | |
1519 | //! and in distance(first, last). | |
1520 | //! | |
1521 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this | |
1522 | //! list. Iterators of this list and all the references are not invalidated. | |
1523 | void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW | |
1524 | { this->splice(p, static_cast<slist&>(x), first, last); } | |
1525 | ||
1526 | //! <b>Effects</b>: Returns true if x and y are equal | |
1527 | //! | |
1528 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1529 | friend bool operator==(const slist& x, const slist& y) | |
1530 | { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } | |
1531 | ||
1532 | //! <b>Effects</b>: Returns true if x and y are unequal | |
1533 | //! | |
1534 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1535 | friend bool operator!=(const slist& x, const slist& y) | |
1536 | { return !(x == y); } | |
1537 | ||
1538 | //! <b>Effects</b>: Returns true if x is less than y | |
1539 | //! | |
1540 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1541 | friend bool operator<(const slist& x, const slist& y) | |
1542 | { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } | |
1543 | ||
1544 | //! <b>Effects</b>: Returns true if x is greater than y | |
1545 | //! | |
1546 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1547 | friend bool operator>(const slist& x, const slist& y) | |
1548 | { return y < x; } | |
1549 | ||
1550 | //! <b>Effects</b>: Returns true if x is equal or less than y | |
1551 | //! | |
1552 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1553 | friend bool operator<=(const slist& x, const slist& y) | |
1554 | { return !(y < x); } | |
1555 | ||
1556 | //! <b>Effects</b>: Returns true if x is equal or greater than y | |
1557 | //! | |
1558 | //! <b>Complexity</b>: Linear to the number of elements in the container. | |
1559 | friend bool operator>=(const slist& x, const slist& y) | |
1560 | { return !(x < y); } | |
1561 | ||
1562 | //! <b>Effects</b>: x.swap(y) | |
1563 | //! | |
1564 | //! <b>Complexity</b>: Constant. | |
1565 | friend void swap(slist& x, slist& y) | |
1566 | { x.swap(y); } | |
1567 | ||
1568 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1569 | private: | |
1570 | ||
1571 | void priv_push_front (const T &x) | |
1572 | { this->insert_after(this->cbefore_begin(), x); } | |
1573 | ||
1574 | void priv_push_front (BOOST_RV_REF(T) x) | |
1575 | { this->insert_after(this->cbefore_begin(), ::boost::move(x)); } | |
1576 | ||
1577 | bool priv_try_shrink(size_type new_size, const_iterator &last_pos) | |
1578 | { | |
1579 | typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next; | |
1580 | while (++(cur_next = cur) != end_n && new_size > 0){ | |
1581 | --new_size; | |
1582 | cur = cur_next; | |
1583 | } | |
1584 | last_pos = const_iterator(cur); | |
1585 | if (cur_next != end_n){ | |
1586 | this->erase_after(last_pos, const_iterator(end_n)); | |
1587 | return true; | |
1588 | } | |
1589 | else{ | |
1590 | return false; | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | template<class U> | |
1595 | iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x) | |
1596 | { return this->insert_after(previous(p), ::boost::forward<U>(x)); } | |
1597 | ||
1598 | template<class U> | |
1599 | iterator priv_insert_after(const_iterator prev_p, BOOST_FWD_REF(U) x) | |
1600 | { return iterator(this->icont().insert_after(prev_p.get(), *this->create_node(::boost::forward<U>(x)))); } | |
1601 | ||
1602 | class insertion_functor; | |
1603 | friend class insertion_functor; | |
1604 | ||
1605 | class insertion_functor | |
1606 | { | |
1607 | Icont &icont_; | |
1608 | typedef typename Icont::iterator iiterator; | |
1609 | typedef typename Icont::const_iterator iconst_iterator; | |
1610 | const iconst_iterator prev_; | |
1611 | iiterator ret_; | |
1612 | ||
1613 | public: | |
1614 | insertion_functor(Icont &icont, typename Icont::const_iterator prev) | |
1615 | : icont_(icont), prev_(prev), ret_(prev.unconst()) | |
1616 | {} | |
1617 | ||
1618 | void operator()(Node &n) | |
1619 | { | |
1620 | ret_ = this->icont_.insert_after(prev_, n); | |
1621 | } | |
1622 | ||
1623 | iiterator inserted_first() const | |
1624 | { return ret_; } | |
1625 | }; | |
1626 | ||
1627 | //Functors for member algorithm defaults | |
1628 | struct value_less | |
1629 | { | |
1630 | bool operator()(const value_type &a, const value_type &b) const | |
1631 | { return a < b; } | |
1632 | }; | |
1633 | ||
1634 | struct value_equal | |
1635 | { | |
1636 | bool operator()(const value_type &a, const value_type &b) const | |
1637 | { return a == b; } | |
1638 | }; | |
1639 | ||
1640 | struct value_equal_to_this | |
1641 | { | |
1642 | explicit value_equal_to_this(const value_type &ref) | |
1643 | : m_ref(ref){} | |
1644 | ||
1645 | bool operator()(const value_type &val) const | |
1646 | { return m_ref == val; } | |
1647 | ||
1648 | const value_type &m_ref; | |
1649 | }; | |
1650 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1651 | }; | |
1652 | ||
1653 | }} | |
1654 | ||
1655 | #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1656 | ||
1657 | namespace boost { | |
1658 | ||
1659 | //!has_trivial_destructor_after_move<> == true_type | |
1660 | //!specialization for optimizations | |
1661 | template <class T, class Allocator> | |
1662 | struct has_trivial_destructor_after_move<boost::container::slist<T, Allocator> > | |
1663 | { | |
1664 | typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer; | |
1665 | static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value && | |
1666 | ::boost::has_trivial_destructor_after_move<pointer>::value; | |
1667 | }; | |
1668 | ||
1669 | namespace container { | |
1670 | ||
1671 | }} //namespace boost{ namespace container { | |
1672 | ||
1673 | #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED | |
1674 | ||
1675 | // Specialization of insert_iterator so that insertions will be constant | |
1676 | // time rather than linear time. | |
1677 | ||
1678 | #include <boost/move/detail/std_ns_begin.hpp> | |
1679 | BOOST_CONTAINER_DOC1ST(namespace std {, BOOST_MOVE_STD_NS_BEG) | |
1680 | ||
1681 | //! A specialization of insert_iterator | |
1682 | //! that works with slist | |
1683 | template <class T, class Allocator> | |
1684 | class insert_iterator<boost::container::slist<T, Allocator> > | |
1685 | { | |
1686 | private: | |
1687 | typedef boost::container::slist<T, Allocator> Container; | |
1688 | Container* container; | |
1689 | typename Container::iterator iter; | |
1690 | ||
1691 | public: | |
1692 | typedef Container container_type; | |
1693 | typedef output_iterator_tag iterator_category; | |
1694 | typedef void value_type; | |
1695 | typedef void difference_type; | |
1696 | typedef void pointer; | |
1697 | typedef void reference; | |
1698 | ||
1699 | insert_iterator(Container& x, | |
1700 | typename Container::iterator i, | |
1701 | bool is_previous = false) | |
1702 | : container(&x), iter(is_previous ? i : x.previous(i)){ } | |
1703 | ||
1704 | insert_iterator<Container>& | |
1705 | operator=(const typename Container::value_type& value) | |
1706 | { | |
1707 | iter = container->insert_after(iter, value); | |
1708 | return *this; | |
1709 | } | |
1710 | insert_iterator<Container>& operator*(){ return *this; } | |
1711 | insert_iterator<Container>& operator++(){ return *this; } | |
1712 | insert_iterator<Container>& operator++(int){ return *this; } | |
1713 | }; | |
1714 | ||
1715 | BOOST_CONTAINER_DOC1ST( }, BOOST_MOVE_STD_NS_END) | |
1716 | #include <boost/move/detail/std_ns_end.hpp> | |
1717 | ||
1718 | #include <boost/container/detail/config_end.hpp> | |
1719 | ||
1720 | #endif // BOOST_CONTAINER_SLIST_HPP |