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