123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518 |
- #ifndef BOOST_INTRUSIVE_LIST_HPP
- #define BOOST_INTRUSIVE_LIST_HPP
- #include <boost/intrusive/detail/config_begin.hpp>
- #include <boost/intrusive/intrusive_fwd.hpp>
- #include <boost/intrusive/detail/assert.hpp>
- #include <boost/intrusive/list_hook.hpp>
- #include <boost/intrusive/circular_list_algorithms.hpp>
- #include <boost/intrusive/pointer_traits.hpp>
- #include <boost/intrusive/detail/mpl.hpp>
- #include <boost/intrusive/link_mode.hpp>
- #include <boost/intrusive/detail/get_value_traits.hpp>
- #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
- #include <boost/intrusive/detail/default_header_holder.hpp>
- #include <boost/intrusive/detail/reverse_iterator.hpp>
- #include <boost/intrusive/detail/uncast.hpp>
- #include <boost/intrusive/detail/list_iterator.hpp>
- #include <boost/intrusive/detail/array_initializer.hpp>
- #include <boost/intrusive/detail/exception_disposer.hpp>
- #include <boost/intrusive/detail/equal_to_value.hpp>
- #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
- #include <boost/intrusive/detail/simple_disposers.hpp>
- #include <boost/intrusive/detail/size_holder.hpp>
- #include <boost/intrusive/detail/algorithm.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/intrusive/detail/value_functors.hpp>
- #include <cstddef> //std::size_t, etc.
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- namespace boost {
- namespace intrusive {
- struct default_list_hook_applier
- { template <class T> struct apply{ typedef typename T::default_list_hook type; }; };
- template<>
- struct is_default_hook_tag<default_list_hook_applier>
- { static const bool value = true; };
- struct list_defaults
- {
- typedef default_list_hook_applier proto_value_traits;
- static const bool constant_time_size = true;
- typedef std::size_t size_type;
- typedef void header_holder_type;
- };
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
- template<class T, class ...Options>
- #else
- template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
- #endif
- class list_impl
- {
-
- public:
- typedef ValueTraits value_traits;
- typedef typename value_traits::pointer pointer;
- typedef typename value_traits::const_pointer const_pointer;
- typedef typename pointer_traits<pointer>::element_type value_type;
- typedef typename pointer_traits<pointer>::reference reference;
- typedef typename pointer_traits<const_pointer>::reference const_reference;
- typedef typename pointer_traits<pointer>::difference_type difference_type;
- typedef SizeType size_type;
- typedef list_iterator<value_traits, false> iterator;
- typedef list_iterator<value_traits, true> const_iterator;
- typedef boost::intrusive::reverse_iterator<iterator> reverse_iterator;
- typedef boost::intrusive::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef typename value_traits::node_traits node_traits;
- typedef typename node_traits::node node;
- typedef typename node_traits::node_ptr node_ptr;
- typedef typename node_traits::const_node_ptr const_node_ptr;
- typedef circular_list_algorithms<node_traits> node_algorithms;
- typedef typename detail::get_header_holder_type
- < value_traits, HeaderHolder >::type header_holder_type;
- static const bool constant_time_size = ConstantTimeSize;
- static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
- static const bool has_container_from_iterator =
- detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value;
-
- private:
- typedef detail::size_holder<constant_time_size, size_type> size_traits;
-
- BOOST_MOVABLE_BUT_NOT_COPYABLE(list_impl)
- static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
-
- BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size &&
- ((int)value_traits::link_mode == (int)auto_unlink)
- ));
- inline node_ptr get_root_node()
- { return data_.root_plus_size_.m_header.get_node(); }
- inline const_node_ptr get_root_node() const
- { return data_.root_plus_size_.m_header.get_node(); }
- struct root_plus_size : public size_traits
- {
- header_holder_type m_header;
- };
- struct data_t : public value_traits
- {
- typedef typename list_impl::value_traits value_traits;
- inline explicit data_t(const value_traits &val_traits)
- : value_traits(val_traits)
- {}
- root_plus_size root_plus_size_;
- } data_;
- inline size_traits &priv_size_traits() BOOST_NOEXCEPT
- { return data_.root_plus_size_; }
- inline const size_traits &priv_size_traits() const BOOST_NOEXCEPT
- { return data_.root_plus_size_; }
- inline const value_traits &priv_value_traits() const BOOST_NOEXCEPT
- { return data_; }
- inline value_traits &priv_value_traits() BOOST_NOEXCEPT
- { return data_; }
- typedef typename boost::intrusive::value_traits_pointers
- <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
- inline const_value_traits_ptr priv_value_traits_ptr() const BOOST_NOEXCEPT
- { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); }
-
- public:
-
-
-
-
-
-
- list_impl()
- : data_(value_traits())
- {
- this->priv_size_traits().set_size(size_type(0));
- node_algorithms::init_header(this->get_root_node());
- }
-
-
-
-
-
-
- explicit list_impl(const value_traits &v_traits)
- : data_(v_traits)
- {
- this->priv_size_traits().set_size(size_type(0));
- node_algorithms::init_header(this->get_root_node());
- }
-
-
-
-
-
-
-
-
- template<class Iterator>
- list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
- : data_(v_traits)
- {
-
- this->priv_size_traits().set_size(size_type(0));
- node_algorithms::init_header(this->get_root_node());
-
- this->insert(this->cend(), b, e);
- }
-
-
-
-
-
-
-
-
-
- list_impl(BOOST_RV_REF(list_impl) x)
- : data_(::boost::move(x.priv_value_traits()))
- {
- this->priv_size_traits().set_size(size_type(0));
- node_algorithms::init_header(this->get_root_node());
-
- this->swap(x);
- }
-
-
- list_impl& operator=(BOOST_RV_REF(list_impl) x)
- { this->swap(x); return *this; }
-
-
-
-
-
-
-
-
-
-
-
- ~list_impl()
- {
- BOOST_IF_CONSTEXPR(is_safe_autounlink<ValueTraits::link_mode>::value){
- this->clear();
- node_algorithms::init(this->get_root_node());
- }
- }
-
-
-
-
-
-
-
-
-
-
- void push_back(reference value) BOOST_NOEXCEPT
- {
- node_ptr to_insert = priv_value_traits().to_node_ptr(value);
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
- node_algorithms::link_before(this->get_root_node(), to_insert);
- this->priv_size_traits().increment();
- }
-
-
-
-
-
-
-
-
-
-
- void push_front(reference value) BOOST_NOEXCEPT
- {
- node_ptr to_insert = priv_value_traits().to_node_ptr(value);
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
- node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
- this->priv_size_traits().increment();
- }
-
-
-
-
-
-
-
-
- void pop_back() BOOST_NOEXCEPT
- { return this->pop_back_and_dispose(detail::null_disposer()); }
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- void pop_back_and_dispose(Disposer disposer) BOOST_NOEXCEPT
- {
- node_ptr to_erase = node_traits::get_previous(this->get_root_node());
- node_algorithms::unlink(to_erase);
- this->priv_size_traits().decrement();
- BOOST_IF_CONSTEXPR(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- disposer(priv_value_traits().to_value_ptr(to_erase));
- }
-
-
-
-
-
-
-
-
- void pop_front() BOOST_NOEXCEPT
- { return this->pop_front_and_dispose(detail::null_disposer()); }
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- void pop_front_and_dispose(Disposer disposer) BOOST_NOEXCEPT
- {
- node_ptr to_erase = node_traits::get_next(this->get_root_node());
- node_algorithms::unlink(to_erase);
- this->priv_size_traits().decrement();
- BOOST_IF_CONSTEXPR(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- disposer(priv_value_traits().to_value_ptr(to_erase));
- }
-
-
-
-
-
- inline reference front() BOOST_NOEXCEPT
- { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
-
-
-
-
-
- inline const_reference front() const BOOST_NOEXCEPT
- { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
-
-
-
-
-
- inline reference back() BOOST_NOEXCEPT
- { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
-
-
-
-
-
- inline const_reference back() const BOOST_NOEXCEPT
- { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); }
-
-
-
-
-
- inline iterator begin() BOOST_NOEXCEPT
- { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
-
-
-
-
-
- inline const_iterator begin() const BOOST_NOEXCEPT
- { return this->cbegin(); }
-
-
-
-
-
- inline const_iterator cbegin() const BOOST_NOEXCEPT
- { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); }
-
-
-
-
-
- inline iterator end() BOOST_NOEXCEPT
- { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); }
-
-
-
-
-
- inline const_iterator end() const BOOST_NOEXCEPT
- { return this->cend(); }
-
-
-
-
-
- inline const_iterator cend() const BOOST_NOEXCEPT
- { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); }
-
-
-
-
-
-
- inline reverse_iterator rbegin() BOOST_NOEXCEPT
- { return reverse_iterator(this->end()); }
-
-
-
-
-
-
- inline const_reverse_iterator rbegin() const BOOST_NOEXCEPT
- { return this->crbegin(); }
-
-
-
-
-
-
- inline const_reverse_iterator crbegin() const BOOST_NOEXCEPT
- { return const_reverse_iterator(end()); }
-
-
-
-
-
-
- inline reverse_iterator rend() BOOST_NOEXCEPT
- { return reverse_iterator(begin()); }
-
-
-
-
-
-
- inline const_reverse_iterator rend() const BOOST_NOEXCEPT
- { return this->crend(); }
-
-
-
-
-
-
- inline const_reverse_iterator crend() const BOOST_NOEXCEPT
- { return const_reverse_iterator(this->begin()); }
-
-
-
-
-
-
-
-
- inline static list_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
- { return list_impl::priv_container_from_end_iterator(end_iterator); }
-
-
-
-
-
-
-
-
- inline static const list_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
- { return list_impl::priv_container_from_end_iterator(end_iterator); }
-
-
-
-
-
-
-
-
- inline size_type size() const BOOST_NOEXCEPT
- {
- BOOST_IF_CONSTEXPR(constant_time_size)
- return this->priv_size_traits().get_size();
- else
- return node_algorithms::count(this->get_root_node()) - 1;
- }
-
-
-
-
-
-
-
- inline bool empty() const BOOST_NOEXCEPT
- { return node_algorithms::unique(this->get_root_node()); }
-
-
-
-
-
-
-
- void swap(list_impl& other) BOOST_NOEXCEPT
- {
- node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
- this->priv_size_traits().swap(other.priv_size_traits());
- }
-
-
-
-
-
-
-
-
-
- inline void shift_backwards(size_type n = 1) BOOST_NOEXCEPT
- { node_algorithms::move_forward(this->get_root_node(), n); }
-
-
-
-
-
-
-
-
-
- inline void shift_forward(size_type n = 1) BOOST_NOEXCEPT
- { node_algorithms::move_backwards(this->get_root_node(), n); }
-
-
-
-
-
-
-
-
-
-
-
-
- inline iterator erase(const_iterator i) BOOST_NOEXCEPT
- { return this->erase_and_dispose(i, detail::null_disposer()); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- inline iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT
- {
- BOOST_IF_CONSTEXPR(safemode_or_autounlink || constant_time_size){
- return this->erase_and_dispose(b, e, detail::null_disposer());
- }
- else{
- node_algorithms::unlink(b.pointed_node(), e.pointed_node());
- return e.unconst();
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iterator erase(const_iterator b, const_iterator e, size_type n) BOOST_NOEXCEPT
- {
- BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n);
- (void)n;
- BOOST_IF_CONSTEXPR(safemode_or_autounlink){
- return this->erase_and_dispose(b, e, detail::null_disposer());
- }
- else{
- BOOST_IF_CONSTEXPR(constant_time_size){
- this->priv_size_traits().decrease(n);
- }
- node_algorithms::unlink(b.pointed_node(), e.pointed_node());
- return e.unconst();
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Disposer>
- iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT
- {
- node_ptr to_erase(i.pointed_node());
- ++i;
- node_algorithms::unlink(to_erase);
- this->priv_size_traits().decrement();
- BOOST_IF_CONSTEXPR(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- disposer(this->priv_value_traits().to_value_ptr(to_erase));
- return i.unconst();
- }
- #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
- template<class Disposer>
- iterator erase_and_dispose(iterator i, Disposer disposer) BOOST_NOEXCEPT
- { return this->erase_and_dispose(const_iterator(i), disposer); }
- #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Disposer>
- iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT
- {
- node_ptr bp(b.pointed_node()), ep(e.pointed_node());
- node_algorithms::unlink(bp, ep);
- while(bp != ep){
- node_ptr to_erase(bp);
- bp = node_traits::get_next(bp);
- BOOST_IF_CONSTEXPR(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- disposer(priv_value_traits().to_value_ptr(to_erase));
- this->priv_size_traits().decrement();
- }
- return e.unconst();
- }
-
-
-
-
-
-
-
-
-
- void clear() BOOST_NOEXCEPT
- {
- BOOST_IF_CONSTEXPR(safemode_or_autounlink){
- this->clear_and_dispose(detail::null_disposer());
- }
- else{
- node_algorithms::init_header(this->get_root_node());
- this->priv_size_traits().set_size(size_type(0));
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- template <class Disposer>
- void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT
- {
- const_iterator it(this->begin()), itend(this->end());
- while(it != itend){
- node_ptr to_erase(it.pointed_node());
- ++it;
- BOOST_IF_CONSTEXPR(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- disposer(priv_value_traits().to_value_ptr(to_erase));
- }
- node_algorithms::init_header(this->get_root_node());
- this->priv_size_traits().set_size(0);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Cloner, class Disposer>
- void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
- {
- this->clear_and_dispose(disposer);
- detail::exception_disposer<list_impl, Disposer>
- rollback(*this, disposer);
- const_iterator b(src.begin()), e(src.end());
- for(; b != e; ++b){
- this->push_back(*cloner(*b));
- }
- rollback.release();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Cloner, class Disposer>
- void clone_from(BOOST_RV_REF(list_impl) src, Cloner cloner, Disposer disposer)
- {
- this->clear_and_dispose(disposer);
- detail::exception_disposer<list_impl, Disposer>
- rollback(*this, disposer);
- iterator b(src.begin()), e(src.end());
- for(; b != e; ++b){
- this->push_back(*cloner(*b));
- }
- rollback.release();
- }
-
-
-
-
-
-
-
-
-
-
-
- iterator insert(const_iterator p, reference value) BOOST_NOEXCEPT
- {
- node_ptr to_insert = this->priv_value_traits().to_node_ptr(value);
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(to_insert));
- node_algorithms::link_before(p.pointed_node(), to_insert);
- this->priv_size_traits().increment();
- return iterator(to_insert, this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator>
- void insert(const_iterator p, Iterator b, Iterator e) BOOST_NOEXCEPT
- {
- for (; b != e; ++b)
- this->insert(p, *b);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator>
- void assign(Iterator b, Iterator e) BOOST_NOEXCEPT
- {
- this->clear();
- this->insert(this->cend(), b, e);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator, class Disposer>
- void dispose_and_assign(Disposer disposer, Iterator b, Iterator e) BOOST_NOEXCEPT
- {
- this->clear_and_dispose(disposer);
- this->insert(this->cend(), b, e);
- }
-
-
-
-
-
-
-
-
-
-
-
- void splice(const_iterator p, list_impl& x) BOOST_NOEXCEPT
- {
- if(!x.empty()){
- node_algorithms::transfer
- (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
- size_traits &thist = this->priv_size_traits();
- size_traits &xt = x.priv_size_traits();
- thist.increase(xt.get_size());
- xt.set_size(size_type(0));
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- void splice(const_iterator p, list_impl&x, const_iterator new_ele) BOOST_NOEXCEPT
- {
- node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
- x.priv_size_traits().decrement();
- this->priv_size_traits().increment();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) BOOST_NOEXCEPT
- {
- BOOST_IF_CONSTEXPR(constant_time_size)
- this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node()));
- else
- this->splice(p, x, f, e, 1);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n) BOOST_NOEXCEPT
- {
- if(n){
- BOOST_IF_CONSTEXPR(constant_time_size){
- BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node()));
- node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
- size_traits &thist = this->priv_size_traits();
- size_traits &xt = x.priv_size_traits();
- thist.increase(n);
- xt.decrease(n);
- }
- else{
- node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- void sort()
- { this->sort(value_less<value_type>()); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Predicate>
- void sort(Predicate p)
- {
- if(node_traits::get_next(this->get_root_node())
- != node_traits::get_previous(this->get_root_node())){
- list_impl carry(this->priv_value_traits());
- detail::array_initializer<list_impl, 64> counter(this->priv_value_traits());
- int fill = 0;
- while(!this->empty()){
- carry.splice(carry.cbegin(), *this, this->cbegin());
- int i = 0;
- while(i < fill && !counter[i].empty()) {
- counter[i].merge(carry, p);
- carry.swap(counter[i++]);
- }
- carry.swap(counter[i]);
- if(i == fill)
- ++fill;
- }
- for (int i = 1; i < fill; ++i)
- counter[i].merge(counter[i-1], p);
- this->swap(counter[fill-1]);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- void merge(list_impl& x)
- { this->merge(x, value_less<value_type>()); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Predicate>
- void merge(list_impl& x, Predicate p)
- {
- const_iterator e(this->cend()), ex(x.cend());
- const_iterator b(this->cbegin());
- while(!x.empty()){
- const_iterator ix(x.cbegin());
- while (b != e && !p(*ix, *b)){
- ++b;
- }
- if(b == e){
-
- this->splice(e, x);
- break;
- }
- else{
- size_type n(0);
- do{
- ++ix; ++n;
- } while(ix != ex && p(*ix, *b));
- this->splice(b, x, x.begin(), ix, n);
- }
- }
- }
-
-
-
-
-
-
-
- void reverse() BOOST_NOEXCEPT
- { node_algorithms::reverse(this->get_root_node()); }
-
-
-
-
-
-
-
-
-
- void remove(const_reference value) BOOST_NOEXCEPT
- { this->remove_if(detail::equal_to_value<const_reference>(value)); }
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- void remove_and_dispose(const_reference value, Disposer disposer) BOOST_NOEXCEPT
- { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
-
-
-
-
-
-
-
-
-
- template<class Pred>
- void remove_if(Pred pred)
- {
- const node_ptr root_node = this->get_root_node();
- typename node_algorithms::stable_partition_info info;
- node_algorithms::stable_partition
- (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
-
-
- this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
- , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
- , info.num_1st_partition);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Pred, class Disposer>
- void remove_and_dispose_if(Pred pred, Disposer disposer)
- {
- const node_ptr root_node = this->get_root_node();
- typename node_algorithms::stable_partition_info info;
- node_algorithms::stable_partition
- (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info);
-
-
- this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr())
- , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr())
- , disposer);
- }
-
-
-
-
-
-
-
-
-
- void unique()
- { this->unique_and_dispose(value_equal<value_type>(), detail::null_disposer()); }
-
-
-
-
-
-
-
-
-
-
- template<class BinaryPredicate>
- void unique(BinaryPredicate pred)
- { this->unique_and_dispose(pred, detail::null_disposer()); }
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- void unique_and_dispose(Disposer disposer)
- { this->unique_and_dispose(value_equal<value_type>(), disposer); }
-
-
-
-
-
-
-
-
-
-
-
-
- template<class BinaryPredicate, class Disposer>
- void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
- {
- const_iterator itend(this->cend());
- const_iterator cur(this->cbegin());
- if(cur != itend){
- const_iterator after(cur);
- ++after;
- while(after != itend){
- if(pred(*cur, *after)){
- after = this->erase_and_dispose(after, disposer);
- }
- else{
- cur = after;
- ++after;
- }
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- static iterator s_iterator_to(reference value) BOOST_NOEXCEPT
- {
- BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
- BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
- return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
-
-
- static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT
- {
- BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
- reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
- BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r)));
- return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
- iterator iterator_to(reference value) BOOST_NOEXCEPT
- {
- BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
- return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
- const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT
- {
- reference r = *detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
- BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r)));
- return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
- void check() const
- {
- const_node_ptr header_ptr = get_root_node();
-
- BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr));
- BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr));
-
- BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr)
- == (node_traits::get_previous(header_ptr) == header_ptr));
- if (node_traits::get_next(header_ptr) == header_ptr)
- {
- BOOST_IF_CONSTEXPR(constant_time_size)
- BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0);
- return;
- }
- size_t node_count = 0; (void)node_count;
- const_node_ptr p = header_ptr;
- while (true)
- {
- const_node_ptr next_p = node_traits::get_next(p);
- BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p);
- BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p);
- p = next_p;
- if (p == header_ptr) break;
- ++node_count;
- }
- BOOST_IF_CONSTEXPR(constant_time_size)
- BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count);
- }
- friend bool operator==(const list_impl &x, const list_impl &y)
- {
- if(constant_time_size && x.size() != y.size()){
- return false;
- }
- return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
- }
- inline friend bool operator!=(const list_impl &x, const list_impl &y)
- { return !(x == y); }
- inline friend bool operator<(const list_impl &x, const list_impl &y)
- { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
- inline friend bool operator>(const list_impl &x, const list_impl &y)
- { return y < x; }
- inline friend bool operator<=(const list_impl &x, const list_impl &y)
- { return !(y < x); }
- inline friend bool operator>=(const list_impl &x, const list_impl &y)
- { return !(x < y); }
- inline friend void swap(list_impl &x, list_impl &y) BOOST_NOEXCEPT
- { x.swap(y); }
-
- private:
- static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) BOOST_NOEXCEPT
- {
- BOOST_INTRUSIVE_STATIC_ASSERT((has_container_from_iterator));
- node_ptr p = end_iterator.pointed_node();
- header_holder_type* h = header_holder_type::get_holder(p);
- root_plus_size* r = detail::parent_from_member
- < root_plus_size, header_holder_type>(h, &root_plus_size::m_header);
- data_t *d = detail::parent_from_member<data_t, root_plus_size>
- ( r, &data_t::root_plus_size_);
- list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
- return *s;
- }
-
- };
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- template<class T, class ...Options>
- #else
- template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void>
- #endif
- struct make_list
- {
-
- typedef typename pack_options
- < list_defaults,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4
- #else
- Options...
- #endif
- >::type packed_options;
- typedef typename detail::get_value_traits
- <T, typename packed_options::proto_value_traits>::type value_traits;
- typedef list_impl
- <
- value_traits,
- typename packed_options::size_type,
- packed_options::constant_time_size,
- typename packed_options::header_holder_type
- > implementation_defined;
-
- typedef implementation_defined type;
- };
- #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- template<class T, class O1, class O2, class O3, class O4>
- #else
- template<class T, class ...Options>
- #endif
- class list
- : public make_list<T,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4
- #else
- Options...
- #endif
- >::type
- {
- typedef typename make_list
- <T,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4
- #else
- Options...
- #endif
- >::type Base;
-
- BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
- BOOST_MOVABLE_BUT_NOT_COPYABLE(list)
- public:
- typedef typename Base::value_traits value_traits;
- typedef typename Base::iterator iterator;
- typedef typename Base::const_iterator const_iterator;
- inline list()
- : Base()
- {}
- inline explicit list(const value_traits &v_traits)
- : Base(v_traits)
- {}
- template<class Iterator>
- inline list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
- : Base(b, e, v_traits)
- {}
- inline list(BOOST_RV_REF(list) x)
- : Base(BOOST_MOVE_BASE(Base, x))
- {}
- inline list& operator=(BOOST_RV_REF(list) x)
- { return static_cast<list &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
- template <class Cloner, class Disposer>
- inline void clone_from(const list &src, Cloner cloner, Disposer disposer)
- { Base::clone_from(src, cloner, disposer); }
- template <class Cloner, class Disposer>
- inline void clone_from(BOOST_RV_REF(list) src, Cloner cloner, Disposer disposer)
- { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
- inline static list &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
- { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); }
- inline static const list &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
- { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); }
- };
- #endif
- }
- }
- #include <boost/intrusive/detail/config_end.hpp>
- #endif
|