123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000 |
- #define BOOST_CONTAINER_DEVECTOR_HPP
- #include <boost/container/detail/config_begin.hpp>
- #include <boost/container/detail/workaround.hpp>
- #include <cstring>
- #include <boost/assert.hpp>
- #include <boost/aligned_storage.hpp>
- #include <boost/container/detail/copy_move_algo.hpp>
- #include <boost/container/new_allocator.hpp>
- #include <boost/container/allocator_traits.hpp>
- #include <boost/container/detail/algorithm.hpp>
- #include <boost/container/throw_exception.hpp>
- #include <boost/container/options.hpp>
- #include <boost/container/detail/guards_dended.hpp>
- #include <boost/container/detail/iterator.hpp>
- #include <boost/container/detail/iterators.hpp>
- #include <boost/container/detail/destroyers.hpp>
- #include <boost/container/detail/min_max.hpp>
- #include <boost/container/detail/next_capacity.hpp>
- #include <boost/container/detail/alloc_helpers.hpp>
- #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- #include <boost/move/detail/fwd_macros.hpp>
- #endif
- #include <boost/move/detail/move_helpers.hpp>
- #include <boost/move/adl_move_swap.hpp>
- #include <boost/move/iterator.hpp>
- #include <boost/move/traits.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/move/detail/to_raw_pointer.hpp>
- #include <boost/move/algo/detail/merge.hpp>
- #include <boost/type_traits/is_nothrow_move_constructible.hpp>
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- #include <initializer_list>
- #endif
- namespace boost {
- namespace container {
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- struct growth_factor_60;
- template<class Options, class AllocatorSizeType>
- struct get_devector_opt
- {
- typedef devector_opt< typename default_if_void<typename Options::growth_factor_type, growth_factor_60>::type
- , typename default_if_void<typename Options::stored_size_type, AllocatorSizeType>::type
- > type;
- };
- template<class AllocatorSizeType>
- struct get_devector_opt<void, AllocatorSizeType>
- {
- typedef vector_opt<growth_factor_60, AllocatorSizeType> type;
- };
- #endif
- struct reserve_only_tag_t {};
- template < typename T, class A BOOST_CONTAINER_DOCONLY(= void), class Options BOOST_CONTAINER_DOCONLY(= void)>
- class devector
- {
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- typedef boost::container::allocator_traits
- <typename real_allocator<T, A>::type> allocator_traits_type;
- typedef typename allocator_traits_type::size_type alloc_size_type;
- typedef typename get_devector_opt<Options, alloc_size_type>::type options_type;
- typedef typename options_type::growth_factor_type growth_factor_type;
- typedef typename options_type::stored_size_type stored_size_type;
- #endif
- public:
-
- typedef T value_type;
- typedef BOOST_CONTAINER_IMPDEF
- (typename real_allocator<T BOOST_MOVE_I A>::type) allocator_type;
- typedef allocator_type stored_allocator_type;
- typedef typename allocator_traits<allocator_type>::pointer pointer;
- typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
- typedef typename allocator_traits<allocator_type>::reference reference;
- typedef typename allocator_traits<allocator_type>::const_reference const_reference;
- typedef typename allocator_traits<allocator_type>::size_type size_type;
- typedef typename allocator_traits<allocator_type>::difference_type difference_type;
- typedef pointer iterator;
- typedef const_pointer const_iterator;
- typedef BOOST_CONTAINER_IMPDEF
- (boost::container::reverse_iterator<iterator>) reverse_iterator;
- typedef BOOST_CONTAINER_IMPDEF
- (boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- private:
- BOOST_COPYABLE_AND_MOVABLE(devector)
-
- typedef typename detail::allocation_guard<allocator_type> allocation_guard;
-
- typedef constant_iterator<T, difference_type> cvalue_iterator;
- #endif
-
- public:
-
-
- devector() BOOST_NOEXCEPT
- : m_()
- {}
-
- explicit devector(const allocator_type& allocator) BOOST_NOEXCEPT
- : m_(allocator)
- {}
-
- devector(size_type n, reserve_only_tag_t, const allocator_type& allocator = allocator_type())
- : m_(allocator, this->allocate(n), 0u, 0u, n)
- {}
-
- devector(size_type front_cap, size_type back_cap, reserve_only_tag_t, const allocator_type& allocator = allocator_type())
- : m_(allocator, this->allocate(front_cap + back_cap), front_cap, front_cap, front_cap + back_cap)
- {}
-
- explicit devector(size_type n, const allocator_type& allocator = allocator_type())
- : m_(allocator, n ? allocate(n): pointer(), 0u, n, n)
- {
-
-
- allocation_guard buffer_guard(m_.buffer, m_.capacity, get_allocator_ref());
- detail::construction_guard<allocator_type> copy_guard(m_.buffer, get_allocator_ref());
- for (size_type i = 0; i < n; ++i)
- {
- this->alloc_construct(m_.buffer + i);
- copy_guard.extend();
- }
- copy_guard.release();
- buffer_guard.release();
- BOOST_ASSERT(invariants_ok());
- }
-
- devector(size_type n, const T& value, const allocator_type& allocator = allocator_type())
- : m_(allocator, n ? allocate(n): pointer(), 0u, n, n)
- {
- construct_from_range(cvalue_iterator(value, n), cvalue_iterator());
- BOOST_ASSERT(invariants_ok());
- }
-
- template <class InputIterator>
- devector(InputIterator first, InputIterator last, const allocator_type& allocator = allocator_type()
- //Input iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<InputIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_not_input_iterator<InputIterator>
- >::type * = 0)
- )
- : m_(allocator, pointer(), 0u, 0u, 0u)
- {
- while (first != last) {
- this->emplace_back(*first++);
- }
- BOOST_ASSERT(invariants_ok());
- }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class ForwardIterator>
- devector(ForwardIterator first, ForwardIterator last, const allocator_type& allocator = allocator_type()
- //Other iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<ForwardIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_input_iterator<ForwardIterator>
- >::type * = 0)
- )
- : m_(allocator, pointer(), 0u, 0u, 0u)
- {
- const size_type n = boost::container::iterator_distance(first, last);
- m_.buffer = n ? allocate(n) : pointer();
- m_.front_idx = 0u;
-
- m_.set_back_idx(n);
- m_.set_capacity(n);
-
- this->construct_from_range(first, last);
- BOOST_ASSERT(invariants_ok());
- }
- #endif
-
- devector(const devector& x)
- : m_( allocator_traits_type::select_on_container_copy_construction(x.get_allocator_ref())
- , pointer(), 0u, 0u, 0u)
- {
- const size_type n = x.size();
- m_.buffer = n ? allocate(n) : pointer();
- m_.front_idx = 0u;
-
- m_.set_back_idx(n);
- m_.set_capacity(n);
- this->construct_from_range(x.begin(), x.end());
- BOOST_ASSERT(invariants_ok());
- }
-
- devector(const devector& x, const allocator_type& allocator)
- : m_(allocator, pointer(), 0u, 0u, 0u)
- {
- const size_type n = x.size();
- m_.buffer = n ? this->allocate(n) : pointer();
- m_.front_idx = 0u;
-
- m_.set_back_idx(n);
- m_.set_capacity(n);
- this->construct_from_range(x.begin(), x.end());
- BOOST_ASSERT(invariants_ok());
- }
-
- devector(BOOST_RV_REF(devector) rhs) BOOST_NOEXCEPT_OR_NOTHROW
- : m_(::boost::move(rhs.get_allocator_ref()), rhs.m_.buffer, rhs.m_.front_idx, rhs.m_.back_idx, rhs.capacity())
- {
-
- rhs.m_.capacity = 0u;
- rhs.m_.buffer = pointer();
- rhs.m_.front_idx = 0;
- rhs.m_.back_idx = 0;
- BOOST_ASSERT( invariants_ok());
- BOOST_ASSERT(rhs.invariants_ok());
- }
-
- devector(BOOST_RV_REF(devector) rhs, const allocator_type& allocator)
- : m_(allocator, rhs.m_.buffer, rhs.m_.front_idx, rhs.m_.back_idx, rhs.capacity())
- {
-
-
- rhs.m_.capacity = 0u;
- rhs.m_.buffer = pointer();
- rhs.m_.front_idx = 0;
- rhs.m_.back_idx = 0;
- BOOST_ASSERT( invariants_ok());
- BOOST_ASSERT(rhs.invariants_ok());
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- devector(const std::initializer_list<T>& il, const allocator_type& allocator = allocator_type())
- : m_(allocator, pointer(), 0u, 0u, 0u)
- {
- const size_type n = il.size();
- m_.buffer = n ? allocate(n) : pointer();
- m_.front_idx = 0u;
-
- m_.set_back_idx(n);
- m_.set_capacity(n);
-
- this->construct_from_range(il.begin(), il.end());
- BOOST_ASSERT(invariants_ok());
- }
- #endif
-
- ~devector() BOOST_NOEXCEPT
- {
- destroy_elements(m_.buffer + m_.front_idx, m_.buffer + m_.back_idx);
- deallocate_buffer();
- }
-
- BOOST_CONTAINER_FORCEINLINE devector& operator=(BOOST_COPY_ASSIGN_REF(devector) rhs)
- {
- const devector &x = rhs;
- if (this == &x) { return *this; }
- BOOST_IF_CONSTEXPR(allocator_traits_type::propagate_on_container_copy_assignment::value)
- {
- allocator_type &this_alloc = this->get_allocator_ref();
- const allocator_type &other_alloc = x.get_allocator_ref();
- if (this_alloc != other_alloc)
- {
-
- this->clear();
- this->deallocate_buffer();
- m_.capacity = 0u;
- m_.buffer = pointer();
- }
- this_alloc = other_alloc;
- }
- size_type n = x.size();
- if (capacity() >= n)
- {
- this->overwrite_buffer(x.begin(), x.end());
- }
- else
- {
- this->allocate_and_copy_range(x.begin(), x.end());
- }
- BOOST_ASSERT(invariants_ok());
- return *this;
- }
-
- devector& operator=(BOOST_RV_REF(devector) x)
- BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
- || allocator_traits_type::is_always_equal::value)
- {
- BOOST_CONSTEXPR_OR_CONST bool copy_alloc = allocator_traits_type::propagate_on_container_move_assignment::value;
- BOOST_IF_CONSTEXPR (copy_alloc || get_allocator_ref() == x.get_allocator_ref())
- {
- this->clear();
- this->deallocate_buffer();
- if (copy_alloc)
- {
- this->get_allocator_ref() = boost::move(x.get_allocator_ref());
- }
- m_.capacity = x.m_.capacity;
- m_.buffer = x.m_.buffer;
- m_.front_idx = x.m_.front_idx;
- m_.back_idx = x.m_.back_idx;
-
- x.m_.capacity = 0u;
- x.m_.buffer = pointer();
- x.m_.back_idx = x.m_.front_idx = 0;
- }
- else
- {
-
-
- move_iterator<iterator> xbegin = boost::make_move_iterator(x.begin());
- move_iterator<iterator> xend = boost::make_move_iterator(x.end());
- if (copy_alloc)
- {
- get_allocator_ref() = boost::move(x.get_allocator_ref());
- }
- if (capacity() >= x.size())
- {
- overwrite_buffer(xbegin, xend);
- }
- else
- {
- allocate_and_copy_range(xbegin, xend);
- }
- }
- BOOST_ASSERT(invariants_ok());
- return *this;
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- devector& operator=(std::initializer_list<T> il)
- {
- assign(il.begin(), il.end());
- return *this;
- }
- #endif
-
- template <class InputIterator>
- void assign(InputIterator first, InputIterator last
- //Input iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<InputIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_not_input_iterator<InputIterator>
- >::type * = 0)
- )
- {
- first = overwrite_buffer_impl(first, last, dtl::false_());
- while (first != last)
- {
- this->emplace_back(*first++);
- }
- }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class ForwardIterator>
- void assign(ForwardIterator first, ForwardIterator last
- //Other iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<ForwardIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_input_iterator<ForwardIterator>
- >::type * = 0)
- )
- {
- const size_type n = boost::container::iterator_distance(first, last);
- if (capacity() >= n)
- {
- overwrite_buffer(first, last);
- }
- else
- {
- allocate_and_copy_range(first, last);
- }
- BOOST_ASSERT(invariants_ok());
- }
- #endif
-
- void assign(size_type n, const T& u)
- {
- cvalue_iterator first(u, n);
- cvalue_iterator last;
- assign(first, last);
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- void assign(std::initializer_list<T> il)
- {
- assign(il.begin(), il.end());
- }
- #endif
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- allocator_type get_allocator() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const allocator_type &get_stored_allocator() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- allocator_type &get_stored_allocator() BOOST_NOEXCEPT
- {
- return static_cast<allocator_type&>(m_);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- iterator begin() BOOST_NOEXCEPT
- {
- return m_.buffer + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_iterator begin() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- iterator end() BOOST_NOEXCEPT
- {
- return m_.buffer + m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_iterator end() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reverse_iterator rbegin() BOOST_NOEXCEPT
- {
- return reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reverse_iterator rbegin() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reverse_iterator rend() BOOST_NOEXCEPT
- {
- return reverse_iterator(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reverse_iterator rend() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_iterator cbegin() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.front_idx;
- }
-
- const_iterator cend() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reverse_iterator crbegin() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reverse_iterator crend() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.front_idx);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- bool empty() const BOOST_NOEXCEPT
- {
- return m_.front_idx == m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- size_type size() const BOOST_NOEXCEPT
- {
- return m_.back_idx - m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- size_type max_size() const BOOST_NOEXCEPT
- {
- size_type alloc_max = allocator_traits_type::max_size(get_allocator_ref());
- size_type size_type_max = (size_type)-1;
- return (alloc_max <= size_type_max) ? size_type(alloc_max) : size_type_max;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- size_type capacity() const BOOST_NOEXCEPT
- {
- return m_.capacity;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- size_type front_free_capacity() const BOOST_NOEXCEPT
- {
- return m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- size_type back_free_capacity() const BOOST_NOEXCEPT
- {
- return m_.capacity - m_.back_idx;
- }
-
- void resize(size_type sz) { resize_back(sz); }
-
- void resize(size_type sz, const T& c) { resize_back(sz, c); }
-
- void resize_front(size_type sz)
- {
- resize_front_impl(sz);
- BOOST_ASSERT(invariants_ok());
- }
-
- void resize_front(size_type sz, const T& c)
- {
- resize_front_impl(sz, c);
- BOOST_ASSERT(invariants_ok());
- }
-
- void resize_back(size_type sz)
- {
- resize_back_impl(sz);
- BOOST_ASSERT(invariants_ok());
- }
-
- void resize_back(size_type sz, const T& c)
- {
- resize_back_impl(sz, c);
- BOOST_ASSERT(invariants_ok());
- }
-
-
-
-
-
-
- void reserve(size_type new_capacity) { reserve_back(new_capacity); }
-
- void reserve_front(size_type new_capacity)
- {
- if (front_capacity() >= new_capacity) { return; }
- reallocate_at(new_capacity + back_free_capacity(), new_capacity - size());
- BOOST_ASSERT(invariants_ok());
- }
-
- void reserve_back(size_type new_capacity)
- {
- if (back_capacity() >= new_capacity) { return; }
- reallocate_at(new_capacity + front_free_capacity(), m_.front_idx);
- BOOST_ASSERT(invariants_ok());
- }
-
- void shrink_to_fit()
- {
- if(this->front_capacity() || this->back_capacity())
- this->reallocate_at(size(), 0);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reference operator[](size_type n) BOOST_NOEXCEPT
- {
- BOOST_ASSERT(n < size());
- return *(begin() + n);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reference operator[](size_type n) const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(n < size());
- return *(begin() + n);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reference at(size_type n)
- {
- if (size() <= n)
- throw_out_of_range("devector::at out of range");
- return (*this)[n];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reference at(size_type n) const
- {
- if (size() <= n)
- throw_out_of_range("devector::at out of range");
- return (*this)[n];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reference front() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return *(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reference front() const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return *(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- reference back() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return *(m_.buffer + m_.back_idx -1);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const_reference back() const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return *(m_.buffer + m_.back_idx -1);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- T* data() BOOST_NOEXCEPT
- {
- return boost::movelib::to_raw_pointer(m_.buffer) + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- const T* data() const BOOST_NOEXCEPT
- {
- return boost::movelib::to_raw_pointer(m_.buffer) + m_.front_idx;
- }
-
-
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <class... Args>
- void emplace_front(Args&&... args)
- {
- if (front_free_capacity())
- {
- this->alloc_construct(m_.buffer + m_.front_idx - 1, boost::forward<Args>(args)...);
- --m_.front_idx;
- }
- else
- {
- this->emplace_reallocating_slow_path(true, 0, boost::forward<Args>(args)...);
- }
- BOOST_ASSERT(invariants_ok());
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_EMPLACE_FRONT(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- BOOST_CONTAINER_FORCEINLINE void emplace_front(BOOST_MOVE_UREF##N)\
- {\
- if (front_free_capacity())\
- {\
- this->alloc_construct(m_.buffer + m_.front_idx - 1 BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- --m_.front_idx;\
- }\
- else\
- {\
- this->emplace_reallocating_slow_path(true, 0 BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- \
- BOOST_ASSERT(invariants_ok());\
- }\
-
- BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEVECTOR_EMPLACE_FRONT)
- #undef BOOST_CONTAINER_DEVECTOR_EMPLACE_FRONT
- #endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
-
- void push_front(const T& x);
-
- void push_front(T&& x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
- #endif
-
- void pop_front() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(! empty());
- allocator_traits_type::destroy(get_allocator_ref(), m_.buffer + m_.front_idx);
- ++m_.front_idx;
- BOOST_ASSERT(invariants_ok());
- }
-
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <class... Args>
- BOOST_CONTAINER_FORCEINLINE void emplace_back(Args&&... args)
- {
- if (this->back_free_capacity()){
- this->alloc_construct(m_.buffer + m_.back_idx, boost::forward<Args>(args)...);
- ++m_.back_idx;
- }
- else {
- this->emplace_reallocating_slow_path(false, size(), boost::forward<Args>(args)...);
- }
- BOOST_ASSERT(invariants_ok());
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_EMPLACE_BACK(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- BOOST_CONTAINER_FORCEINLINE void emplace_back(BOOST_MOVE_UREF##N)\
- {\
- if (this->back_free_capacity()){\
- this->alloc_construct(m_.buffer + m_.back_idx BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ++m_.back_idx;\
- }\
- else {\
- this->emplace_reallocating_slow_path(false, size() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- BOOST_ASSERT(invariants_ok());\
- }\
-
- BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEVECTOR_EMPLACE_BACK)
- #undef BOOST_CONTAINER_DEVECTOR_EMPLACE_BACK
- #endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
-
- void push_back(const T& x);
-
- void push_back(T&& x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
- #endif
-
- void pop_back() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(! empty());
- --m_.back_idx;
- allocator_traits_type::destroy(get_allocator_ref(), m_.buffer + m_.back_idx);
- BOOST_ASSERT(invariants_ok());
- }
-
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <class... Args>
- iterator emplace(const_iterator position, Args&&... args)
- {
- BOOST_ASSERT(position >= begin());
- BOOST_ASSERT(position <= end());
- if (position == end() && back_free_capacity())
- {
- this->alloc_construct(m_.buffer + m_.back_idx, boost::forward<Args>(args)...);
- ++m_.back_idx;
- return end() - 1;
- }
- else if (position == begin() && front_free_capacity())
- {
- this->alloc_construct(m_.buffer + (m_.front_idx - 1), boost::forward<Args>(args)...);
- --m_.front_idx;
- return begin();
- }
- else
- {
- size_type new_elem_index = position - begin();
- return this->emplace_slow_path(new_elem_index, boost::forward<Args>(args)...);
- }
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_EMPLACE(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- iterator emplace(const_iterator position BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- BOOST_ASSERT(position >= begin());\
- BOOST_ASSERT(position <= end());\
- \
- if (position == end() && back_free_capacity()){\
- this->alloc_construct(m_.buffer + m_.back_idx BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ++m_.back_idx;\
- return end() - 1;\
- }\
- else if (position == begin() && front_free_capacity()){\
- this->alloc_construct(m_.buffer + m_.front_idx - 1 BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- --m_.front_idx;\
- return begin();\
- }\
- else{\
- size_type new_elem_index = position - begin();\
- return this->emplace_slow_path(new_elem_index BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- }\
-
- BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEVECTOR_EMPLACE)
- #undef BOOST_CONTAINER_DEVECTOR_EMPLACE
- #endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
-
- iterator insert(const_iterator position, const T &x);
-
- iterator insert(const_iterator position, T &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
- #endif
-
- iterator insert(const_iterator position, size_type n, const T& x)
- {
- cvalue_iterator first(x, n);
- cvalue_iterator last = first + n;
- return insert_range(position, first, last);
- }
-
- template <class InputIterator>
- iterator insert(const_iterator position, InputIterator first, InputIterator last
- //Input iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<InputIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_not_input_iterator<InputIterator>
- >::type * = 0)
- )
- {
- if (position == end())
- {
- size_type insert_index = size();
- for (; first != last; ++first)
- {
- this->emplace_back(*first);
- }
- return begin() + insert_index;
- }
- else
- {
- const size_type insert_index = static_cast<size_type>(position - this->cbegin());
- const size_type old_size = static_cast<size_type>(this->size());
- for (; first != last; ++first) {
- this->emplace_back(*first);
- }
- iterator rit (this->begin() + insert_index);
- boost::movelib::rotate_gcd(rit, this->begin() + old_size, this->begin() + this->size());
- return rit;
- }
- }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class ForwardIterator>
- iterator insert(const_iterator position, ForwardIterator first, ForwardIterator last
- //Other iterators
- BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename dtl::disable_if_or
- < void
- BOOST_MOVE_I dtl::is_convertible<ForwardIterator BOOST_MOVE_I size_type>
- BOOST_MOVE_I dtl::is_input_iterator<ForwardIterator>
- >::type * = 0)
- )
- {
- return insert_range(position, first, last);
- }
- #endif
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- iterator insert(const_iterator position, std::initializer_list<T> il)
- {
- return insert_range(position, il.begin(), il.end());
- }
- #endif
-
- iterator erase(const_iterator position)
- {
- return erase(position, position + 1);
- }
-
- iterator erase(const_iterator first, const_iterator last)
- {
- iterator nc_first = begin() + (first - begin());
- iterator nc_last = begin() + (last - begin());
- return erase(nc_first, nc_last);
- }
-
- iterator erase(iterator first, iterator last)
- {
- size_type front_distance = last - begin();
- size_type back_distance = end() - first;
- size_type n = boost::container::iterator_distance(first, last);
- if (front_distance < back_distance)
- {
-
- boost::container::move_backward(begin(), first, last);
- for (iterator i = begin(); i != begin() + n; ++i)
- {
- allocator_traits_type::destroy(get_allocator_ref(), i);
- }
-
- m_.set_front_idx(m_.front_idx + n);
- BOOST_ASSERT(invariants_ok());
- return last;
- }
- else {
-
- boost::container::move(last, end(), first);
- for (iterator i = end() - n; i != end(); ++i)
- {
- allocator_traits_type::destroy(get_allocator_ref(), i);
- }
-
- m_.set_back_idx(m_.back_idx - n);
- BOOST_ASSERT(invariants_ok());
- return first;
- }
- }
-
- void swap(devector& b)
- BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
- || allocator_traits_type::is_always_equal::value)
- {
- BOOST_CONSTEXPR_OR_CONST bool propagate_alloc = allocator_traits_type::propagate_on_container_swap::value;
- BOOST_ASSERT(propagate_alloc || get_allocator_ref() == b.get_allocator_ref());
- swap_big_big(*this, b);
-
- boost::adl_move_swap(m_.front_idx, b.m_.front_idx);
- boost::adl_move_swap(m_.back_idx, b.m_.back_idx);
-
- dtl::swap_alloc(this->get_allocator_ref(), b.get_allocator_ref(), dtl::bool_<propagate_alloc>());
- BOOST_ASSERT( invariants_ok());
- BOOST_ASSERT(b.invariants_ok());
- }
-
- void clear() BOOST_NOEXCEPT
- {
- destroy_elements(begin(), end());
- m_.front_idx = m_.back_idx = 0;
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator==(const devector& x, const devector& y)
- { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator!=(const devector& x, const devector& y)
- { return !(x == y); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator< (const devector& x, const devector& y)
- { return boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator>(const devector& x, const devector& y)
- { return y < x; }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator<=(const devector& x, const devector& y)
- { return !(y < x); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
- friend bool operator>=(const devector& x, const devector& y)
- { return !(x < y); }
- BOOST_CONTAINER_FORCEINLINE friend void swap(devector& x, devector& y)
- BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
- || allocator_traits_type::is_always_equal::value)
- { x.swap(y); }
- private:
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- BOOST_CONTAINER_FORCEINLINE T* raw_begin() BOOST_NOEXCEPT
- { return boost::movelib::to_raw_pointer(m_.buffer) + m_.front_idx; }
- BOOST_CONTAINER_FORCEINLINE T* raw_end() BOOST_NOEXCEPT
- { return boost::movelib::to_raw_pointer(m_.buffer) + m_.back_idx; }
- template <class U>
- BOOST_CONTAINER_FORCEINLINE void priv_push_front(BOOST_FWD_REF(U) u)
- {
- this->emplace_front(boost::forward<U>(u));
- }
- template <class U>
- BOOST_CONTAINER_FORCEINLINE void priv_push_back(BOOST_FWD_REF(U) u)
- {
- this->emplace_back(boost::forward<U>(u));
- }
- template <class U>
- BOOST_CONTAINER_FORCEINLINE iterator priv_insert(const_iterator pos, BOOST_FWD_REF(U) u)
- {
- return this->emplace(pos, boost::forward<U>(u));
- }
-
- BOOST_CONTAINER_FORCEINLINE allocator_type& get_allocator_ref() BOOST_NOEXCEPT
- {
- return static_cast<allocator_type&>(m_);
- }
- BOOST_CONTAINER_FORCEINLINE const allocator_type& get_allocator_ref() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- pointer allocate(size_type capacity)
- {
-
- if (capacity > stored_size_type(-1)){
- boost::container::throw_length_error("get_next_capacity, allocator's max size reached");
- }
-
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- ++m_.capacity_alloc_count;
- #endif
- return allocator_traits_type::allocate(get_allocator_ref(), capacity);
- }
- void destroy_elements(pointer begin, pointer end)
- {
- for (; begin != end; ++begin)
- {
- allocator_traits_type::destroy(get_allocator_ref(), begin);
- }
- }
- void deallocate_buffer()
- {
- if (m_.buffer)
- {
- allocator_traits_type::deallocate(get_allocator_ref(), m_.buffer, m_.capacity);
- }
- }
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <typename... Args>
- BOOST_CONTAINER_FORCEINLINE void alloc_construct(pointer dst, Args&&... args)
- {
- allocator_traits_type::construct(
- get_allocator_ref(),
- dst,
- boost::forward<Args>(args)...
- );
- }
- template <typename... Args>
- void construct_n(pointer buffer, size_type n, Args&&... args)
- {
- detail::construction_guard<allocator_type> ctr_guard(buffer, get_allocator_ref());
- guarded_construct_n(buffer, n, ctr_guard, boost::forward<Args>(args)...);
- ctr_guard.release();
- }
- template <typename... Args>
- void guarded_construct_n(pointer buffer, size_type n, detail::construction_guard<allocator_type>& ctr_guard, Args&&... args)
- {
- for (size_type i = 0; i < n; ++i) {
- this->alloc_construct(buffer + i, boost::forward<Args>(args)...);
- ctr_guard.extend();
- }
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_ALLOC_CONSTRUCT(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- BOOST_CONTAINER_FORCEINLINE void alloc_construct(pointer dst BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- allocator_traits_type::construct(\
- get_allocator_ref(), dst BOOST_MOVE_I##N BOOST_MOVE_FWD##N );\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void construct_n(pointer buffer, size_type n BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- detail::construction_guard<allocator_type> ctr_guard(buffer, get_allocator_ref());\
- guarded_construct_n(buffer, n, ctr_guard BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ctr_guard.release();\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void guarded_construct_n(pointer buffer, size_type n, detail::construction_guard<allocator_type>& ctr_guard BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- for (size_type i = 0; i < n; ++i) {\
- this->alloc_construct(buffer + i BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ctr_guard.extend();\
- }\
- }
-
- BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEVECTOR_ALLOC_CONSTRUCT)
- #undef BOOST_CONTAINER_DEVECTOR_ALLOC_CONSTRUCT
- #endif
- BOOST_CONTAINER_FORCEINLINE size_type front_capacity() const
- {
- return m_.back_idx;
- }
- BOOST_CONTAINER_FORCEINLINE size_type back_capacity() const
- {
- return m_.capacity - m_.front_idx;
- }
- size_type calculate_new_capacity(size_type requested_capacity)
- {
- size_type max = allocator_traits_type::max_size(this->get_allocator_ref());
- (clamp_by_stored_size_type)(max, stored_size_type());
- const size_type remaining_additional_cap = max - size_type(m_.capacity);
- const size_type min_additional_cap = requested_capacity - size_type(m_.capacity);
- if ( remaining_additional_cap < min_additional_cap )
- boost::container::throw_length_error("devector: get_next_capacity, max size exceeded");
- return growth_factor_type()( size_type(m_.capacity), min_additional_cap, max);
- }
- void buffer_move_or_copy(pointer dst)
- {
- detail::construction_guard<allocator_type> guard(dst, get_allocator_ref());
- buffer_move_or_copy(dst, guard);
- guard.release();
- }
- void buffer_move_or_copy(pointer dst, detail::construction_guard<allocator_type>& guard)
- {
- opt_move_or_copy(begin(), end(), dst, guard);
- destroy_elements(data(), data() + size());
- deallocate_buffer();
- }
- void opt_move_or_copy(pointer begin, pointer end, pointer dst)
- {
- typedef typename dtl::if_c
- < boost::move_detail::is_nothrow_copy_constructible<T>::value || boost::is_nothrow_move_constructible<T>::value
- , detail::null_construction_guard
- , detail::construction_guard<allocator_type>
- >::type guard_t;
- guard_t guard(dst, get_allocator_ref());
- opt_move_or_copy(begin, end, dst, guard);
- guard.release();
- }
- template <typename Guard>
- void opt_move_or_copy(pointer begin, pointer end, pointer dst, Guard& guard)
- {
-
- boost::container::uninitialized_move_alloc(get_allocator_ref(), begin, end, dst);
- guard.extend();
- }
- template <typename Iterator>
- void opt_copy(Iterator begin, Iterator end, pointer dst)
- {
- typedef typename dtl::if_c
- < boost::move_detail::is_nothrow_copy_constructible<T>::value
- , detail::null_construction_guard
- , detail::construction_guard<allocator_type>
- >::type guard_t;
- guard_t guard(dst, get_allocator_ref());
- opt_copy(begin, end, dst, guard);
- guard.release();
- }
- template <typename Iterator, typename Guard>
- void opt_copy(Iterator begin, Iterator end, pointer dst, Guard& guard)
- {
- while (begin != end)
- {
- this->alloc_construct(dst++, *begin++);
- guard.extend();
- }
- }
- template <typename Guard>
- void opt_copy(const_pointer begin, const_pointer end, pointer dst, Guard& guard)
- {
-
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), begin, end, dst);
- guard.extend();
- }
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <typename... Args>
- void resize_front_impl(size_type sz , Args&&... args)
- {
- if (sz > size())
- {
- const size_type n = sz - size();
- if (sz <= front_capacity())
- {
- construct_n(m_.buffer + m_.front_idx - n, n, boost::forward<Args>(args)...);
- m_.set_front_idx(m_.front_idx - n);
- }
- else
- {
- resize_front_slow_path(sz, n, boost::forward<Args>(args)...);
- }
- }
- else {
- while (this->size() > sz)
- {
- this->pop_front();
- }
- }
- }
- template <typename... Args>
- void resize_front_slow_path(size_type sz, size_type n, Args&&... args)
- {
- const size_type new_capacity = calculate_new_capacity(sz + back_free_capacity());
- pointer new_buffer = allocate(new_capacity);
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- const size_type new_old_elem_index = new_capacity - size();
- const size_type new_elem_index = new_old_elem_index - n;
- detail::construction_guard<allocator_type> guard(new_buffer + new_elem_index, get_allocator_ref());
- guarded_construct_n(new_buffer + new_elem_index, n, guard, boost::forward<Args>(args)...);
- buffer_move_or_copy(new_buffer + new_old_elem_index, guard);
- guard.release();
- new_buffer_guard.release();
- m_.buffer = new_buffer;
- m_.set_capacity(new_capacity);
- m_.set_back_idx(new_old_elem_index + m_.back_idx - m_.front_idx);
- m_.set_front_idx(new_elem_index);
- }
- template <typename... Args>
- void resize_back_impl(size_type sz, Args&&... args)
- {
- if (sz > size())
- {
- const size_type n = sz - size();
- if (sz <= back_capacity())
- {
- construct_n(m_.buffer + m_.back_idx, n, boost::forward<Args>(args)...);
- m_.set_back_idx(m_.back_idx + n);
- }
- else
- {
- resize_back_slow_path(sz, n, boost::forward<Args>(args)...);
- }
- }
- else
- {
- while (size() > sz)
- {
- pop_back();
- }
- }
- }
- template <typename... Args>
- void resize_back_slow_path(size_type sz, size_type n, Args&&... args)
- {
- const size_type new_capacity = calculate_new_capacity(sz + front_free_capacity());
- pointer new_buffer = allocate(new_capacity);
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- detail::construction_guard<allocator_type> guard(new_buffer + m_.back_idx, get_allocator_ref());
- guarded_construct_n(new_buffer + m_.back_idx, n, guard, boost::forward<Args>(args)...);
- buffer_move_or_copy(new_buffer + m_.front_idx);
- guard.release();
- new_buffer_guard.release();
- m_.buffer = new_buffer;
- m_.set_capacity(new_capacity);
- m_.set_back_idx(m_.back_idx + n);
- }
- template <typename... Args>
- iterator emplace_slow_path(size_type new_elem_index, Args&&... args)
- {
- pointer position = begin() + new_elem_index;
-
- bool prefer_move_front = new_elem_index <= size()/2;
- if (front_free_capacity() && (!back_free_capacity() || prefer_move_front))
- {
- BOOST_ASSERT(size() >= 1);
-
-
- T tmp(boost::forward<Args>(args)...);
-
- this->alloc_construct(begin() - 1, boost::move(*begin()));
-
- boost::move(begin() + 1, position, begin());
- --m_.front_idx;
-
- --position;
- *position = boost::move(tmp);
- return position;
- }
- else if (back_free_capacity()) {
- BOOST_ASSERT(size() >= 1);
-
-
- T tmp(boost::forward<Args>(args)...);
-
- this->alloc_construct(end(), boost::move(back()));
-
- boost::container::move_backward(position, end() - 1, end());
- ++m_.back_idx;
-
- *position = boost::move(tmp);
- return position;
- }
- else
- {
- return emplace_reallocating_slow_path(prefer_move_front, new_elem_index, boost::forward<Args>(args)...);
- }
- }
- template <typename... Args>
- pointer emplace_reallocating_slow_path(bool make_front_free, size_type new_elem_index, Args&&... args)
- {
-
- size_type new_capacity = calculate_new_capacity(capacity() + 1);
- pointer new_buffer = allocate(new_capacity);
-
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- size_type new_front_index = (make_front_free)
- ? new_capacity - back_free_capacity() - size() - 1
- : m_.front_idx;
- iterator new_begin = new_buffer + new_front_index;
- iterator new_position = new_begin + new_elem_index;
- iterator old_position = begin() + new_elem_index;
-
- this->alloc_construct(new_position, boost::forward<Args>(args)...);
- detail::construction_guard<allocator_type> second_half_guard(new_position, get_allocator_ref());
- second_half_guard.extend();
-
- detail::construction_guard<allocator_type> first_half_guard(new_begin, get_allocator_ref());
- opt_move_or_copy(begin(), old_position, new_begin, first_half_guard);
-
- opt_move_or_copy(old_position, end(), new_position + 1, second_half_guard);
-
- destroy_elements(begin(), end());
- deallocate_buffer();
-
- second_half_guard.release();
- first_half_guard.release();
- new_buffer_guard.release();
-
- m_.set_capacity(new_capacity);
- m_.buffer = new_buffer;
- m_.set_back_idx(new_front_index + size() + 1);
- m_.set_front_idx(new_front_index);
- return new_position;
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_SLOW_PATH(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void resize_front_impl(size_type sz BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- if (sz > size())\
- {\
- const size_type n = sz - size();\
- if (sz <= front_capacity()){\
- construct_n(m_.buffer + m_.front_idx - n, n BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- m_.set_front_idx(m_.front_idx - n);\
- }\
- else\
- {\
- resize_front_slow_path(sz, n BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- }\
- else {\
- while (this->size() > sz)\
- {\
- this->pop_front();\
- }\
- }\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void resize_front_slow_path(size_type sz, size_type n BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- const size_type new_capacity = calculate_new_capacity(sz + back_free_capacity());\
- pointer new_buffer = allocate(new_capacity);\
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());\
- \
- const size_type new_old_elem_index = new_capacity - size();\
- const size_type new_elem_index = new_old_elem_index - n;\
- \
- detail::construction_guard<allocator_type> guard(new_buffer + new_elem_index, get_allocator_ref());\
- guarded_construct_n(new_buffer + new_elem_index, n, guard BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- \
- buffer_move_or_copy(new_buffer + new_old_elem_index, guard);\
- \
- guard.release();\
- new_buffer_guard.release();\
- m_.buffer = new_buffer;\
- m_.set_capacity(new_capacity);\
- m_.set_back_idx(new_old_elem_index + m_.back_idx - m_.front_idx);\
- m_.set_front_idx(new_elem_index);\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void resize_back_impl(size_type sz BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- if (sz > size())\
- {\
- const size_type n = sz - size();\
- \
- if (sz <= back_capacity())\
- {\
- construct_n(m_.buffer + m_.back_idx, n BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- m_.set_back_idx(m_.back_idx + n);\
- }\
- else\
- {\
- resize_back_slow_path(sz, n BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- }\
- else\
- {\
- while (size() > sz)\
- {\
- pop_back();\
- }\
- }\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- void resize_back_slow_path(size_type sz, size_type n BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- const size_type new_capacity = calculate_new_capacity(sz + front_free_capacity());\
- pointer new_buffer = allocate(new_capacity);\
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());\
- \
- detail::construction_guard<allocator_type> guard(new_buffer + m_.back_idx, get_allocator_ref());\
- guarded_construct_n(new_buffer + m_.back_idx, n, guard BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- \
- buffer_move_or_copy(new_buffer + m_.front_idx);\
- \
- guard.release();\
- new_buffer_guard.release();\
- \
- m_.buffer = new_buffer;\
- m_.set_capacity(new_capacity);\
- m_.set_back_idx(m_.back_idx + n);\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- iterator emplace_slow_path(size_type new_elem_index BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- pointer position = begin() + new_elem_index;\
- \
- bool prefer_move_front = new_elem_index <= size()/2;\
- \
- if (front_free_capacity() && (!back_free_capacity() || prefer_move_front))\
- {\
- BOOST_ASSERT(size() >= 1);\
- typename dtl::aligned_storage<sizeof(T), dtl::alignment_of<T>::value>::type v;\
- T *vp = reinterpret_cast<T *>(v.data);\
- allocator_traits_type::construct(get_stored_allocator(), vp BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- T &tmp = *vp;\
- dtl::value_destructor<allocator_type> on_exit(get_stored_allocator(), tmp); (void)on_exit;\
- \
- this->alloc_construct(begin() - 1, boost::move(*begin()));\
- boost::move(begin() + 1, position, begin());\
- --m_.front_idx;\
- --position;\
- *position = boost::move(tmp);\
- return position;\
- }\
- else if (back_free_capacity()) {\
- BOOST_ASSERT(size() >= 1);\
- typename dtl::aligned_storage<sizeof(T), dtl::alignment_of<T>::value>::type v;\
- T *vp = reinterpret_cast<T *>(v.data);\
- allocator_traits_type::construct(get_stored_allocator(), vp BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- T &tmp = *vp;\
- dtl::value_destructor<allocator_type> on_exit(get_stored_allocator(), tmp); (void)on_exit;\
- this->alloc_construct(end(), boost::move(back()));\
- boost::container::move_backward(position, end() - 1, end());\
- ++m_.back_idx;\
- *position = boost::move(tmp);\
- return position;\
- }\
- else {\
- return emplace_reallocating_slow_path(prefer_move_front, new_elem_index BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- }\
- }\
- \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- pointer emplace_reallocating_slow_path(bool make_front_free, size_type new_elem_index BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- size_type new_capacity = calculate_new_capacity(capacity() + 1);\
- pointer new_buffer = allocate(new_capacity);\
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());\
- size_type new_front_index = (make_front_free)\
- ? new_capacity - back_free_capacity() - size() - 1\
- : m_.front_idx;\
- iterator new_begin = new_buffer + new_front_index;\
- iterator new_position = new_begin + new_elem_index;\
- iterator old_position = begin() + new_elem_index;\
- this->alloc_construct(new_position BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- detail::construction_guard<allocator_type> second_half_guard(new_position, get_allocator_ref());\
- second_half_guard.extend();\
- detail::construction_guard<allocator_type> first_half_guard(new_begin, get_allocator_ref());\
- opt_move_or_copy(begin(), old_position, new_begin, first_half_guard);\
- opt_move_or_copy(old_position, end(), new_position + 1, second_half_guard);\
- destroy_elements(begin(), end());\
- deallocate_buffer();\
- second_half_guard.release();\
- first_half_guard.release();\
- new_buffer_guard.release();\
- m_.set_capacity(new_capacity);\
- m_.buffer = new_buffer;\
- m_.set_back_idx(new_front_index + size() + 1);\
- m_.set_front_idx(new_front_index);\
- return new_position;\
- }\
-
- BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEVECTOR_SLOW_PATH)
- #undef BOOST_CONTAINER_DEVECTOR_SLOW_PATH
- #endif
- void reallocate_at(size_type new_capacity, size_type buffer_offset)
- {
- pointer new_buffer = allocate(new_capacity);
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- buffer_move_or_copy(new_buffer + buffer_offset);
- new_buffer_guard.release();
- m_.buffer = new_buffer;
-
- m_.set_capacity(new_capacity);
- m_.set_back_idx(m_.back_idx - m_.front_idx + buffer_offset);
- m_.set_front_idx(buffer_offset);
- BOOST_ASSERT(invariants_ok());
- }
- template <typename ForwardIterator>
- iterator insert_range(const_iterator position, ForwardIterator first, ForwardIterator last)
- {
- size_type n = boost::container::iterator_distance(first, last);
- if (position == end() && back_free_capacity() >= n) {
- iterator r(this->end());
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), first, last, this->raw_end());
- m_.set_back_idx(m_.back_idx + n);
- return r;
- }
- else if (position == begin() && front_free_capacity() >= n) {
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), first, last, this->raw_begin() - n);
- m_.set_front_idx(m_.front_idx - n);
- return begin();
- }
- else {
- return insert_range_slow_path(position, first, last);
- }
- }
- template <typename ForwardIterator>
- iterator insert_range_slow_path(const_iterator position, ForwardIterator first, ForwardIterator last)
- {
- size_type n = boost::container::iterator_distance(first, last);
- size_type index = position - begin();
- if (front_free_capacity() + back_free_capacity() >= n) {
-
- iterator middle = begin() + index;
- n -= insert_range_slow_path_near_front(middle, first, n);
- if (n) {
- insert_range_slow_path_near_back(middle, first, n);
- }
- BOOST_ASSERT(first == last);
- return begin() + index;
- }
- else {
- const bool prefer_move_front = 2 * index <= size();
- return insert_range_reallocating_slow_path(prefer_move_front, index, first, n);
- }
- }
- template <typename Iterator>
- size_type insert_range_slow_path_near_front(iterator position, Iterator& first, size_type n)
- {
- size_type n_front = dtl::min_value(front_free_capacity(), n);
- iterator new_begin = begin() - n_front;
- iterator ctr_pos = new_begin;
- detail::construction_guard<allocator_type> ctr_guard(ctr_pos, get_allocator_ref());
- while (ctr_pos != begin()) {
- this->alloc_construct(ctr_pos++, *(first++));
- ctr_guard.extend();
- }
- boost::movelib::rotate_gcd(new_begin, ctr_pos, position);
- m_.set_front_idx(m_.front_idx - n_front);
- ctr_guard.release();
- BOOST_ASSERT(invariants_ok());
- return n_front;
- }
- template <typename Iterator>
- size_type insert_range_slow_path_near_back(iterator position, Iterator& first, size_type n)
- {
- const size_type n_back = dtl::min_value(back_free_capacity(), n);
- iterator ctr_pos = end();
- detail::construction_guard<allocator_type> ctr_guard(ctr_pos, get_allocator_ref());
- for (size_type i = 0; i < n_back; ++i) {
- this->alloc_construct(ctr_pos++, *first++);
- ctr_guard.extend();
- }
- boost::movelib::rotate_gcd(position, end(), ctr_pos);
- m_.set_back_idx(m_.back_idx + n_back);
- ctr_guard.release();
- BOOST_ASSERT(invariants_ok());
- return n_back;
- }
- template <typename Iterator>
- iterator insert_range_reallocating_slow_path
- (bool make_front_free, size_type new_elem_index, Iterator elems, size_type n)
- {
-
- const size_type new_capacity = calculate_new_capacity(capacity() + n);
- pointer new_buffer = allocate(new_capacity);
-
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- const size_type new_front_index = (make_front_free)
- ? new_capacity - back_free_capacity() - size() - n
- : m_.front_idx;
- const iterator new_begin = new_buffer + new_front_index;
- const iterator new_position = new_begin + new_elem_index;
- const iterator old_position = begin() + new_elem_index;
-
- iterator second_half_position = new_position;
- detail::construction_guard<allocator_type> second_half_guard(second_half_position, get_allocator_ref());
- for (size_type i = 0; i < n; ++i) {
- this->alloc_construct(second_half_position++, *(elems++));
- second_half_guard.extend();
- }
-
- detail::construction_guard<allocator_type> first_half_guard(new_begin, get_allocator_ref());
- opt_move_or_copy(begin(), old_position, new_begin, first_half_guard);
-
- opt_move_or_copy(old_position, end(), second_half_position, second_half_guard);
-
- destroy_elements(begin(), end());
- deallocate_buffer();
-
- second_half_guard.release();
- first_half_guard.release();
- new_buffer_guard.release();
-
- m_.set_capacity(new_capacity);
- m_.buffer = new_buffer;
- m_.set_back_idx(new_front_index + size() + n);
- m_.set_front_idx(new_front_index);
- return new_position;
- }
- template <typename Iterator>
- void construct_from_range(Iterator begin, Iterator end)
- {
- allocation_guard buffer_guard(m_.buffer, m_.capacity, get_allocator_ref());
- opt_copy(begin, end, m_.buffer);
- buffer_guard.release();
- }
- template <typename ForwardIterator>
- void allocate_and_copy_range(ForwardIterator first, ForwardIterator last)
- {
- size_type n = boost::container::iterator_distance(first, last);
- pointer new_buffer = n ? allocate(n) : pointer();
- allocation_guard new_buffer_guard(new_buffer, n, get_allocator_ref());
- opt_copy(first, last, new_buffer);
- destroy_elements(begin(), end());
- deallocate_buffer();
- m_.set_capacity(n);
- m_.buffer = new_buffer;
- m_.front_idx = 0;
- m_.set_back_idx(n);
- new_buffer_guard.release();
- }
- static void swap_big_big(devector& a, devector& b) BOOST_NOEXCEPT
- {
- boost::adl_move_swap(a.m_.capacity, b.m_.capacity);
- boost::adl_move_swap(a.m_.buffer, b.m_.buffer);
- }
- template <typename ForwardIterator>
- void overwrite_buffer_impl(ForwardIterator first, ForwardIterator last, dtl::true_)
- {
- const size_type n = boost::container::iterator_distance(first, last);
- BOOST_ASSERT(capacity() >= n);
- boost::container::uninitialized_copy_alloc_n
- ( get_allocator_ref(), boost::movelib::iterator_to_raw_pointer(first)
- , n, boost::movelib::iterator_to_raw_pointer(m_.buffer));
- m_.front_idx = 0;
- m_.set_back_idx(n);
- }
- template <typename InputIterator>
- InputIterator overwrite_buffer_impl(InputIterator first, InputIterator last, dtl::false_)
- {
- pointer pos = m_.buffer;
- detail::construction_guard<allocator_type> front_guard(pos, get_allocator_ref());
- while (first != last && pos != begin()) {
- this->alloc_construct(pos++, *first++);
- front_guard.extend();
- }
- while (first != last && pos != end()) {
- *pos++ = *first++;
- }
- detail::construction_guard<allocator_type> back_guard(pos, get_allocator_ref());
- iterator capacity_end = m_.buffer + capacity();
- while (first != last && pos != capacity_end) {
- this->alloc_construct(pos++, *first++);
- back_guard.extend();
- }
- pointer destroy_after = dtl::min_value(dtl::max_value(begin(), pos), end());
- destroy_elements(destroy_after, end());
- front_guard.release();
- back_guard.release();
- m_.front_idx = 0;
- m_.set_back_idx(pos - begin());
- return first;
- }
- template <typename ForwardIterator>
- BOOST_CONTAINER_FORCEINLINE void overwrite_buffer(ForwardIterator first, ForwardIterator last)
- {
- this->overwrite_buffer_impl(first, last,
- dtl::bool_<dtl::is_trivially_destructible<T>::value>());
- }
- bool invariants_ok()
- {
- return (!m_.capacity || m_.buffer)
- && m_.front_idx <= m_.back_idx
- && m_.back_idx <= m_.capacity;
- }
- struct impl : allocator_type
- {
- impl()
- : allocator_type(), buffer(), front_idx(), back_idx(), capacity()
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count()
- #endif
- {}
- explicit impl(const allocator_type &a)
- : allocator_type(a), buffer(), front_idx(), back_idx(), capacity()
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count()
- #endif
- {}
- impl(const allocator_type &a, pointer p, size_type f, size_type b, size_type c)
- : allocator_type(a), buffer(p)
-
- , front_idx(static_cast<stored_size_type>(f))
- , back_idx(static_cast<stored_size_type>(b))
- , capacity(static_cast<stored_size_type>(c))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count()
- #endif
- {}
- impl(BOOST_RV_REF(allocator_type) a, pointer p, size_type f, size_type b, size_type c)
- : allocator_type(boost::move(a)), buffer(p)
-
- , front_idx(static_cast<stored_size_type>(f))
- , back_idx(static_cast<stored_size_type>(b))
- , capacity(static_cast<stored_size_type>(c))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count()
- #endif
- {}
- void set_back_idx(size_type bi)
- { back_idx = static_cast<stored_size_type>(bi);}
- void set_front_idx(size_type fi)
- { front_idx = static_cast<stored_size_type>(fi);}
- void set_capacity(size_type c)
- { capacity = static_cast<stored_size_type>(c);}
- pointer buffer;
- stored_size_type front_idx;
- stored_size_type back_idx;
- stored_size_type capacity;
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- size_type capacity_alloc_count;
- #endif
- } m_;
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- public:
- void reset_alloc_stats()
- {
- m_.capacity_alloc_count = 0;
- }
- size_type get_alloc_count() const
- {
- return m_.capacity_alloc_count;
- }
- #endif
- #endif
- };
- }}
- #include <boost/container/detail/config_end.hpp>
- #endif
|