12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041 |
- #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/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>
- #include <boost/container/detail/advanced_insert_int.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>
- #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
- , default_if_zero<Options::free_fraction, relocate_on_90::value>::value
- > type;
- };
- template<class AllocatorSizeType>
- struct get_devector_opt<void, AllocatorSizeType>
- {
- typedef devector_opt< growth_factor_60, AllocatorSizeType, relocate_on_90::value> type;
- };
- #endif
- struct reserve_only_tag_t {};
- struct reserve_uninitialized_t {};
- struct review_implementation_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;
- BOOST_STATIC_CONSTEXPR std::size_t devector_min_free_fraction =
- options_type::free_fraction;
- #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> cvalue_iterator;
- static size_type to_internal_capacity(size_type desired_capacity)
- {
- const size_type rounder = devector_min_free_fraction - 2u;
- const size_type divisor = devector_min_free_fraction - 1u;
- size_type const nc = ((desired_capacity + rounder) / divisor) * devector_min_free_fraction;
- BOOST_ASSERT(desired_capacity <= (nc - nc / devector_min_free_fraction));
- return nc;
- }
- #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_(reserve_only_tag_t(), allocator, to_internal_capacity(n))
- {}
-
- devector(size_type front_free_cap, size_type back_free_cap, reserve_only_tag_t, const allocator_type& allocator = allocator_type())
- : m_(reserve_only_tag_t(), allocator, front_free_cap, back_free_cap)
- {}
-
- explicit devector(size_type n, const allocator_type& allocator = allocator_type())
- : m_(reserve_uninitialized_t(), allocator, n)
- {
- allocation_guard buffer_guard(m_.buffer, m_.capacity, get_allocator_ref());
- boost::container::uninitialized_value_init_alloc_n(get_allocator_ref(), n, this->priv_raw_begin());
- buffer_guard.release();
- BOOST_ASSERT(invariants_ok());
- }
-
- explicit devector(size_type n, default_init_t, const allocator_type& allocator = allocator_type())
- : m_(reserve_uninitialized_t(), allocator, n)
- {
- allocation_guard buffer_guard(m_.buffer, m_.capacity, get_allocator_ref());
- boost::container::uninitialized_default_init_alloc_n(get_allocator_ref(), n, this->priv_raw_begin());
- buffer_guard.release();
- BOOST_ASSERT(invariants_ok());
- }
-
- devector(size_type n, const T& value, const allocator_type& allocator = allocator_type())
- : m_(reserve_uninitialized_t(), allocator, 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)
- {
- BOOST_CONTAINER_TRY{
- while (first != last) {
- this->emplace_back(*first++);
- }
- BOOST_ASSERT(invariants_ok());
- }
- BOOST_CONTAINER_CATCH(...){
- this->destroy_elements(m_.buffer + m_.front_idx, m_.buffer + m_.back_idx);
- this->deallocate_buffer();
- }
- BOOST_CONTAINER_CATCH_END
- }
- #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_(reserve_uninitialized_t(), allocator, boost::container::iterator_udistance(first, last))
- {
- this->construct_from_range(first, last);
- BOOST_ASSERT(invariants_ok());
- }
- #endif
-
- devector(const devector& x)
- : m_(reserve_uninitialized_t(), allocator_traits_type::select_on_container_copy_construction(x.get_allocator_ref()), x.size())
- {
- this->construct_from_range(x.begin(), x.end());
- BOOST_ASSERT(invariants_ok());
- }
-
- devector(const devector& x, const allocator_type& allocator)
- : m_(reserve_uninitialized_t(), allocator, x.size())
- {
- 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.m_))
- {
- BOOST_ASSERT( invariants_ok());
- BOOST_ASSERT(rhs.invariants_ok());
- }
-
- devector(BOOST_RV_REF(devector) rhs, const allocator_type& allocator)
- : m_(review_implementation_t(), allocator, rhs.m_.buffer, rhs.m_.front_idx, rhs.m_.back_idx, rhs.m_.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_(reserve_uninitialized_t(), allocator, il.size())
- {
- 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();
- }
- inline devector& operator=(BOOST_COPY_ASSIGN_REF(devector) rhs)
- {
- const devector &x = rhs;
- if (this == &x) { return *this; }
- const bool do_propagate = allocator_traits_type::propagate_on_container_copy_assignment::value;
- BOOST_IF_CONSTEXPR(do_propagate)
- {
- 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();
- }
- dtl::bool_<do_propagate> flag;
- dtl::assign_alloc(this_alloc, other_alloc, flag);
- }
- size_type n = x.size();
- if (m_.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)
- {
- if (BOOST_LIKELY(this != &x)) {
-
-
- const bool can_steal_resources_alloc
- = allocator_traits_type::propagate_on_container_move_assignment::value
- || allocator_traits_type::is_always_equal::value;
- dtl::bool_<can_steal_resources_alloc> flag;
- this->priv_move_assign(boost::move(x), flag);
- }
- BOOST_ASSERT(invariants_ok());
- return *this;
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- inline devector& operator=(std::initializer_list<T> il)
- {
- this->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_udistance(first, last);
- if (m_.capacity >= n)
- {
- overwrite_buffer(first, last);
- }
- else
- {
- allocate_and_copy_range(first, last);
- }
- BOOST_ASSERT(invariants_ok());
- }
- #endif
-
- inline void assign(size_type n, const T& u)
- {
- cvalue_iterator first(u, n);
- cvalue_iterator last;
- this->assign(first, last);
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
- inline void assign(std::initializer_list<T> il)
- {
- this->assign(il.begin(), il.end());
- }
- #endif
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- allocator_type get_allocator() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const allocator_type &get_stored_allocator() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- allocator_type &get_stored_allocator() BOOST_NOEXCEPT
- {
- return static_cast<allocator_type&>(m_);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- iterator begin() BOOST_NOEXCEPT
- {
- return m_.buffer + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator begin() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- iterator end() BOOST_NOEXCEPT
- {
- return m_.buffer + m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator end() const BOOST_NOEXCEPT
- {
- return m_.buffer + m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reverse_iterator rbegin() BOOST_NOEXCEPT
- {
- return reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator rbegin() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reverse_iterator rend() BOOST_NOEXCEPT
- {
- return reverse_iterator(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator rend() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- 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 inline
- const_reverse_iterator crbegin() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.back_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator crend() const BOOST_NOEXCEPT
- {
- return const_reverse_iterator(m_.buffer + m_.front_idx);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- bool empty() const BOOST_NOEXCEPT
- {
- return m_.front_idx == m_.back_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type size() const BOOST_NOEXCEPT
- {
- return size_type(m_.back_idx - m_.front_idx);
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- 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 inline
- size_type capacity() const BOOST_NOEXCEPT
- {
- size_type const cap_reserve = m_.capacity/devector_min_free_fraction;
- return m_.capacity > cap_reserve ? (m_.capacity - cap_reserve) : 0u;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type front_free_capacity() const BOOST_NOEXCEPT
- {
- return m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type back_free_capacity() const BOOST_NOEXCEPT
- {
- return size_type(m_.capacity - m_.back_idx);
- }
-
- inline void resize(size_type sz)
- {
- this->resize_back(sz);
- }
-
- inline void resize(size_type sz, default_init_t)
- {
- this->resize_back(sz, default_init);
- }
-
- inline void resize(size_type sz, const T& c)
- {
- this->resize_back(sz, c);
- }
-
- inline void resize_front(size_type sz)
- {
- resize_front_impl(sz);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void resize_front(size_type sz, default_init_t)
- {
- resize_front_impl(sz, default_init);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void resize_front(size_type sz, const T& c)
- {
- resize_front_impl(sz, c);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void resize_back(size_type sz)
- {
- resize_back_impl(sz);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void resize_back(size_type sz, default_init_t)
- {
- resize_back_impl(sz, default_init);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void resize_back(size_type sz, const T& c)
- {
- resize_back_impl(sz, c);
- BOOST_ASSERT(invariants_ok());
- }
-
- inline void reserve(size_type new_capacity)
- {
- if (this->capacity() < new_capacity) {
- const size_type rounder = devector_min_free_fraction - 2u;
- const size_type divisor = devector_min_free_fraction - 1u;
- size_type const nc = ((new_capacity + rounder)/divisor)*devector_min_free_fraction;
- BOOST_ASSERT(new_capacity <= (nc - nc / devector_min_free_fraction));
- size_type const sz = this->size();
- reallocate_at(nc, (nc-sz)/2u);
- }
- BOOST_ASSERT(invariants_ok());
- }
-
- inline 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());
- }
-
- inline 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());
- }
-
- inline void shrink_to_fit()
- {
- if(this->front_capacity() || this->back_capacity())
- this->reallocate_at(size(), 0);
- }
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference operator[](size_type n) BOOST_NOEXCEPT
- {
- BOOST_ASSERT(n < size());
- return m_.buffer[m_.front_idx + n];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference operator[](size_type n) const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(n < size());
- return m_.buffer[m_.front_idx + n];
- }
-
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(n <= size());
- return iterator(m_.buffer + (m_.front_idx + n));
- }
-
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(n <= size());
- return const_iterator(m_.buffer + (m_.front_idx + n));
- }
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(p >= begin());
- BOOST_ASSERT(p <= end());
- return static_cast<size_type>(p - this->begin());
- }
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(p >= cbegin());
- BOOST_ASSERT(p <= cend());
- return static_cast<size_type>(p - this->cbegin());
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference at(size_type n)
- {
- if (size() <= n)
- throw_out_of_range("devector::at out of range");
- return (*this)[n];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- 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 inline
- reference front() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return m_.buffer[m_.front_idx];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference front() const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return m_.buffer[m_.front_idx];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference back() BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return m_.buffer[m_.back_idx - 1u];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference back() const BOOST_NOEXCEPT
- {
- BOOST_ASSERT(!empty());
- return m_.buffer[m_.back_idx - 1u];
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- T* data() BOOST_NOEXCEPT
- {
- return boost::movelib::to_raw_pointer(m_.buffer) + m_.front_idx;
- }
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- 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>
- reference emplace_front(Args&&... args)
- {
- if (BOOST_LIKELY(front_free_capacity() != 0))
- {
- pointer const p = m_.buffer + (m_.front_idx - 1u);
- this->alloc_construct(p, boost::forward<Args>(args)...);
- --m_.front_idx;
- BOOST_ASSERT(invariants_ok());
- return *p;
- }
- else
- {
- typedef dtl::insert_emplace_proxy<allocator_type, Args...> proxy_t;
- return *this->insert_range_slow_path(this->begin(), 1, proxy_t(::boost::forward<Args>(args)...));
- }
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_EMPLACE_FRONT(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- inline reference emplace_front(BOOST_MOVE_UREF##N)\
- {\
- if (front_free_capacity())\
- {\
- pointer const p = m_.buffer + (m_.front_idx - 1u);\
- this->alloc_construct(p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- --m_.front_idx;\
- return *p;\
- }\
- else\
- {\
- typedef dtl::insert_emplace_proxy_arg##N<allocator_type BOOST_MOVE_I##N BOOST_MOVE_TARG##N> proxy_t;\
- return *this->insert_range_slow_path(this->begin(), 1, proxy_t(BOOST_MOVE_FWD##N));\
- }\
- }\
-
- 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(), boost::movelib::to_raw_pointer(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>
- inline reference emplace_back(Args&&... args)
- {
- if (BOOST_LIKELY(this->back_free_capacity() != 0)){
- pointer const p = m_.buffer + m_.back_idx;
- this->alloc_construct(p, boost::forward<Args>(args)...);
- ++m_.back_idx;
- BOOST_ASSERT(invariants_ok());
- return *p;
- }
- else {
- typedef dtl::insert_emplace_proxy<allocator_type, Args...> proxy_t;
- return *this->insert_range_slow_path(this->end(), 1, proxy_t(::boost::forward<Args>(args)...));
- }
- }
- #else
- #define BOOST_CONTAINER_DEVECTOR_EMPLACE_BACK(N) \
- BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
- inline reference emplace_back(BOOST_MOVE_UREF##N)\
- {\
- if (this->back_free_capacity()){\
- pointer const p = m_.buffer + m_.back_idx;\
- this->alloc_construct(p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ++m_.back_idx;\
- return *p;\
- }\
- else {\
- typedef dtl::insert_emplace_proxy_arg##N<allocator_type BOOST_MOVE_I##N BOOST_MOVE_TARG##N> proxy_t;\
- return *this->insert_range_slow_path(this->end(), 1, proxy_t(BOOST_MOVE_FWD##N));\
- }\
- }\
-
- 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(), boost::movelib::to_raw_pointer(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());
- typedef dtl::insert_emplace_proxy<allocator_type, Args...> proxy_t;
- bool prefer_move_back;
- if (position == end()){
- if(back_free_capacity())
- {
- pointer const p = m_.buffer + m_.back_idx;
- this->alloc_construct(p, boost::forward<Args>(args)...);
- ++m_.back_idx;
- return iterator(p);
- }
- prefer_move_back = true;
- }
- else if (position == begin()){
- if(front_free_capacity())
- {
- pointer const p = m_.buffer + (m_.front_idx - 1);
- this->alloc_construct(p, boost::forward<Args>(args)...);
- --m_.front_idx;
- return iterator(p);
- }
- prefer_move_back = false;
- }
- else{
- iterator nonconst_pos = unconst_iterator(position);
- prefer_move_back = should_move_back(position);
- if(prefer_move_back){
- if(back_free_capacity()){
- boost::container::expand_forward_and_insert_nonempty_middle_alloc
- ( get_allocator_ref()
- , boost::movelib::to_raw_pointer(nonconst_pos)
- , this->priv_raw_end()
- , 1, proxy_t(::boost::forward<Args>(args)...));
- ++m_.back_idx;
- return nonconst_pos;
- }
- }
- else{
- if (front_free_capacity()){
- boost::container::expand_backward_and_insert_nonempty_middle_alloc
- (get_allocator_ref()
- , this->priv_raw_begin()
- , boost::movelib::to_raw_pointer(nonconst_pos)
- , 1, proxy_t(::boost::forward<Args>(args)...));
- --m_.front_idx;
- return --nonconst_pos;
- }
- }
- }
- return this->insert_range_slow_path(position, 1, proxy_t(::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());\
- typedef dtl::insert_emplace_proxy_arg##N<allocator_type BOOST_MOVE_I##N BOOST_MOVE_TARG##N> proxy_t;\
- bool prefer_move_back;\
- if (position == end()){\
- if(back_free_capacity())\
- {\
- pointer const p = m_.buffer + m_.back_idx;\
- this->alloc_construct(p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- ++m_.back_idx;\
- return iterator(p);\
- }\
- prefer_move_back = true;\
- }\
- else if (position == begin()){\
- if(front_free_capacity())\
- {\
- pointer const p = m_.buffer + (m_.front_idx - 1);\
- this->alloc_construct(p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
- --m_.front_idx;\
- return iterator(p);\
- }\
- prefer_move_back = false;\
- }\
- else{\
- iterator nonconst_pos = unconst_iterator(position);\
- prefer_move_back = should_move_back(position);\
- \
- if(prefer_move_back){\
- if(back_free_capacity()){\
- boost::container::expand_forward_and_insert_nonempty_middle_alloc\
- ( get_allocator_ref()\
- , boost::movelib::to_raw_pointer(nonconst_pos)\
- , this->priv_raw_end()\
- , 1, proxy_t(BOOST_MOVE_FWD##N));\
- ++m_.back_idx;\
- return nonconst_pos;\
- }\
- }\
- else{\
- if (front_free_capacity()){\
- boost::container::expand_backward_and_insert_nonempty_middle_alloc\
- (get_allocator_ref()\
- , this->priv_raw_begin()\
- , boost::movelib::to_raw_pointer(nonconst_pos)\
- , 1, proxy_t(BOOST_MOVE_FWD##N));\
- --m_.front_idx;\
- return --nonconst_pos;\
- }\
- }\
- }\
- return this->insert_range_slow_path(position, 1, proxy_t(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
-
- inline iterator insert(const_iterator position, size_type n, const T& x)
- {
- cvalue_iterator first(x, n);
- cvalue_iterator last = first + n;
- return this->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>
- inline 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)
-
- inline iterator insert(const_iterator position, std::initializer_list<T> il)
- {
- return this->insert(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 = unconst_iterator(first);
- iterator nc_last = unconst_iterator(last);
- return erase(nc_first, nc_last);
- }
-
- iterator erase(iterator first, iterator last)
- {
- size_type front_distance = pos_to_index(last);
- size_type back_distance = size_type(end() - first);
- size_type n = boost::container::iterator_udistance(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(), boost::movelib::to_raw_pointer(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(), boost::movelib::to_raw_pointer(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 inline
- 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 inline
- friend bool operator!=(const devector& x, const devector& y)
- { return !(x == y); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- 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 inline
- friend bool operator>(const devector& x, const devector& y)
- { return y < x; }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- friend bool operator<=(const devector& x, const devector& y)
- { return !(y < x); }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- friend bool operator>=(const devector& x, const devector& y)
- { return !(x < y); }
- inline 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:
- void priv_move_assign(BOOST_RV_REF(devector) x, dtl::bool_<true> )
- {
- this->clear();
- this->deallocate_buffer();
-
- dtl::bool_<allocator_traits_type::
- propagate_on_container_move_assignment::value> flag;
- dtl::move_alloc(this->get_allocator_ref(), x.get_allocator_ref(), flag);
- 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;
- }
- void priv_move_assign(BOOST_RV_REF(devector) x, dtl::bool_<false> )
- {
-
-
- if (get_allocator_ref() == x.get_allocator_ref()) {
- this->priv_move_assign(boost::move(x), dtl::true_());
- }
- else {
-
- move_iterator<iterator> xbegin = boost::make_move_iterator(x.begin());
- move_iterator<iterator> xend = boost::make_move_iterator(x.end());
-
- dtl::bool_<allocator_traits_type::
- propagate_on_container_move_assignment::value> flag;
- dtl::move_alloc(this->get_allocator_ref(), x.get_allocator_ref(), flag);
- if (m_.capacity >= x.size()) {
- overwrite_buffer(xbegin, xend);
- }
- else {
- allocate_and_copy_range(xbegin, xend);
- }
- }
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type pos_to_index(const_iterator i) const
- {
- return static_cast<size_type>(i - cbegin());
- }
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- bool should_move_back(const_iterator i) const
- {
- return static_cast<size_type>(this->pos_to_index(i)) >= this->size()/2u;
- }
- inline static iterator unconst_iterator(const_iterator i)
- {
- return boost::intrusive::pointer_traits<pointer>::const_cast_from(i);
- }
- inline size_type front_capacity() const
- {
- return m_.back_idx;
- }
- inline size_type back_capacity() const
- {
- return size_type(m_.capacity - m_.front_idx);
- }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- inline T* priv_raw_begin() BOOST_NOEXCEPT
- { return boost::movelib::to_raw_pointer(m_.buffer) + m_.front_idx; }
- inline T* priv_raw_end() BOOST_NOEXCEPT
- { return boost::movelib::to_raw_pointer(m_.buffer) + m_.back_idx; }
- template <class U>
- inline void priv_push_front(BOOST_FWD_REF(U) u)
- {
- this->emplace_front(boost::forward<U>(u));
- }
- template <class U>
- inline void priv_push_back(BOOST_FWD_REF(U) u)
- {
- this->emplace_back(boost::forward<U>(u));
- }
- template <class U>
- inline iterator priv_insert(const_iterator pos, BOOST_FWD_REF(U) u)
- {
- return this->emplace(pos, boost::forward<U>(u));
- }
-
- inline allocator_type& get_allocator_ref() BOOST_NOEXCEPT
- {
- return static_cast<allocator_type&>(m_);
- }
- inline const allocator_type& get_allocator_ref() const BOOST_NOEXCEPT
- {
- return static_cast<const allocator_type&>(m_);
- }
- pointer allocate(size_type capacity)
- {
- pointer const p = impl::do_allocate(get_allocator_ref(), capacity);
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- ++m_.capacity_alloc_count;
- #endif
- return p;
- }
- void destroy_elements(pointer begin, pointer end)
- {
- for (; begin != end; ++begin)
- {
- allocator_traits_type::destroy(get_allocator_ref(), boost::movelib::to_raw_pointer(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>
- inline void alloc_construct(pointer dst, Args&&... args)
- {
- allocator_traits_type::construct(
- get_allocator_ref(),
- boost::movelib::to_raw_pointer(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 \
- inline void alloc_construct(pointer dst BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
- {\
- allocator_traits_type::construct(\
- get_allocator_ref(), boost::movelib::to_raw_pointer(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
- 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();
- }
- 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();
- }
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <typename... Args>
- void resize_impl(size_type sz, Args&&... args)
- {
- const size_type old_sz = this->size();
- if (sz > old_sz)
- {
- const size_type n = sz - old_sz;
- if (sz <= m_.capacity)
- {
-
- const size_type bfc = this->back_free_capacity();
- const size_type b = n < bfc ? n : bfc;
- construct_n(m_.buffer + m_.back_idx, b, boost::forward<Args>(args)...);
- m_.set_back_idx(m_.back_idx + b);
-
- const size_type f = n - b;
- construct_n(m_.buffer + m_.front_idx - f, f, boost::forward<Args>(args)...);
- m_.set_front_idx(m_.front_idx - f);
- }
- else
- {
- resize_back_slow_path(sz, n, boost::forward<Args>(args)...);
- }
- }
- else
- {
- const size_type n = old_sz - sz;
- const size_type new_bidx = m_.back_idx - n;
- destroy_elements(m_.buffer + new_bidx, m_.buffer + m_.back_idx);
- m_.set_back_idx(new_bidx);
- }
- }
- template <typename... Args>
- void resize_front_impl(size_type sz , Args&&... args)
- {
- const size_type old_sz = this->size();
- if (sz > old_sz)
- {
- const size_type n = sz - old_sz;
- if (sz <= this->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 {
- const size_type n = old_sz - sz;
- const size_type new_fidx = m_.front_idx + n;
- destroy_elements(m_.buffer + m_.front_idx, m_.buffer + new_fidx);
- m_.set_front_idx(new_fidx);
- }
- }
- 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 old_sz = this->size();
- const size_type new_old_elem_index = new_capacity - old_sz;
- 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_front_idx(new_elem_index);
- m_.set_back_idx(new_elem_index + old_sz + n);
- }
- template <typename... Args>
- void resize_back_impl(size_type sz, Args&&... args)
- {
- const size_type old_sz = this->size();
- if (sz > old_sz)
- {
- const size_type n = sz - old_sz;
- if (sz <= this->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
- {
- const size_type n = old_sz - sz;
- const size_type new_bidx = m_.back_idx - n;
- destroy_elements(m_.buffer + new_bidx, m_.buffer + m_.back_idx);
- m_.set_back_idx(new_bidx);
- }
- }
- 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);
- }
- #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_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());
- boost::container::uninitialized_move_alloc(get_allocator_ref(), this->begin(), this->end(), new_buffer + buffer_offset);
- new_buffer_guard.release();
- }
- destroy_elements(m_.buffer + m_.front_idx, m_.buffer + m_.back_idx);
- deallocate_buffer();
- m_.buffer = new_buffer;
-
- m_.set_capacity(new_capacity);
- m_.set_back_idx(size_type(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)
- {
- BOOST_ASSERT(position >= begin());
- BOOST_ASSERT(position <= end());
- typedef dtl::insert_range_proxy<allocator_type, ForwardIterator> proxy_t;
- size_type const n = boost::container::iterator_udistance(first, last);
- bool prefer_move_back;
- if (BOOST_UNLIKELY(!n)) {
- return begin() + size_type(position - cbegin());
- }
- else if (position == end()) {
- if(back_free_capacity() >= n)
- {
- iterator r(this->end());
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), first, last, this->priv_raw_end());
- m_.set_back_idx(m_.back_idx + n);
- return r;
- }
- prefer_move_back = true;
- }
- else if (position == begin()) {
- if(front_free_capacity() >= n) {
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), first, last, this->priv_raw_begin() - n);
- m_.set_front_idx(m_.front_idx - n);
- return begin();
- }
- prefer_move_back = false;
- }
- else{
- iterator nonconst_pos = unconst_iterator(position);
- prefer_move_back = should_move_back(position);
- if(prefer_move_back){
- if(back_free_capacity() >= n){
- boost::container::expand_forward_and_insert_nonempty_middle_alloc
- ( get_allocator_ref()
- , boost::movelib::to_raw_pointer(nonconst_pos)
- , this->priv_raw_end()
- , n, proxy_t(first));
- m_.set_back_idx(m_.back_idx + n);
- return nonconst_pos;
- }
- }
- else{
- if (front_free_capacity() >= n){
- boost::container::expand_backward_and_insert_nonempty_middle_alloc
- ( get_allocator_ref()
- , this->priv_raw_begin()
- , boost::movelib::to_raw_pointer(nonconst_pos)
- , n, proxy_t(first));
- m_.set_front_idx(m_.front_idx - n);
- return (nonconst_pos -= n);
- }
- }
- }
- return this->insert_range_slow_path(position, n, proxy_t(first));
- }
- template <class InsertionProxy>
- BOOST_CONTAINER_NOINLINE iterator insert_range_slow_path
- (const_iterator p, const size_type n, const InsertionProxy proxy)
- {
- size_type const back_free_cap = back_free_capacity();
- size_type const front_free_cap = front_free_capacity();
- size_type const free_cap = front_free_cap + back_free_cap;
- size_type const index = size_type(p - cbegin());
- size_type const cap = m_.capacity;
-
- if (free_cap >= n && (free_cap - n) >= cap/devector_min_free_fraction) {
- size_type const old_size = this->size();
- T* const raw_pos = const_cast<T*>(boost::movelib::to_raw_pointer(p));
- size_type const new_size = old_size + n;
- size_type const new_front_idx = (cap - new_size) / 2u;
- T* const raw_beg = this->priv_raw_begin();
- T* const new_raw_beg = raw_beg - std::ptrdiff_t(m_.front_idx - new_front_idx);
- m_.back_idx = 0u;
- m_.front_idx = 0u;
- boost::container::expand_backward_forward_and_insert_alloc
- (raw_beg, old_size, new_raw_beg, raw_pos, n, proxy, get_allocator_ref());
- m_.set_front_idx(new_front_idx);
- m_.set_back_idx(new_front_idx + new_size);
- }
- else {
-
- const size_type new_capacity = calculate_new_capacity(m_.capacity + n);
- pointer new_buffer = allocate(new_capacity);
-
- allocation_guard new_buffer_guard(new_buffer, new_capacity, get_allocator_ref());
- size_type const old_size = this->size();
- const size_type new_front_index = (new_capacity - old_size - n) / 2u;
- T* const raw_pos = const_cast<T*>(boost::movelib::to_raw_pointer(p));
- T* const raw_new_start = const_cast<T*>(boost::movelib::to_raw_pointer(new_buffer)) + new_front_index;
- boost::container::uninitialized_move_and_insert_alloc
- (get_allocator_ref(), this->priv_raw_begin(), raw_pos, this->priv_raw_end(), raw_new_start, n, proxy);
- new_buffer_guard.release();
-
- destroy_elements(begin(), end());
- deallocate_buffer();
-
- m_.set_capacity(new_capacity);
- m_.buffer = new_buffer;
- m_.set_back_idx(new_front_index + old_size + n);
- m_.set_front_idx(new_front_index);
- }
- return begin() + index;
- }
- template <typename Iterator>
- void construct_from_range(Iterator begin, Iterator end)
- {
- allocation_guard buffer_guard(m_.buffer, m_.capacity, get_allocator_ref());
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), 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_udistance(first, last);
- pointer new_buffer = n ? allocate(n) : pointer();
- allocation_guard new_buffer_guard(new_buffer, n, get_allocator_ref());
- boost::container::uninitialized_copy_alloc(get_allocator_ref(), 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_udistance(first, last);
- BOOST_ASSERT(m_.capacity >= n);
- boost::container::uninitialized_copy_alloc_n
- ( get_allocator_ref(), first
- , n, boost::movelib::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 + m_.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_to_index(pos));
- return first;
- }
- template <typename ForwardIterator>
- inline 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
- {
- BOOST_MOVABLE_BUT_NOT_COPYABLE(impl)
- public:
- allocator_type &get_al()
- { return *this; }
- static pointer do_allocate(allocator_type &a, size_type cap)
- {
- if (cap) {
-
- if (cap > stored_size_type(-1)){
- boost::container::throw_length_error("get_next_capacity, allocator's max size reached");
- }
- return allocator_traits_type::allocate(a, cap);
- }
- else {
- return pointer();
- }
- }
- impl()
- : allocator_type(), buffer(), front_idx(), back_idx(), capacity()
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(0)
- #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(0)
- #endif
- {}
- impl(reserve_uninitialized_t, const allocator_type& a, size_type c)
- : allocator_type(a), buffer(do_allocate(get_al(), c) )
-
- , front_idx(static_cast<stored_size_type>(0u))
- , back_idx(static_cast<stored_size_type>(c))
- , capacity(static_cast<stored_size_type>(c))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(size_type(buffer != pointer()))
- #endif
- {}
- impl(reserve_only_tag_t, const allocator_type &a, size_type const ffc, size_type const bfc)
- : allocator_type(a), buffer(do_allocate(get_al(), ffc+bfc) )
-
- , front_idx(static_cast<stored_size_type>(ffc))
- , back_idx(static_cast<stored_size_type>(ffc))
- , capacity(static_cast<stored_size_type>(ffc + bfc))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(size_type(buffer != pointer()))
- #endif
- {}
- impl(reserve_only_tag_t, const allocator_type &a, size_type const c)
- : allocator_type(a), buffer(do_allocate(get_al(), c) )
-
- , front_idx(static_cast<stored_size_type>(c/2u))
- , back_idx(static_cast<stored_size_type>(c/2u))
- , capacity(static_cast<stored_size_type>(c))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(size_type(buffer != pointer()))
- #endif
- {}
- impl(review_implementation_t, const allocator_type &a, pointer p, size_type fi, size_type bi, size_type c)
- : allocator_type(a), buffer(p)
-
- , front_idx(static_cast<stored_size_type>(fi))
- , back_idx(static_cast<stored_size_type>(bi))
- , capacity(static_cast<stored_size_type>(c))
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(0)
- #endif
- {}
- impl(BOOST_RV_REF(impl) m)
- : allocator_type(BOOST_MOVE_BASE(allocator_type, m))
- , buffer(static_cast<impl&>(m).buffer)
- , front_idx(static_cast<impl&>(m).front_idx)
- , back_idx(static_cast<impl&>(m).back_idx)
- , capacity(static_cast<impl&>(m).capacity)
- #ifdef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
- , capacity_alloc_count(0)
- #endif
- {
- impl &i = static_cast<impl&>(m);
-
- i.capacity = 0u;
- i.buffer = pointer();
- i.front_idx = 0;
- i.back_idx = 0;
- }
- inline void set_back_idx(size_type bi)
- {
- back_idx = static_cast<stored_size_type>(bi);
- }
- inline void set_front_idx(size_type fi)
- {
- front_idx = static_cast<stored_size_type>(fi);
- }
- inline 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
- };
- }}
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- namespace boost {
- template <class T, class Allocator, class Options>
- struct has_trivial_destructor_after_move<boost::container::devector<T, Allocator, Options> >
- {
- typedef typename boost::container::devector<T, Allocator, Options>::allocator_type allocator_type;
- typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
- BOOST_STATIC_CONSTEXPR bool value =
- ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
- ::boost::has_trivial_destructor_after_move<pointer>::value;
- };
- }
- #endif
- #include <boost/container/detail/config_end.hpp>
- #endif
|