annotate DEPENDENCIES/generic/include/boost/container/list.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@101 3 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
Chris@16 4 // Software License, Version 1.0. (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 //
Chris@16 7 // See http://www.boost.org/libs/container for documentation.
Chris@16 8 //
Chris@101 9 //////////////////////////////////////////////////////////////////////////////
Chris@16 10 #ifndef BOOST_CONTAINER_LIST_HPP
Chris@16 11 #define BOOST_CONTAINER_LIST_HPP
Chris@16 12
Chris@101 13 #ifndef BOOST_CONFIG_HPP
Chris@101 14 # include <boost/config.hpp>
Chris@101 15 #endif
Chris@101 16
Chris@101 17 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@16 18 # pragma once
Chris@16 19 #endif
Chris@16 20
Chris@16 21 #include <boost/container/detail/config_begin.hpp>
Chris@16 22 #include <boost/container/detail/workaround.hpp>
Chris@101 23
Chris@101 24 // container
Chris@16 25 #include <boost/container/container_fwd.hpp>
Chris@101 26 #include <boost/container/new_allocator.hpp> //new_allocator
Chris@101 27 #include <boost/container/throw_exception.hpp>
Chris@101 28 // container/detail
Chris@101 29 #include <boost/container/detail/algorithm.hpp>
Chris@101 30 #include <boost/container/detail/compare_functors.hpp>
Chris@101 31 #include <boost/container/detail/iterator.hpp>
Chris@16 32 #include <boost/container/detail/iterators.hpp>
Chris@16 33 #include <boost/container/detail/mpl.hpp>
Chris@101 34 #include <boost/container/detail/node_alloc_holder.hpp>
Chris@101 35 #include <boost/container/detail/version_type.hpp>
Chris@101 36 // move
Chris@101 37 #include <boost/move/utility_core.hpp>
Chris@16 38 #include <boost/move/iterator.hpp>
Chris@101 39 #include <boost/move/traits.hpp>
Chris@101 40 // move/detail
Chris@101 41 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@101 42 # include <boost/move/detail/fwd_macros.hpp>
Chris@101 43 #endif
Chris@16 44 #include <boost/move/detail/move_helpers.hpp>
Chris@101 45
Chris@101 46 // intrusive
Chris@16 47 #include <boost/intrusive/pointer_traits.hpp>
Chris@16 48 #include <boost/intrusive/list.hpp>
Chris@101 49 // other
Chris@16 50 #include <boost/assert.hpp>
Chris@101 51 // std
Chris@101 52 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 53 #include <initializer_list>
Chris@16 54 #endif
Chris@16 55
Chris@16 56 namespace boost {
Chris@16 57 namespace container {
Chris@16 58
Chris@101 59 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 60 namespace container_detail {
Chris@16 61
Chris@16 62 template<class VoidPointer>
Chris@16 63 struct list_hook
Chris@16 64 {
Chris@16 65 typedef typename container_detail::bi::make_list_base_hook
Chris@16 66 <container_detail::bi::void_pointer<VoidPointer>, container_detail::bi::link_mode<container_detail::bi::normal_link> >::type type;
Chris@16 67 };
Chris@16 68
Chris@16 69 template <class T, class VoidPointer>
Chris@16 70 struct list_node
Chris@16 71 : public list_hook<VoidPointer>::type
Chris@16 72 {
Chris@16 73 private:
Chris@16 74 list_node();
Chris@16 75
Chris@16 76 public:
Chris@16 77 typedef T value_type;
Chris@16 78 typedef typename list_hook<VoidPointer>::type hook_type;
Chris@16 79
Chris@16 80 T m_data;
Chris@16 81
Chris@16 82 T &get_data()
Chris@16 83 { return this->m_data; }
Chris@16 84
Chris@16 85 const T &get_data() const
Chris@16 86 { return this->m_data; }
Chris@16 87 };
Chris@16 88
Chris@101 89 template <class T, class VoidPointer>
Chris@101 90 struct iiterator_node_value_type< list_node<T,VoidPointer> > {
Chris@101 91 typedef T type;
Chris@101 92 };
Chris@101 93
Chris@16 94 template<class Allocator>
Chris@16 95 struct intrusive_list_type
Chris@16 96 {
Chris@16 97 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
Chris@16 98 typedef typename allocator_traits_type::value_type value_type;
Chris@16 99 typedef typename boost::intrusive::pointer_traits
Chris@16 100 <typename allocator_traits_type::pointer>::template
Chris@16 101 rebind_pointer<void>::type
Chris@16 102 void_pointer;
Chris@16 103 typedef typename container_detail::list_node
Chris@16 104 <value_type, void_pointer> node_type;
Chris@16 105 typedef typename container_detail::bi::make_list
Chris@16 106 < node_type
Chris@16 107 , container_detail::bi::base_hook<typename list_hook<void_pointer>::type>
Chris@16 108 , container_detail::bi::constant_time_size<true>
Chris@16 109 , container_detail::bi::size_type
Chris@16 110 <typename allocator_traits_type::size_type>
Chris@16 111 >::type container_type;
Chris@16 112 typedef container_type type ;
Chris@16 113 };
Chris@16 114
Chris@16 115 } //namespace container_detail {
Chris@101 116 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 117
Chris@16 118 //! A list is a doubly linked list. That is, it is a Sequence that supports both
Chris@16 119 //! forward and backward traversal, and (amortized) constant time insertion and
Chris@16 120 //! removal of elements at the beginning or the end, or in the middle. Lists have
Chris@16 121 //! the important property that insertion and splicing do not invalidate iterators
Chris@16 122 //! to list elements, and that even removal invalidates only the iterators that point
Chris@16 123 //! to the elements that are removed. The ordering of iterators may be changed
Chris@16 124 //! (that is, list<T>::iterator might have a different predecessor or successor
Chris@16 125 //! after a list operation than it did before), but the iterators themselves will
Chris@16 126 //! not be invalidated or made to point to different elements unless that invalidation
Chris@16 127 //! or mutation is explicit.
Chris@101 128 //!
Chris@101 129 //! \tparam T The type of object that is stored in the list
Chris@101 130 //! \tparam Allocator The allocator used for all internal memory management
Chris@16 131 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@101 132 template <class T, class Allocator = new_allocator<T> >
Chris@16 133 #else
Chris@16 134 template <class T, class Allocator>
Chris@16 135 #endif
Chris@16 136 class list
Chris@16 137 : protected container_detail::node_alloc_holder
Chris@16 138 <Allocator, typename container_detail::intrusive_list_type<Allocator>::type>
Chris@16 139 {
Chris@101 140 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 141 typedef typename
Chris@16 142 container_detail::intrusive_list_type<Allocator>::type Icont;
Chris@16 143 typedef container_detail::node_alloc_holder<Allocator, Icont> AllocHolder;
Chris@16 144 typedef typename AllocHolder::NodePtr NodePtr;
Chris@16 145 typedef typename AllocHolder::NodeAlloc NodeAlloc;
Chris@16 146 typedef typename AllocHolder::ValAlloc ValAlloc;
Chris@16 147 typedef typename AllocHolder::Node Node;
Chris@16 148 typedef container_detail::allocator_destroyer<NodeAlloc> Destroyer;
Chris@16 149 typedef typename AllocHolder::alloc_version alloc_version;
Chris@16 150 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
Chris@101 151 typedef boost::container::equal_to_value<Allocator> equal_to_value_type;
Chris@16 152
Chris@16 153 BOOST_COPYABLE_AND_MOVABLE(list)
Chris@16 154
Chris@101 155 typedef container_detail::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl;
Chris@101 156 typedef container_detail::iterator_from_iiterator<typename Icont::iterator, true> const_iterator_impl;
Chris@101 157 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 158
Chris@16 159 public:
Chris@16 160 //////////////////////////////////////////////
Chris@16 161 //
Chris@16 162 // types
Chris@16 163 //
Chris@16 164 //////////////////////////////////////////////
Chris@16 165
Chris@16 166 typedef T value_type;
Chris@16 167 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
Chris@16 168 typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
Chris@16 169 typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
Chris@16 170 typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
Chris@16 171 typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
Chris@16 172 typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
Chris@16 173 typedef Allocator allocator_type;
Chris@16 174 typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type;
Chris@16 175 typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
Chris@16 176 typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
Chris@101 177 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator;
Chris@101 178 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
Chris@16 179
Chris@16 180 //////////////////////////////////////////////
Chris@16 181 //
Chris@16 182 // construct/copy/destroy
Chris@16 183 //
Chris@16 184 //////////////////////////////////////////////
Chris@16 185
Chris@16 186 //! <b>Effects</b>: Default constructs a list.
Chris@16 187 //!
Chris@16 188 //! <b>Throws</b>: If allocator_type's default constructor throws.
Chris@16 189 //!
Chris@16 190 //! <b>Complexity</b>: Constant.
Chris@16 191 list()
Chris@16 192 : AllocHolder()
Chris@16 193 {}
Chris@16 194
Chris@16 195 //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
Chris@16 196 //!
Chris@16 197 //! <b>Throws</b>: Nothing
Chris@16 198 //!
Chris@16 199 //! <b>Complexity</b>: Constant.
Chris@101 200 explicit list(const allocator_type &a) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 201 : AllocHolder(a)
Chris@16 202 {}
Chris@16 203
Chris@101 204 //! <b>Effects</b>: Constructs a list
Chris@101 205 //! and inserts n value-initialized value_types.
Chris@16 206 //!
Chris@101 207 //! <b>Throws</b>: If allocator_type's default constructor
Chris@16 208 //! throws or T's default or copy constructor throws.
Chris@16 209 //!
Chris@16 210 //! <b>Complexity</b>: Linear to n.
Chris@16 211 explicit list(size_type n)
Chris@16 212 : AllocHolder(Allocator())
Chris@16 213 { this->resize(n); }
Chris@16 214
Chris@16 215 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
Chris@16 216 //! and inserts n copies of value.
Chris@16 217 //!
Chris@101 218 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 219 //! throws or T's default or copy constructor throws.
Chris@101 220 //!
Chris@101 221 //! <b>Complexity</b>: Linear to n.
Chris@101 222 list(size_type n, const allocator_type &a)
Chris@101 223 : AllocHolder(a)
Chris@101 224 { this->resize(n); }
Chris@101 225
Chris@101 226 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
Chris@101 227 //! and inserts n copies of value.
Chris@101 228 //!
Chris@101 229 //! <b>Throws</b>: If allocator_type's default constructor
Chris@16 230 //! throws or T's default or copy constructor throws.
Chris@16 231 //!
Chris@16 232 //! <b>Complexity</b>: Linear to n.
Chris@16 233 list(size_type n, const T& value, const Allocator& a = Allocator())
Chris@16 234 : AllocHolder(a)
Chris@16 235 { this->insert(this->cbegin(), n, value); }
Chris@16 236
Chris@16 237 //! <b>Effects</b>: Copy constructs a list.
Chris@16 238 //!
Chris@16 239 //! <b>Postcondition</b>: x == *this.
Chris@16 240 //!
Chris@101 241 //! <b>Throws</b>: If allocator_type's default constructor throws.
Chris@16 242 //!
Chris@16 243 //! <b>Complexity</b>: Linear to the elements x contains.
Chris@16 244 list(const list& x)
Chris@16 245 : AllocHolder(x)
Chris@16 246 { this->insert(this->cbegin(), x.begin(), x.end()); }
Chris@16 247
Chris@101 248 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
Chris@16 249 //!
Chris@16 250 //! <b>Throws</b>: If allocator_type's copy constructor throws.
Chris@16 251 //!
Chris@16 252 //! <b>Complexity</b>: Constant.
Chris@16 253 list(BOOST_RV_REF(list) x)
Chris@101 254 : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x))
Chris@16 255 {}
Chris@16 256
Chris@16 257 //! <b>Effects</b>: Copy constructs a list using the specified allocator.
Chris@16 258 //!
Chris@16 259 //! <b>Postcondition</b>: x == *this.
Chris@16 260 //!
Chris@16 261 //! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws.
Chris@16 262 //!
Chris@16 263 //! <b>Complexity</b>: Linear to the elements x contains.
Chris@16 264 list(const list& x, const allocator_type &a)
Chris@16 265 : AllocHolder(a)
Chris@16 266 { this->insert(this->cbegin(), x.begin(), x.end()); }
Chris@16 267
Chris@16 268 //! <b>Effects</b>: Move constructor sing the specified allocator.
Chris@101 269 //! Moves x's resources to *this.
Chris@16 270 //!
Chris@16 271 //! <b>Throws</b>: If allocation or value_type's copy constructor throws.
Chris@16 272 //!
Chris@16 273 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
Chris@16 274 list(BOOST_RV_REF(list) x, const allocator_type &a)
Chris@16 275 : AllocHolder(a)
Chris@16 276 {
Chris@16 277 if(this->node_alloc() == x.node_alloc()){
Chris@16 278 this->icont().swap(x.icont());
Chris@16 279 }
Chris@16 280 else{
Chris@101 281 this->insert(this->cbegin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end()));
Chris@16 282 }
Chris@16 283 }
Chris@16 284
Chris@16 285 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
Chris@16 286 //! and inserts a copy of the range [first, last) in the list.
Chris@16 287 //!
Chris@101 288 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 289 //! throws or T's constructor taking a dereferenced InIt throws.
Chris@16 290 //!
Chris@16 291 //! <b>Complexity</b>: Linear to the range [first, last).
Chris@16 292 template <class InpIt>
Chris@16 293 list(InpIt first, InpIt last, const Allocator &a = Allocator())
Chris@16 294 : AllocHolder(a)
Chris@16 295 { this->insert(this->cbegin(), first, last); }
Chris@16 296
Chris@101 297
Chris@101 298 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 299 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
Chris@101 300 //! and inserts a copy of the range [il.begin(), il.end()) in the list.
Chris@101 301 //!
Chris@101 302 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 303 //! throws or T's constructor taking a dereferenced
Chris@101 304 //! std::initializer_list iterator throws.
Chris@101 305 //!
Chris@101 306 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
Chris@101 307 list(std::initializer_list<value_type> il, const Allocator &a = Allocator())
Chris@101 308 : AllocHolder(a)
Chris@101 309 { this->insert(this->cbegin(), il.begin(), il.end()); }
Chris@101 310 #endif
Chris@101 311
Chris@16 312 //! <b>Effects</b>: Destroys the list. All stored values are destroyed
Chris@16 313 //! and used memory is deallocated.
Chris@16 314 //!
Chris@16 315 //! <b>Throws</b>: Nothing.
Chris@16 316 //!
Chris@16 317 //! <b>Complexity</b>: Linear to the number of elements.
Chris@101 318 ~list() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 319 {} //AllocHolder clears the list
Chris@16 320
Chris@16 321 //! <b>Effects</b>: Makes *this contain the same elements as x.
Chris@16 322 //!
Chris@16 323 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
Chris@16 324 //! of each of x's elements.
Chris@16 325 //!
Chris@16 326 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 327 //!
Chris@16 328 //! <b>Complexity</b>: Linear to the number of elements in x.
Chris@16 329 list& operator=(BOOST_COPY_ASSIGN_REF(list) x)
Chris@16 330 {
Chris@16 331 if (&x != this){
Chris@16 332 NodeAlloc &this_alloc = this->node_alloc();
Chris@16 333 const NodeAlloc &x_alloc = x.node_alloc();
Chris@16 334 container_detail::bool_<allocator_traits_type::
Chris@16 335 propagate_on_container_copy_assignment::value> flag;
Chris@16 336 if(flag && this_alloc != x_alloc){
Chris@16 337 this->clear();
Chris@16 338 }
Chris@16 339 this->AllocHolder::copy_assign_alloc(x);
Chris@16 340 this->assign(x.begin(), x.end());
Chris@16 341 }
Chris@16 342 return *this;
Chris@16 343 }
Chris@16 344
Chris@101 345 //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
Chris@16 346 //!
Chris@16 347 //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
Chris@16 348 //! before the function.
Chris@16 349 //!
Chris@101 350 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
Chris@101 351 //! is false and (allocation throws or value_type's move constructor throws)
Chris@16 352 //!
Chris@101 353 //! <b>Complexity</b>: Constant if allocator_traits_type::
Chris@101 354 //! propagate_on_container_move_assignment is true or
Chris@101 355 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
Chris@16 356 list& operator=(BOOST_RV_REF(list) x)
Chris@101 357 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
Chris@101 358 || allocator_traits_type::is_always_equal::value)
Chris@16 359 {
Chris@101 360 BOOST_ASSERT(this != &x);
Chris@101 361 NodeAlloc &this_alloc = this->node_alloc();
Chris@101 362 NodeAlloc &x_alloc = x.node_alloc();
Chris@101 363 const bool propagate_alloc = allocator_traits_type::
Chris@101 364 propagate_on_container_move_assignment::value;
Chris@101 365 const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
Chris@101 366 //Resources can be transferred if both allocators are
Chris@101 367 //going to be equal after this function (either propagated or already equal)
Chris@101 368 if(propagate_alloc || allocators_equal){
Chris@101 369 //Destroy
Chris@101 370 this->clear();
Chris@101 371 //Move allocator if needed
Chris@101 372 this->AllocHolder::move_assign_alloc(x);
Chris@101 373 //Obtain resources
Chris@101 374 this->icont() = boost::move(x.icont());
Chris@101 375 }
Chris@101 376 //Else do a one by one move
Chris@101 377 else{
Chris@101 378 this->assign( boost::make_move_iterator(x.begin())
Chris@101 379 , boost::make_move_iterator(x.end()));
Chris@16 380 }
Chris@16 381 return *this;
Chris@16 382 }
Chris@16 383
Chris@101 384 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 385 //! <b>Effects</b>: Makes *this contain the same elements as il.
Chris@101 386 //!
Chris@101 387 //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
Chris@101 388 //! of each of x's elements.
Chris@101 389 //!
Chris@101 390 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@101 391 //!
Chris@101 392 //! <b>Complexity</b>: Linear to the number of elements in x.
Chris@101 393 list& operator=(std::initializer_list<value_type> il)
Chris@101 394 {
Chris@101 395 assign(il.begin(), il.end());
Chris@101 396 return *this;
Chris@101 397 }
Chris@101 398 #endif
Chris@101 399
Chris@16 400 //! <b>Effects</b>: Assigns the n copies of val to *this.
Chris@16 401 //!
Chris@16 402 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 403 //!
Chris@16 404 //! <b>Complexity</b>: Linear to n.
Chris@16 405 void assign(size_type n, const T& val)
Chris@16 406 {
Chris@16 407 typedef constant_iterator<value_type, difference_type> cvalue_iterator;
Chris@16 408 return this->assign(cvalue_iterator(val, n), cvalue_iterator());
Chris@16 409 }
Chris@16 410
Chris@16 411 //! <b>Effects</b>: Assigns the the range [first, last) to *this.
Chris@16 412 //!
Chris@16 413 //! <b>Throws</b>: If memory allocation throws or
Chris@16 414 //! T's constructor from dereferencing InpIt throws.
Chris@16 415 //!
Chris@16 416 //! <b>Complexity</b>: Linear to n.
Chris@16 417 template <class InpIt>
Chris@16 418 void assign(InpIt first, InpIt last
Chris@16 419 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 420 , typename container_detail::enable_if_c
Chris@16 421 < !container_detail::is_convertible<InpIt, size_type>::value
Chris@16 422 >::type * = 0
Chris@16 423 #endif
Chris@16 424 )
Chris@16 425 {
Chris@16 426 iterator first1 = this->begin();
Chris@16 427 const iterator last1 = this->end();
Chris@16 428 for ( ; first1 != last1 && first != last; ++first1, ++first)
Chris@16 429 *first1 = *first;
Chris@16 430 if (first == last)
Chris@16 431 this->erase(first1, last1);
Chris@16 432 else{
Chris@16 433 this->insert(last1, first, last);
Chris@16 434 }
Chris@16 435 }
Chris@16 436
Chris@101 437 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 438 //! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
Chris@101 439 //!
Chris@101 440 //! <b>Throws</b>: If memory allocation throws or
Chris@101 441 //! T's constructor from dereferencing std::initializer_list iterator throws.
Chris@101 442 //!
Chris@101 443 //! <b>Complexity</b>: Linear to n.
Chris@101 444 void assign(std::initializer_list<value_type> il)
Chris@101 445 { assign(il.begin(), il.end()); }
Chris@101 446 #endif
Chris@101 447
Chris@16 448 //! <b>Effects</b>: Returns a copy of the internal allocator.
Chris@16 449 //!
Chris@16 450 //! <b>Throws</b>: If allocator's copy constructor throws.
Chris@16 451 //!
Chris@16 452 //! <b>Complexity</b>: Constant.
Chris@101 453 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 454 { return allocator_type(this->node_alloc()); }
Chris@16 455
Chris@16 456 //! <b>Effects</b>: Returns a reference to the internal allocator.
Chris@16 457 //!
Chris@16 458 //! <b>Throws</b>: Nothing
Chris@16 459 //!
Chris@16 460 //! <b>Complexity</b>: Constant.
Chris@16 461 //!
Chris@16 462 //! <b>Note</b>: Non-standard extension.
Chris@101 463 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 464 { return this->node_alloc(); }
Chris@16 465
Chris@16 466 //! <b>Effects</b>: Returns a reference to the internal allocator.
Chris@16 467 //!
Chris@16 468 //! <b>Throws</b>: Nothing
Chris@16 469 //!
Chris@16 470 //! <b>Complexity</b>: Constant.
Chris@16 471 //!
Chris@16 472 //! <b>Note</b>: Non-standard extension.
Chris@101 473 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 474 { return this->node_alloc(); }
Chris@16 475
Chris@16 476 //////////////////////////////////////////////
Chris@16 477 //
Chris@16 478 // iterators
Chris@16 479 //
Chris@16 480 //////////////////////////////////////////////
Chris@16 481
Chris@16 482 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
Chris@16 483 //!
Chris@16 484 //! <b>Throws</b>: Nothing.
Chris@16 485 //!
Chris@16 486 //! <b>Complexity</b>: Constant.
Chris@101 487 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 488 { return iterator(this->icont().begin()); }
Chris@16 489
Chris@16 490 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
Chris@16 491 //!
Chris@16 492 //! <b>Throws</b>: Nothing.
Chris@16 493 //!
Chris@16 494 //! <b>Complexity</b>: Constant.
Chris@101 495 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 496 { return this->cbegin(); }
Chris@16 497
Chris@16 498 //! <b>Effects</b>: Returns an iterator to the end of the list.
Chris@16 499 //!
Chris@16 500 //! <b>Throws</b>: Nothing.
Chris@16 501 //!
Chris@16 502 //! <b>Complexity</b>: Constant.
Chris@101 503 iterator end() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 504 { return iterator(this->icont().end()); }
Chris@16 505
Chris@16 506 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
Chris@16 507 //!
Chris@16 508 //! <b>Throws</b>: Nothing.
Chris@16 509 //!
Chris@16 510 //! <b>Complexity</b>: Constant.
Chris@101 511 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 512 { return this->cend(); }
Chris@16 513
Chris@16 514 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
Chris@16 515 //! of the reversed list.
Chris@16 516 //!
Chris@16 517 //! <b>Throws</b>: Nothing.
Chris@16 518 //!
Chris@16 519 //! <b>Complexity</b>: Constant.
Chris@101 520 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 521 { return reverse_iterator(end()); }
Chris@16 522
Chris@16 523 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
Chris@16 524 //! of the reversed list.
Chris@16 525 //!
Chris@16 526 //! <b>Throws</b>: Nothing.
Chris@16 527 //!
Chris@16 528 //! <b>Complexity</b>: Constant.
Chris@101 529 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 530 { return this->crbegin(); }
Chris@16 531
Chris@16 532 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
Chris@16 533 //! of the reversed list.
Chris@16 534 //!
Chris@16 535 //! <b>Throws</b>: Nothing.
Chris@16 536 //!
Chris@16 537 //! <b>Complexity</b>: Constant.
Chris@101 538 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 539 { return reverse_iterator(begin()); }
Chris@16 540
Chris@16 541 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
Chris@16 542 //! of the reversed list.
Chris@16 543 //!
Chris@16 544 //! <b>Throws</b>: Nothing.
Chris@16 545 //!
Chris@16 546 //! <b>Complexity</b>: Constant.
Chris@101 547 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 548 { return this->crend(); }
Chris@16 549
Chris@16 550 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
Chris@16 551 //!
Chris@16 552 //! <b>Throws</b>: Nothing.
Chris@16 553 //!
Chris@16 554 //! <b>Complexity</b>: Constant.
Chris@101 555 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 556 { return const_iterator(this->non_const_icont().begin()); }
Chris@16 557
Chris@16 558 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
Chris@16 559 //!
Chris@16 560 //! <b>Throws</b>: Nothing.
Chris@16 561 //!
Chris@16 562 //! <b>Complexity</b>: Constant.
Chris@101 563 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 564 { return const_iterator(this->non_const_icont().end()); }
Chris@16 565
Chris@16 566 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
Chris@16 567 //! of the reversed list.
Chris@16 568 //!
Chris@16 569 //! <b>Throws</b>: Nothing.
Chris@16 570 //!
Chris@16 571 //! <b>Complexity</b>: Constant.
Chris@101 572 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 573 { return const_reverse_iterator(this->cend()); }
Chris@16 574
Chris@16 575 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
Chris@16 576 //! of the reversed list.
Chris@16 577 //!
Chris@16 578 //! <b>Throws</b>: Nothing.
Chris@16 579 //!
Chris@16 580 //! <b>Complexity</b>: Constant.
Chris@101 581 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 582 { return const_reverse_iterator(this->cbegin()); }
Chris@16 583
Chris@16 584 //////////////////////////////////////////////
Chris@16 585 //
Chris@16 586 // capacity
Chris@16 587 //
Chris@16 588 //////////////////////////////////////////////
Chris@16 589
Chris@16 590 //! <b>Effects</b>: Returns true if the list contains no elements.
Chris@16 591 //!
Chris@16 592 //! <b>Throws</b>: Nothing.
Chris@16 593 //!
Chris@16 594 //! <b>Complexity</b>: Constant.
Chris@101 595 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 596 { return !this->size(); }
Chris@16 597
Chris@16 598 //! <b>Effects</b>: Returns the number of the elements contained in the list.
Chris@16 599 //!
Chris@16 600 //! <b>Throws</b>: Nothing.
Chris@16 601 //!
Chris@16 602 //! <b>Complexity</b>: Constant.
Chris@101 603 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 604 { return this->icont().size(); }
Chris@16 605
Chris@16 606 //! <b>Effects</b>: Returns the largest possible size of the list.
Chris@16 607 //!
Chris@16 608 //! <b>Throws</b>: Nothing.
Chris@16 609 //!
Chris@16 610 //! <b>Complexity</b>: Constant.
Chris@101 611 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 612 { return AllocHolder::max_size(); }
Chris@16 613
Chris@16 614 //! <b>Effects</b>: Inserts or erases elements at the end such that
Chris@16 615 //! the size becomes n. New elements are value initialized.
Chris@16 616 //!
Chris@16 617 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
Chris@16 618 //!
Chris@16 619 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
Chris@16 620 void resize(size_type new_size)
Chris@16 621 {
Chris@16 622 if(!priv_try_shrink(new_size)){
Chris@16 623 typedef value_init_construct_iterator<value_type, difference_type> value_init_iterator;
Chris@16 624 this->insert(this->cend(), value_init_iterator(new_size - this->size()), value_init_iterator());
Chris@16 625 }
Chris@16 626 }
Chris@16 627
Chris@16 628 //! <b>Effects</b>: Inserts or erases elements at the end such that
Chris@16 629 //! the size becomes n. New elements are copy constructed from x.
Chris@16 630 //!
Chris@16 631 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
Chris@16 632 //!
Chris@16 633 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
Chris@16 634 void resize(size_type new_size, const T& x)
Chris@16 635 {
Chris@16 636 if(!priv_try_shrink(new_size)){
Chris@16 637 this->insert(this->cend(), new_size - this->size(), x);
Chris@16 638 }
Chris@16 639 }
Chris@16 640
Chris@16 641 //////////////////////////////////////////////
Chris@16 642 //
Chris@16 643 // element access
Chris@16 644 //
Chris@16 645 //////////////////////////////////////////////
Chris@16 646
Chris@16 647 //! <b>Requires</b>: !empty()
Chris@16 648 //!
Chris@16 649 //! <b>Effects</b>: Returns a reference to the first element
Chris@16 650 //! from the beginning of the container.
Chris@16 651 //!
Chris@16 652 //! <b>Throws</b>: Nothing.
Chris@16 653 //!
Chris@16 654 //! <b>Complexity</b>: Constant.
Chris@101 655 reference front() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 656 { return *this->begin(); }
Chris@16 657
Chris@16 658 //! <b>Requires</b>: !empty()
Chris@16 659 //!
Chris@16 660 //! <b>Effects</b>: Returns a const reference to the first element
Chris@16 661 //! from the beginning of the container.
Chris@16 662 //!
Chris@16 663 //! <b>Throws</b>: Nothing.
Chris@16 664 //!
Chris@16 665 //! <b>Complexity</b>: Constant.
Chris@101 666 const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 667 { return *this->begin(); }
Chris@16 668
Chris@16 669 //! <b>Requires</b>: !empty()
Chris@16 670 //!
Chris@16 671 //! <b>Effects</b>: Returns a reference to the first element
Chris@16 672 //! from the beginning of the container.
Chris@16 673 //!
Chris@16 674 //! <b>Throws</b>: Nothing.
Chris@16 675 //!
Chris@16 676 //! <b>Complexity</b>: Constant.
Chris@101 677 reference back() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 678 { return *(--this->end()); }
Chris@16 679
Chris@16 680 //! <b>Requires</b>: !empty()
Chris@16 681 //!
Chris@16 682 //! <b>Effects</b>: Returns a const reference to the first element
Chris@16 683 //! from the beginning of the container.
Chris@16 684 //!
Chris@16 685 //! <b>Throws</b>: Nothing.
Chris@16 686 //!
Chris@16 687 //! <b>Complexity</b>: Constant.
Chris@101 688 const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 689 { return *(--this->end()); }
Chris@16 690
Chris@16 691 //////////////////////////////////////////////
Chris@16 692 //
Chris@16 693 // modifiers
Chris@16 694 //
Chris@16 695 //////////////////////////////////////////////
Chris@16 696
Chris@101 697 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 698
Chris@16 699 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@16 700 //! std::forward<Args>(args)... in the end of the list.
Chris@16 701 //!
Chris@16 702 //! <b>Throws</b>: If memory allocation throws or
Chris@16 703 //! T's in-place constructor throws.
Chris@16 704 //!
Chris@16 705 //! <b>Complexity</b>: Constant
Chris@16 706 template <class... Args>
Chris@101 707 void emplace_back(BOOST_FWD_REF(Args)... args)
Chris@16 708 { this->emplace(this->cend(), boost::forward<Args>(args)...); }
Chris@16 709
Chris@16 710 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@16 711 //! std::forward<Args>(args)... in the beginning of the list.
Chris@16 712 //!
Chris@16 713 //! <b>Throws</b>: If memory allocation throws or
Chris@16 714 //! T's in-place constructor throws.
Chris@16 715 //!
Chris@16 716 //! <b>Complexity</b>: Constant
Chris@16 717 template <class... Args>
Chris@101 718 void emplace_front(BOOST_FWD_REF(Args)... args)
Chris@16 719 { this->emplace(this->cbegin(), boost::forward<Args>(args)...); }
Chris@16 720
Chris@16 721 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@16 722 //! std::forward<Args>(args)... before p.
Chris@16 723 //!
Chris@16 724 //! <b>Throws</b>: If memory allocation throws or
Chris@16 725 //! T's in-place constructor throws.
Chris@16 726 //!
Chris@16 727 //! <b>Complexity</b>: Constant
Chris@16 728 template <class... Args>
Chris@101 729 iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args)
Chris@16 730 {
Chris@16 731 NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...));
Chris@16 732 return iterator(this->icont().insert(p.get(), *pnode));
Chris@16 733 }
Chris@16 734
Chris@101 735 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@16 736
Chris@101 737 #define BOOST_CONTAINER_LIST_EMPLACE_CODE(N) \
Chris@101 738 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
Chris@101 739 void emplace_back(BOOST_MOVE_UREF##N)\
Chris@101 740 { this->emplace(this->cend() BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
Chris@101 741 \
Chris@101 742 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
Chris@101 743 void emplace_front(BOOST_MOVE_UREF##N)\
Chris@101 744 { this->emplace(this->cbegin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\
Chris@101 745 \
Chris@101 746 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
Chris@101 747 iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
Chris@101 748 {\
Chris@101 749 NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\
Chris@101 750 return iterator(this->icont().insert(p.get(), *pnode));\
Chris@101 751 }\
Chris@101 752 //
Chris@101 753 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_LIST_EMPLACE_CODE)
Chris@101 754 #undef BOOST_CONTAINER_LIST_EMPLACE_CODE
Chris@16 755
Chris@101 756 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@16 757
Chris@16 758 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 759 //! <b>Effects</b>: Inserts a copy of x at the beginning of the list.
Chris@16 760 //!
Chris@16 761 //! <b>Throws</b>: If memory allocation throws or
Chris@16 762 //! T's copy constructor throws.
Chris@16 763 //!
Chris@16 764 //! <b>Complexity</b>: Amortized constant time.
Chris@16 765 void push_front(const T &x);
Chris@16 766
Chris@16 767 //! <b>Effects</b>: Constructs a new element in the beginning of the list
Chris@101 768 //! and moves the resources of x to this new element.
Chris@16 769 //!
Chris@16 770 //! <b>Throws</b>: If memory allocation throws.
Chris@16 771 //!
Chris@16 772 //! <b>Complexity</b>: Amortized constant time.
Chris@16 773 void push_front(T &&x);
Chris@16 774 #else
Chris@16 775 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
Chris@16 776 #endif
Chris@16 777
Chris@16 778 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 779 //! <b>Effects</b>: Inserts a copy of x at the end of the list.
Chris@16 780 //!
Chris@16 781 //! <b>Throws</b>: If memory allocation throws or
Chris@16 782 //! T's copy constructor throws.
Chris@16 783 //!
Chris@16 784 //! <b>Complexity</b>: Amortized constant time.
Chris@16 785 void push_back(const T &x);
Chris@16 786
Chris@16 787 //! <b>Effects</b>: Constructs a new element in the end of the list
Chris@101 788 //! and moves the resources of x to this new element.
Chris@16 789 //!
Chris@16 790 //! <b>Throws</b>: If memory allocation throws.
Chris@16 791 //!
Chris@16 792 //! <b>Complexity</b>: Amortized constant time.
Chris@16 793 void push_back(T &&x);
Chris@16 794 #else
Chris@16 795 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
Chris@16 796 #endif
Chris@16 797
Chris@16 798 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@101 799 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 800 //!
Chris@101 801 //! <b>Effects</b>: Insert a copy of x before p.
Chris@16 802 //!
Chris@16 803 //! <b>Returns</b>: an iterator to the inserted element.
Chris@16 804 //!
Chris@16 805 //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
Chris@16 806 //!
Chris@16 807 //! <b>Complexity</b>: Amortized constant time.
Chris@101 808 iterator insert(const_iterator p, const T &x);
Chris@16 809
Chris@101 810 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 811 //!
Chris@101 812 //! <b>Effects</b>: Insert a new element before p with x's resources.
Chris@16 813 //!
Chris@16 814 //! <b>Returns</b>: an iterator to the inserted element.
Chris@16 815 //!
Chris@16 816 //! <b>Throws</b>: If memory allocation throws.
Chris@16 817 //!
Chris@16 818 //! <b>Complexity</b>: Amortized constant time.
Chris@101 819 iterator insert(const_iterator p, T &&x);
Chris@16 820 #else
Chris@16 821 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
Chris@16 822 #endif
Chris@16 823
Chris@16 824 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 825 //!
Chris@16 826 //! <b>Effects</b>: Inserts n copies of x before p.
Chris@16 827 //!
Chris@16 828 //! <b>Returns</b>: an iterator to the first inserted element or p if n is 0.
Chris@16 829 //!
Chris@16 830 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 831 //!
Chris@16 832 //! <b>Complexity</b>: Linear to n.
Chris@16 833 iterator insert(const_iterator p, size_type n, const T& x)
Chris@16 834 {
Chris@16 835 typedef constant_iterator<value_type, difference_type> cvalue_iterator;
Chris@16 836 return this->insert(p, cvalue_iterator(x, n), cvalue_iterator());
Chris@16 837 }
Chris@16 838
Chris@16 839 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 840 //!
Chris@16 841 //! <b>Effects</b>: Insert a copy of the [first, last) range before p.
Chris@16 842 //!
Chris@16 843 //! <b>Returns</b>: an iterator to the first inserted element or p if first == last.
Chris@16 844 //!
Chris@16 845 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
Chris@16 846 //! dereferenced InpIt throws.
Chris@16 847 //!
Chris@101 848 //! <b>Complexity</b>: Linear to distance [first, last).
Chris@16 849 template <class InpIt>
Chris@16 850 iterator insert(const_iterator p, InpIt first, InpIt last
Chris@16 851 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 852 , typename container_detail::enable_if_c
Chris@16 853 < !container_detail::is_convertible<InpIt, size_type>::value
Chris@16 854 && (container_detail::is_input_iterator<InpIt>::value
Chris@101 855 || container_detail::is_same<alloc_version, version_1>::value
Chris@16 856 )
Chris@16 857 >::type * = 0
Chris@16 858 #endif
Chris@16 859 )
Chris@16 860 {
Chris@16 861 const typename Icont::iterator ipos(p.get());
Chris@16 862 iterator ret_it(ipos);
Chris@16 863 if(first != last){
Chris@16 864 ret_it = iterator(this->icont().insert(ipos, *this->create_node_from_it(first)));
Chris@16 865 ++first;
Chris@16 866 }
Chris@16 867 for (; first != last; ++first){
Chris@16 868 this->icont().insert(ipos, *this->create_node_from_it(first));
Chris@16 869 }
Chris@16 870 return ret_it;
Chris@16 871 }
Chris@16 872
Chris@16 873 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 874 template <class FwdIt>
Chris@16 875 iterator insert(const_iterator p, FwdIt first, FwdIt last
Chris@16 876 , typename container_detail::enable_if_c
Chris@16 877 < !container_detail::is_convertible<FwdIt, size_type>::value
Chris@16 878 && !(container_detail::is_input_iterator<FwdIt>::value
Chris@101 879 || container_detail::is_same<alloc_version, version_1>::value
Chris@16 880 )
Chris@16 881 >::type * = 0
Chris@16 882 )
Chris@16 883 {
Chris@16 884 //Optimized allocation and construction
Chris@16 885 insertion_functor func(this->icont(), p.get());
Chris@16 886 iterator before_p(p.get());
Chris@16 887 --before_p;
Chris@101 888 this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func);
Chris@16 889 return ++before_p;
Chris@16 890 }
Chris@16 891 #endif
Chris@16 892
Chris@101 893 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 894 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@101 895 //!
Chris@101 896 //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
Chris@101 897 //!
Chris@101 898 //! <b>Returns</b>: an iterator to the first inserted element or p if if.begin() == il.end().
Chris@101 899 //!
Chris@101 900 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
Chris@101 901 //! dereferenced std::initializer_list iterator throws.
Chris@101 902 //!
Chris@101 903 //! <b>Complexity</b>: Linear to distance [il.begin(), il.end()).
Chris@101 904 iterator insert(const_iterator p, std::initializer_list<value_type> il)
Chris@101 905 { return insert(p, il.begin(), il.end()); }
Chris@101 906 #endif
Chris@101 907
Chris@16 908 //! <b>Effects</b>: Removes the first element from the list.
Chris@16 909 //!
Chris@16 910 //! <b>Throws</b>: Nothing.
Chris@16 911 //!
Chris@16 912 //! <b>Complexity</b>: Amortized constant time.
Chris@101 913 void pop_front() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 914 { this->erase(this->cbegin()); }
Chris@16 915
Chris@16 916 //! <b>Effects</b>: Removes the last element from the list.
Chris@16 917 //!
Chris@16 918 //! <b>Throws</b>: Nothing.
Chris@16 919 //!
Chris@16 920 //! <b>Complexity</b>: Amortized constant time.
Chris@101 921 void pop_back() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 922 { const_iterator tmp = this->cend(); this->erase(--tmp); }
Chris@16 923
Chris@16 924 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 925 //!
Chris@16 926 //! <b>Effects</b>: Erases the element at p p.
Chris@16 927 //!
Chris@16 928 //! <b>Throws</b>: Nothing.
Chris@16 929 //!
Chris@16 930 //! <b>Complexity</b>: Amortized constant time.
Chris@101 931 iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 932 { return iterator(this->icont().erase_and_dispose(p.get(), Destroyer(this->node_alloc()))); }
Chris@16 933
Chris@16 934 //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
Chris@16 935 //!
Chris@16 936 //! <b>Effects</b>: Erases the elements pointed by [first, last).
Chris@16 937 //!
Chris@16 938 //! <b>Throws</b>: Nothing.
Chris@16 939 //!
Chris@16 940 //! <b>Complexity</b>: Linear to the distance between first and last.
Chris@101 941 iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 942 { return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version())); }
Chris@16 943
Chris@16 944 //! <b>Effects</b>: Swaps the contents of *this and x.
Chris@16 945 //!
Chris@16 946 //! <b>Throws</b>: Nothing.
Chris@16 947 //!
Chris@16 948 //! <b>Complexity</b>: Constant.
Chris@16 949 void swap(list& x)
Chris@101 950 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
Chris@101 951 || allocator_traits_type::is_always_equal::value)
Chris@16 952 { AllocHolder::swap(x); }
Chris@16 953
Chris@16 954 //! <b>Effects</b>: Erases all the elements of the list.
Chris@16 955 //!
Chris@16 956 //! <b>Throws</b>: Nothing.
Chris@16 957 //!
Chris@16 958 //! <b>Complexity</b>: Linear to the number of elements in the list.
Chris@101 959 void clear() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 960 { AllocHolder::clear(alloc_version()); }
Chris@16 961
Chris@16 962 //////////////////////////////////////////////
Chris@16 963 //
Chris@16 964 // slist operations
Chris@16 965 //
Chris@16 966 //////////////////////////////////////////////
Chris@16 967
Chris@16 968 //! <b>Requires</b>: p must point to an element contained
Chris@16 969 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
Chris@16 970 //!
Chris@16 971 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
Chris@16 972 //! the element pointed by p. No destructors or copy constructors are called.
Chris@16 973 //!
Chris@16 974 //! <b>Throws</b>: Nothing
Chris@16 975 //!
Chris@16 976 //! <b>Complexity</b>: Constant.
Chris@16 977 //!
Chris@16 978 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
Chris@16 979 //! this list. Iterators of this list and all the references are not invalidated.
Chris@101 980 void splice(const_iterator p, list& x) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 981 {
Chris@16 982 BOOST_ASSERT(this != &x);
Chris@16 983 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
Chris@16 984 this->icont().splice(p.get(), x.icont());
Chris@16 985 }
Chris@16 986
Chris@16 987 //! <b>Requires</b>: p must point to an element contained
Chris@16 988 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
Chris@16 989 //!
Chris@16 990 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
Chris@16 991 //! the element pointed by p. No destructors or copy constructors are called.
Chris@16 992 //!
Chris@16 993 //! <b>Throws</b>: Nothing
Chris@16 994 //!
Chris@16 995 //! <b>Complexity</b>: Constant.
Chris@16 996 //!
Chris@16 997 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
Chris@16 998 //! this list. Iterators of this list and all the references are not invalidated.
Chris@101 999 void splice(const_iterator p, BOOST_RV_REF(list) x) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1000 { this->splice(p, static_cast<list&>(x)); }
Chris@16 1001
Chris@16 1002 //! <b>Requires</b>: p must point to an element contained
Chris@16 1003 //! by this list. i must point to an element contained in list x.
Chris@16 1004 //! this' allocator and x's allocator shall compare equal
Chris@16 1005 //!
Chris@16 1006 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
Chris@16 1007 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1008 //! If p == i or p == ++i, this function is a null operation.
Chris@16 1009 //!
Chris@16 1010 //! <b>Throws</b>: Nothing
Chris@16 1011 //!
Chris@16 1012 //! <b>Complexity</b>: Constant.
Chris@16 1013 //!
Chris@16 1014 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1015 //! list. Iterators of this list and all the references are not invalidated.
Chris@101 1016 void splice(const_iterator p, list &x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1017 {
Chris@16 1018 //BOOST_ASSERT(this != &x);
Chris@16 1019 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
Chris@16 1020 this->icont().splice(p.get(), x.icont(), i.get());
Chris@16 1021 }
Chris@16 1022
Chris@16 1023 //! <b>Requires</b>: p must point to an element contained
Chris@16 1024 //! by this list. i must point to an element contained in list x.
Chris@16 1025 //! this' allocator and x's allocator shall compare equal.
Chris@16 1026 //!
Chris@16 1027 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
Chris@16 1028 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1029 //! If p == i or p == ++i, this function is a null operation.
Chris@16 1030 //!
Chris@16 1031 //! <b>Throws</b>: Nothing
Chris@16 1032 //!
Chris@16 1033 //! <b>Complexity</b>: Constant.
Chris@16 1034 //!
Chris@16 1035 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1036 //! list. Iterators of this list and all the references are not invalidated.
Chris@101 1037 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1038 { this->splice(p, static_cast<list&>(x), i); }
Chris@16 1039
Chris@16 1040 //! <b>Requires</b>: p must point to an element contained
Chris@16 1041 //! by this list. first and last must point to elements contained in list x.
Chris@16 1042 //! this' allocator and x's allocator shall compare equal
Chris@16 1043 //!
Chris@16 1044 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
Chris@16 1045 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1046 //!
Chris@16 1047 //! <b>Throws</b>: Nothing
Chris@16 1048 //!
Chris@16 1049 //! <b>Complexity</b>: Linear to the number of elements transferred.
Chris@16 1050 //!
Chris@16 1051 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1052 //! list. Iterators of this list and all the references are not invalidated.
Chris@101 1053 void splice(const_iterator p, list &x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1054 {
Chris@16 1055 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
Chris@16 1056 this->icont().splice(p.get(), x.icont(), first.get(), last.get());
Chris@16 1057 }
Chris@16 1058
Chris@16 1059 //! <b>Requires</b>: p must point to an element contained
Chris@16 1060 //! by this list. first and last must point to elements contained in list x.
Chris@16 1061 //! this' allocator and x's allocator shall compare equal.
Chris@16 1062 //!
Chris@16 1063 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
Chris@16 1064 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1065 //!
Chris@16 1066 //! <b>Throws</b>: Nothing
Chris@16 1067 //!
Chris@16 1068 //! <b>Complexity</b>: Linear to the number of elements transferred.
Chris@16 1069 //!
Chris@16 1070 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1071 //! list. Iterators of this list and all the references are not invalidated.
Chris@101 1072 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1073 { this->splice(p, static_cast<list&>(x), first, last); }
Chris@16 1074
Chris@16 1075 //! <b>Requires</b>: p must point to an element contained
Chris@16 1076 //! by this list. first and last must point to elements contained in list x.
Chris@101 1077 //! n == distance(first, last). this' allocator and x's allocator shall compare equal
Chris@16 1078 //!
Chris@16 1079 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
Chris@16 1080 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1081 //!
Chris@16 1082 //! <b>Throws</b>: Nothing
Chris@16 1083 //!
Chris@16 1084 //! <b>Complexity</b>: Constant.
Chris@16 1085 //!
Chris@16 1086 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1087 //! list. Iterators of this list and all the references are not invalidated.
Chris@16 1088 //!
Chris@16 1089 //! <b>Note</b>: Non-standard extension
Chris@101 1090 void splice(const_iterator p, list &x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1091 {
Chris@16 1092 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
Chris@16 1093 this->icont().splice(p.get(), x.icont(), first.get(), last.get(), n);
Chris@16 1094 }
Chris@16 1095
Chris@16 1096 //! <b>Requires</b>: p must point to an element contained
Chris@16 1097 //! by this list. first and last must point to elements contained in list x.
Chris@101 1098 //! n == distance(first, last). this' allocator and x's allocator shall compare equal
Chris@16 1099 //!
Chris@16 1100 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
Chris@16 1101 //! before the the element pointed by p. No destructors or copy constructors are called.
Chris@16 1102 //!
Chris@16 1103 //! <b>Throws</b>: Nothing
Chris@16 1104 //!
Chris@16 1105 //! <b>Complexity</b>: Constant.
Chris@16 1106 //!
Chris@16 1107 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
Chris@16 1108 //! list. Iterators of this list and all the references are not invalidated.
Chris@16 1109 //!
Chris@16 1110 //! <b>Note</b>: Non-standard extension
Chris@101 1111 void splice(const_iterator p, BOOST_RV_REF(list) x, const_iterator first, const_iterator last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1112 { this->splice(p, static_cast<list&>(x), first, last, n); }
Chris@16 1113
Chris@16 1114 //! <b>Effects</b>: Removes all the elements that compare equal to value.
Chris@16 1115 //!
Chris@16 1116 //! <b>Throws</b>: If comparison throws.
Chris@16 1117 //!
Chris@16 1118 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
Chris@16 1119 //!
Chris@16 1120 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
Chris@16 1121 //! and iterators to elements that are not removed remain valid.
Chris@16 1122 void remove(const T& value)
Chris@101 1123 { this->remove_if(equal_to_value_type(value)); }
Chris@16 1124
Chris@16 1125 //! <b>Effects</b>: Removes all the elements for which a specified
Chris@16 1126 //! predicate is satisfied.
Chris@16 1127 //!
Chris@16 1128 //! <b>Throws</b>: If pred throws.
Chris@16 1129 //!
Chris@16 1130 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
Chris@16 1131 //!
Chris@16 1132 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
Chris@16 1133 //! and iterators to elements that are not removed remain valid.
Chris@16 1134 template <class Pred>
Chris@16 1135 void remove_if(Pred pred)
Chris@16 1136 {
Chris@101 1137 typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
Chris@101 1138 this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
Chris@16 1139 }
Chris@16 1140
Chris@16 1141 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
Chris@16 1142 //! elements that are equal from the list.
Chris@16 1143 //!
Chris@16 1144 //! <b>Throws</b>: If comparison throws.
Chris@16 1145 //!
Chris@16 1146 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
Chris@16 1147 //!
Chris@16 1148 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
Chris@16 1149 //! and iterators to elements that are not removed remain valid.
Chris@16 1150 void unique()
Chris@16 1151 { this->unique(value_equal()); }
Chris@16 1152
Chris@16 1153 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
Chris@16 1154 //! elements that satisfy some binary predicate from the list.
Chris@16 1155 //!
Chris@16 1156 //! <b>Throws</b>: If pred throws.
Chris@16 1157 //!
Chris@16 1158 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
Chris@16 1159 //!
Chris@16 1160 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
Chris@16 1161 //! and iterators to elements that are not removed remain valid.
Chris@16 1162 template <class BinaryPredicate>
Chris@16 1163 void unique(BinaryPredicate binary_pred)
Chris@16 1164 {
Chris@101 1165 typedef value_to_node_compare<Node, BinaryPredicate> value_to_node_compare_type;
Chris@101 1166 this->icont().unique_and_dispose(value_to_node_compare_type(binary_pred), Destroyer(this->node_alloc()));
Chris@16 1167 }
Chris@16 1168
Chris@16 1169 //! <b>Requires</b>: The lists x and *this must be distinct.
Chris@16 1170 //!
Chris@16 1171 //! <b>Effects</b>: This function removes all of x's elements and inserts them
Chris@16 1172 //! in order into *this according to std::less<value_type>. The merge is stable;
Chris@16 1173 //! that is, if an element from *this is equivalent to one from x, then the element
Chris@16 1174 //! from *this will precede the one from x.
Chris@16 1175 //!
Chris@16 1176 //! <b>Throws</b>: If comparison throws.
Chris@16 1177 //!
Chris@16 1178 //! <b>Complexity</b>: This function is linear time: it performs at most
Chris@16 1179 //! size() + x.size() - 1 comparisons.
Chris@16 1180 void merge(list &x)
Chris@16 1181 { this->merge(x, value_less()); }
Chris@16 1182
Chris@16 1183 //! <b>Requires</b>: The lists x and *this must be distinct.
Chris@16 1184 //!
Chris@16 1185 //! <b>Effects</b>: This function removes all of x's elements and inserts them
Chris@16 1186 //! in order into *this according to std::less<value_type>. The merge is stable;
Chris@16 1187 //! that is, if an element from *this is equivalent to one from x, then the element
Chris@16 1188 //! from *this will precede the one from x.
Chris@16 1189 //!
Chris@16 1190 //! <b>Throws</b>: If comparison throws.
Chris@16 1191 //!
Chris@16 1192 //! <b>Complexity</b>: This function is linear time: it performs at most
Chris@16 1193 //! size() + x.size() - 1 comparisons.
Chris@16 1194 void merge(BOOST_RV_REF(list) x)
Chris@16 1195 { this->merge(static_cast<list&>(x)); }
Chris@16 1196
Chris@16 1197 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
Chris@16 1198 //! ordering and both *this and x must be sorted according to that ordering
Chris@16 1199 //! The lists x and *this must be distinct.
Chris@16 1200 //!
Chris@16 1201 //! <b>Effects</b>: This function removes all of x's elements and inserts them
Chris@16 1202 //! in order into *this. The merge is stable; that is, if an element from *this is
Chris@16 1203 //! equivalent to one from x, then the element from *this will precede the one from x.
Chris@16 1204 //!
Chris@16 1205 //! <b>Throws</b>: If comp throws.
Chris@16 1206 //!
Chris@16 1207 //! <b>Complexity</b>: This function is linear time: it performs at most
Chris@16 1208 //! size() + x.size() - 1 comparisons.
Chris@16 1209 //!
Chris@16 1210 //! <b>Note</b>: Iterators and references to *this are not invalidated.
Chris@16 1211 template <class StrictWeakOrdering>
Chris@16 1212 void merge(list &x, const StrictWeakOrdering &comp)
Chris@16 1213 {
Chris@16 1214 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
Chris@101 1215 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
Chris@101 1216 this->icont().merge(x.icont(), value_to_node_compare_type(comp));
Chris@16 1217 }
Chris@16 1218
Chris@16 1219 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
Chris@16 1220 //! ordering and both *this and x must be sorted according to that ordering
Chris@16 1221 //! The lists x and *this must be distinct.
Chris@16 1222 //!
Chris@16 1223 //! <b>Effects</b>: This function removes all of x's elements and inserts them
Chris@16 1224 //! in order into *this. The merge is stable; that is, if an element from *this is
Chris@16 1225 //! equivalent to one from x, then the element from *this will precede the one from x.
Chris@16 1226 //!
Chris@16 1227 //! <b>Throws</b>: If comp throws.
Chris@16 1228 //!
Chris@16 1229 //! <b>Complexity</b>: This function is linear time: it performs at most
Chris@16 1230 //! size() + x.size() - 1 comparisons.
Chris@16 1231 //!
Chris@16 1232 //! <b>Note</b>: Iterators and references to *this are not invalidated.
Chris@16 1233 template <class StrictWeakOrdering>
Chris@16 1234 void merge(BOOST_RV_REF(list) x, StrictWeakOrdering comp)
Chris@16 1235 { this->merge(static_cast<list&>(x), comp); }
Chris@16 1236
Chris@16 1237 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
Chris@16 1238 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
Chris@16 1239 //!
Chris@16 1240 //! <b>Throws</b>: If comparison throws.
Chris@16 1241 //!
Chris@16 1242 //! <b>Notes</b>: Iterators and references are not invalidated.
Chris@101 1243 //!
Chris@16 1244 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
Chris@16 1245 //! is the list's size.
Chris@16 1246 void sort()
Chris@16 1247 { this->sort(value_less()); }
Chris@16 1248
Chris@16 1249 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
Chris@16 1250 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
Chris@16 1251 //!
Chris@16 1252 //! <b>Throws</b>: If comp throws.
Chris@16 1253 //!
Chris@16 1254 //! <b>Notes</b>: Iterators and references are not invalidated.
Chris@16 1255 //!
Chris@16 1256 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
Chris@16 1257 //! is the list's size.
Chris@16 1258 template <class StrictWeakOrdering>
Chris@16 1259 void sort(StrictWeakOrdering comp)
Chris@16 1260 {
Chris@16 1261 // nothing if the list has length 0 or 1.
Chris@16 1262 if (this->size() < 2)
Chris@16 1263 return;
Chris@101 1264 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
Chris@101 1265 this->icont().sort(value_to_node_compare_type(comp));
Chris@16 1266 }
Chris@16 1267
Chris@16 1268 //! <b>Effects</b>: Reverses the order of elements in the list.
Chris@16 1269 //!
Chris@16 1270 //! <b>Throws</b>: Nothing.
Chris@16 1271 //!
Chris@16 1272 //! <b>Complexity</b>: This function is linear time.
Chris@16 1273 //!
Chris@16 1274 //! <b>Note</b>: Iterators and references are not invalidated
Chris@101 1275 void reverse() BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 1276 { this->icont().reverse(); }
Chris@16 1277
Chris@101 1278 //! <b>Effects</b>: Returns true if x and y are equal
Chris@101 1279 //!
Chris@101 1280 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1281 friend bool operator==(const list& x, const list& y)
Chris@101 1282 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
Chris@101 1283
Chris@101 1284 //! <b>Effects</b>: Returns true if x and y are unequal
Chris@101 1285 //!
Chris@101 1286 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1287 friend bool operator!=(const list& x, const list& y)
Chris@101 1288 { return !(x == y); }
Chris@101 1289
Chris@101 1290 //! <b>Effects</b>: Returns true if x is less than y
Chris@101 1291 //!
Chris@101 1292 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1293 friend bool operator<(const list& x, const list& y)
Chris@101 1294 { return boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
Chris@101 1295
Chris@101 1296 //! <b>Effects</b>: Returns true if x is greater than y
Chris@101 1297 //!
Chris@101 1298 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1299 friend bool operator>(const list& x, const list& y)
Chris@101 1300 { return y < x; }
Chris@101 1301
Chris@101 1302 //! <b>Effects</b>: Returns true if x is equal or less than y
Chris@101 1303 //!
Chris@101 1304 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1305 friend bool operator<=(const list& x, const list& y)
Chris@101 1306 { return !(y < x); }
Chris@101 1307
Chris@101 1308 //! <b>Effects</b>: Returns true if x is equal or greater than y
Chris@101 1309 //!
Chris@101 1310 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1311 friend bool operator>=(const list& x, const list& y)
Chris@101 1312 { return !(x < y); }
Chris@101 1313
Chris@101 1314 //! <b>Effects</b>: x.swap(y)
Chris@101 1315 //!
Chris@101 1316 //! <b>Complexity</b>: Constant.
Chris@101 1317 friend void swap(list& x, list& y)
Chris@101 1318 { x.swap(y); }
Chris@101 1319
Chris@101 1320 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 1321 private:
Chris@16 1322
Chris@16 1323 bool priv_try_shrink(size_type new_size)
Chris@16 1324 {
Chris@16 1325 const size_type len = this->size();
Chris@16 1326 if(len > new_size){
Chris@16 1327 const const_iterator iend = this->cend();
Chris@16 1328 size_type to_erase = len - new_size;
Chris@16 1329 const_iterator ifirst;
Chris@16 1330 if(to_erase < len/2u){
Chris@16 1331 ifirst = iend;
Chris@16 1332 while(to_erase--){
Chris@16 1333 --ifirst;
Chris@16 1334 }
Chris@16 1335 }
Chris@16 1336 else{
Chris@16 1337 ifirst = this->cbegin();
Chris@16 1338 size_type to_skip = len - to_erase;
Chris@16 1339 while(to_skip--){
Chris@16 1340 ++ifirst;
Chris@16 1341 }
Chris@16 1342 }
Chris@16 1343 this->erase(ifirst, iend);
Chris@16 1344 return true;
Chris@16 1345 }
Chris@16 1346 else{
Chris@16 1347 return false;
Chris@16 1348 }
Chris@16 1349 }
Chris@16 1350
Chris@16 1351 iterator priv_insert(const_iterator p, const T &x)
Chris@16 1352 {
Chris@16 1353 NodePtr tmp = AllocHolder::create_node(x);
Chris@16 1354 return iterator(this->icont().insert(p.get(), *tmp));
Chris@16 1355 }
Chris@16 1356
Chris@16 1357 iterator priv_insert(const_iterator p, BOOST_RV_REF(T) x)
Chris@16 1358 {
Chris@16 1359 NodePtr tmp = AllocHolder::create_node(boost::move(x));
Chris@16 1360 return iterator(this->icont().insert(p.get(), *tmp));
Chris@16 1361 }
Chris@16 1362
Chris@101 1363 void priv_push_back (const T &x)
Chris@16 1364 { this->insert(this->cend(), x); }
Chris@16 1365
Chris@16 1366 void priv_push_back (BOOST_RV_REF(T) x)
Chris@16 1367 { this->insert(this->cend(), boost::move(x)); }
Chris@16 1368
Chris@101 1369 void priv_push_front (const T &x)
Chris@16 1370 { this->insert(this->cbegin(), x); }
Chris@16 1371
Chris@16 1372 void priv_push_front (BOOST_RV_REF(T) x)
Chris@16 1373 { this->insert(this->cbegin(), boost::move(x)); }
Chris@16 1374
Chris@16 1375 class insertion_functor;
Chris@16 1376 friend class insertion_functor;
Chris@16 1377
Chris@16 1378 class insertion_functor
Chris@16 1379 {
Chris@16 1380 Icont &icont_;
Chris@16 1381 typedef typename Icont::const_iterator iconst_iterator;
Chris@16 1382 const iconst_iterator pos_;
Chris@16 1383
Chris@16 1384 public:
Chris@16 1385 insertion_functor(Icont &icont, typename Icont::const_iterator pos)
Chris@16 1386 : icont_(icont), pos_(pos)
Chris@16 1387 {}
Chris@16 1388
Chris@16 1389 void operator()(Node &n)
Chris@16 1390 {
Chris@16 1391 this->icont_.insert(pos_, n);
Chris@16 1392 }
Chris@16 1393 };
Chris@16 1394
Chris@16 1395 //Functors for member algorithm defaults
Chris@16 1396 struct value_less
Chris@16 1397 {
Chris@16 1398 bool operator()(const value_type &a, const value_type &b) const
Chris@16 1399 { return a < b; }
Chris@16 1400 };
Chris@16 1401
Chris@16 1402 struct value_equal
Chris@16 1403 {
Chris@16 1404 bool operator()(const value_type &a, const value_type &b) const
Chris@16 1405 { return a == b; }
Chris@16 1406 };
Chris@101 1407 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 1408
Chris@16 1409 };
Chris@16 1410
Chris@101 1411 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 1412
Chris@16 1413 } //namespace container {
Chris@16 1414
Chris@16 1415 //!has_trivial_destructor_after_move<> == true_type
Chris@16 1416 //!specialization for optimizations
Chris@16 1417 template <class T, class Allocator>
Chris@16 1418 struct has_trivial_destructor_after_move<boost::container::list<T, Allocator> >
Chris@101 1419 {
Chris@101 1420 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
Chris@101 1421 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
Chris@101 1422 ::boost::has_trivial_destructor_after_move<pointer>::value;
Chris@101 1423 };
Chris@16 1424
Chris@16 1425 namespace container {
Chris@16 1426
Chris@101 1427 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 1428
Chris@16 1429 }}
Chris@16 1430
Chris@16 1431 #include <boost/container/detail/config_end.hpp>
Chris@16 1432
Chris@16 1433 #endif // BOOST_CONTAINER_LIST_HPP