Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:34:23

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Olaf Krzikalla 2004-2006.
0004 // (C) Copyright Ion Gaztanaga  2006-2014
0005 //
0006 // Distributed under the Boost Software License, Version 1.0.
0007 //    (See accompanying file LICENSE_1_0.txt or copy at
0008 //          http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 // See http://www.boost.org/libs/intrusive for documentation.
0011 //
0012 /////////////////////////////////////////////////////////////////////////////
0013 
0014 #ifndef BOOST_INTRUSIVE_LIST_HPP
0015 #define BOOST_INTRUSIVE_LIST_HPP
0016 
0017 #include <boost/intrusive/detail/config_begin.hpp>
0018 #include <boost/intrusive/intrusive_fwd.hpp>
0019 #include <boost/intrusive/detail/assert.hpp>
0020 #include <boost/intrusive/list_hook.hpp>
0021 #include <boost/intrusive/circular_list_algorithms.hpp>
0022 #include <boost/intrusive/pointer_traits.hpp>
0023 #include <boost/intrusive/detail/mpl.hpp>
0024 #include <boost/intrusive/link_mode.hpp>
0025 #include <boost/intrusive/detail/get_value_traits.hpp>
0026 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
0027 #include <boost/intrusive/detail/default_header_holder.hpp>
0028 #include <boost/intrusive/detail/reverse_iterator.hpp>
0029 #include <boost/intrusive/detail/uncast.hpp>
0030 #include <boost/intrusive/detail/list_iterator.hpp>
0031 #include <boost/intrusive/detail/array_initializer.hpp>
0032 #include <boost/intrusive/detail/exception_disposer.hpp>
0033 #include <boost/intrusive/detail/equal_to_value.hpp>
0034 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
0035 #include <boost/intrusive/detail/simple_disposers.hpp>
0036 #include <boost/intrusive/detail/size_holder.hpp>
0037 #include <boost/intrusive/detail/algorithm.hpp>
0038 
0039 #include <boost/move/utility_core.hpp>
0040 
0041 #include <boost/intrusive/detail/value_functors.hpp>
0042 #include <cstddef>   //std::size_t, etc.
0043 
0044 #if defined(BOOST_HAS_PRAGMA_ONCE)
0045 #  pragma once
0046 #endif
0047 
0048 namespace boost {
0049 namespace intrusive {
0050 
0051 /// @cond
0052 
0053 struct default_list_hook_applier
0054 {  template <class T> struct apply{ typedef typename T::default_list_hook type;  };  };
0055 
0056 template<>
0057 struct is_default_hook_tag<default_list_hook_applier>
0058 {  static const bool value = true;  };
0059 
0060 struct list_defaults
0061 {
0062    typedef default_list_hook_applier proto_value_traits;
0063    static const bool constant_time_size = true;
0064    typedef std::size_t size_type;
0065    typedef void header_holder_type;
0066 };
0067 
0068 /// @endcond
0069 
0070 //! The class template list is an intrusive container that mimics most of the
0071 //! interface of std::list as described in the C++ standard.
0072 //!
0073 //! The template parameter \c T is the type to be managed by the container.
0074 //! The user can specify additional options and if no options are provided
0075 //! default options are used.
0076 //!
0077 //! The container supports the following options:
0078 //! \c base_hook<>/member_hook<>/value_traits<>,
0079 //! \c constant_time_size<> and \c size_type<>.
0080 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
0081 template<class T, class ...Options>
0082 #else
0083 template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
0084 #endif
0085 class list_impl
0086 {
0087    //Public typedefs
0088    public:
0089    typedef ValueTraits                                               value_traits;
0090    typedef typename value_traits::pointer                            pointer;
0091    typedef typename value_traits::const_pointer                      const_pointer;
0092    typedef typename pointer_traits<pointer>::element_type            value_type;
0093    typedef typename pointer_traits<pointer>::reference               reference;
0094    typedef typename pointer_traits<const_pointer>::reference         const_reference;
0095    typedef typename pointer_traits<pointer>::difference_type         difference_type;
0096    typedef SizeType                                                  size_type;
0097    typedef list_iterator<value_traits, false>                        iterator;
0098    typedef list_iterator<value_traits, true>                         const_iterator;
0099    typedef boost::intrusive::reverse_iterator<iterator>              reverse_iterator;
0100    typedef boost::intrusive::reverse_iterator<const_iterator>        const_reverse_iterator;
0101    typedef typename value_traits::node_traits                        node_traits;
0102    typedef typename node_traits::node                                node;
0103    typedef typename node_traits::node_ptr                            node_ptr;
0104    typedef typename node_traits::const_node_ptr                      const_node_ptr;
0105    typedef circular_list_algorithms<node_traits>                     node_algorithms;
0106    typedef typename detail::get_header_holder_type
0107       < value_traits, HeaderHolder >::type                           header_holder_type;
0108 
0109    static const bool constant_time_size = ConstantTimeSize;
0110    static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
0111    static const bool has_container_from_iterator =
0112         detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value;
0113 
0114    /// @cond
0115 
0116    private:
0117    typedef detail::size_holder<constant_time_size, size_type>          size_traits;
0118 
0119    //noncopyable
0120    BOOST_MOVABLE_BUT_NOT_COPYABLE(list_impl)
0121 
0122    static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
0123 
0124    //Constant-time size is incompatible with auto-unlink hooks!
0125    BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size &&
0126                         ((int)value_traits::link_mode == (int)auto_unlink)
0127                       ));
0128 
0129    inline node_ptr get_root_node()
0130    { return data_.root_plus_size_.m_header.get_node(); }
0131 
0132    inline const_node_ptr get_root_node() const
0133    { return data_.root_plus_size_.m_header.get_node(); }
0134 
0135    struct root_plus_size : public size_traits
0136    {
0137       header_holder_type m_header;
0138    };
0139 
0140    struct data_t : public value_traits
0141    {
0142       typedef typename list_impl::value_traits value_traits;
0143       inline explicit data_t(const value_traits &val_traits)
0144          :  value_traits(val_traits)
0145       {}
0146 
0147       root_plus_size root_plus_size_;
0148    } data_;
0149 
0150    inline size_traits &priv_size_traits() BOOST_NOEXCEPT
0151    {  return data_.root_plus_size_;  }
0152 
0153    inline const size_traits &priv_size_traits() const BOOST_NOEXCEPT
0154    {  return data_.root_plus_size_;  }
0155 
0156    inline const value_traits &priv_value_traits() const BOOST_NOEXCEPT
0157    {  return data_;  }
0158 
0159    inline value_traits &priv_value_traits() BOOST_NOEXCEPT
0160    {  return data_;  }
0161 
0162    typedef typename boost::intrusive::value_traits_pointers
0163       <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
0164 
0165    inline const_value_traits_ptr priv_value_traits_ptr() const BOOST_NOEXCEPT
0166    {  return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits());  }
0167 
0168    /// @endcond
0169 
0170    public:
0171 
0172    //! <b>Effects</b>: constructs an empty list.
0173    //!
0174    //! <b>Complexity</b>: Constant
0175    //!
0176    //! <b>Throws</b>: If value_traits::node_traits::node
0177    //!   constructor throws (this does not happen with predefined Boost.Intrusive hooks).
0178    list_impl()
0179       :  data_(value_traits())
0180    {
0181       this->priv_size_traits().set_size(size_type(0));
0182       node_algorithms::init_header(this->get_root_node());
0183    }
0184 
0185    //! <b>Effects</b>: constructs an empty list.
0186    //!
0187    //! <b>Complexity</b>: Constant
0188    //!
0189    //! <b>Throws</b>: If value_traits::node_traits::node
0190    //!   constructor throws (this does not happen with predefined Boost.Intrusive hooks).
0191    explicit list_impl(const value_traits &v_traits)
0192       :  data_(v_traits)
0193    {
0194       this->priv_size_traits().set_size(size_type(0));
0195       node_algorithms::init_header(this->get_root_node());
0196    }
0197 
0198    //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
0199    //!
0200    //! <b>Effects</b>: Constructs a list equal to the range [first,last).
0201    //!
0202    //! <b>Complexity</b>: Linear in distance(b, e). No copy constructors are called.
0203    //!
0204    //! <b>Throws</b>: If value_traits::node_traits::node
0205    //!   constructor throws (this does not happen with predefined Boost.Intrusive hooks).
0206    template<class Iterator>
0207    list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
0208       :  data_(v_traits)
0209    {
0210       //nothrow, no need to rollback to release elements on exception
0211       this->priv_size_traits().set_size(size_type(0));
0212       node_algorithms::init_header(this->get_root_node());
0213       //nothrow, no need to rollback to release elements on exception
0214       this->insert(this->cend(), b, e);
0215    }
0216 
0217    //! <b>Effects</b>: Constructs a container moving resources from another container.
0218    //!   Internal value traits are move constructed and
0219    //!   nodes belonging to x (except the node representing the "end") are linked to *this.
0220    //!
0221    //! <b>Complexity</b>: Constant.
0222    //!
0223    //! <b>Throws</b>: If value_traits::node_traits::node's
0224    //!   move constructor throws (this does not happen with predefined Boost.Intrusive hooks)
0225    //!   or the move constructor of value traits throws.
0226    list_impl(BOOST_RV_REF(list_impl) x)
0227       : data_(::boost::move(x.priv_value_traits()))
0228    {
0229       this->priv_size_traits().set_size(size_type(0));
0230       node_algorithms::init_header(this->get_root_node());
0231       //nothrow, no need to rollback to release elements on exception
0232       this->swap(x);
0233    }
0234 
0235    //! <b>Effects</b>: Equivalent to swap
0236    //!
0237    list_impl& operator=(BOOST_RV_REF(list_impl) x)
0238    {  this->swap(x); return *this;  }
0239 
0240    //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type
0241    //!   the destructor does nothing
0242    //!   (ie. no code is generated). Otherwise it detaches all elements from this.
0243    //!   In this case the objects in the list are not deleted (i.e. no destructors
0244    //!   are called), but the hooks according to the ValueTraits template parameter
0245    //!   are set to their default value.
0246    //!
0247    //! <b>Throws</b>: Nothing.
0248    //! 
0249    //! <b>Complexity</b>: Linear to the number of elements in the list, if
0250    //!   it's a safe-mode or auto-unlink value . Otherwise constant.
0251    ~list_impl()
0252    {
0253       BOOST_IF_CONSTEXPR(is_safe_autounlink<ValueTraits::link_mode>::value){
0254          this->clear();
0255          node_algorithms::init(this->get_root_node());
0256       }
0257    }
0258 
0259    //! <b>Requires</b>: value must be an lvalue.
0260    //!
0261    //! <b>Effects</b>: Inserts the value in the back of the list.
0262    //!   No copy constructors are called.
0263    //!
0264    //! <b>Throws</b>: Nothing.
0265    //!
0266    //! <b>Complexity</b>: Constant.
0267    //!
0268    //! <b>Note</b>: Does not affect the validity of iterators and references.
0269    void push_back(reference value) BOOST_NOEXCEPT
0270    {
0271       node_ptr to_insert = priv_value_traits().to_node_ptr(value);
0272       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
0273       node_algorithms::link_before(this->get_root_node(), to_insert);
0274       this->priv_size_traits().increment();
0275    }
0276 
0277    //! <b>Requires</b>: value must be an lvalue.
0278    //!
0279    //! <b>Effects</b>: Inserts the value in the front of the list.
0280    //!   No copy constructors are called.
0281    //!
0282    //! <b>Throws</b>: Nothing.
0283    //!
0284    //! <b>Complexity</b>: Constant.
0285    //!
0286    //! <b>Note</b>: Does not affect the validity of iterators and references.
0287    void push_front(reference value) BOOST_NOEXCEPT
0288    {
0289       node_ptr to_insert = priv_value_traits().to_node_ptr(value);
0290       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
0291       node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
0292       this->priv_size_traits().increment();
0293    }
0294 
0295    //! <b>Effects</b>: Erases the last element of the list.
0296    //!   No destructors are called.
0297    //!
0298    //! <b>Throws</b>: Nothing.
0299    //!
0300    //! <b>Complexity</b>: Constant.
0301    //!
0302    //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
0303    void pop_back() BOOST_NOEXCEPT
0304    {  return this->pop_back_and_dispose(detail::null_disposer());   }
0305 
0306    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0307    //!
0308    //! <b>Effects</b>: Erases the last element of the list.
0309    //!   No destructors are called.
0310    //!   Disposer::operator()(pointer) is called for the removed element.
0311    //!
0312    //! <b>Throws</b>: Nothing.
0313    //!
0314    //! <b>Complexity</b>: Constant.
0315    //!
0316    //! <b>Note</b>: Invalidates the iterators to the erased element.
0317    template<class Disposer>
0318    void pop_back_and_dispose(Disposer disposer) BOOST_NOEXCEPT
0319    {
0320       node_ptr to_erase = node_traits::get_previous(this->get_root_node());
0321       node_algorithms::unlink(to_erase);
0322       this->priv_size_traits().decrement();
0323       BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0324          node_algorithms::init(to_erase);
0325       disposer(priv_value_traits().to_value_ptr(to_erase));
0326    }
0327 
0328    //! <b>Effects</b>: Erases the first element of the list.
0329    //!   No destructors are called.
0330    //!
0331    //! <b>Throws</b>: Nothing.
0332    //!
0333    //! <b>Complexity</b>: Constant.
0334    //!
0335    //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
0336    void pop_front() BOOST_NOEXCEPT
0337    {  return this->pop_front_and_dispose(detail::null_disposer());   }
0338 
0339    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0340    //!
0341    //! <b>Effects</b>: Erases the first element of the list.
0342    //!   No destructors are called.
0343    //!   Disposer::operator()(pointer) is called for the removed element.
0344    //!
0345    //! <b>Throws</b>: Nothing.
0346    //!
0347    //! <b>Complexity</b>: Constant.
0348    //!
0349    //! <b>Note</b>: Invalidates the iterators to the erased element.
0350    template<class Disposer>
0351    void pop_front_and_dispose(Disposer disposer) BOOST_NOEXCEPT
0352    {
0353       node_ptr to_erase = node_traits::get_next(this->get_root_node());
0354       node_algorithms::unlink(to_erase);
0355       this->priv_size_traits().decrement();
0356       BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0357          node_algorithms::init(to_erase);
0358       disposer(priv_value_traits().to_value_ptr(to_erase));
0359    }
0360 
0361    //! <b>Effects</b>: Returns a reference to the first element of the list.
0362    //!
0363    //! <b>Throws</b>: Nothing.
0364    //!
0365    //! <b>Complexity</b>: Constant.
0366    inline reference front() BOOST_NOEXCEPT
0367    { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
0368 
0369    //! <b>Effects</b>: Returns a const_reference to the first element of the list.
0370    //!
0371    //! <b>Throws</b>: Nothing.
0372    //!
0373    //! <b>Complexity</b>: Constant.
0374    inline const_reference front() const BOOST_NOEXCEPT
0375    { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
0376 
0377    //! <b>Effects</b>: Returns a reference to the last element of the list.
0378    //!
0379    //! <b>Throws</b>: Nothing.
0380    //!
0381    //! <b>Complexity</b>: Constant.
0382    inline reference back() BOOST_NOEXCEPT
0383    { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
0384 
0385    //! <b>Effects</b>: Returns a const_reference to the last element of the list.
0386    //!
0387    //! <b>Throws</b>: Nothing.
0388    //!
0389    //! <b>Complexity</b>: Constant.
0390    inline const_reference back() const BOOST_NOEXCEPT
0391    { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); }
0392 
0393    //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
0394    //!
0395    //! <b>Throws</b>: Nothing.
0396    //!
0397    //! <b>Complexity</b>: Constant.
0398    inline iterator begin() BOOST_NOEXCEPT
0399    { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
0400 
0401    //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
0402    //!
0403    //! <b>Throws</b>: Nothing.
0404    //!
0405    //! <b>Complexity</b>: Constant.
0406    inline const_iterator begin() const BOOST_NOEXCEPT
0407    { return this->cbegin(); }
0408 
0409    //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
0410    //!
0411    //! <b>Throws</b>: Nothing.
0412    //!
0413    //! <b>Complexity</b>: Constant.
0414    inline const_iterator cbegin() const BOOST_NOEXCEPT
0415    { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
0416 
0417    //! <b>Effects</b>: Returns an iterator to the end of the list.
0418    //!
0419    //! <b>Throws</b>: Nothing.
0420    //!
0421    //! <b>Complexity</b>: Constant.
0422    inline iterator end() BOOST_NOEXCEPT
0423    { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); }
0424 
0425    //! <b>Effects</b>: Returns a const_iterator to the end of the list.
0426    //!
0427    //! <b>Throws</b>: Nothing.
0428    //!
0429    //! <b>Complexity</b>: Constant.
0430    inline const_iterator end() const BOOST_NOEXCEPT
0431    { return this->cend(); }
0432 
0433    //! <b>Effects</b>: Returns a constant iterator to the end of the list.
0434    //!
0435    //! <b>Throws</b>: Nothing.
0436    //!
0437    //! <b>Complexity</b>: Constant.
0438    inline const_iterator cend() const BOOST_NOEXCEPT
0439    { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); }
0440 
0441    //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
0442    //! of the reversed list.
0443    //!
0444    //! <b>Throws</b>: Nothing.
0445    //!
0446    //! <b>Complexity</b>: Constant.
0447    inline reverse_iterator rbegin() BOOST_NOEXCEPT
0448    { return reverse_iterator(this->end()); }
0449 
0450    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
0451    //! of the reversed list.
0452    //!
0453    //! <b>Throws</b>: Nothing.
0454    //!
0455    //! <b>Complexity</b>: Constant.
0456    inline const_reverse_iterator rbegin() const BOOST_NOEXCEPT
0457    { return this->crbegin(); }
0458 
0459    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
0460    //! of the reversed list.
0461    //!
0462    //! <b>Throws</b>: Nothing.
0463    //!
0464    //! <b>Complexity</b>: Constant.
0465    inline const_reverse_iterator crbegin() const BOOST_NOEXCEPT
0466    { return const_reverse_iterator(end()); }
0467 
0468    //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
0469    //! of the reversed list.
0470    //!
0471    //! <b>Throws</b>: Nothing.
0472    //!
0473    //! <b>Complexity</b>: Constant.
0474    inline reverse_iterator rend() BOOST_NOEXCEPT
0475    { return reverse_iterator(begin()); }
0476 
0477    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
0478    //! of the reversed list.
0479    //!
0480    //! <b>Throws</b>: Nothing.
0481    //!
0482    //! <b>Complexity</b>: Constant.
0483    inline const_reverse_iterator rend() const BOOST_NOEXCEPT
0484    { return this->crend(); }
0485 
0486    //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
0487    //! of the reversed list.
0488    //!
0489    //! <b>Throws</b>: Nothing.
0490    //!
0491    //! <b>Complexity</b>: Constant.
0492    inline const_reverse_iterator crend() const BOOST_NOEXCEPT
0493    { return const_reverse_iterator(this->begin()); }
0494 
0495    //! <b>Precondition</b>: end_iterator must be a valid end iterator
0496    //!   of list.
0497    //!
0498    //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
0499    //!
0500    //! <b>Throws</b>: Nothing.
0501    //!
0502    //! <b>Complexity</b>: Constant.
0503    BOOST_INTRUSIVE_NO_DANGLING
0504    inline static list_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
0505    {  return list_impl::priv_container_from_end_iterator(end_iterator);   }
0506 
0507    //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
0508    //!   of list.
0509    //!
0510    //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
0511    //!
0512    //! <b>Throws</b>: Nothing.
0513    //!
0514    //! <b>Complexity</b>: Constant.
0515    BOOST_INTRUSIVE_NO_DANGLING
0516    inline static const list_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
0517    {  return list_impl::priv_container_from_end_iterator(end_iterator);   }
0518 
0519    //! <b>Effects</b>: Returns the number of the elements contained in the list.
0520    //!
0521    //! <b>Throws</b>: Nothing.
0522    //!
0523    //! <b>Complexity</b>: Linear to the number of elements contained in the list.
0524    //!   if constant-time size option is disabled. Constant time otherwise.
0525    //!
0526    //! <b>Note</b>: Does not affect the validity of iterators and references.
0527    inline size_type size() const BOOST_NOEXCEPT
0528    {
0529       BOOST_IF_CONSTEXPR(constant_time_size)
0530          return this->priv_size_traits().get_size();
0531       else
0532          return node_algorithms::count(this->get_root_node()) - 1;
0533    }
0534 
0535    //! <b>Effects</b>: Returns true if the list contains no elements.
0536    //!
0537    //! <b>Throws</b>: Nothing.
0538    //!
0539    //! <b>Complexity</b>: Constant.
0540    //!
0541    //! <b>Note</b>: Does not affect the validity of iterators and references.
0542    inline bool empty() const BOOST_NOEXCEPT
0543    {  return node_algorithms::unique(this->get_root_node());   }
0544 
0545    //! <b>Effects</b>: Swaps the elements of x and *this.
0546    //!
0547    //! <b>Throws</b>: Nothing.
0548    //!
0549    //! <b>Complexity</b>: Constant.
0550    //!
0551    //! <b>Note</b>: Does not affect the validity of iterators and references.
0552    void swap(list_impl& other) BOOST_NOEXCEPT
0553    {
0554       node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
0555       this->priv_size_traits().swap(other.priv_size_traits());
0556    }
0557 
0558    //! <b>Effects</b>: Moves backwards all the elements, so that the first
0559    //!   element becomes the second, the second becomes the third...
0560    //!   the last element becomes the first one.
0561    //!
0562    //! <b>Throws</b>: Nothing.
0563    //!
0564    //! <b>Complexity</b>: Linear to the number of shifts.
0565    //!
0566    //! <b>Note</b>: Does not affect the validity of iterators and references.
0567    inline void shift_backwards(size_type n = 1) BOOST_NOEXCEPT
0568    {  node_algorithms::move_forward(this->get_root_node(), n);  }
0569 
0570    //! <b>Effects</b>: Moves forward all the elements, so that the second
0571    //!   element becomes the first, the third becomes the second...
0572    //!   the first element becomes the last one.
0573    //!
0574    //! <b>Throws</b>: Nothing.
0575    //!
0576    //! <b>Complexity</b>: Linear to the number of shifts.
0577    //!
0578    //! <b>Note</b>: Does not affect the validity of iterators and references.
0579    inline void shift_forward(size_type n = 1) BOOST_NOEXCEPT
0580    {  node_algorithms::move_backwards(this->get_root_node(), n);  }
0581 
0582    //! <b>Effects</b>: Erases the element pointed by i of the list.
0583    //!   No destructors are called.
0584    //!
0585    //! <b>Returns</b>: the first element remaining beyond the removed element,
0586    //!   or end() if no such element exists.
0587    //!
0588    //! <b>Throws</b>: Nothing.
0589    //!
0590    //! <b>Complexity</b>: Constant.
0591    //!
0592    //! <b>Note</b>: Invalidates the iterators (but not the references) to the
0593    //!   erased element.
0594    inline iterator erase(const_iterator i) BOOST_NOEXCEPT
0595    {  return this->erase_and_dispose(i, detail::null_disposer());  }
0596 
0597    //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
0598    //!
0599    //! <b>Effects</b>: Erases the element range pointed by b and e
0600    //! No destructors are called.
0601    //!
0602    //! <b>Returns</b>: the first element remaining beyond the removed elements,
0603    //!   or end() if no such element exists.
0604    //!
0605    //! <b>Throws</b>: Nothing.
0606    //!
0607    //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
0608    //!   or auto-unlink value, or constant-time size is enabled. Constant-time otherwise.
0609    //!
0610    //! <b>Note</b>: Invalidates the iterators (but not the references) to the
0611    //!   erased elements.
0612    inline iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT
0613    {
0614       BOOST_IF_CONSTEXPR(safemode_or_autounlink || constant_time_size){
0615          return this->erase_and_dispose(b, e, detail::null_disposer());
0616       }
0617       else{
0618          node_algorithms::unlink(b.pointed_node(), e.pointed_node());
0619          return e.unconst();
0620       }
0621    }
0622 
0623    //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
0624    //!   n must be distance(b, e).
0625    //!
0626    //! <b>Effects</b>: Erases the element range pointed by b and e
0627    //! No destructors are called.
0628    //!
0629    //! <b>Returns</b>: the first element remaining beyond the removed elements,
0630    //!   or end() if no such element exists.
0631    //!
0632    //! <b>Throws</b>: Nothing.
0633    //!
0634    //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
0635    //!   or auto-unlink value is enabled. Constant-time otherwise.
0636    //!
0637    //! <b>Note</b>: Invalidates the iterators (but not the references) to the
0638    //!   erased elements.
0639    iterator erase(const_iterator b, const_iterator e, size_type n) BOOST_NOEXCEPT
0640    {
0641       BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n);
0642       (void)n;
0643       BOOST_IF_CONSTEXPR(safemode_or_autounlink){
0644          return this->erase_and_dispose(b, e, detail::null_disposer());
0645       }
0646       else{
0647          BOOST_IF_CONSTEXPR(constant_time_size){
0648             this->priv_size_traits().decrease(n);
0649          }
0650          node_algorithms::unlink(b.pointed_node(), e.pointed_node());
0651          return e.unconst();
0652       }
0653    }
0654 
0655    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0656    //!
0657    //! <b>Effects</b>: Erases the element pointed by i of the list.
0658    //!   No destructors are called.
0659    //!   Disposer::operator()(pointer) is called for the removed element.
0660    //!
0661    //! <b>Returns</b>: the first element remaining beyond the removed element,
0662    //!   or end() if no such element exists.
0663    //!
0664    //! <b>Throws</b>: Nothing.
0665    //!
0666    //! <b>Complexity</b>: Constant.
0667    //!
0668    //! <b>Note</b>: Invalidates the iterators to the erased element.
0669    template <class Disposer>
0670    iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT
0671    {
0672       node_ptr to_erase(i.pointed_node());
0673       ++i;
0674       node_algorithms::unlink(to_erase);
0675       this->priv_size_traits().decrement();
0676       BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0677          node_algorithms::init(to_erase);
0678       disposer(this->priv_value_traits().to_value_ptr(to_erase));
0679       return i.unconst();
0680    }
0681 
0682    #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
0683    template<class Disposer>
0684    iterator erase_and_dispose(iterator i, Disposer disposer) BOOST_NOEXCEPT
0685    {  return this->erase_and_dispose(const_iterator(i), disposer);   }
0686    #endif
0687 
0688    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0689    //!
0690    //! <b>Effects</b>: Erases the element range pointed by b and e
0691    //!   No destructors are called.
0692    //!   Disposer::operator()(pointer) is called for the removed elements.
0693    //!
0694    //! <b>Returns</b>: the first element remaining beyond the removed elements,
0695    //!   or end() if no such element exists.
0696    //!
0697    //! <b>Throws</b>: Nothing.
0698    //!
0699    //! <b>Complexity</b>: Linear to the number of elements erased.
0700    //!
0701    //! <b>Note</b>: Invalidates the iterators to the erased elements.
0702    template <class Disposer>
0703    iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT
0704    {
0705       node_ptr bp(b.pointed_node()), ep(e.pointed_node());
0706       node_algorithms::unlink(bp, ep);
0707       while(bp != ep){
0708          node_ptr to_erase(bp);
0709          bp = node_traits::get_next(bp);
0710          BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0711             node_algorithms::init(to_erase);
0712          disposer(priv_value_traits().to_value_ptr(to_erase));
0713          this->priv_size_traits().decrement();
0714       }
0715       return e.unconst();
0716    }
0717 
0718    //! <b>Effects</b>: Erases all the elements of the container.
0719    //!   No destructors are called.
0720    //!
0721    //! <b>Throws</b>: Nothing.
0722    //!
0723    //! <b>Complexity</b>: Linear to the number of elements of the list.
0724    //!   if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
0725    //!
0726    //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
0727    void clear() BOOST_NOEXCEPT
0728    {
0729       BOOST_IF_CONSTEXPR(safemode_or_autounlink){
0730          this->clear_and_dispose(detail::null_disposer());
0731       }
0732       else{
0733          node_algorithms::init_header(this->get_root_node());
0734          this->priv_size_traits().set_size(size_type(0));
0735       }
0736    }
0737 
0738    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0739    //!
0740    //! <b>Effects</b>: Erases all the elements of the container.
0741    //!   No destructors are called.
0742    //!   Disposer::operator()(pointer) is called for the removed elements.
0743    //!
0744    //! <b>Throws</b>: Nothing.
0745    //!
0746    //! <b>Complexity</b>: Linear to the number of elements of the list.
0747    //!
0748    //! <b>Note</b>: Invalidates the iterators to the erased elements.
0749    template <class Disposer>
0750    void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT
0751    {
0752       const_iterator it(this->begin()), itend(this->end());
0753       while(it != itend){
0754          node_ptr to_erase(it.pointed_node());
0755          ++it;
0756          BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0757             node_algorithms::init(to_erase);
0758          disposer(priv_value_traits().to_value_ptr(to_erase));
0759       }
0760       node_algorithms::init_header(this->get_root_node());
0761       this->priv_size_traits().set_size(0);
0762    }
0763 
0764    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0765    //!   Cloner should yield to nodes equivalent to the original nodes.
0766    //!
0767    //! <b>Effects</b>: Erases all the elements from *this
0768    //!   calling Disposer::operator()(pointer), clones all the
0769    //!   elements from src calling Cloner::operator()(const_reference )
0770    //!   and inserts them on *this.
0771    //!
0772    //!   If cloner throws, all cloned elements are unlinked and disposed
0773    //!   calling Disposer::operator()(pointer).
0774    //!
0775    //! <b>Complexity</b>: Linear to erased plus inserted elements.
0776    //!
0777    //! <b>Throws</b>: If cloner throws. Basic guarantee.
0778    template <class Cloner, class Disposer>
0779    void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
0780    {
0781       this->clear_and_dispose(disposer);
0782       detail::exception_disposer<list_impl, Disposer>
0783          rollback(*this, disposer);
0784       const_iterator b(src.begin()), e(src.end());
0785       for(; b != e; ++b){
0786          this->push_back(*cloner(*b));
0787       }
0788       rollback.release();
0789    }
0790 
0791    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0792    //!   Cloner should yield to nodes equivalent to the original nodes.
0793    //!
0794    //! <b>Effects</b>: Erases all the elements from *this
0795    //!   calling Disposer::operator()(pointer), clones all the
0796    //!   elements from src calling Cloner::operator()(reference)
0797    //!   and inserts them on *this.
0798    //!
0799    //!   If cloner throws, all cloned elements are unlinked and disposed
0800    //!   calling Disposer::operator()(pointer).
0801    //!
0802    //! <b>Complexity</b>: Linear to erased plus inserted elements.
0803    //!
0804    //! <b>Throws</b>: If cloner throws. Basic guarantee.
0805    template <class Cloner, class Disposer>
0806    void clone_from(BOOST_RV_REF(list_impl) src, Cloner cloner, Disposer disposer)
0807    {
0808       this->clear_and_dispose(disposer);
0809       detail::exception_disposer<list_impl, Disposer>
0810          rollback(*this, disposer);
0811       iterator b(src.begin()), e(src.end());
0812       for(; b != e; ++b){
0813          this->push_back(*cloner(*b));
0814       }
0815       rollback.release();
0816    }
0817 
0818    //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this.
0819    //!
0820    //! <b>Effects</b>: Inserts the value before the position pointed by p.
0821    //!
0822    //! <b>Returns</b>: An iterator to the inserted element.
0823    //!
0824    //! <b>Throws</b>: Nothing.
0825    //!
0826    //! <b>Complexity</b>: Constant time. No copy constructors are called.
0827    //!
0828    //! <b>Note</b>: Does not affect the validity of iterators and references.
0829    iterator insert(const_iterator p, reference value) BOOST_NOEXCEPT
0830    {
0831       node_ptr to_insert = this->priv_value_traits().to_node_ptr(value);
0832       BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
0833       node_algorithms::link_before(p.pointed_node(), to_insert);
0834       this->priv_size_traits().increment();
0835       return iterator(to_insert, this->priv_value_traits_ptr());
0836    }
0837 
0838    //! <b>Requires</b>: Dereferencing iterator must yield
0839    //!   an lvalue of type value_type and p must be a valid iterator of *this.
0840    //!
0841    //! <b>Effects</b>: Inserts the range pointed by b and e before the position p.
0842    //!   No copy constructors are called.
0843    //!
0844    //! <b>Throws</b>: Nothing.
0845    //!
0846    //! <b>Complexity</b>: Linear to the number of elements inserted.
0847    //!
0848    //! <b>Note</b>: Does not affect the validity of iterators and references.
0849    template<class Iterator>
0850    void insert(const_iterator p, Iterator b, Iterator e) BOOST_NOEXCEPT
0851    {
0852       for (; b != e; ++b)
0853          this->insert(p, *b);
0854    }
0855 
0856    //! <b>Requires</b>: Dereferencing iterator must yield
0857    //!   an lvalue of type value_type.
0858    //!
0859    //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
0860    //!   No destructors or copy constructors are called.
0861    //!
0862    //! <b>Throws</b>: Nothing.
0863    //!
0864    //! <b>Complexity</b>: Linear to the number of elements inserted plus
0865    //!   linear to the elements contained in the list if it's a safe-mode
0866    //!   or auto-unlink value.
0867    //!   Linear to the number of elements inserted in the list otherwise.
0868    //!
0869    //! <b>Note</b>: Invalidates the iterators (but not the references)
0870    //!   to the erased elements.
0871    template<class Iterator>
0872    void assign(Iterator b, Iterator e) BOOST_NOEXCEPT
0873    {
0874       this->clear();
0875       this->insert(this->cend(), b, e);
0876    }
0877 
0878    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
0879    //!
0880    //! <b>Requires</b>: Dereferencing iterator must yield
0881    //!   an lvalue of type value_type.
0882    //!
0883    //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
0884    //!   No destructors or copy constructors are called.
0885    //!   Disposer::operator()(pointer) is called for the removed elements.
0886    //!
0887    //! <b>Throws</b>: Nothing.
0888    //!
0889    //! <b>Complexity</b>: Linear to the number of elements inserted plus
0890    //!   linear to the elements contained in the list.
0891    //!
0892    //! <b>Note</b>: Invalidates the iterators (but not the references)
0893    //!   to the erased elements.
0894    template<class Iterator, class Disposer>
0895    void dispose_and_assign(Disposer disposer, Iterator b, Iterator e) BOOST_NOEXCEPT
0896    {
0897       this->clear_and_dispose(disposer);
0898       this->insert(this->cend(), b, e);
0899    }
0900 
0901    //! <b>Requires</b>: p must be a valid iterator of *this.
0902    //!
0903    //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
0904    //!   the element pointed by p. No destructors or copy constructors are called.
0905    //!
0906    //! <b>Throws</b>: Nothing.
0907    //!
0908    //! <b>Complexity</b>: Constant.
0909    //!
0910    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
0911    //!    this list. Iterators of this list and all the references are not invalidated.
0912    void splice(const_iterator p, list_impl& x) BOOST_NOEXCEPT
0913    {
0914       if(!x.empty()){
0915          node_algorithms::transfer
0916             (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
0917          size_traits &thist = this->priv_size_traits();
0918          size_traits &xt = x.priv_size_traits();
0919          thist.increase(xt.get_size());
0920          xt.set_size(size_type(0));
0921       }
0922    }
0923 
0924    //! <b>Requires</b>: p must be a valid iterator of *this.
0925    //!   new_ele must point to an element contained in list x.
0926    //!
0927    //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list,
0928    //!   before the element pointed by p. No destructors or copy constructors are called.
0929    //!   If p == new_ele or p == ++new_ele, this function is a null operation.
0930    //!
0931    //! <b>Throws</b>: Nothing.
0932    //!
0933    //! <b>Complexity</b>: Constant.
0934    //!
0935    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
0936    //!   list. Iterators of this list and all the references are not invalidated.
0937    void splice(const_iterator p, list_impl&x, const_iterator new_ele) BOOST_NOEXCEPT
0938    {
0939       node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
0940       x.priv_size_traits().decrement();
0941       this->priv_size_traits().increment();
0942    }
0943 
0944    //! <b>Requires</b>: p must be a valid iterator of *this.
0945    //!   f and e must point to elements contained in list x.
0946    //!
0947    //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
0948    //!   before the element pointed by p. No destructors or copy constructors are called.
0949    //!
0950    //! <b>Throws</b>: Nothing.
0951    //!
0952    //! <b>Complexity</b>: Linear to the number of elements transferred
0953    //!   if constant-time size option is enabled. Constant-time otherwise.
0954    //!
0955    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
0956    //!   list. Iterators of this list and all the references are not invalidated.
0957    void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) BOOST_NOEXCEPT
0958    {
0959       BOOST_IF_CONSTEXPR(constant_time_size)
0960          this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node()));
0961       else
0962          this->splice(p, x, f, e, 1);//intrusive::iterator_distance is a dummy value
0963    }
0964 
0965    //! <b>Requires</b>: p must be a valid iterator of *this.
0966    //!   f and e must point to elements contained in list x.
0967    //!   n == distance(f, e)
0968    //!
0969    //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list,
0970    //!   before the element pointed by p. No destructors or copy constructors are called.
0971    //!
0972    //! <b>Throws</b>: Nothing.
0973    //!
0974    //! <b>Complexity</b>: Constant.
0975    //!
0976    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
0977    //!   list. Iterators of this list and all the references are not invalidated.
0978    void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n) BOOST_NOEXCEPT
0979    {
0980       if(n){
0981          BOOST_IF_CONSTEXPR(constant_time_size){
0982             BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node()));
0983             node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
0984             size_traits &thist = this->priv_size_traits();
0985             size_traits &xt = x.priv_size_traits();
0986             thist.increase(n);
0987             xt.decrease(n);
0988          }
0989          else{
0990             node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
0991          }
0992       }
0993    }
0994 
0995    //! <b>Effects</b>: This function sorts the list *this according to operator <.
0996    //!   The sort is stable, that is, the relative order of equivalent elements is preserved.
0997    //!
0998    //! <b>Throws</b>: If value_traits::node_traits::node
0999    //!   constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1000    //!   or operator < throws. Basic guarantee.
1001    //!
1002    //! <b>Notes</b>: Iterators and references are not invalidated.
1003    //!
1004    //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1005    //!   is the list's size.
1006    void sort()
1007    {  this->sort(value_less<value_type>());  }
1008 
1009    //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering
1010    //!
1011    //! <b>Effects</b>: This function sorts the list *this according to p. The sort is
1012    //!   stable, that is, the relative order of equivalent elements is preserved.
1013    //!
1014    //! <b>Throws</b>: If value_traits::node_traits::node
1015    //!   constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1016    //!   or the predicate throws. Basic guarantee.
1017    //!
1018    //! <b>Notes</b>: This won't throw if list_base_hook<> or
1019    //!   list_member_hook are used.
1020    //!   Iterators and references are not invalidated.
1021    //!
1022    //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1023    //!   is the list's size.
1024    template<class Predicate>
1025    void sort(Predicate p)
1026    {
1027       if(node_traits::get_next(this->get_root_node())
1028          != node_traits::get_previous(this->get_root_node())){
1029          list_impl carry(this->priv_value_traits());
1030          detail::array_initializer<list_impl, 64> counter(this->priv_value_traits());
1031          int fill = 0;
1032          while(!this->empty()){
1033             carry.splice(carry.cbegin(), *this, this->cbegin());
1034             int i = 0;
1035             while(i < fill && !counter[i].empty()) {
1036                counter[i].merge(carry, p);
1037                carry.swap(counter[i++]);
1038             }
1039             carry.swap(counter[i]);
1040             if(i == fill)
1041                ++fill;
1042          }
1043          for (int i = 1; i < fill; ++i)
1044             counter[i].merge(counter[i-1], p);
1045          this->swap(counter[fill-1]);
1046       }
1047    }
1048 
1049    //! <b>Effects</b>: This function removes all of x's elements and inserts them
1050    //!   in order into *this according to operator <. The merge is stable;
1051    //!   that is, if an element from *this is equivalent to one from x, then the element
1052    //!   from *this will precede the one from x.
1053    //!
1054    //! <b>Throws</b>: If operator < throws. Basic guarantee.
1055    //!
1056    //! <b>Complexity</b>: This function is linear time: it performs at most
1057    //!   size() + x.size() - 1 comparisons.
1058    //!
1059    //! <b>Note</b>: Iterators and references are not invalidated
1060    void merge(list_impl& x)
1061    { this->merge(x, value_less<value_type>()); }
1062 
1063    //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1064    //!   ordering and both *this and x must be sorted according to that ordering
1065    //!   The lists x and *this must be distinct.
1066    //!
1067    //! <b>Effects</b>: This function removes all of x's elements and inserts them
1068    //!   in order into *this. The merge is stable; that is, if an element from *this is
1069    //!   equivalent to one from x, then the element from *this will precede the one from x.
1070    //!
1071    //! <b>Throws</b>: If the predicate throws. Basic guarantee.
1072    //!
1073    //! <b>Complexity</b>: This function is linear time: it performs at most
1074    //!   size() + x.size() - 1 comparisons.
1075    //!
1076    //! <b>Note</b>: Iterators and references are not invalidated.
1077    template<class Predicate>
1078    void merge(list_impl& x, Predicate p)
1079    {
1080       const_iterator e(this->cend()), ex(x.cend());
1081       const_iterator b(this->cbegin());
1082       while(!x.empty()){
1083          const_iterator ix(x.cbegin());
1084          while (b != e && !p(*ix, *b)){
1085             ++b;
1086          }
1087          if(b == e){
1088             //Now transfer the rest to the end of the container
1089             this->splice(e, x);
1090             break;
1091          }
1092          else{
1093             size_type n(0);
1094             do{
1095                ++ix; ++n;
1096             } while(ix != ex && p(*ix, *b));
1097             this->splice(b, x, x.begin(), ix, n);
1098          }
1099       }
1100    }
1101 
1102    //! <b>Effects</b>: Reverses the order of elements in the list.
1103    //!
1104    //! <b>Throws</b>: Nothing.
1105    //!
1106    //! <b>Complexity</b>: This function is linear time.
1107    //!
1108    //! <b>Note</b>: Iterators and references are not invalidated
1109    void reverse() BOOST_NOEXCEPT
1110    {  node_algorithms::reverse(this->get_root_node());   }
1111 
1112    //! <b>Effects</b>: Removes all the elements that compare equal to value.
1113    //!   No destructors are called.
1114    //!
1115    //! <b>Throws</b>: If operator == throws. Basic guarantee.
1116    //!
1117    //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1118    //!
1119    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1120    //!   and iterators to elements that are not removed remain valid.
1121    void remove(const_reference value) BOOST_NOEXCEPT
1122    {  this->remove_if(detail::equal_to_value<const_reference>(value));  }
1123 
1124    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1125    //!
1126    //! <b>Effects</b>: Removes all the elements that compare equal to value.
1127    //!   Disposer::operator()(pointer) is called for every removed element.
1128    //!
1129    //! <b>Throws</b>: If operator == throws. Basic guarantee.
1130    //!
1131    //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1132    //!
1133    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1134    //!   and iterators to elements that are not removed remain valid.
1135    template<class Disposer>
1136    void remove_and_dispose(const_reference value, Disposer disposer) BOOST_NOEXCEPT
1137    {  this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer);  }
1138 
1139    //! <b>Effects</b>: Removes all the elements for which a specified
1140    //!   predicate is satisfied. No destructors are called.
1141    //!
1142    //! <b>Throws</b>: If pred throws. Basic guarantee.
1143    //!
1144    //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1145    //!
1146    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1147    //!   and iterators to elements that are not removed remain valid.
1148    template<class Pred>
1149    void remove_if(Pred pred)
1150    {
1151       const node_ptr root_node = this->get_root_node();
1152       typename node_algorithms::stable_partition_info info;
1153       node_algorithms::stable_partition
1154          (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1155       //Invariants preserved by stable_partition so erase can be safely called
1156       //The first element might have changed so calculate it again
1157       this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1158                  , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1159                  , info.num_1st_partition);
1160    }
1161 
1162    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1163    //!
1164    //! <b>Effects</b>: Removes all the elements for which a specified
1165    //!   predicate is satisfied.
1166    //!   Disposer::operator()(pointer) is called for every removed element.
1167    //!
1168    //! <b>Throws</b>: If pred throws. Basic guarantee.
1169    //!
1170    //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1171    //!
1172    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1173    //!   and iterators to elements that are not removed remain valid.
1174    template<class Pred, class Disposer>
1175    void remove_and_dispose_if(Pred pred, Disposer disposer)
1176    {
1177       const node_ptr root_node = this->get_root_node();
1178       typename node_algorithms::stable_partition_info info;
1179       node_algorithms::stable_partition
1180          (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
1181       //Invariants preserved by stable_partition so erase can be safely called
1182       //The first element might have changed so calculate it again
1183       this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
1184                              , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
1185                              , disposer);
1186    }
1187 
1188    //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1189    //!   elements that are equal from the list. No destructors are called.
1190    //!
1191    //! <b>Throws</b>: If the comparison operator throws. Basic guarantee.
1192    //!
1193    //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1194    //!
1195    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1196    //!   and iterators to elements that are not removed remain valid.
1197    void unique()
1198    {  this->unique_and_dispose(value_equal<value_type>(), detail::null_disposer());  }
1199 
1200    //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1201    //!   elements that satisfy some binary predicate from the list.
1202    //!   No destructors are called.
1203    //!
1204    //! <b>Throws</b>: If pred throws. Basic guarantee.
1205    //!
1206    //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1207    //!
1208    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1209    //!   and iterators to elements that are not removed remain valid.
1210    template<class BinaryPredicate>
1211    void unique(BinaryPredicate pred)
1212    {  this->unique_and_dispose(pred, detail::null_disposer());  }
1213 
1214    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1215    //!
1216    //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1217    //!   elements that are equal from the list.
1218    //!   Disposer::operator()(pointer) is called for every removed element.
1219    //!
1220    //! <b>Throws</b>: If the equality operator throws. Basic guarantee.
1221    //!
1222    //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1223    //!
1224    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1225    //!   and iterators to elements that are not removed remain valid.
1226    template<class Disposer>
1227    void unique_and_dispose(Disposer disposer)
1228    {  this->unique_and_dispose(value_equal<value_type>(), disposer);  }
1229 
1230    //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1231    //!
1232    //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1233    //!   elements that satisfy some binary predicate from the list.
1234    //!   Disposer::operator()(pointer) is called for every removed element.
1235    //!
1236    //! <b>Throws</b>: If pred throws. Basic guarantee.
1237    //!
1238    //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
1239    //!
1240    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1241    //!   and iterators to elements that are not removed remain valid.
1242    template<class BinaryPredicate, class Disposer>
1243    void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
1244    {
1245       const_iterator itend(this->cend());
1246       const_iterator cur(this->cbegin());
1247 
1248       if(cur != itend){
1249          const_iterator after(cur);
1250          ++after;
1251          while(after != itend){
1252             if(pred(*cur, *after)){
1253                after = this->erase_and_dispose(after, disposer);
1254             }
1255             else{
1256                cur = after;
1257                ++after;
1258             }
1259          }
1260       }
1261    }
1262 
1263    //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1264    //!
1265    //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1266    //!
1267    //! <b>Throws</b>: Nothing.
1268    //!
1269    //! <b>Complexity</b>: Constant time.
1270    //!
1271    //! <b>Note</b>: Iterators and references are not invalidated.
1272    //!   This static function is available only if the <i>value traits</i>
1273    //!   is stateless.
1274    static iterator s_iterator_to(reference value) BOOST_NOEXCEPT
1275    {
1276       BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
1277       BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
1278       return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr());
1279    }
1280 
1281    //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1282    //!
1283    //! <b>Effects</b>: This function returns an iterator pointing to the element.
1284    //!
1285    //! <b>Throws</b>: Nothing.
1286    //!
1287    //! <b>Complexity</b>: Constant time.
1288    //!
1289    //! <b>Note</b>: Iterators and references are not invalidated.
1290    //!   This static function is available only if the <i>value traits</i>
1291    //!   is stateless.
1292    static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT
1293    {
1294       BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
1295       reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1296       BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r)));
1297       return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr());
1298    }
1299 
1300    //! <b>Requires</b>: value must be a reference to a value inserted in a list.
1301    //!
1302    //! <b>Effects</b>: This function returns a const_iterator pointing to the element
1303    //!
1304    //! <b>Throws</b>: Nothing.
1305    //!
1306    //! <b>Complexity</b>: Constant time.
1307    //!
1308    //! <b>Note</b>: Iterators and references are not invalidated.
1309    iterator iterator_to(reference value) BOOST_NOEXCEPT
1310    {
1311       BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
1312       return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr());
1313    }
1314 
1315    //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
1316    //!
1317    //! <b>Effects</b>: This function returns an iterator pointing to the element.
1318    //!
1319    //! <b>Throws</b>: Nothing.
1320    //!
1321    //! <b>Complexity</b>: Constant time.
1322    //!
1323    //! <b>Note</b>: Iterators and references are not invalidated.
1324    const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT
1325    {
1326       reference r = *detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
1327       BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r)));
1328       return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr());
1329    }
1330 
1331    //! <b>Effects</b>: Asserts the integrity of the container.
1332    //!
1333    //! <b>Complexity</b>: Linear time.
1334    //!
1335    //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG).
1336    //!   Experimental function, interface might change in future versions.
1337    void check() const
1338    {
1339       const_node_ptr header_ptr = get_root_node();
1340       // header's next and prev are never null
1341       BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr));
1342       BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr));
1343       // header's next and prev either both point to header (empty list) or neither does
1344       BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr)
1345          == (node_traits::get_previous(header_ptr) == header_ptr));
1346       if (node_traits::get_next(header_ptr) == header_ptr)
1347       {
1348          BOOST_IF_CONSTEXPR(constant_time_size)
1349             BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0);
1350          return;
1351       }
1352       size_t node_count = 0; (void)node_count;
1353       const_node_ptr p = header_ptr;
1354       while (true)
1355       {
1356          const_node_ptr next_p = node_traits::get_next(p);
1357          BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p);
1358          BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p);
1359          p = next_p;
1360          if (p == header_ptr) break;
1361          ++node_count;
1362       }
1363       BOOST_IF_CONSTEXPR(constant_time_size)
1364          BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count);
1365    }
1366 
1367    friend bool operator==(const list_impl &x, const list_impl &y)
1368    {
1369       if(constant_time_size && x.size() != y.size()){
1370          return false;
1371       }
1372       return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
1373    }
1374 
1375    inline friend bool operator!=(const list_impl &x, const list_impl &y)
1376    {  return !(x == y); }
1377 
1378    inline friend bool operator<(const list_impl &x, const list_impl &y)
1379    {  return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());  }
1380 
1381    inline friend bool operator>(const list_impl &x, const list_impl &y)
1382    {  return y < x;  }
1383 
1384    inline friend bool operator<=(const list_impl &x, const list_impl &y)
1385    {  return !(y < x);  }
1386 
1387    inline friend bool operator>=(const list_impl &x, const list_impl &y)
1388    {  return !(x < y);  }
1389 
1390    inline friend void swap(list_impl &x, list_impl &y) BOOST_NOEXCEPT
1391    {  x.swap(y);  }
1392 
1393    /// @cond
1394 
1395    private:
1396    BOOST_INTRUSIVE_NO_DANGLING
1397    static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) BOOST_NOEXCEPT
1398    {
1399       BOOST_INTRUSIVE_STATIC_ASSERT((has_container_from_iterator));
1400       node_ptr p = end_iterator.pointed_node();
1401       header_holder_type* h = header_holder_type::get_holder(p);
1402       root_plus_size* r = detail::parent_from_member
1403          < root_plus_size, header_holder_type>(h, &root_plus_size::m_header);
1404       data_t *d = detail::parent_from_member<data_t, root_plus_size>
1405          ( r, &data_t::root_plus_size_);
1406       list_impl *s  = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
1407       return *s;
1408    }
1409    /// @endcond
1410 };
1411 
1412 
1413 //! Helper metafunction to define a \c list that yields to the same type when the
1414 //! same options (either explicitly or implicitly) are used.
1415 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1416 template<class T, class ...Options>
1417 #else
1418 template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void>
1419 #endif
1420 struct make_list
1421 {
1422    /// @cond
1423    typedef typename pack_options
1424       < list_defaults,
1425          #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1426          O1, O2, O3, O4
1427          #else
1428          Options...
1429          #endif
1430       >::type packed_options;
1431 
1432    typedef typename detail::get_value_traits
1433       <T, typename packed_options::proto_value_traits>::type value_traits;
1434    typedef list_impl
1435       <
1436          value_traits,
1437          typename packed_options::size_type,
1438          packed_options::constant_time_size,
1439          typename packed_options::header_holder_type
1440       > implementation_defined;
1441    /// @endcond
1442    typedef implementation_defined type;
1443 };
1444 
1445 
1446 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1447 
1448 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1449 template<class T, class O1, class O2, class O3, class O4>
1450 #else
1451 template<class T, class ...Options>
1452 #endif
1453 class list
1454    :  public make_list<T,
1455       #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1456       O1, O2, O3, O4
1457       #else
1458       Options...
1459       #endif
1460    >::type
1461 {
1462    typedef typename make_list
1463       <T,
1464       #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1465       O1, O2, O3, O4
1466       #else
1467       Options...
1468       #endif
1469       >::type      Base;
1470    //Assert if passed value traits are compatible with the type
1471    BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
1472    BOOST_MOVABLE_BUT_NOT_COPYABLE(list)
1473 
1474    public:
1475    typedef typename Base::value_traits          value_traits;
1476    typedef typename Base::iterator              iterator;
1477    typedef typename Base::const_iterator        const_iterator;
1478 
1479    inline list()
1480       :  Base()
1481    {}
1482 
1483    inline explicit list(const value_traits &v_traits)
1484       :  Base(v_traits)
1485    {}
1486 
1487    template<class Iterator>
1488    inline list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
1489       :  Base(b, e, v_traits)
1490    {}
1491 
1492    inline list(BOOST_RV_REF(list) x)
1493       :  Base(BOOST_MOVE_BASE(Base, x))
1494    {}
1495 
1496    inline list& operator=(BOOST_RV_REF(list) x)
1497    {  return static_cast<list &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x)));  }
1498 
1499    template <class Cloner, class Disposer>
1500    inline void clone_from(const list &src, Cloner cloner, Disposer disposer)
1501    {  Base::clone_from(src, cloner, disposer);  }
1502 
1503    template <class Cloner, class Disposer>
1504    inline void clone_from(BOOST_RV_REF(list) src, Cloner cloner, Disposer disposer)
1505    {  Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer);  }
1506 
1507    BOOST_INTRUSIVE_NO_DANGLING
1508    inline static list &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
1509    {  return static_cast<list &>(Base::container_from_end_iterator(end_iterator));   }
1510 
1511    BOOST_INTRUSIVE_NO_DANGLING
1512    inline static const list &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
1513    {  return static_cast<const list &>(Base::container_from_end_iterator(end_iterator));   }
1514 };
1515 
1516 #endif
1517 
1518 } //namespace intrusive
1519 } //namespace boost
1520 
1521 #include <boost/intrusive/detail/config_end.hpp>
1522 
1523 #endif //BOOST_INTRUSIVE_LIST_HPP