| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Olaf Krzikalla 2004-2006. |
| 4 | // (C) Copyright Ion Gaztanaga 2006-2014 |
| 5 | // |
| 6 | // Distributed under the Boost Software License, Version 1.0. |
| 7 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | // http://www.boost.org/LICENSE_1_0.txt) |
| 9 | // |
| 10 | // See http://www.boost.org/libs/intrusive for documentation. |
| 11 | // |
| 12 | ///////////////////////////////////////////////////////////////////////////// |
| 13 | |
| 14 | #ifndef BOOST_INTRUSIVE_LIST_HPP |
| 15 | #define BOOST_INTRUSIVE_LIST_HPP |
| 16 | |
| 17 | #include <boost/intrusive/detail/config_begin.hpp> |
| 18 | #include <boost/intrusive/intrusive_fwd.hpp> |
| 19 | #include <boost/intrusive/detail/assert.hpp> |
| 20 | #include <boost/intrusive/list_hook.hpp> |
| 21 | #include <boost/intrusive/circular_list_algorithms.hpp> |
| 22 | #include <boost/intrusive/pointer_traits.hpp> |
| 23 | #include <boost/intrusive/detail/mpl.hpp> |
| 24 | #include <boost/intrusive/link_mode.hpp> |
| 25 | #include <boost/intrusive/detail/get_value_traits.hpp> |
| 26 | #include <boost/intrusive/detail/is_stateful_value_traits.hpp> |
| 27 | #include <boost/intrusive/detail/default_header_holder.hpp> |
| 28 | #include <boost/intrusive/detail/reverse_iterator.hpp> |
| 29 | #include <boost/intrusive/detail/uncast.hpp> |
| 30 | #include <boost/intrusive/detail/list_iterator.hpp> |
| 31 | #include <boost/intrusive/detail/array_initializer.hpp> |
| 32 | #include <boost/intrusive/detail/exception_disposer.hpp> |
| 33 | #include <boost/intrusive/detail/equal_to_value.hpp> |
| 34 | #include <boost/intrusive/detail/key_nodeptr_comp.hpp> |
| 35 | #include <boost/intrusive/detail/simple_disposers.hpp> |
| 36 | #include <boost/intrusive/detail/size_holder.hpp> |
| 37 | #include <boost/intrusive/detail/algorithm.hpp> |
| 38 | |
| 39 | #include <boost/move/utility_core.hpp> |
| 40 | |
| 41 | #include <boost/intrusive/detail/value_functors.hpp> |
| 42 | #include <cstddef> //std::size_t, etc. |
| 43 | |
| 44 | #if defined(BOOST_HAS_PRAGMA_ONCE) |
| 45 | # pragma once |
| 46 | #endif |
| 47 | |
| 48 | namespace boost { |
| 49 | namespace intrusive { |
| 50 | |
| 51 | /// @cond |
| 52 | |
| 53 | struct default_list_hook_applier |
| 54 | { template <class T> struct apply{ typedef typename T::default_list_hook type; }; }; |
| 55 | |
| 56 | template<> |
| 57 | struct is_default_hook_tag<default_list_hook_applier> |
| 58 | { static const bool value = true; }; |
| 59 | |
| 60 | struct list_defaults |
| 61 | { |
| 62 | typedef default_list_hook_applier proto_value_traits; |
| 63 | static const bool constant_time_size = true; |
| 64 | typedef std::size_t size_type; |
| 65 | typedef void ; |
| 66 | }; |
| 67 | |
| 68 | /// @endcond |
| 69 | |
| 70 | //! The class template list is an intrusive container that mimics most of the |
| 71 | //! interface of std::list as described in the C++ standard. |
| 72 | //! |
| 73 | //! The template parameter \c T is the type to be managed by the container. |
| 74 | //! The user can specify additional options and if no options are provided |
| 75 | //! default options are used. |
| 76 | //! |
| 77 | //! The container supports the following options: |
| 78 | //! \c base_hook<>/member_hook<>/value_traits<>, |
| 79 | //! \c constant_time_size<> and \c size_type<>. |
| 80 | #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) |
| 81 | template<class T, class ...Options> |
| 82 | #else |
| 83 | template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> |
| 84 | #endif |
| 85 | class list_impl |
| 86 | { |
| 87 | //Public typedefs |
| 88 | public: |
| 89 | typedef ValueTraits value_traits; |
| 90 | typedef typename value_traits::pointer pointer; |
| 91 | typedef typename value_traits::const_pointer const_pointer; |
| 92 | typedef typename pointer_traits<pointer>::element_type value_type; |
| 93 | typedef typename pointer_traits<pointer>::reference reference; |
| 94 | typedef typename pointer_traits<const_pointer>::reference const_reference; |
| 95 | typedef typename pointer_traits<pointer>::difference_type difference_type; |
| 96 | typedef SizeType size_type; |
| 97 | typedef list_iterator<value_traits, false> iterator; |
| 98 | typedef list_iterator<value_traits, true> const_iterator; |
| 99 | typedef boost::intrusive::reverse_iterator<iterator> reverse_iterator; |
| 100 | typedef boost::intrusive::reverse_iterator<const_iterator> const_reverse_iterator; |
| 101 | typedef typename value_traits::node_traits node_traits; |
| 102 | typedef typename node_traits::node node; |
| 103 | typedef typename node_traits::node_ptr node_ptr; |
| 104 | typedef typename node_traits::const_node_ptr const_node_ptr; |
| 105 | typedef circular_list_algorithms<node_traits> node_algorithms; |
| 106 | typedef typename detail::get_header_holder_type |
| 107 | < value_traits, HeaderHolder >::type ; |
| 108 | |
| 109 | static const bool constant_time_size = ConstantTimeSize; |
| 110 | static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; |
| 111 | static const bool has_container_from_iterator = |
| 112 | detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value; |
| 113 | |
| 114 | /// @cond |
| 115 | |
| 116 | private: |
| 117 | typedef detail::size_holder<constant_time_size, size_type> size_traits; |
| 118 | |
| 119 | //noncopyable |
| 120 | BOOST_MOVABLE_BUT_NOT_COPYABLE(list_impl) |
| 121 | |
| 122 | static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; |
| 123 | |
| 124 | //Constant-time size is incompatible with auto-unlink hooks! |
| 125 | BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size && |
| 126 | ((int)value_traits::link_mode == (int)auto_unlink) |
| 127 | )); |
| 128 | |
| 129 | inline node_ptr get_root_node() |
| 130 | { return data_.root_plus_size_.m_header.get_node(); } |
| 131 | |
| 132 | inline const_node_ptr get_root_node() const |
| 133 | { return data_.root_plus_size_.m_header.get_node(); } |
| 134 | |
| 135 | struct root_plus_size : public size_traits |
| 136 | { |
| 137 | header_holder_type ; |
| 138 | }; |
| 139 | |
| 140 | struct data_t : public value_traits |
| 141 | { |
| 142 | typedef typename list_impl::value_traits value_traits; |
| 143 | inline explicit data_t(const value_traits &val_traits) |
| 144 | : value_traits(val_traits) |
| 145 | {} |
| 146 | |
| 147 | root_plus_size root_plus_size_; |
| 148 | } data_; |
| 149 | |
| 150 | inline size_traits &priv_size_traits() BOOST_NOEXCEPT |
| 151 | { return data_.root_plus_size_; } |
| 152 | |
| 153 | inline const size_traits &priv_size_traits() const BOOST_NOEXCEPT |
| 154 | { return data_.root_plus_size_; } |
| 155 | |
| 156 | inline const value_traits &priv_value_traits() const BOOST_NOEXCEPT |
| 157 | { return data_; } |
| 158 | |
| 159 | inline value_traits &priv_value_traits() BOOST_NOEXCEPT |
| 160 | { return data_; } |
| 161 | |
| 162 | typedef typename boost::intrusive::value_traits_pointers |
| 163 | <ValueTraits>::const_value_traits_ptr const_value_traits_ptr; |
| 164 | |
| 165 | inline const_value_traits_ptr priv_value_traits_ptr() const BOOST_NOEXCEPT |
| 166 | { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); } |
| 167 | |
| 168 | /// @endcond |
| 169 | |
| 170 | public: |
| 171 | |
| 172 | //! <b>Effects</b>: constructs an empty list. |
| 173 | //! |
| 174 | //! <b>Complexity</b>: Constant |
| 175 | //! |
| 176 | //! <b>Throws</b>: If value_traits::node_traits::node |
| 177 | //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). |
| 178 | list_impl() |
| 179 | : data_(value_traits()) |
| 180 | { |
| 181 | this->priv_size_traits().set_size(size_type(0)); |
| 182 | node_algorithms::init_header(this->get_root_node()); |
| 183 | } |
| 184 | |
| 185 | //! <b>Effects</b>: constructs an empty list. |
| 186 | //! |
| 187 | //! <b>Complexity</b>: Constant |
| 188 | //! |
| 189 | //! <b>Throws</b>: If value_traits::node_traits::node |
| 190 | //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). |
| 191 | explicit list_impl(const value_traits &v_traits) |
| 192 | : data_(v_traits) |
| 193 | { |
| 194 | this->priv_size_traits().set_size(size_type(0)); |
| 195 | node_algorithms::init_header(this->get_root_node()); |
| 196 | } |
| 197 | |
| 198 | //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. |
| 199 | //! |
| 200 | //! <b>Effects</b>: Constructs a list equal to the range [first,last). |
| 201 | //! |
| 202 | //! <b>Complexity</b>: Linear in distance(b, e). No copy constructors are called. |
| 203 | //! |
| 204 | //! <b>Throws</b>: If value_traits::node_traits::node |
| 205 | //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). |
| 206 | template<class Iterator> |
| 207 | list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits()) |
| 208 | : data_(v_traits) |
| 209 | { |
| 210 | //nothrow, no need to rollback to release elements on exception |
| 211 | this->priv_size_traits().set_size(size_type(0)); |
| 212 | node_algorithms::init_header(this->get_root_node()); |
| 213 | //nothrow, no need to rollback to release elements on exception |
| 214 | this->insert(this->cend(), b, e); |
| 215 | } |
| 216 | |
| 217 | //! <b>Effects</b>: Constructs a container moving resources from another container. |
| 218 | //! Internal value traits are move constructed and |
| 219 | //! nodes belonging to x (except the node representing the "end") are linked to *this. |
| 220 | //! |
| 221 | //! <b>Complexity</b>: Constant. |
| 222 | //! |
| 223 | //! <b>Throws</b>: If value_traits::node_traits::node's |
| 224 | //! move constructor throws (this does not happen with predefined Boost.Intrusive hooks) |
| 225 | //! or the move constructor of value traits throws. |
| 226 | list_impl(BOOST_RV_REF(list_impl) x) |
| 227 | : data_(::boost::move(x.priv_value_traits())) |
| 228 | { |
| 229 | this->priv_size_traits().set_size(size_type(0)); |
| 230 | node_algorithms::init_header(this->get_root_node()); |
| 231 | //nothrow, no need to rollback to release elements on exception |
| 232 | this->swap(x); |
| 233 | } |
| 234 | |
| 235 | //! <b>Effects</b>: Equivalent to swap |
| 236 | //! |
| 237 | list_impl& operator=(BOOST_RV_REF(list_impl) x) |
| 238 | { this->swap(x); return *this; } |
| 239 | |
| 240 | //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type |
| 241 | //! the destructor does nothing |
| 242 | //! (ie. no code is generated). Otherwise it detaches all elements from this. |
| 243 | //! In this case the objects in the list are not deleted (i.e. no destructors |
| 244 | //! are called), but the hooks according to the ValueTraits template parameter |
| 245 | //! are set to their default value. |
| 246 | //! |
| 247 | //! <b>Throws</b>: Nothing. |
| 248 | //! |
| 249 | //! <b>Complexity</b>: Linear to the number of elements in the list, if |
| 250 | //! it's a safe-mode or auto-unlink value . Otherwise constant. |
| 251 | ~list_impl() |
| 252 | { |
| 253 | BOOST_IF_CONSTEXPR(is_safe_autounlink<ValueTraits::link_mode>::value){ |
| 254 | this->clear(); |
| 255 | node_algorithms::init(this->get_root_node()); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | //! <b>Requires</b>: value must be an lvalue. |
| 260 | //! |
| 261 | //! <b>Effects</b>: Inserts the value in the back of the list. |
| 262 | //! No copy constructors are called. |
| 263 | //! |
| 264 | //! <b>Throws</b>: Nothing. |
| 265 | //! |
| 266 | //! <b>Complexity</b>: Constant. |
| 267 | //! |
| 268 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 269 | void push_back(reference value) BOOST_NOEXCEPT |
| 270 | { |
| 271 | node_ptr to_insert = priv_value_traits().to_node_ptr(value); |
| 272 | BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert)); |
| 273 | node_algorithms::link_before(this->get_root_node(), to_insert); |
| 274 | this->priv_size_traits().increment(); |
| 275 | } |
| 276 | |
| 277 | //! <b>Requires</b>: value must be an lvalue. |
| 278 | //! |
| 279 | //! <b>Effects</b>: Inserts the value in the front of the list. |
| 280 | //! No copy constructors are called. |
| 281 | //! |
| 282 | //! <b>Throws</b>: Nothing. |
| 283 | //! |
| 284 | //! <b>Complexity</b>: Constant. |
| 285 | //! |
| 286 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 287 | void push_front(reference value) BOOST_NOEXCEPT |
| 288 | { |
| 289 | node_ptr to_insert = priv_value_traits().to_node_ptr(value); |
| 290 | BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert)); |
| 291 | node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert); |
| 292 | this->priv_size_traits().increment(); |
| 293 | } |
| 294 | |
| 295 | //! <b>Effects</b>: Erases the last element of the list. |
| 296 | //! No destructors are called. |
| 297 | //! |
| 298 | //! <b>Throws</b>: Nothing. |
| 299 | //! |
| 300 | //! <b>Complexity</b>: Constant. |
| 301 | //! |
| 302 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element. |
| 303 | void pop_back() BOOST_NOEXCEPT |
| 304 | { return this->pop_back_and_dispose(detail::null_disposer()); } |
| 305 | |
| 306 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 307 | //! |
| 308 | //! <b>Effects</b>: Erases the last element of the list. |
| 309 | //! No destructors are called. |
| 310 | //! Disposer::operator()(pointer) is called for the removed element. |
| 311 | //! |
| 312 | //! <b>Throws</b>: Nothing. |
| 313 | //! |
| 314 | //! <b>Complexity</b>: Constant. |
| 315 | //! |
| 316 | //! <b>Note</b>: Invalidates the iterators to the erased element. |
| 317 | template<class Disposer> |
| 318 | void pop_back_and_dispose(Disposer disposer) BOOST_NOEXCEPT |
| 319 | { |
| 320 | node_ptr to_erase = node_traits::get_previous(this->get_root_node()); |
| 321 | node_algorithms::unlink(to_erase); |
| 322 | this->priv_size_traits().decrement(); |
| 323 | BOOST_IF_CONSTEXPR(safemode_or_autounlink) |
| 324 | node_algorithms::init(to_erase); |
| 325 | disposer(priv_value_traits().to_value_ptr(to_erase)); |
| 326 | } |
| 327 | |
| 328 | //! <b>Effects</b>: Erases the first element of the list. |
| 329 | //! No destructors are called. |
| 330 | //! |
| 331 | //! <b>Throws</b>: Nothing. |
| 332 | //! |
| 333 | //! <b>Complexity</b>: Constant. |
| 334 | //! |
| 335 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element. |
| 336 | void pop_front() BOOST_NOEXCEPT |
| 337 | { return this->pop_front_and_dispose(detail::null_disposer()); } |
| 338 | |
| 339 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 340 | //! |
| 341 | //! <b>Effects</b>: Erases the first element of the list. |
| 342 | //! No destructors are called. |
| 343 | //! Disposer::operator()(pointer) is called for the removed element. |
| 344 | //! |
| 345 | //! <b>Throws</b>: Nothing. |
| 346 | //! |
| 347 | //! <b>Complexity</b>: Constant. |
| 348 | //! |
| 349 | //! <b>Note</b>: Invalidates the iterators to the erased element. |
| 350 | template<class Disposer> |
| 351 | void pop_front_and_dispose(Disposer disposer) BOOST_NOEXCEPT |
| 352 | { |
| 353 | node_ptr to_erase = node_traits::get_next(this->get_root_node()); |
| 354 | node_algorithms::unlink(to_erase); |
| 355 | this->priv_size_traits().decrement(); |
| 356 | BOOST_IF_CONSTEXPR(safemode_or_autounlink) |
| 357 | node_algorithms::init(to_erase); |
| 358 | disposer(priv_value_traits().to_value_ptr(to_erase)); |
| 359 | } |
| 360 | |
| 361 | //! <b>Effects</b>: Returns a reference to the first element of the list. |
| 362 | //! |
| 363 | //! <b>Throws</b>: Nothing. |
| 364 | //! |
| 365 | //! <b>Complexity</b>: Constant. |
| 366 | inline reference front() BOOST_NOEXCEPT |
| 367 | { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } |
| 368 | |
| 369 | //! <b>Effects</b>: Returns a const_reference to the first element of the list. |
| 370 | //! |
| 371 | //! <b>Throws</b>: Nothing. |
| 372 | //! |
| 373 | //! <b>Complexity</b>: Constant. |
| 374 | inline const_reference front() const BOOST_NOEXCEPT |
| 375 | { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } |
| 376 | |
| 377 | //! <b>Effects</b>: Returns a reference to the last element of the list. |
| 378 | //! |
| 379 | //! <b>Throws</b>: Nothing. |
| 380 | //! |
| 381 | //! <b>Complexity</b>: Constant. |
| 382 | inline reference back() BOOST_NOEXCEPT |
| 383 | { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); } |
| 384 | |
| 385 | //! <b>Effects</b>: Returns a const_reference to the last element of the list. |
| 386 | //! |
| 387 | //! <b>Throws</b>: Nothing. |
| 388 | //! |
| 389 | //! <b>Complexity</b>: Constant. |
| 390 | inline const_reference back() const BOOST_NOEXCEPT |
| 391 | { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); } |
| 392 | |
| 393 | //! <b>Effects</b>: Returns an iterator to the first element contained in the list. |
| 394 | //! |
| 395 | //! <b>Throws</b>: Nothing. |
| 396 | //! |
| 397 | //! <b>Complexity</b>: Constant. |
| 398 | inline iterator begin() BOOST_NOEXCEPT |
| 399 | { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } |
| 400 | |
| 401 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. |
| 402 | //! |
| 403 | //! <b>Throws</b>: Nothing. |
| 404 | //! |
| 405 | //! <b>Complexity</b>: Constant. |
| 406 | inline const_iterator begin() const BOOST_NOEXCEPT |
| 407 | { return this->cbegin(); } |
| 408 | |
| 409 | //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. |
| 410 | //! |
| 411 | //! <b>Throws</b>: Nothing. |
| 412 | //! |
| 413 | //! <b>Complexity</b>: Constant. |
| 414 | inline const_iterator cbegin() const BOOST_NOEXCEPT |
| 415 | { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } |
| 416 | |
| 417 | //! <b>Effects</b>: Returns an iterator to the end of the list. |
| 418 | //! |
| 419 | //! <b>Throws</b>: Nothing. |
| 420 | //! |
| 421 | //! <b>Complexity</b>: Constant. |
| 422 | inline iterator end() BOOST_NOEXCEPT |
| 423 | { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); } |
| 424 | |
| 425 | //! <b>Effects</b>: Returns a const_iterator to the end of the list. |
| 426 | //! |
| 427 | //! <b>Throws</b>: Nothing. |
| 428 | //! |
| 429 | //! <b>Complexity</b>: Constant. |
| 430 | inline const_iterator end() const BOOST_NOEXCEPT |
| 431 | { return this->cend(); } |
| 432 | |
| 433 | //! <b>Effects</b>: Returns a constant iterator to the end of the list. |
| 434 | //! |
| 435 | //! <b>Throws</b>: Nothing. |
| 436 | //! |
| 437 | //! <b>Complexity</b>: Constant. |
| 438 | inline const_iterator cend() const BOOST_NOEXCEPT |
| 439 | { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); } |
| 440 | |
| 441 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning |
| 442 | //! of the reversed list. |
| 443 | //! |
| 444 | //! <b>Throws</b>: Nothing. |
| 445 | //! |
| 446 | //! <b>Complexity</b>: Constant. |
| 447 | inline reverse_iterator rbegin() BOOST_NOEXCEPT |
| 448 | { return reverse_iterator(this->end()); } |
| 449 | |
| 450 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning |
| 451 | //! of the reversed list. |
| 452 | //! |
| 453 | //! <b>Throws</b>: Nothing. |
| 454 | //! |
| 455 | //! <b>Complexity</b>: Constant. |
| 456 | inline const_reverse_iterator rbegin() const BOOST_NOEXCEPT |
| 457 | { return this->crbegin(); } |
| 458 | |
| 459 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning |
| 460 | //! of the reversed list. |
| 461 | //! |
| 462 | //! <b>Throws</b>: Nothing. |
| 463 | //! |
| 464 | //! <b>Complexity</b>: Constant. |
| 465 | inline const_reverse_iterator crbegin() const BOOST_NOEXCEPT |
| 466 | { return const_reverse_iterator(end()); } |
| 467 | |
| 468 | //! <b>Effects</b>: Returns a reverse_iterator pointing to the end |
| 469 | //! of the reversed list. |
| 470 | //! |
| 471 | //! <b>Throws</b>: Nothing. |
| 472 | //! |
| 473 | //! <b>Complexity</b>: Constant. |
| 474 | inline reverse_iterator rend() BOOST_NOEXCEPT |
| 475 | { return reverse_iterator(begin()); } |
| 476 | |
| 477 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end |
| 478 | //! of the reversed list. |
| 479 | //! |
| 480 | //! <b>Throws</b>: Nothing. |
| 481 | //! |
| 482 | //! <b>Complexity</b>: Constant. |
| 483 | inline const_reverse_iterator rend() const BOOST_NOEXCEPT |
| 484 | { return this->crend(); } |
| 485 | |
| 486 | //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end |
| 487 | //! of the reversed list. |
| 488 | //! |
| 489 | //! <b>Throws</b>: Nothing. |
| 490 | //! |
| 491 | //! <b>Complexity</b>: Constant. |
| 492 | inline const_reverse_iterator crend() const BOOST_NOEXCEPT |
| 493 | { return const_reverse_iterator(this->begin()); } |
| 494 | |
| 495 | //! <b>Precondition</b>: end_iterator must be a valid end iterator |
| 496 | //! of list. |
| 497 | //! |
| 498 | //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator |
| 499 | //! |
| 500 | //! <b>Throws</b>: Nothing. |
| 501 | //! |
| 502 | //! <b>Complexity</b>: Constant. |
| 503 | inline static list_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT |
| 504 | { return list_impl::priv_container_from_end_iterator(end_iterator); } |
| 505 | |
| 506 | //! <b>Precondition</b>: end_iterator must be a valid end const_iterator |
| 507 | //! of list. |
| 508 | //! |
| 509 | //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator |
| 510 | //! |
| 511 | //! <b>Throws</b>: Nothing. |
| 512 | //! |
| 513 | //! <b>Complexity</b>: Constant. |
| 514 | inline static const list_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT |
| 515 | { return list_impl::priv_container_from_end_iterator(end_iterator); } |
| 516 | |
| 517 | //! <b>Effects</b>: Returns the number of the elements contained in the list. |
| 518 | //! |
| 519 | //! <b>Throws</b>: Nothing. |
| 520 | //! |
| 521 | //! <b>Complexity</b>: Linear to the number of elements contained in the list. |
| 522 | //! if constant-time size option is disabled. Constant time otherwise. |
| 523 | //! |
| 524 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 525 | inline size_type size() const BOOST_NOEXCEPT |
| 526 | { |
| 527 | BOOST_IF_CONSTEXPR(constant_time_size) |
| 528 | return this->priv_size_traits().get_size(); |
| 529 | else |
| 530 | return node_algorithms::count(this->get_root_node()) - 1; |
| 531 | } |
| 532 | |
| 533 | //! <b>Effects</b>: Returns true if the list contains no elements. |
| 534 | //! |
| 535 | //! <b>Throws</b>: Nothing. |
| 536 | //! |
| 537 | //! <b>Complexity</b>: Constant. |
| 538 | //! |
| 539 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 540 | inline bool empty() const BOOST_NOEXCEPT |
| 541 | { return node_algorithms::unique(this->get_root_node()); } |
| 542 | |
| 543 | //! <b>Effects</b>: Swaps the elements of x and *this. |
| 544 | //! |
| 545 | //! <b>Throws</b>: Nothing. |
| 546 | //! |
| 547 | //! <b>Complexity</b>: Constant. |
| 548 | //! |
| 549 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 550 | void swap(list_impl& other) BOOST_NOEXCEPT |
| 551 | { |
| 552 | node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node()); |
| 553 | this->priv_size_traits().swap(other.priv_size_traits()); |
| 554 | } |
| 555 | |
| 556 | //! <b>Effects</b>: Moves backwards all the elements, so that the first |
| 557 | //! element becomes the second, the second becomes the third... |
| 558 | //! the last element becomes the first one. |
| 559 | //! |
| 560 | //! <b>Throws</b>: Nothing. |
| 561 | //! |
| 562 | //! <b>Complexity</b>: Linear to the number of shifts. |
| 563 | //! |
| 564 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 565 | inline void shift_backwards(size_type n = 1) BOOST_NOEXCEPT |
| 566 | { node_algorithms::move_forward(this->get_root_node(), n); } |
| 567 | |
| 568 | //! <b>Effects</b>: Moves forward all the elements, so that the second |
| 569 | //! element becomes the first, the third becomes the second... |
| 570 | //! the first element becomes the last one. |
| 571 | //! |
| 572 | //! <b>Throws</b>: Nothing. |
| 573 | //! |
| 574 | //! <b>Complexity</b>: Linear to the number of shifts. |
| 575 | //! |
| 576 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 577 | inline void shift_forward(size_type n = 1) BOOST_NOEXCEPT |
| 578 | { node_algorithms::move_backwards(this->get_root_node(), n); } |
| 579 | |
| 580 | //! <b>Effects</b>: Erases the element pointed by i of the list. |
| 581 | //! No destructors are called. |
| 582 | //! |
| 583 | //! <b>Returns</b>: the first element remaining beyond the removed element, |
| 584 | //! or end() if no such element exists. |
| 585 | //! |
| 586 | //! <b>Throws</b>: Nothing. |
| 587 | //! |
| 588 | //! <b>Complexity</b>: Constant. |
| 589 | //! |
| 590 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the |
| 591 | //! erased element. |
| 592 | inline iterator erase(const_iterator i) BOOST_NOEXCEPT |
| 593 | { return this->erase_and_dispose(i, detail::null_disposer()); } |
| 594 | |
| 595 | //! <b>Requires</b>: b and e must be valid iterators to elements in *this. |
| 596 | //! |
| 597 | //! <b>Effects</b>: Erases the element range pointed by b and e |
| 598 | //! No destructors are called. |
| 599 | //! |
| 600 | //! <b>Returns</b>: the first element remaining beyond the removed elements, |
| 601 | //! or end() if no such element exists. |
| 602 | //! |
| 603 | //! <b>Throws</b>: Nothing. |
| 604 | //! |
| 605 | //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode |
| 606 | //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise. |
| 607 | //! |
| 608 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the |
| 609 | //! erased elements. |
| 610 | inline iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT |
| 611 | { |
| 612 | BOOST_IF_CONSTEXPR(safemode_or_autounlink || constant_time_size){ |
| 613 | return this->erase_and_dispose(b, e, detail::null_disposer()); |
| 614 | } |
| 615 | else{ |
| 616 | node_algorithms::unlink(b.pointed_node(), e.pointed_node()); |
| 617 | return e.unconst(); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | //! <b>Requires</b>: b and e must be valid iterators to elements in *this. |
| 622 | //! n must be distance(b, e). |
| 623 | //! |
| 624 | //! <b>Effects</b>: Erases the element range pointed by b and e |
| 625 | //! No destructors are called. |
| 626 | //! |
| 627 | //! <b>Returns</b>: the first element remaining beyond the removed elements, |
| 628 | //! or end() if no such element exists. |
| 629 | //! |
| 630 | //! <b>Throws</b>: Nothing. |
| 631 | //! |
| 632 | //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode |
| 633 | //! or auto-unlink value is enabled. Constant-time otherwise. |
| 634 | //! |
| 635 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the |
| 636 | //! erased elements. |
| 637 | iterator erase(const_iterator b, const_iterator e, size_type n) BOOST_NOEXCEPT |
| 638 | { |
| 639 | BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n); |
| 640 | (void)n; |
| 641 | BOOST_IF_CONSTEXPR(safemode_or_autounlink){ |
| 642 | return this->erase_and_dispose(b, e, detail::null_disposer()); |
| 643 | } |
| 644 | else{ |
| 645 | BOOST_IF_CONSTEXPR(constant_time_size){ |
| 646 | this->priv_size_traits().decrease(n); |
| 647 | } |
| 648 | node_algorithms::unlink(b.pointed_node(), e.pointed_node()); |
| 649 | return e.unconst(); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 654 | //! |
| 655 | //! <b>Effects</b>: Erases the element pointed by i of the list. |
| 656 | //! No destructors are called. |
| 657 | //! Disposer::operator()(pointer) is called for the removed element. |
| 658 | //! |
| 659 | //! <b>Returns</b>: the first element remaining beyond the removed element, |
| 660 | //! or end() if no such element exists. |
| 661 | //! |
| 662 | //! <b>Throws</b>: Nothing. |
| 663 | //! |
| 664 | //! <b>Complexity</b>: Constant. |
| 665 | //! |
| 666 | //! <b>Note</b>: Invalidates the iterators to the erased element. |
| 667 | template <class Disposer> |
| 668 | iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT |
| 669 | { |
| 670 | node_ptr to_erase(i.pointed_node()); |
| 671 | ++i; |
| 672 | node_algorithms::unlink(to_erase); |
| 673 | this->priv_size_traits().decrement(); |
| 674 | BOOST_IF_CONSTEXPR(safemode_or_autounlink) |
| 675 | node_algorithms::init(to_erase); |
| 676 | disposer(this->priv_value_traits().to_value_ptr(to_erase)); |
| 677 | return i.unconst(); |
| 678 | } |
| 679 | |
| 680 | #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) |
| 681 | template<class Disposer> |
| 682 | iterator erase_and_dispose(iterator i, Disposer disposer) BOOST_NOEXCEPT |
| 683 | { return this->erase_and_dispose(const_iterator(i), disposer); } |
| 684 | #endif |
| 685 | |
| 686 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 687 | //! |
| 688 | //! <b>Effects</b>: Erases the element range pointed by b and e |
| 689 | //! No destructors are called. |
| 690 | //! Disposer::operator()(pointer) is called for the removed elements. |
| 691 | //! |
| 692 | //! <b>Returns</b>: the first element remaining beyond the removed elements, |
| 693 | //! or end() if no such element exists. |
| 694 | //! |
| 695 | //! <b>Throws</b>: Nothing. |
| 696 | //! |
| 697 | //! <b>Complexity</b>: Linear to the number of elements erased. |
| 698 | //! |
| 699 | //! <b>Note</b>: Invalidates the iterators to the erased elements. |
| 700 | template <class Disposer> |
| 701 | iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT |
| 702 | { |
| 703 | node_ptr bp(b.pointed_node()), ep(e.pointed_node()); |
| 704 | node_algorithms::unlink(bp, ep); |
| 705 | while(bp != ep){ |
| 706 | node_ptr to_erase(bp); |
| 707 | bp = node_traits::get_next(bp); |
| 708 | BOOST_IF_CONSTEXPR(safemode_or_autounlink) |
| 709 | node_algorithms::init(to_erase); |
| 710 | disposer(priv_value_traits().to_value_ptr(to_erase)); |
| 711 | this->priv_size_traits().decrement(); |
| 712 | } |
| 713 | return e.unconst(); |
| 714 | } |
| 715 | |
| 716 | //! <b>Effects</b>: Erases all the elements of the container. |
| 717 | //! No destructors are called. |
| 718 | //! |
| 719 | //! <b>Throws</b>: Nothing. |
| 720 | //! |
| 721 | //! <b>Complexity</b>: Linear to the number of elements of the list. |
| 722 | //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. |
| 723 | //! |
| 724 | //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements. |
| 725 | void clear() BOOST_NOEXCEPT |
| 726 | { |
| 727 | BOOST_IF_CONSTEXPR(safemode_or_autounlink){ |
| 728 | this->clear_and_dispose(detail::null_disposer()); |
| 729 | } |
| 730 | else{ |
| 731 | node_algorithms::init_header(this->get_root_node()); |
| 732 | this->priv_size_traits().set_size(size_type(0)); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 737 | //! |
| 738 | //! <b>Effects</b>: Erases all the elements of the container. |
| 739 | //! No destructors are called. |
| 740 | //! Disposer::operator()(pointer) is called for the removed elements. |
| 741 | //! |
| 742 | //! <b>Throws</b>: Nothing. |
| 743 | //! |
| 744 | //! <b>Complexity</b>: Linear to the number of elements of the list. |
| 745 | //! |
| 746 | //! <b>Note</b>: Invalidates the iterators to the erased elements. |
| 747 | template <class Disposer> |
| 748 | void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT |
| 749 | { |
| 750 | const_iterator it(this->begin()), itend(this->end()); |
| 751 | while(it != itend){ |
| 752 | node_ptr to_erase(it.pointed_node()); |
| 753 | ++it; |
| 754 | BOOST_IF_CONSTEXPR(safemode_or_autounlink) |
| 755 | node_algorithms::init(to_erase); |
| 756 | disposer(priv_value_traits().to_value_ptr(to_erase)); |
| 757 | } |
| 758 | node_algorithms::init_header(this->get_root_node()); |
| 759 | this->priv_size_traits().set_size(0); |
| 760 | } |
| 761 | |
| 762 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 763 | //! Cloner should yield to nodes equivalent to the original nodes. |
| 764 | //! |
| 765 | //! <b>Effects</b>: Erases all the elements from *this |
| 766 | //! calling Disposer::operator()(pointer), clones all the |
| 767 | //! elements from src calling Cloner::operator()(const_reference ) |
| 768 | //! and inserts them on *this. |
| 769 | //! |
| 770 | //! If cloner throws, all cloned elements are unlinked and disposed |
| 771 | //! calling Disposer::operator()(pointer). |
| 772 | //! |
| 773 | //! <b>Complexity</b>: Linear to erased plus inserted elements. |
| 774 | //! |
| 775 | //! <b>Throws</b>: If cloner throws. Basic guarantee. |
| 776 | template <class Cloner, class Disposer> |
| 777 | void clone_from(const list_impl &src, Cloner cloner, Disposer disposer) |
| 778 | { |
| 779 | this->clear_and_dispose(disposer); |
| 780 | detail::exception_disposer<list_impl, Disposer> |
| 781 | rollback(*this, disposer); |
| 782 | const_iterator b(src.begin()), e(src.end()); |
| 783 | for(; b != e; ++b){ |
| 784 | this->push_back(*cloner(*b)); |
| 785 | } |
| 786 | rollback.release(); |
| 787 | } |
| 788 | |
| 789 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 790 | //! Cloner should yield to nodes equivalent to the original nodes. |
| 791 | //! |
| 792 | //! <b>Effects</b>: Erases all the elements from *this |
| 793 | //! calling Disposer::operator()(pointer), clones all the |
| 794 | //! elements from src calling Cloner::operator()(reference) |
| 795 | //! and inserts them on *this. |
| 796 | //! |
| 797 | //! If cloner throws, all cloned elements are unlinked and disposed |
| 798 | //! calling Disposer::operator()(pointer). |
| 799 | //! |
| 800 | //! <b>Complexity</b>: Linear to erased plus inserted elements. |
| 801 | //! |
| 802 | //! <b>Throws</b>: If cloner throws. Basic guarantee. |
| 803 | template <class Cloner, class Disposer> |
| 804 | void clone_from(BOOST_RV_REF(list_impl) src, Cloner cloner, Disposer disposer) |
| 805 | { |
| 806 | this->clear_and_dispose(disposer); |
| 807 | detail::exception_disposer<list_impl, Disposer> |
| 808 | rollback(*this, disposer); |
| 809 | iterator b(src.begin()), e(src.end()); |
| 810 | for(; b != e; ++b){ |
| 811 | this->push_back(*cloner(*b)); |
| 812 | } |
| 813 | rollback.release(); |
| 814 | } |
| 815 | |
| 816 | //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this. |
| 817 | //! |
| 818 | //! <b>Effects</b>: Inserts the value before the position pointed by p. |
| 819 | //! |
| 820 | //! <b>Returns</b>: An iterator to the inserted element. |
| 821 | //! |
| 822 | //! <b>Throws</b>: Nothing. |
| 823 | //! |
| 824 | //! <b>Complexity</b>: Constant time. No copy constructors are called. |
| 825 | //! |
| 826 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 827 | iterator insert(const_iterator p, reference value) BOOST_NOEXCEPT |
| 828 | { |
| 829 | node_ptr to_insert = this->priv_value_traits().to_node_ptr(value); |
| 830 | BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert)); |
| 831 | node_algorithms::link_before(p.pointed_node(), to_insert); |
| 832 | this->priv_size_traits().increment(); |
| 833 | return iterator(to_insert, this->priv_value_traits_ptr()); |
| 834 | } |
| 835 | |
| 836 | //! <b>Requires</b>: Dereferencing iterator must yield |
| 837 | //! an lvalue of type value_type and p must be a valid iterator of *this. |
| 838 | //! |
| 839 | //! <b>Effects</b>: Inserts the range pointed by b and e before the position p. |
| 840 | //! No copy constructors are called. |
| 841 | //! |
| 842 | //! <b>Throws</b>: Nothing. |
| 843 | //! |
| 844 | //! <b>Complexity</b>: Linear to the number of elements inserted. |
| 845 | //! |
| 846 | //! <b>Note</b>: Does not affect the validity of iterators and references. |
| 847 | template<class Iterator> |
| 848 | void insert(const_iterator p, Iterator b, Iterator e) BOOST_NOEXCEPT |
| 849 | { |
| 850 | for (; b != e; ++b) |
| 851 | this->insert(p, *b); |
| 852 | } |
| 853 | |
| 854 | //! <b>Requires</b>: Dereferencing iterator must yield |
| 855 | //! an lvalue of type value_type. |
| 856 | //! |
| 857 | //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e. |
| 858 | //! No destructors or copy constructors are called. |
| 859 | //! |
| 860 | //! <b>Throws</b>: Nothing. |
| 861 | //! |
| 862 | //! <b>Complexity</b>: Linear to the number of elements inserted plus |
| 863 | //! linear to the elements contained in the list if it's a safe-mode |
| 864 | //! or auto-unlink value. |
| 865 | //! Linear to the number of elements inserted in the list otherwise. |
| 866 | //! |
| 867 | //! <b>Note</b>: Invalidates the iterators (but not the references) |
| 868 | //! to the erased elements. |
| 869 | template<class Iterator> |
| 870 | void assign(Iterator b, Iterator e) BOOST_NOEXCEPT |
| 871 | { |
| 872 | this->clear(); |
| 873 | this->insert(this->cend(), b, e); |
| 874 | } |
| 875 | |
| 876 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 877 | //! |
| 878 | //! <b>Requires</b>: Dereferencing iterator must yield |
| 879 | //! an lvalue of type value_type. |
| 880 | //! |
| 881 | //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e. |
| 882 | //! No destructors or copy constructors are called. |
| 883 | //! Disposer::operator()(pointer) is called for the removed elements. |
| 884 | //! |
| 885 | //! <b>Throws</b>: Nothing. |
| 886 | //! |
| 887 | //! <b>Complexity</b>: Linear to the number of elements inserted plus |
| 888 | //! linear to the elements contained in the list. |
| 889 | //! |
| 890 | //! <b>Note</b>: Invalidates the iterators (but not the references) |
| 891 | //! to the erased elements. |
| 892 | template<class Iterator, class Disposer> |
| 893 | void dispose_and_assign(Disposer disposer, Iterator b, Iterator e) BOOST_NOEXCEPT |
| 894 | { |
| 895 | this->clear_and_dispose(disposer); |
| 896 | this->insert(this->cend(), b, e); |
| 897 | } |
| 898 | |
| 899 | //! <b>Requires</b>: p must be a valid iterator of *this. |
| 900 | //! |
| 901 | //! <b>Effects</b>: Transfers all the elements of list x to this list, before the |
| 902 | //! the element pointed by p. No destructors or copy constructors are called. |
| 903 | //! |
| 904 | //! <b>Throws</b>: Nothing. |
| 905 | //! |
| 906 | //! <b>Complexity</b>: Constant. |
| 907 | //! |
| 908 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of |
| 909 | //! this list. Iterators of this list and all the references are not invalidated. |
| 910 | void splice(const_iterator p, list_impl& x) BOOST_NOEXCEPT |
| 911 | { |
| 912 | if(!x.empty()){ |
| 913 | node_algorithms::transfer |
| 914 | (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node()); |
| 915 | size_traits &thist = this->priv_size_traits(); |
| 916 | size_traits &xt = x.priv_size_traits(); |
| 917 | thist.increase(xt.get_size()); |
| 918 | xt.set_size(size_type(0)); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | //! <b>Requires</b>: p must be a valid iterator of *this. |
| 923 | //! new_ele must point to an element contained in list x. |
| 924 | //! |
| 925 | //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list, |
| 926 | //! before the element pointed by p. No destructors or copy constructors are called. |
| 927 | //! If p == new_ele or p == ++new_ele, this function is a null operation. |
| 928 | //! |
| 929 | //! <b>Throws</b>: Nothing. |
| 930 | //! |
| 931 | //! <b>Complexity</b>: Constant. |
| 932 | //! |
| 933 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this |
| 934 | //! list. Iterators of this list and all the references are not invalidated. |
| 935 | void splice(const_iterator p, list_impl&x, const_iterator new_ele) BOOST_NOEXCEPT |
| 936 | { |
| 937 | node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node()); |
| 938 | x.priv_size_traits().decrement(); |
| 939 | this->priv_size_traits().increment(); |
| 940 | } |
| 941 | |
| 942 | //! <b>Requires</b>: p must be a valid iterator of *this. |
| 943 | //! f and e must point to elements contained in list x. |
| 944 | //! |
| 945 | //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list, |
| 946 | //! before the element pointed by p. No destructors or copy constructors are called. |
| 947 | //! |
| 948 | //! <b>Throws</b>: Nothing. |
| 949 | //! |
| 950 | //! <b>Complexity</b>: Linear to the number of elements transferred |
| 951 | //! if constant-time size option is enabled. Constant-time otherwise. |
| 952 | //! |
| 953 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this |
| 954 | //! list. Iterators of this list and all the references are not invalidated. |
| 955 | void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) BOOST_NOEXCEPT |
| 956 | { |
| 957 | BOOST_IF_CONSTEXPR(constant_time_size) |
| 958 | this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node())); |
| 959 | else |
| 960 | this->splice(p, x, f, e, 1);//intrusive::iterator_distance is a dummy value |
| 961 | } |
| 962 | |
| 963 | //! <b>Requires</b>: p must be a valid iterator of *this. |
| 964 | //! f and e must point to elements contained in list x. |
| 965 | //! n == distance(f, e) |
| 966 | //! |
| 967 | //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list, |
| 968 | //! before the element pointed by p. No destructors or copy constructors are called. |
| 969 | //! |
| 970 | //! <b>Throws</b>: Nothing. |
| 971 | //! |
| 972 | //! <b>Complexity</b>: Constant. |
| 973 | //! |
| 974 | //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this |
| 975 | //! list. Iterators of this list and all the references are not invalidated. |
| 976 | void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n) BOOST_NOEXCEPT |
| 977 | { |
| 978 | if(n){ |
| 979 | BOOST_IF_CONSTEXPR(constant_time_size){ |
| 980 | BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node())); |
| 981 | node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); |
| 982 | size_traits &thist = this->priv_size_traits(); |
| 983 | size_traits &xt = x.priv_size_traits(); |
| 984 | thist.increase(n); |
| 985 | xt.decrease(n); |
| 986 | } |
| 987 | else{ |
| 988 | node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | //! <b>Effects</b>: This function sorts the list *this according to operator <. |
| 994 | //! The sort is stable, that is, the relative order of equivalent elements is preserved. |
| 995 | //! |
| 996 | //! <b>Throws</b>: If value_traits::node_traits::node |
| 997 | //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) |
| 998 | //! or operator < throws. Basic guarantee. |
| 999 | //! |
| 1000 | //! <b>Notes</b>: Iterators and references are not invalidated. |
| 1001 | //! |
| 1002 | //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N |
| 1003 | //! is the list's size. |
| 1004 | void sort() |
| 1005 | { this->sort(value_less<value_type>()); } |
| 1006 | |
| 1007 | //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering |
| 1008 | //! |
| 1009 | //! <b>Effects</b>: This function sorts the list *this according to p. The sort is |
| 1010 | //! stable, that is, the relative order of equivalent elements is preserved. |
| 1011 | //! |
| 1012 | //! <b>Throws</b>: If value_traits::node_traits::node |
| 1013 | //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) |
| 1014 | //! or the predicate throws. Basic guarantee. |
| 1015 | //! |
| 1016 | //! <b>Notes</b>: This won't throw if list_base_hook<> or |
| 1017 | //! list_member_hook are used. |
| 1018 | //! Iterators and references are not invalidated. |
| 1019 | //! |
| 1020 | //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N |
| 1021 | //! is the list's size. |
| 1022 | template<class Predicate> |
| 1023 | void sort(Predicate p) |
| 1024 | { |
| 1025 | if(node_traits::get_next(this->get_root_node()) |
| 1026 | != node_traits::get_previous(this->get_root_node())){ |
| 1027 | list_impl carry(this->priv_value_traits()); |
| 1028 | detail::array_initializer<list_impl, 64> counter(this->priv_value_traits()); |
| 1029 | int fill = 0; |
| 1030 | while(!this->empty()){ |
| 1031 | carry.splice(carry.cbegin(), *this, this->cbegin()); |
| 1032 | int i = 0; |
| 1033 | while(i < fill && !counter[i].empty()) { |
| 1034 | counter[i].merge(carry, p); |
| 1035 | carry.swap(counter[i++]); |
| 1036 | } |
| 1037 | carry.swap(counter[i]); |
| 1038 | if(i == fill) |
| 1039 | ++fill; |
| 1040 | } |
| 1041 | for (int i = 1; i < fill; ++i) |
| 1042 | counter[i].merge(counter[i-1], p); |
| 1043 | this->swap(counter[fill-1]); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | //! <b>Effects</b>: This function removes all of x's elements and inserts them |
| 1048 | //! in order into *this according to operator <. The merge is stable; |
| 1049 | //! that is, if an element from *this is equivalent to one from x, then the element |
| 1050 | //! from *this will precede the one from x. |
| 1051 | //! |
| 1052 | //! <b>Throws</b>: If operator < throws. Basic guarantee. |
| 1053 | //! |
| 1054 | //! <b>Complexity</b>: This function is linear time: it performs at most |
| 1055 | //! size() + x.size() - 1 comparisons. |
| 1056 | //! |
| 1057 | //! <b>Note</b>: Iterators and references are not invalidated |
| 1058 | void merge(list_impl& x) |
| 1059 | { this->merge(x, value_less<value_type>()); } |
| 1060 | |
| 1061 | //! <b>Requires</b>: p must be a comparison function that induces a strict weak |
| 1062 | //! ordering and both *this and x must be sorted according to that ordering |
| 1063 | //! The lists x and *this must be distinct. |
| 1064 | //! |
| 1065 | //! <b>Effects</b>: This function removes all of x's elements and inserts them |
| 1066 | //! in order into *this. The merge is stable; that is, if an element from *this is |
| 1067 | //! equivalent to one from x, then the element from *this will precede the one from x. |
| 1068 | //! |
| 1069 | //! <b>Throws</b>: If the predicate throws. Basic guarantee. |
| 1070 | //! |
| 1071 | //! <b>Complexity</b>: This function is linear time: it performs at most |
| 1072 | //! size() + x.size() - 1 comparisons. |
| 1073 | //! |
| 1074 | //! <b>Note</b>: Iterators and references are not invalidated. |
| 1075 | template<class Predicate> |
| 1076 | void merge(list_impl& x, Predicate p) |
| 1077 | { |
| 1078 | const_iterator e(this->cend()), ex(x.cend()); |
| 1079 | const_iterator b(this->cbegin()); |
| 1080 | while(!x.empty()){ |
| 1081 | const_iterator ix(x.cbegin()); |
| 1082 | while (b != e && !p(*ix, *b)){ |
| 1083 | ++b; |
| 1084 | } |
| 1085 | if(b == e){ |
| 1086 | //Now transfer the rest to the end of the container |
| 1087 | this->splice(e, x); |
| 1088 | break; |
| 1089 | } |
| 1090 | else{ |
| 1091 | size_type n(0); |
| 1092 | do{ |
| 1093 | ++ix; ++n; |
| 1094 | } while(ix != ex && p(*ix, *b)); |
| 1095 | this->splice(b, x, x.begin(), ix, n); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | //! <b>Effects</b>: Reverses the order of elements in the list. |
| 1101 | //! |
| 1102 | //! <b>Throws</b>: Nothing. |
| 1103 | //! |
| 1104 | //! <b>Complexity</b>: This function is linear time. |
| 1105 | //! |
| 1106 | //! <b>Note</b>: Iterators and references are not invalidated |
| 1107 | void reverse() BOOST_NOEXCEPT |
| 1108 | { node_algorithms::reverse(this->get_root_node()); } |
| 1109 | |
| 1110 | //! <b>Effects</b>: Removes all the elements that compare equal to value. |
| 1111 | //! No destructors are called. |
| 1112 | //! |
| 1113 | //! <b>Throws</b>: If operator == throws. Basic guarantee. |
| 1114 | //! |
| 1115 | //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality. |
| 1116 | //! |
| 1117 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1118 | //! and iterators to elements that are not removed remain valid. |
| 1119 | void remove(const_reference value) BOOST_NOEXCEPT |
| 1120 | { this->remove_if(detail::equal_to_value<const_reference>(value)); } |
| 1121 | |
| 1122 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 1123 | //! |
| 1124 | //! <b>Effects</b>: Removes all the elements that compare equal to value. |
| 1125 | //! Disposer::operator()(pointer) is called for every removed element. |
| 1126 | //! |
| 1127 | //! <b>Throws</b>: If operator == throws. Basic guarantee. |
| 1128 | //! |
| 1129 | //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality. |
| 1130 | //! |
| 1131 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1132 | //! and iterators to elements that are not removed remain valid. |
| 1133 | template<class Disposer> |
| 1134 | void remove_and_dispose(const_reference value, Disposer disposer) BOOST_NOEXCEPT |
| 1135 | { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); } |
| 1136 | |
| 1137 | //! <b>Effects</b>: Removes all the elements for which a specified |
| 1138 | //! predicate is satisfied. No destructors are called. |
| 1139 | //! |
| 1140 | //! <b>Throws</b>: If pred throws. Basic guarantee. |
| 1141 | //! |
| 1142 | //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate. |
| 1143 | //! |
| 1144 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1145 | //! and iterators to elements that are not removed remain valid. |
| 1146 | template<class Pred> |
| 1147 | void remove_if(Pred pred) |
| 1148 | { |
| 1149 | const node_ptr root_node = this->get_root_node(); |
| 1150 | typename node_algorithms::stable_partition_info info; |
| 1151 | node_algorithms::stable_partition |
| 1152 | (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); |
| 1153 | //Invariants preserved by stable_partition so erase can be safely called |
| 1154 | //The first element might have changed so calculate it again |
| 1155 | this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr()) |
| 1156 | , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) |
| 1157 | , info.num_1st_partition); |
| 1158 | } |
| 1159 | |
| 1160 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 1161 | //! |
| 1162 | //! <b>Effects</b>: Removes all the elements for which a specified |
| 1163 | //! predicate is satisfied. |
| 1164 | //! Disposer::operator()(pointer) is called for every removed element. |
| 1165 | //! |
| 1166 | //! <b>Throws</b>: If pred throws. Basic guarantee. |
| 1167 | //! |
| 1168 | //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality. |
| 1169 | //! |
| 1170 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1171 | //! and iterators to elements that are not removed remain valid. |
| 1172 | template<class Pred, class Disposer> |
| 1173 | void remove_and_dispose_if(Pred pred, Disposer disposer) |
| 1174 | { |
| 1175 | const node_ptr root_node = this->get_root_node(); |
| 1176 | typename node_algorithms::stable_partition_info info; |
| 1177 | node_algorithms::stable_partition |
| 1178 | (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); |
| 1179 | //Invariants preserved by stable_partition so erase can be safely called |
| 1180 | //The first element might have changed so calculate it again |
| 1181 | this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr()) |
| 1182 | , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) |
| 1183 | , disposer); |
| 1184 | } |
| 1185 | |
| 1186 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent |
| 1187 | //! elements that are equal from the list. No destructors are called. |
| 1188 | //! |
| 1189 | //! <b>Throws</b>: If the comparison operator throws. Basic guarantee. |
| 1190 | //! |
| 1191 | //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()). |
| 1192 | //! |
| 1193 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1194 | //! and iterators to elements that are not removed remain valid. |
| 1195 | void unique() |
| 1196 | { this->unique_and_dispose(value_equal<value_type>(), detail::null_disposer()); } |
| 1197 | |
| 1198 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent |
| 1199 | //! elements that satisfy some binary predicate from the list. |
| 1200 | //! No destructors are called. |
| 1201 | //! |
| 1202 | //! <b>Throws</b>: If pred throws. Basic guarantee. |
| 1203 | //! |
| 1204 | //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons). |
| 1205 | //! |
| 1206 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1207 | //! and iterators to elements that are not removed remain valid. |
| 1208 | template<class BinaryPredicate> |
| 1209 | void unique(BinaryPredicate pred) |
| 1210 | { this->unique_and_dispose(pred, detail::null_disposer()); } |
| 1211 | |
| 1212 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 1213 | //! |
| 1214 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent |
| 1215 | //! elements that are equal from the list. |
| 1216 | //! Disposer::operator()(pointer) is called for every removed element. |
| 1217 | //! |
| 1218 | //! <b>Throws</b>: If the equality operator throws. Basic guarantee. |
| 1219 | //! |
| 1220 | //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons. |
| 1221 | //! |
| 1222 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1223 | //! and iterators to elements that are not removed remain valid. |
| 1224 | template<class Disposer> |
| 1225 | void unique_and_dispose(Disposer disposer) |
| 1226 | { this->unique_and_dispose(value_equal<value_type>(), disposer); } |
| 1227 | |
| 1228 | //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. |
| 1229 | //! |
| 1230 | //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent |
| 1231 | //! elements that satisfy some binary predicate from the list. |
| 1232 | //! Disposer::operator()(pointer) is called for every removed element. |
| 1233 | //! |
| 1234 | //! <b>Throws</b>: If pred throws. Basic guarantee. |
| 1235 | //! |
| 1236 | //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons. |
| 1237 | //! |
| 1238 | //! <b>Note</b>: The relative order of elements that are not removed is unchanged, |
| 1239 | //! and iterators to elements that are not removed remain valid. |
| 1240 | template<class BinaryPredicate, class Disposer> |
| 1241 | void unique_and_dispose(BinaryPredicate pred, Disposer disposer) |
| 1242 | { |
| 1243 | const_iterator itend(this->cend()); |
| 1244 | const_iterator cur(this->cbegin()); |
| 1245 | |
| 1246 | if(cur != itend){ |
| 1247 | const_iterator after(cur); |
| 1248 | ++after; |
| 1249 | while(after != itend){ |
| 1250 | if(pred(*cur, *after)){ |
| 1251 | after = this->erase_and_dispose(after, disposer); |
| 1252 | } |
| 1253 | else{ |
| 1254 | cur = after; |
| 1255 | ++after; |
| 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | //! <b>Requires</b>: value must be a reference to a value inserted in a list. |
| 1262 | //! |
| 1263 | //! <b>Effects</b>: This function returns a const_iterator pointing to the element |
| 1264 | //! |
| 1265 | //! <b>Throws</b>: Nothing. |
| 1266 | //! |
| 1267 | //! <b>Complexity</b>: Constant time. |
| 1268 | //! |
| 1269 | //! <b>Note</b>: Iterators and references are not invalidated. |
| 1270 | //! This static function is available only if the <i>value traits</i> |
| 1271 | //! is stateless. |
| 1272 | static iterator s_iterator_to(reference value) BOOST_NOEXCEPT |
| 1273 | { |
| 1274 | BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits)); |
| 1275 | BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value))); |
| 1276 | return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr()); |
| 1277 | } |
| 1278 | |
| 1279 | //! <b>Requires</b>: value must be a const reference to a value inserted in a list. |
| 1280 | //! |
| 1281 | //! <b>Effects</b>: This function returns an iterator pointing to the element. |
| 1282 | //! |
| 1283 | //! <b>Throws</b>: Nothing. |
| 1284 | //! |
| 1285 | //! <b>Complexity</b>: Constant time. |
| 1286 | //! |
| 1287 | //! <b>Note</b>: Iterators and references are not invalidated. |
| 1288 | //! This static function is available only if the <i>value traits</i> |
| 1289 | //! is stateless. |
| 1290 | static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT |
| 1291 | { |
| 1292 | BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits)); |
| 1293 | reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value)); |
| 1294 | BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r))); |
| 1295 | return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr()); |
| 1296 | } |
| 1297 | |
| 1298 | //! <b>Requires</b>: value must be a reference to a value inserted in a list. |
| 1299 | //! |
| 1300 | //! <b>Effects</b>: This function returns a const_iterator pointing to the element |
| 1301 | //! |
| 1302 | //! <b>Throws</b>: Nothing. |
| 1303 | //! |
| 1304 | //! <b>Complexity</b>: Constant time. |
| 1305 | //! |
| 1306 | //! <b>Note</b>: Iterators and references are not invalidated. |
| 1307 | iterator iterator_to(reference value) BOOST_NOEXCEPT |
| 1308 | { |
| 1309 | BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value))); |
| 1310 | return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); |
| 1311 | } |
| 1312 | |
| 1313 | //! <b>Requires</b>: value must be a const reference to a value inserted in a list. |
| 1314 | //! |
| 1315 | //! <b>Effects</b>: This function returns an iterator pointing to the element. |
| 1316 | //! |
| 1317 | //! <b>Throws</b>: Nothing. |
| 1318 | //! |
| 1319 | //! <b>Complexity</b>: Constant time. |
| 1320 | //! |
| 1321 | //! <b>Note</b>: Iterators and references are not invalidated. |
| 1322 | const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT |
| 1323 | { |
| 1324 | reference r = *detail::uncast(pointer_traits<const_pointer>::pointer_to(value)); |
| 1325 | BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r))); |
| 1326 | return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr()); |
| 1327 | } |
| 1328 | |
| 1329 | //! <b>Effects</b>: Asserts the integrity of the container. |
| 1330 | //! |
| 1331 | //! <b>Complexity</b>: Linear time. |
| 1332 | //! |
| 1333 | //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG). |
| 1334 | //! Experimental function, interface might change in future versions. |
| 1335 | void check() const |
| 1336 | { |
| 1337 | const_node_ptr = get_root_node(); |
| 1338 | // header's next and prev are never null |
| 1339 | BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr)); |
| 1340 | BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr)); |
| 1341 | // header's next and prev either both point to header (empty list) or neither does |
| 1342 | BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr) |
| 1343 | == (node_traits::get_previous(header_ptr) == header_ptr)); |
| 1344 | if (node_traits::get_next(header_ptr) == header_ptr) |
| 1345 | { |
| 1346 | BOOST_IF_CONSTEXPR(constant_time_size) |
| 1347 | BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0); |
| 1348 | return; |
| 1349 | } |
| 1350 | size_t node_count = 0; (void)node_count; |
| 1351 | const_node_ptr p = header_ptr; |
| 1352 | while (true) |
| 1353 | { |
| 1354 | const_node_ptr next_p = node_traits::get_next(p); |
| 1355 | BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p); |
| 1356 | BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p); |
| 1357 | p = next_p; |
| 1358 | if (p == header_ptr) break; |
| 1359 | ++node_count; |
| 1360 | } |
| 1361 | BOOST_IF_CONSTEXPR(constant_time_size) |
| 1362 | BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count); |
| 1363 | } |
| 1364 | |
| 1365 | friend bool operator==(const list_impl &x, const list_impl &y) |
| 1366 | { |
| 1367 | if(constant_time_size && x.size() != y.size()){ |
| 1368 | return false; |
| 1369 | } |
| 1370 | return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend()); |
| 1371 | } |
| 1372 | |
| 1373 | inline friend bool operator!=(const list_impl &x, const list_impl &y) |
| 1374 | { return !(x == y); } |
| 1375 | |
| 1376 | inline friend bool operator<(const list_impl &x, const list_impl &y) |
| 1377 | { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } |
| 1378 | |
| 1379 | inline friend bool operator>(const list_impl &x, const list_impl &y) |
| 1380 | { return y < x; } |
| 1381 | |
| 1382 | inline friend bool operator<=(const list_impl &x, const list_impl &y) |
| 1383 | { return !(y < x); } |
| 1384 | |
| 1385 | inline friend bool operator>=(const list_impl &x, const list_impl &y) |
| 1386 | { return !(x < y); } |
| 1387 | |
| 1388 | inline friend void swap(list_impl &x, list_impl &y) BOOST_NOEXCEPT |
| 1389 | { x.swap(y); } |
| 1390 | |
| 1391 | /// @cond |
| 1392 | |
| 1393 | private: |
| 1394 | static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) BOOST_NOEXCEPT |
| 1395 | { |
| 1396 | BOOST_INTRUSIVE_STATIC_ASSERT((has_container_from_iterator)); |
| 1397 | node_ptr p = end_iterator.pointed_node(); |
| 1398 | header_holder_type* h = header_holder_type::get_holder(p); |
| 1399 | root_plus_size* r = detail::parent_from_member |
| 1400 | < root_plus_size, header_holder_type>(h, &root_plus_size::m_header); |
| 1401 | data_t *d = detail::parent_from_member<data_t, root_plus_size> |
| 1402 | ( r, &data_t::root_plus_size_); |
| 1403 | list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_); |
| 1404 | return *s; |
| 1405 | } |
| 1406 | /// @endcond |
| 1407 | }; |
| 1408 | |
| 1409 | |
| 1410 | //! Helper metafunction to define a \c list that yields to the same type when the |
| 1411 | //! same options (either explicitly or implicitly) are used. |
| 1412 | #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) |
| 1413 | template<class T, class ...Options> |
| 1414 | #else |
| 1415 | template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void> |
| 1416 | #endif |
| 1417 | struct make_list |
| 1418 | { |
| 1419 | /// @cond |
| 1420 | typedef typename pack_options |
| 1421 | < list_defaults, |
| 1422 | #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) |
| 1423 | O1, O2, O3, O4 |
| 1424 | #else |
| 1425 | Options... |
| 1426 | #endif |
| 1427 | >::type packed_options; |
| 1428 | |
| 1429 | typedef typename detail::get_value_traits |
| 1430 | <T, typename packed_options::proto_value_traits>::type value_traits; |
| 1431 | typedef list_impl |
| 1432 | < |
| 1433 | value_traits, |
| 1434 | typename packed_options::size_type, |
| 1435 | packed_options::constant_time_size, |
| 1436 | typename packed_options::header_holder_type |
| 1437 | > implementation_defined; |
| 1438 | /// @endcond |
| 1439 | typedef implementation_defined type; |
| 1440 | }; |
| 1441 | |
| 1442 | |
| 1443 | #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED |
| 1444 | |
| 1445 | #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) |
| 1446 | template<class T, class O1, class O2, class O3, class O4> |
| 1447 | #else |
| 1448 | template<class T, class ...Options> |
| 1449 | #endif |
| 1450 | class list |
| 1451 | : public make_list<T, |
| 1452 | #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) |
| 1453 | O1, O2, O3, O4 |
| 1454 | #else |
| 1455 | Options... |
| 1456 | #endif |
| 1457 | >::type |
| 1458 | { |
| 1459 | typedef typename make_list |
| 1460 | <T, |
| 1461 | #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) |
| 1462 | O1, O2, O3, O4 |
| 1463 | #else |
| 1464 | Options... |
| 1465 | #endif |
| 1466 | >::type Base; |
| 1467 | //Assert if passed value traits are compatible with the type |
| 1468 | BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value)); |
| 1469 | BOOST_MOVABLE_BUT_NOT_COPYABLE(list) |
| 1470 | |
| 1471 | public: |
| 1472 | typedef typename Base::value_traits value_traits; |
| 1473 | typedef typename Base::iterator iterator; |
| 1474 | typedef typename Base::const_iterator const_iterator; |
| 1475 | |
| 1476 | inline list() |
| 1477 | : Base() |
| 1478 | {} |
| 1479 | |
| 1480 | inline explicit list(const value_traits &v_traits) |
| 1481 | : Base(v_traits) |
| 1482 | {} |
| 1483 | |
| 1484 | template<class Iterator> |
| 1485 | inline list(Iterator b, Iterator e, const value_traits &v_traits = value_traits()) |
| 1486 | : Base(b, e, v_traits) |
| 1487 | {} |
| 1488 | |
| 1489 | inline list(BOOST_RV_REF(list) x) |
| 1490 | : Base(BOOST_MOVE_BASE(Base, x)) |
| 1491 | {} |
| 1492 | |
| 1493 | inline list& operator=(BOOST_RV_REF(list) x) |
| 1494 | { return static_cast<list &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); } |
| 1495 | |
| 1496 | template <class Cloner, class Disposer> |
| 1497 | inline void clone_from(const list &src, Cloner cloner, Disposer disposer) |
| 1498 | { Base::clone_from(src, cloner, disposer); } |
| 1499 | |
| 1500 | template <class Cloner, class Disposer> |
| 1501 | inline void clone_from(BOOST_RV_REF(list) src, Cloner cloner, Disposer disposer) |
| 1502 | { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); } |
| 1503 | |
| 1504 | inline static list &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT |
| 1505 | { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); } |
| 1506 | |
| 1507 | inline static const list &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT |
| 1508 | { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); } |
| 1509 | }; |
| 1510 | |
| 1511 | #endif |
| 1512 | |
| 1513 | } //namespace intrusive |
| 1514 | } //namespace boost |
| 1515 | |
| 1516 | #include <boost/intrusive/detail/config_end.hpp> |
| 1517 | |
| 1518 | #endif //BOOST_INTRUSIVE_LIST_HPP |
| 1519 | |