12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317 |
- // -*- C++ -*-
- //===------------------------------ vector --------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP_VECTOR
- #define _LIBCPP_VECTOR
- /*
- vector synopsis
- namespace std
- {
- template <class T, class Allocator = allocator<T> >
- class vector
- {
- public:
- typedef T value_type;
- typedef Allocator allocator_type;
- typedef typename allocator_type::reference reference;
- typedef typename allocator_type::const_reference const_reference;
- typedef implementation-defined iterator;
- typedef implementation-defined const_iterator;
- typedef typename allocator_type::size_type size_type;
- typedef typename allocator_type::difference_type difference_type;
- typedef typename allocator_type::pointer pointer;
- typedef typename allocator_type::const_pointer const_pointer;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- vector()
- noexcept(is_nothrow_default_constructible<allocator_type>::value);
- explicit vector(const allocator_type&);
- explicit vector(size_type n);
- explicit vector(size_type n, const allocator_type&); // C++14
- vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
- template <class InputIterator>
- vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
- vector(const vector& x);
- vector(vector&& x)
- noexcept(is_nothrow_move_constructible<allocator_type>::value);
- vector(initializer_list<value_type> il);
- vector(initializer_list<value_type> il, const allocator_type& a);
- ~vector();
- vector& operator=(const vector& x);
- vector& operator=(vector&& x)
- noexcept(
- allocator_type::propagate_on_container_move_assignment::value ||
- allocator_type::is_always_equal::value); // C++17
- vector& operator=(initializer_list<value_type> il);
- template <class InputIterator>
- void assign(InputIterator first, InputIterator last);
- void assign(size_type n, const value_type& u);
- void assign(initializer_list<value_type> il);
- allocator_type get_allocator() const noexcept;
- iterator begin() noexcept;
- const_iterator begin() const noexcept;
- iterator end() noexcept;
- const_iterator end() const noexcept;
- reverse_iterator rbegin() noexcept;
- const_reverse_iterator rbegin() const noexcept;
- reverse_iterator rend() noexcept;
- const_reverse_iterator rend() const noexcept;
- const_iterator cbegin() const noexcept;
- const_iterator cend() const noexcept;
- const_reverse_iterator crbegin() const noexcept;
- const_reverse_iterator crend() const noexcept;
- size_type size() const noexcept;
- size_type max_size() const noexcept;
- size_type capacity() const noexcept;
- bool empty() const noexcept;
- void reserve(size_type n);
- void shrink_to_fit() noexcept;
- reference operator[](size_type n);
- const_reference operator[](size_type n) const;
- reference at(size_type n);
- const_reference at(size_type n) const;
- reference front();
- const_reference front() const;
- reference back();
- const_reference back() const;
- value_type* data() noexcept;
- const value_type* data() const noexcept;
- void push_back(const value_type& x);
- void push_back(value_type&& x);
- template <class... Args>
- void emplace_back(Args&&... args);
- void pop_back();
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
- iterator insert(const_iterator position, const value_type& x);
- iterator insert(const_iterator position, value_type&& x);
- iterator insert(const_iterator position, size_type n, const value_type& x);
- template <class InputIterator>
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
- iterator insert(const_iterator position, initializer_list<value_type> il);
- iterator erase(const_iterator position);
- iterator erase(const_iterator first, const_iterator last);
- void clear() noexcept;
- void resize(size_type sz);
- void resize(size_type sz, const value_type& c);
- void swap(vector&)
- noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
- allocator_traits<allocator_type>::is_always_equal::value); // C++17
- bool __invariants() const;
- };
- template <class Allocator = allocator<T> >
- class vector<bool, Allocator>
- {
- public:
- typedef bool value_type;
- typedef Allocator allocator_type;
- typedef implementation-defined iterator;
- typedef implementation-defined const_iterator;
- typedef typename allocator_type::size_type size_type;
- typedef typename allocator_type::difference_type difference_type;
- typedef iterator pointer;
- typedef const_iterator const_pointer;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- class reference
- {
- public:
- reference(const reference&) noexcept;
- operator bool() const noexcept;
- reference& operator=(const bool x) noexcept;
- reference& operator=(const reference& x) noexcept;
- iterator operator&() const noexcept;
- void flip() noexcept;
- };
- class const_reference
- {
- public:
- const_reference(const reference&) noexcept;
- operator bool() const noexcept;
- const_iterator operator&() const noexcept;
- };
- vector()
- noexcept(is_nothrow_default_constructible<allocator_type>::value);
- explicit vector(const allocator_type&);
- explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
- vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
- template <class InputIterator>
- vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
- vector(const vector& x);
- vector(vector&& x)
- noexcept(is_nothrow_move_constructible<allocator_type>::value);
- vector(initializer_list<value_type> il);
- vector(initializer_list<value_type> il, const allocator_type& a);
- ~vector();
- vector& operator=(const vector& x);
- vector& operator=(vector&& x)
- noexcept(
- allocator_type::propagate_on_container_move_assignment::value ||
- allocator_type::is_always_equal::value); // C++17
- vector& operator=(initializer_list<value_type> il);
- template <class InputIterator>
- void assign(InputIterator first, InputIterator last);
- void assign(size_type n, const value_type& u);
- void assign(initializer_list<value_type> il);
- allocator_type get_allocator() const noexcept;
- iterator begin() noexcept;
- const_iterator begin() const noexcept;
- iterator end() noexcept;
- const_iterator end() const noexcept;
- reverse_iterator rbegin() noexcept;
- const_reverse_iterator rbegin() const noexcept;
- reverse_iterator rend() noexcept;
- const_reverse_iterator rend() const noexcept;
- const_iterator cbegin() const noexcept;
- const_iterator cend() const noexcept;
- const_reverse_iterator crbegin() const noexcept;
- const_reverse_iterator crend() const noexcept;
- size_type size() const noexcept;
- size_type max_size() const noexcept;
- size_type capacity() const noexcept;
- bool empty() const noexcept;
- void reserve(size_type n);
- void shrink_to_fit() noexcept;
- reference operator[](size_type n);
- const_reference operator[](size_type n) const;
- reference at(size_type n);
- const_reference at(size_type n) const;
- reference front();
- const_reference front() const;
- reference back();
- const_reference back() const;
- void push_back(const value_type& x);
- template <class... Args> void emplace_back(Args&&... args); // C++14
- void pop_back();
- template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
- iterator insert(const_iterator position, const value_type& x);
- iterator insert(const_iterator position, size_type n, const value_type& x);
- template <class InputIterator>
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
- iterator insert(const_iterator position, initializer_list<value_type> il);
- iterator erase(const_iterator position);
- iterator erase(const_iterator first, const_iterator last);
- void clear() noexcept;
- void resize(size_type sz);
- void resize(size_type sz, value_type x);
- void swap(vector&)
- noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
- allocator_traits<allocator_type>::is_always_equal::value); // C++17
- void flip() noexcept;
- bool __invariants() const;
- };
- template <class Allocator> struct hash<std::vector<bool, Allocator>>;
- template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
- template <class T, class Allocator>
- void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
- noexcept(noexcept(x.swap(y)));
- } // std
- */
- #include <__config>
- #include <iosfwd> // for forward declaration of vector
- #include <__bit_reference>
- #include <type_traits>
- #include <climits>
- #include <limits>
- #include <initializer_list>
- #include <memory>
- #include <stdexcept>
- #include <algorithm>
- #include <cstring>
- #include <__split_buffer>
- #include <__functional_base>
- #include <__undef_min_max>
- #include <__debug>
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- #pragma GCC system_header
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- template <bool>
- class __vector_base_common
- {
- protected:
- _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
- void __throw_length_error() const;
- void __throw_out_of_range() const;
- };
- template <bool __b>
- void
- __vector_base_common<__b>::__throw_length_error() const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- throw length_error("vector");
- #else
- assert(!"vector length_error");
- #endif
- }
- template <bool __b>
- void
- __vector_base_common<__b>::__throw_out_of_range() const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- throw out_of_range("vector");
- #else
- assert(!"vector out_of_range");
- #endif
- }
- #ifdef _LIBCPP_MSVC
- #pragma warning( push )
- #pragma warning( disable: 4231 )
- #endif // _LIBCPP_MSVC
- _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
- #ifdef _LIBCPP_MSVC
- #pragma warning( pop )
- #endif // _LIBCPP_MSVC
- template <class _Tp, class _Allocator>
- class __vector_base
- : protected __vector_base_common<true>
- {
- protected:
- typedef _Tp value_type;
- typedef _Allocator allocator_type;
- typedef allocator_traits<allocator_type> __alloc_traits;
- typedef value_type& reference;
- typedef const value_type& const_reference;
- typedef typename __alloc_traits::size_type size_type;
- typedef typename __alloc_traits::difference_type difference_type;
- typedef typename __alloc_traits::pointer pointer;
- typedef typename __alloc_traits::const_pointer const_pointer;
- typedef pointer iterator;
- typedef const_pointer const_iterator;
- pointer __begin_;
- pointer __end_;
- __compressed_pair<pointer, allocator_type> __end_cap_;
- _LIBCPP_INLINE_VISIBILITY
- allocator_type& __alloc() _NOEXCEPT
- {return __end_cap_.second();}
- _LIBCPP_INLINE_VISIBILITY
- const allocator_type& __alloc() const _NOEXCEPT
- {return __end_cap_.second();}
- _LIBCPP_INLINE_VISIBILITY
- pointer& __end_cap() _NOEXCEPT
- {return __end_cap_.first();}
- _LIBCPP_INLINE_VISIBILITY
- const pointer& __end_cap() const _NOEXCEPT
- {return __end_cap_.first();}
- _LIBCPP_INLINE_VISIBILITY
- __vector_base()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
- _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
- ~__vector_base();
- _LIBCPP_INLINE_VISIBILITY
- void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
- _LIBCPP_INLINE_VISIBILITY
- size_type capacity() const _NOEXCEPT
- {return static_cast<size_type>(__end_cap() - __begin_);}
- _LIBCPP_INLINE_VISIBILITY
- void __destruct_at_end(pointer __new_last) _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base& __c)
- {__copy_assign_alloc(__c, integral_constant<bool,
- __alloc_traits::propagate_on_container_copy_assignment::value>());}
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base& __c)
- _NOEXCEPT_(
- !__alloc_traits::propagate_on_container_move_assignment::value ||
- is_nothrow_move_assignable<allocator_type>::value)
- {__move_assign_alloc(__c, integral_constant<bool,
- __alloc_traits::propagate_on_container_move_assignment::value>());}
- private:
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base& __c, true_type)
- {
- if (__alloc() != __c.__alloc())
- {
- clear();
- __alloc_traits::deallocate(__alloc(), __begin_, capacity());
- __begin_ = __end_ = __end_cap() = nullptr;
- }
- __alloc() = __c.__alloc();
- }
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __vector_base&, false_type)
- {}
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- __alloc() = _VSTD::move(__c.__alloc());
- }
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__vector_base&, false_type)
- _NOEXCEPT
- {}
- };
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
- {
- while (__new_last != __end_)
- __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- __vector_base<_Tp, _Allocator>::__vector_base()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr)
- {
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
- : __begin_(nullptr),
- __end_(nullptr),
- __end_cap_(nullptr, __a)
- {
- }
- template <class _Tp, class _Allocator>
- __vector_base<_Tp, _Allocator>::~__vector_base()
- {
- if (__begin_ != nullptr)
- {
- clear();
- __alloc_traits::deallocate(__alloc(), __begin_, capacity());
- }
- }
- template <class _Tp, class _Allocator /* = allocator<_Tp> */>
- class _LIBCPP_TYPE_VIS_ONLY vector
- : private __vector_base<_Tp, _Allocator>
- {
- private:
- typedef __vector_base<_Tp, _Allocator> __base;
- typedef allocator<_Tp> __default_allocator_type;
- public:
- typedef vector __self;
- typedef _Tp value_type;
- typedef _Allocator allocator_type;
- typedef typename __base::__alloc_traits __alloc_traits;
- typedef typename __base::reference reference;
- typedef typename __base::const_reference const_reference;
- typedef typename __base::size_type size_type;
- typedef typename __base::difference_type difference_type;
- typedef typename __base::pointer pointer;
- typedef typename __base::const_pointer const_pointer;
- typedef __wrap_iter<pointer> iterator;
- typedef __wrap_iter<const_pointer> const_iterator;
- typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
- typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
- static_assert((is_same<typename allocator_type::value_type, value_type>::value),
- "Allocator::value_type must be same type as value_type");
- _LIBCPP_INLINE_VISIBILITY
- vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
- #else
- _NOEXCEPT
- #endif
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- explicit vector(size_type __n);
- #if _LIBCPP_STD_VER > 11
- explicit vector(size_type __n, const allocator_type& __a);
- #endif
- vector(size_type __n, const_reference __x);
- vector(size_type __n, const_reference __x, const allocator_type& __a);
- template <class _InputIterator>
- vector(_InputIterator __first,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value,
- _InputIterator>::type __last);
- template <class _InputIterator>
- vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
- template <class _ForwardIterator>
- vector(_ForwardIterator __first,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- _ForwardIterator>::type __last);
- template <class _ForwardIterator>
- vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- vector(initializer_list<value_type> __il);
- _LIBCPP_INLINE_VISIBILITY
- vector(initializer_list<value_type> __il, const allocator_type& __a);
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_INLINE_VISIBILITY
- ~vector()
- {
- __get_db()->__erase_c(this);
- }
- #endif
- vector(const vector& __x);
- vector(const vector& __x, const allocator_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(const vector& __x);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- vector(vector&& __x)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
- #endif
- _LIBCPP_INLINE_VISIBILITY
- vector(vector&& __x, const allocator_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(vector&& __x)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end()); return *this;}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value,
- void
- >::type
- assign(_InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- void
- >::type
- assign(_ForwardIterator __first, _ForwardIterator __last);
- void assign(size_type __n, const_reference __u);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- void assign(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- allocator_type get_allocator() const _NOEXCEPT
- {return this->__alloc();}
- _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rbegin() _NOEXCEPT
- {return reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rbegin() const _NOEXCEPT
- {return const_reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rend() _NOEXCEPT
- {return reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rend() const _NOEXCEPT
- {return const_reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cbegin() const _NOEXCEPT
- {return begin();}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cend() const _NOEXCEPT
- {return end();}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crbegin() const _NOEXCEPT
- {return rbegin();}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crend() const _NOEXCEPT
- {return rend();}
- _LIBCPP_INLINE_VISIBILITY
- size_type size() const _NOEXCEPT
- {return static_cast<size_type>(this->__end_ - this->__begin_);}
- _LIBCPP_INLINE_VISIBILITY
- size_type capacity() const _NOEXCEPT
- {return __base::capacity();}
- _LIBCPP_INLINE_VISIBILITY
- bool empty() const _NOEXCEPT
- {return this->__begin_ == this->__end_;}
- size_type max_size() const _NOEXCEPT;
- void reserve(size_type __n);
- void shrink_to_fit() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
- _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
- reference at(size_type __n);
- const_reference at(size_type __n) const;
- _LIBCPP_INLINE_VISIBILITY reference front()
- {
- _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
- return *this->__begin_;
- }
- _LIBCPP_INLINE_VISIBILITY const_reference front() const
- {
- _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
- return *this->__begin_;
- }
- _LIBCPP_INLINE_VISIBILITY reference back()
- {
- _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
- return *(this->__end_ - 1);
- }
- _LIBCPP_INLINE_VISIBILITY const_reference back() const
- {
- _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
- return *(this->__end_ - 1);
- }
- _LIBCPP_INLINE_VISIBILITY
- value_type* data() _NOEXCEPT
- {return _VSTD::__to_raw_pointer(this->__begin_);}
- _LIBCPP_INLINE_VISIBILITY
- const value_type* data() const _NOEXCEPT
- {return _VSTD::__to_raw_pointer(this->__begin_);}
- _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
- #ifndef _LIBCPP_HAS_NO_VARIADICS
- template <class... _Args>
- _LIBCPP_INLINE_VISIBILITY
- void emplace_back(_Args&&... __args);
- #endif // _LIBCPP_HAS_NO_VARIADICS
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- void pop_back();
- iterator insert(const_iterator __position, const_reference __x);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- iterator insert(const_iterator __position, value_type&& __x);
- #ifndef _LIBCPP_HAS_NO_VARIADICS
- template <class... _Args>
- iterator emplace(const_iterator __position, _Args&&... __args);
- #endif // _LIBCPP_HAS_NO_VARIADICS
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- iterator insert(const_iterator __position, size_type __n, const_reference __x);
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value,
- iterator
- >::type
- insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- iterator
- >::type
- insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- iterator insert(const_iterator __position, initializer_list<value_type> __il)
- {return insert(__position, __il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
- iterator erase(const_iterator __first, const_iterator __last);
- _LIBCPP_INLINE_VISIBILITY
- void clear() _NOEXCEPT
- {
- size_type __old_size = size();
- __base::clear();
- __annotate_shrink(__old_size);
- __invalidate_all_iterators();
- }
- void resize(size_type __sz);
- void resize(size_type __sz, const_reference __x);
- void swap(vector&)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value);
- #endif
- bool __invariants() const;
- #if _LIBCPP_DEBUG_LEVEL >= 2
- bool __dereferenceable(const const_iterator* __i) const;
- bool __decrementable(const const_iterator* __i) const;
- bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
- bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- private:
- _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
- void allocate(size_type __n);
- void deallocate() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
- void __construct_at_end(size_type __n);
- _LIBCPP_INLINE_VISIBILITY
- void __construct_at_end(size_type __n, const_reference __x);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
- void __append(size_type __n);
- void __append(size_type __n, const_reference __x);
- _LIBCPP_INLINE_VISIBILITY
- iterator __make_iter(pointer __p) _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
- void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
- pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
- void __move_range(pointer __from_s, pointer __from_e, pointer __to);
- void __move_assign(vector& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
- void __move_assign(vector& __c, false_type)
- _NOEXCEPT_(__alloc_traits::is_always_equal::value);
- _LIBCPP_INLINE_VISIBILITY
- void __destruct_at_end(pointer __new_last) _NOEXCEPT
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __c_node* __c = __get_db()->__find_c_and_lock(this);
- for (__i_node** __p = __c->end_; __p != __c->beg_; )
- {
- --__p;
- const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
- if (__i->base() > __new_last)
- {
- (*__p)->__c_ = nullptr;
- if (--__c->end_ != __p)
- memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
- }
- }
- __get_db()->unlock();
- #endif
- size_type __old_size = size();
- __base::__destruct_at_end(__new_last);
- __annotate_shrink(__old_size);
- }
- template <class _Up>
- void
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- __push_back_slow_path(_Up&& __x);
- #else
- __push_back_slow_path(_Up& __x);
- #endif
- #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
- template <class... _Args>
- void
- __emplace_back_slow_path(_Args&&... __args);
- #endif
- // The following functions are no-ops outside of AddressSanitizer mode.
- // We call annotatations only for the default Allocator because other allocators
- // may not meet the AddressSanitizer alignment constraints.
- // See the documentation for __sanitizer_annotate_contiguous_container for more details.
- void __annotate_contiguous_container
- (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
- {
- #ifndef _LIBCPP_HAS_NO_ASAN
- if (__beg && is_same<allocator_type, __default_allocator_type>::value)
- __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
- #endif
- }
- void __annotate_new(size_type __current_size) const
- {
- __annotate_contiguous_container(data(), data() + capacity(),
- data() + capacity(), data() + __current_size);
- }
- void __annotate_delete() const
- {
- __annotate_contiguous_container(data(), data() + capacity(),
- data() + size(), data() + capacity());
- }
- void __annotate_increase(size_type __n) const
- {
- __annotate_contiguous_container(data(), data() + capacity(),
- data() + size(), data() + size() + __n);
- }
- void __annotate_shrink(size_type __old_size) const
- {
- __annotate_contiguous_container(data(), data() + capacity(),
- data() + __old_size, data() + size());
- }
- #ifndef _LIBCPP_HAS_NO_ASAN
- // The annotation for size increase should happen before the actual increase,
- // but if an exception is thrown after that the annotation has to be undone.
- struct __RAII_IncreaseAnnotator {
- __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
- : __commit(false), __v(__v), __old_size(__v.size() + __n) {
- __v.__annotate_increase(__n);
- }
- void __done() { __commit = true; }
- ~__RAII_IncreaseAnnotator() {
- if (__commit) return;
- __v.__annotate_shrink(__old_size);
- }
- bool __commit;
- const vector &__v;
- size_type __old_size;
- };
- #else
- struct __RAII_IncreaseAnnotator {
- inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
- inline void __done() {}
- };
- #endif
- };
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
- {
- __annotate_delete();
- __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
- _VSTD::swap(this->__begin_, __v.__begin_);
- _VSTD::swap(this->__end_, __v.__end_);
- _VSTD::swap(this->__end_cap(), __v.__end_cap());
- __v.__first_ = __v.__begin_;
- __annotate_new(size());
- __invalidate_all_iterators();
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::pointer
- vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
- {
- __annotate_delete();
- pointer __r = __v.__begin_;
- __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
- __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
- _VSTD::swap(this->__begin_, __v.__begin_);
- _VSTD::swap(this->__end_, __v.__end_);
- _VSTD::swap(this->__end_cap(), __v.__end_cap());
- __v.__first_ = __v.__begin_;
- __annotate_new(size());
- __invalidate_all_iterators();
- return __r;
- }
- // Allocate space for __n objects
- // throws length_error if __n > max_size()
- // throws (probably bad_alloc) if memory run out
- // Precondition: __begin_ == __end_ == __end_cap() == 0
- // Precondition: __n > 0
- // Postcondition: capacity() == __n
- // Postcondition: size() == 0
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::allocate(size_type __n)
- {
- if (__n > max_size())
- this->__throw_length_error();
- this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
- this->__end_cap() = this->__begin_ + __n;
- __annotate_new(0);
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
- {
- if (this->__begin_ != nullptr)
- {
- clear();
- __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
- this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
- }
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::size_type
- vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
- {
- return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
- }
- // Precondition: __new_size > capacity()
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::size_type
- vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
- {
- const size_type __ms = max_size();
- if (__new_size > __ms)
- this->__throw_length_error();
- const size_type __cap = capacity();
- if (__cap >= __ms / 2)
- return __ms;
- return _VSTD::max<size_type>(2*__cap, __new_size);
- }
- // Default constructs __n objects starting at __end_
- // throws if construction throws
- // Precondition: __n > 0
- // Precondition: size() + __n <= capacity()
- // Postcondition: size() == size() + __n
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
- {
- allocator_type& __a = this->__alloc();
- do
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
- ++this->__end_;
- --__n;
- __annotator.__done();
- } while (__n > 0);
- }
- // Copy constructs __n objects starting at __end_ from __x
- // throws if construction throws
- // Precondition: __n > 0
- // Precondition: size() + __n <= capacity()
- // Postcondition: size() == old size() + __n
- // Postcondition: [i] == __x for all i in [size() - __n, __n)
- template <class _Tp, class _Allocator>
- inline
- void
- vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
- {
- allocator_type& __a = this->__alloc();
- do
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
- ++this->__end_;
- --__n;
- __annotator.__done();
- } while (__n > 0);
- }
- template <class _Tp, class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
- {
- allocator_type& __a = this->__alloc();
- __RAII_IncreaseAnnotator __annotator(*this, __n);
- __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
- __annotator.__done();
- }
- // Default constructs __n objects starting at __end_
- // throws if construction throws
- // Postcondition: size() == size() + __n
- // Exception safety: strong.
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__append(size_type __n)
- {
- if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
- this->__construct_at_end(__n);
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
- __v.__construct_at_end(__n);
- __swap_out_circular_buffer(__v);
- }
- }
- // Default constructs __n objects starting at __end_
- // throws if construction throws
- // Postcondition: size() == size() + __n
- // Exception safety: strong.
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
- {
- if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
- this->__construct_at_end(__n, __x);
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
- __v.__construct_at_end(__n, __x);
- __swap_out_circular_buffer(__v);
- }
- }
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(size_type __n)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n);
- }
- }
- #if _LIBCPP_STD_VER > 11
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n);
- }
- }
- #endif
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, __x);
- }
- }
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, __x);
- }
- }
- template <class _Tp, class _Allocator>
- template <class _InputIterator>
- vector<_Tp, _Allocator>::vector(_InputIterator __first,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value,
- _InputIterator>::type __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- for (; __first != __last; ++__first)
- push_back(*__first);
- }
- template <class _Tp, class _Allocator>
- template <class _InputIterator>
- vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_InputIterator>::reference>::value>::type*)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- for (; __first != __last; ++__first)
- push_back(*__first);
- }
- template <class _Tp, class _Allocator>
- template <class _ForwardIterator>
- vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- _ForwardIterator>::type __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__first, __last, __n);
- }
- }
- template <class _Tp, class _Allocator>
- template <class _ForwardIterator>
- vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- value_type,
- typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__first, __last, __n);
- }
- }
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(const vector& __x)
- : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- size_type __n = __x.size();
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__x.__begin_, __x.__end_, __n);
- }
- }
- template <class _Tp, class _Allocator>
- vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- size_type __n = __x.size();
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__x.__begin_, __x.__end_, __n);
- }
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>::vector(vector&& __x)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
- #endif
- : __base(_VSTD::move(__x.__alloc()))
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- __get_db()->swap(this, &__x);
- #endif
- this->__begin_ = __x.__begin_;
- this->__end_ = __x.__end_;
- this->__end_cap() = __x.__end_cap();
- __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__a == __x.__alloc())
- {
- this->__begin_ = __x.__begin_;
- this->__end_ = __x.__end_;
- this->__end_cap() = __x.__end_cap();
- __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->swap(this, &__x);
- #endif
- }
- else
- {
- typedef move_iterator<iterator> _Ip;
- assign(_Ip(__x.begin()), _Ip(__x.end()));
- }
- }
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__il.size() > 0)
- {
- allocate(__il.size());
- __construct_at_end(__il.begin(), __il.end(), __il.size());
- }
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
- : __base(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- if (__il.size() > 0)
- {
- allocate(__il.size());
- __construct_at_end(__il.begin(), __il.end(), __il.size());
- }
- }
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>&
- vector<_Tp, _Allocator>::operator=(vector&& __x)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
- {
- __move_assign(__x, integral_constant<bool,
- __alloc_traits::propagate_on_container_move_assignment::value>());
- return *this;
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
- _NOEXCEPT_(__alloc_traits::is_always_equal::value)
- {
- if (__base::__alloc() != __c.__alloc())
- {
- typedef move_iterator<iterator> _Ip;
- assign(_Ip(__c.begin()), _Ip(__c.end()));
- }
- else
- __move_assign(__c, true_type());
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- deallocate();
- __base::__move_assign_alloc(__c); // this can throw
- this->__begin_ = __c.__begin_;
- this->__end_ = __c.__end_;
- this->__end_cap() = __c.__end_cap();
- __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->swap(this, &__c);
- #endif
- }
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<_Tp, _Allocator>&
- vector<_Tp, _Allocator>::operator=(const vector& __x)
- {
- if (this != &__x)
- {
- __base::__copy_assign_alloc(__x);
- assign(__x.__begin_, __x.__end_);
- }
- return *this;
- }
- template <class _Tp, class _Allocator>
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- _Tp,
- typename iterator_traits<_InputIterator>::reference>::value,
- void
- >::type
- vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
- {
- clear();
- for (; __first != __last; ++__first)
- push_back(*__first);
- }
- template <class _Tp, class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- _Tp,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- void
- >::type
- vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
- {
- size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__new_size <= capacity())
- {
- _ForwardIterator __mid = __last;
- bool __growing = false;
- if (__new_size > size())
- {
- __growing = true;
- __mid = __first;
- _VSTD::advance(__mid, size());
- }
- pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
- if (__growing)
- __construct_at_end(__mid, __last, __new_size - size());
- else
- this->__destruct_at_end(__m);
- }
- else
- {
- deallocate();
- allocate(__recommend(__new_size));
- __construct_at_end(__first, __last, __new_size);
- }
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
- {
- if (__n <= capacity())
- {
- size_type __s = size();
- _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
- if (__n > __s)
- __construct_at_end(__n - __s, __u);
- else
- this->__destruct_at_end(this->__begin_ + __n);
- }
- else
- {
- deallocate();
- allocate(__recommend(static_cast<size_type>(__n)));
- __construct_at_end(__n, __u);
- }
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- return iterator(this, __p);
- #else
- return iterator(__p);
- #endif
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::const_iterator
- vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- return const_iterator(this, __p);
- #else
- return const_iterator(__p);
- #endif
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::begin() _NOEXCEPT
- {
- return __make_iter(this->__begin_);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::const_iterator
- vector<_Tp, _Allocator>::begin() const _NOEXCEPT
- {
- return __make_iter(this->__begin_);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::end() _NOEXCEPT
- {
- return __make_iter(this->__end_);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::const_iterator
- vector<_Tp, _Allocator>::end() const _NOEXCEPT
- {
- return __make_iter(this->__end_);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::reference
- vector<_Tp, _Allocator>::operator[](size_type __n)
- {
- _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
- return this->__begin_[__n];
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::const_reference
- vector<_Tp, _Allocator>::operator[](size_type __n) const
- {
- _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
- return this->__begin_[__n];
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::reference
- vector<_Tp, _Allocator>::at(size_type __n)
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return this->__begin_[__n];
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::const_reference
- vector<_Tp, _Allocator>::at(size_type __n) const
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return this->__begin_[__n];
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::reserve(size_type __n)
- {
- if (__n > capacity())
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
- __swap_out_circular_buffer(__v);
- }
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
- {
- if (capacity() > size())
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
- __swap_out_circular_buffer(__v);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- }
- template <class _Tp, class _Allocator>
- template <class _Up>
- void
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
- #else
- vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
- #endif
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
- // __v.push_back(_VSTD::forward<_Up>(__x));
- __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
- __v.__end_++;
- __swap_out_circular_buffer(__v);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- vector<_Tp, _Allocator>::push_back(const_reference __x)
- {
- if (this->__end_ != this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_), __x);
- __annotator.__done();
- ++this->__end_;
- }
- else
- __push_back_slow_path(__x);
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- vector<_Tp, _Allocator>::push_back(value_type&& __x)
- {
- if (this->__end_ < this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_),
- _VSTD::move(__x));
- __annotator.__done();
- ++this->__end_;
- }
- else
- __push_back_slow_path(_VSTD::move(__x));
- }
- #ifndef _LIBCPP_HAS_NO_VARIADICS
- template <class _Tp, class _Allocator>
- template <class... _Args>
- void
- vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
- // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
- __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
- __v.__end_++;
- __swap_out_circular_buffer(__v);
- }
- template <class _Tp, class _Allocator>
- template <class... _Args>
- inline
- void
- vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
- {
- if (this->__end_ < this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_),
- _VSTD::forward<_Args>(__args)...);
- __annotator.__done();
- ++this->__end_;
- }
- else
- __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
- }
- #endif // _LIBCPP_HAS_NO_VARIADICS
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- inline
- void
- vector<_Tp, _Allocator>::pop_back()
- {
- _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
- this->__destruct_at_end(this->__end_ - 1);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::erase(const_iterator __position)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::erase(iterator) called with an iterator not"
- " referring to this vector");
- #endif
- _LIBCPP_ASSERT(__position != end(),
- "vector::erase(iterator) called with a non-dereferenceable iterator");
- difference_type __ps = __position - cbegin();
- pointer __p = this->__begin_ + __ps;
- iterator __r = __make_iter(__p);
- this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
- return __r;
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
- "vector::erase(iterator, iterator) called with an iterator not"
- " referring to this vector");
- #endif
- _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
- pointer __p = this->__begin_ + (__first - begin());
- iterator __r = __make_iter(__p);
- if (__first != __last)
- this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
- return __r;
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
- {
- pointer __old_last = this->__end_;
- difference_type __n = __old_last - __to;
- for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_),
- _VSTD::move(*__i));
- _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
- }
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::insert(iterator, x) called with an iterator not"
- " referring to this vector");
- #endif
- pointer __p = this->__begin_ + (__position - begin());
- if (this->__end_ < this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- if (__p == this->__end_)
- {
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_), __x);
- ++this->__end_;
- }
- else
- {
- __move_range(__p, this->__end_, __p + 1);
- const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
- if (__p <= __xr && __xr < this->__end_)
- ++__xr;
- *__p = *__xr;
- }
- __annotator.__done();
- }
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
- __v.push_back(__x);
- __p = __swap_out_circular_buffer(__v, __p);
- }
- return __make_iter(__p);
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::insert(iterator, x) called with an iterator not"
- " referring to this vector");
- #endif
- pointer __p = this->__begin_ + (__position - begin());
- if (this->__end_ < this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- if (__p == this->__end_)
- {
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_),
- _VSTD::move(__x));
- ++this->__end_;
- }
- else
- {
- __move_range(__p, this->__end_, __p + 1);
- *__p = _VSTD::move(__x);
- }
- __annotator.__done();
- }
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
- __v.push_back(_VSTD::move(__x));
- __p = __swap_out_circular_buffer(__v, __p);
- }
- return __make_iter(__p);
- }
- #ifndef _LIBCPP_HAS_NO_VARIADICS
- template <class _Tp, class _Allocator>
- template <class... _Args>
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::emplace(iterator, x) called with an iterator not"
- " referring to this vector");
- #endif
- pointer __p = this->__begin_ + (__position - begin());
- if (this->__end_ < this->__end_cap())
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- if (__p == this->__end_)
- {
- __alloc_traits::construct(this->__alloc(),
- _VSTD::__to_raw_pointer(this->__end_),
- _VSTD::forward<_Args>(__args)...);
- ++this->__end_;
- }
- else
- {
- __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
- __move_range(__p, this->__end_, __p + 1);
- *__p = _VSTD::move(__tmp.get());
- }
- __annotator.__done();
- }
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
- __v.emplace_back(_VSTD::forward<_Args>(__args)...);
- __p = __swap_out_circular_buffer(__v, __p);
- }
- return __make_iter(__p);
- }
- #endif // _LIBCPP_HAS_NO_VARIADICS
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Tp, class _Allocator>
- typename vector<_Tp, _Allocator>::iterator
- vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::insert(iterator, n, x) called with an iterator not"
- " referring to this vector");
- #endif
- pointer __p = this->__begin_ + (__position - begin());
- if (__n > 0)
- {
- if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
- {
- size_type __old_n = __n;
- pointer __old_last = this->__end_;
- if (__n > static_cast<size_type>(this->__end_ - __p))
- {
- size_type __cx = __n - (this->__end_ - __p);
- __construct_at_end(__cx, __x);
- __n -= __cx;
- }
- if (__n > 0)
- {
- __RAII_IncreaseAnnotator __annotator(*this, __n);
- __move_range(__p, __old_last, __p + __old_n);
- __annotator.__done();
- const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
- if (__p <= __xr && __xr < this->__end_)
- __xr += __old_n;
- _VSTD::fill_n(__p, __n, *__xr);
- }
- }
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
- __v.__construct_at_end(__n, __x);
- __p = __swap_out_circular_buffer(__v, __p);
- }
- }
- return __make_iter(__p);
- }
- template <class _Tp, class _Allocator>
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value &&
- is_constructible<
- _Tp,
- typename iterator_traits<_InputIterator>::reference>::value,
- typename vector<_Tp, _Allocator>::iterator
- >::type
- vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::insert(iterator, range) called with an iterator not"
- " referring to this vector");
- #endif
- difference_type __off = __position - begin();
- pointer __p = this->__begin_ + __off;
- allocator_type& __a = this->__alloc();
- pointer __old_last = this->__end_;
- for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
- {
- __RAII_IncreaseAnnotator __annotator(*this);
- __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
- *__first);
- ++this->__end_;
- __annotator.__done();
- }
- __split_buffer<value_type, allocator_type&> __v(__a);
- if (__first != __last)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- __v.__construct_at_end(__first, __last);
- difference_type __old_size = __old_last - this->__begin_;
- difference_type __old_p = __p - this->__begin_;
- reserve(__recommend(size() + __v.size()));
- __p = this->__begin_ + __old_p;
- __old_last = this->__begin_ + __old_size;
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- erase(__make_iter(__old_last), end());
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __p = _VSTD::rotate(__p, __old_last, this->__end_);
- insert(__make_iter(__p), make_move_iterator(__v.begin()),
- make_move_iterator(__v.end()));
- return begin() + __off;
- }
- template <class _Tp, class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value &&
- is_constructible<
- _Tp,
- typename iterator_traits<_ForwardIterator>::reference>::value,
- typename vector<_Tp, _Allocator>::iterator
- >::type
- vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
- "vector::insert(iterator, range) called with an iterator not"
- " referring to this vector");
- #endif
- pointer __p = this->__begin_ + (__position - begin());
- difference_type __n = _VSTD::distance(__first, __last);
- if (__n > 0)
- {
- if (__n <= this->__end_cap() - this->__end_)
- {
- size_type __old_n = __n;
- pointer __old_last = this->__end_;
- _ForwardIterator __m = __last;
- difference_type __dx = this->__end_ - __p;
- if (__n > __dx)
- {
- __m = __first;
- difference_type __diff = this->__end_ - __p;
- _VSTD::advance(__m, __diff);
- __construct_at_end(__m, __last, __n - __diff);
- __n = __dx;
- }
- if (__n > 0)
- {
- __RAII_IncreaseAnnotator __annotator(*this, __n);
- __move_range(__p, __old_last, __p + __old_n);
- __annotator.__done();
- _VSTD::copy(__first, __m, __p);
- }
- }
- else
- {
- allocator_type& __a = this->__alloc();
- __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
- __v.__construct_at_end(__first, __last);
- __p = __swap_out_circular_buffer(__v, __p);
- }
- }
- return __make_iter(__p);
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::resize(size_type __sz)
- {
- size_type __cs = size();
- if (__cs < __sz)
- this->__append(__sz - __cs);
- else if (__cs > __sz)
- this->__destruct_at_end(this->__begin_ + __sz);
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
- {
- size_type __cs = size();
- if (__cs < __sz)
- this->__append(__sz - __cs, __x);
- else if (__cs > __sz)
- this->__destruct_at_end(this->__begin_ + __sz);
- }
- template <class _Tp, class _Allocator>
- void
- vector<_Tp, _Allocator>::swap(vector& __x)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
- #endif
- {
- _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
- this->__alloc() == __x.__alloc(),
- "vector::swap: Either propagate_on_container_swap must be true"
- " or the allocators must compare equal");
- _VSTD::swap(this->__begin_, __x.__begin_);
- _VSTD::swap(this->__end_, __x.__end_);
- _VSTD::swap(this->__end_cap(), __x.__end_cap());
- __swap_allocator(this->__alloc(), __x.__alloc(),
- integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->swap(this, &__x);
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- }
- template <class _Tp, class _Allocator>
- bool
- vector<_Tp, _Allocator>::__invariants() const
- {
- if (this->__begin_ == nullptr)
- {
- if (this->__end_ != nullptr || this->__end_cap() != nullptr)
- return false;
- }
- else
- {
- if (this->__begin_ > this->__end_)
- return false;
- if (this->__begin_ == this->__end_cap())
- return false;
- if (this->__end_ > this->__end_cap())
- return false;
- }
- return true;
- }
- #if _LIBCPP_DEBUG_LEVEL >= 2
- template <class _Tp, class _Allocator>
- bool
- vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
- {
- return this->__begin_ <= __i->base() && __i->base() < this->__end_;
- }
- template <class _Tp, class _Allocator>
- bool
- vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
- {
- return this->__begin_ < __i->base() && __i->base() <= this->__end_;
- }
- template <class _Tp, class _Allocator>
- bool
- vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
- {
- const_pointer __p = __i->base() + __n;
- return this->__begin_ <= __p && __p <= this->__end_;
- }
- template <class _Tp, class _Allocator>
- bool
- vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
- {
- const_pointer __p = __i->base() + __n;
- return this->__begin_ <= __p && __p < this->__end_;
- }
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- vector<_Tp, _Allocator>::__invalidate_all_iterators()
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__invalidate_all(this);
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- }
- // vector<bool>
- template <class _Allocator> class vector<bool, _Allocator>;
- template <class _Allocator> struct hash<vector<bool, _Allocator> >;
- template <class _Allocator>
- struct __has_storage_type<vector<bool, _Allocator> >
- {
- static const bool value = true;
- };
- template <class _Allocator>
- class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
- : private __vector_base_common<true>
- {
- public:
- typedef vector __self;
- typedef bool value_type;
- typedef _Allocator allocator_type;
- typedef allocator_traits<allocator_type> __alloc_traits;
- typedef typename __alloc_traits::size_type size_type;
- typedef typename __alloc_traits::difference_type difference_type;
- typedef size_type __storage_type;
- typedef __bit_iterator<vector, false> pointer;
- typedef __bit_iterator<vector, true> const_pointer;
- typedef pointer iterator;
- typedef const_pointer const_iterator;
- typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
- typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
- private:
- typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
- typedef allocator_traits<__storage_allocator> __storage_traits;
- typedef typename __storage_traits::pointer __storage_pointer;
- typedef typename __storage_traits::const_pointer __const_storage_pointer;
- __storage_pointer __begin_;
- size_type __size_;
- __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
- public:
- typedef __bit_reference<vector> reference;
- typedef __bit_const_reference<vector> const_reference;
- private:
- _LIBCPP_INLINE_VISIBILITY
- size_type& __cap() _NOEXCEPT
- {return __cap_alloc_.first();}
- _LIBCPP_INLINE_VISIBILITY
- const size_type& __cap() const _NOEXCEPT
- {return __cap_alloc_.first();}
- _LIBCPP_INLINE_VISIBILITY
- __storage_allocator& __alloc() _NOEXCEPT
- {return __cap_alloc_.second();}
- _LIBCPP_INLINE_VISIBILITY
- const __storage_allocator& __alloc() const _NOEXCEPT
- {return __cap_alloc_.second();}
- static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
- _LIBCPP_INLINE_VISIBILITY
- static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
- {return __n * __bits_per_word;}
- _LIBCPP_INLINE_VISIBILITY
- static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
- {return (__n - 1) / __bits_per_word + 1;}
- public:
- _LIBCPP_INLINE_VISIBILITY
- vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
- _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
- #else
- _NOEXCEPT;
- #endif
- ~vector();
- explicit vector(size_type __n);
- #if _LIBCPP_STD_VER > 11
- explicit vector(size_type __n, const allocator_type& __a);
- #endif
- vector(size_type __n, const value_type& __v);
- vector(size_type __n, const value_type& __v, const allocator_type& __a);
- template <class _InputIterator>
- vector(_InputIterator __first, _InputIterator __last,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value>::type* = 0);
- template <class _InputIterator>
- vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value>::type* = 0);
- template <class _ForwardIterator>
- vector(_ForwardIterator __first, _ForwardIterator __last,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
- template <class _ForwardIterator>
- vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
- vector(const vector& __v);
- vector(const vector& __v, const allocator_type& __a);
- vector& operator=(const vector& __v);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- vector(initializer_list<value_type> __il);
- vector(initializer_list<value_type> __il, const allocator_type& __a);
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- vector(vector&& __v)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
- #endif
- vector(vector&& __v, const allocator_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(vector&& __v)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- vector& operator=(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end()); return *this;}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator<_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
- void
- >::type
- assign(_InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- assign(_ForwardIterator __first, _ForwardIterator __last);
- void assign(size_type __n, const value_type& __x);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- void assign(initializer_list<value_type> __il)
- {assign(__il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
- {return allocator_type(this->__alloc());}
- size_type max_size() const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type capacity() const _NOEXCEPT
- {return __internal_cap_to_external(__cap());}
- _LIBCPP_INLINE_VISIBILITY
- size_type size() const _NOEXCEPT
- {return __size_;}
- _LIBCPP_INLINE_VISIBILITY
- bool empty() const _NOEXCEPT
- {return __size_ == 0;}
- void reserve(size_type __n);
- void shrink_to_fit() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- iterator begin() _NOEXCEPT
- {return __make_iter(0);}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator begin() const _NOEXCEPT
- {return __make_iter(0);}
- _LIBCPP_INLINE_VISIBILITY
- iterator end() _NOEXCEPT
- {return __make_iter(__size_);}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator end() const _NOEXCEPT
- {return __make_iter(__size_);}
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rbegin() _NOEXCEPT
- {return reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rbegin() const _NOEXCEPT
- {return const_reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rend() _NOEXCEPT
- {return reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rend() const _NOEXCEPT
- {return const_reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cbegin() const _NOEXCEPT
- {return __make_iter(0);}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cend() const _NOEXCEPT
- {return __make_iter(__size_);}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crbegin() const _NOEXCEPT
- {return rbegin();}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crend() const _NOEXCEPT
- {return rend();}
- _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
- _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
- reference at(size_type __n);
- const_reference at(size_type __n) const;
- _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
- _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
- _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
- _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
- void push_back(const value_type& __x);
- #if _LIBCPP_STD_VER > 11
- template <class... _Args>
- _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
- { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
- #endif
- _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
- #if _LIBCPP_STD_VER > 11
- template <class... _Args>
- _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
- { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
- #endif
- iterator insert(const_iterator __position, const value_type& __x);
- iterator insert(const_iterator __position, size_type __n, const value_type& __x);
- iterator insert(const_iterator __position, size_type __n, const_reference __x);
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
- iterator
- >::type
- insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- iterator
- >::type
- insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- iterator insert(const_iterator __position, initializer_list<value_type> __il)
- {return insert(__position, __il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
- iterator erase(const_iterator __first, const_iterator __last);
- _LIBCPP_INLINE_VISIBILITY
- void clear() _NOEXCEPT {__size_ = 0;}
- void swap(vector&)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value);
- #endif
- static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
- void resize(size_type __sz, value_type __x = false);
- void flip() _NOEXCEPT;
- bool __invariants() const;
- private:
- _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
- void allocate(size_type __n);
- void deallocate() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- static size_type __align_it(size_type __new_size) _NOEXCEPT
- {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
- _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
- _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
- void __append(size_type __n, const_reference __x);
- _LIBCPP_INLINE_VISIBILITY
- reference __make_ref(size_type __pos) _NOEXCEPT
- {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
- _LIBCPP_INLINE_VISIBILITY
- const_reference __make_ref(size_type __pos) const _NOEXCEPT
- {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
- _LIBCPP_INLINE_VISIBILITY
- iterator __make_iter(size_type __pos) _NOEXCEPT
- {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator __make_iter(size_type __pos) const _NOEXCEPT
- {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
- _LIBCPP_INLINE_VISIBILITY
- iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
- {return begin() + (__p - cbegin());}
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const vector& __v)
- {__copy_assign_alloc(__v, integral_constant<bool,
- __storage_traits::propagate_on_container_copy_assignment::value>());}
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const vector& __c, true_type)
- {
- if (__alloc() != __c.__alloc())
- deallocate();
- __alloc() = __c.__alloc();
- }
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const vector&, false_type)
- {}
- void __move_assign(vector& __c, false_type);
- void __move_assign(vector& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(vector& __c)
- _NOEXCEPT_(
- !__storage_traits::propagate_on_container_move_assignment::value ||
- is_nothrow_move_assignable<allocator_type>::value)
- {__move_assign_alloc(__c, integral_constant<bool,
- __storage_traits::propagate_on_container_move_assignment::value>());}
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(vector& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- __alloc() = _VSTD::move(__c.__alloc());
- }
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(vector&, false_type)
- _NOEXCEPT
- {}
- size_t __hash_code() const _NOEXCEPT;
- friend class __bit_reference<vector>;
- friend class __bit_const_reference<vector>;
- friend class __bit_iterator<vector, false>;
- friend class __bit_iterator<vector, true>;
- friend struct __bit_array<vector>;
- friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
- };
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- vector<bool, _Allocator>::__invalidate_all_iterators()
- {
- }
- // Allocate space for __n objects
- // throws length_error if __n > max_size()
- // throws (probably bad_alloc) if memory run out
- // Precondition: __begin_ == __end_ == __cap() == 0
- // Precondition: __n > 0
- // Postcondition: capacity() == __n
- // Postcondition: size() == 0
- template <class _Allocator>
- void
- vector<bool, _Allocator>::allocate(size_type __n)
- {
- if (__n > max_size())
- this->__throw_length_error();
- __n = __external_cap_to_internal(__n);
- this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
- this->__size_ = 0;
- this->__cap() = __n;
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::deallocate() _NOEXCEPT
- {
- if (this->__begin_ != nullptr)
- {
- __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
- __invalidate_all_iterators();
- this->__begin_ = nullptr;
- this->__size_ = this->__cap() = 0;
- }
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::size_type
- vector<bool, _Allocator>::max_size() const _NOEXCEPT
- {
- size_type __amax = __storage_traits::max_size(__alloc());
- size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
- if (__nmax / __bits_per_word <= __amax)
- return __nmax;
- return __internal_cap_to_external(__amax);
- }
- // Precondition: __new_size > capacity()
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<bool, _Allocator>::size_type
- vector<bool, _Allocator>::__recommend(size_type __new_size) const
- {
- const size_type __ms = max_size();
- if (__new_size > __ms)
- this->__throw_length_error();
- const size_type __cap = capacity();
- if (__cap >= __ms / 2)
- return __ms;
- return _VSTD::max(2*__cap, __align_it(__new_size));
- }
- // Default constructs __n objects starting at __end_
- // Precondition: __n > 0
- // Precondition: size() + __n <= capacity()
- // Postcondition: size() == size() + __n
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
- {
- size_type __old_size = this->__size_;
- this->__size_ += __n;
- _VSTD::fill_n(__make_iter(__old_size), __n, __x);
- }
- template <class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
- {
- size_type __old_size = this->__size_;
- this->__size_ += _VSTD::distance(__first, __last);
- _VSTD::copy(__first, __last, __make_iter(__old_size));
- }
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<bool, _Allocator>::vector()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- }
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<bool, _Allocator>::vector(const allocator_type& __a)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
- #else
- _NOEXCEPT
- #endif
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(size_type __n)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, false);
- }
- }
- #if _LIBCPP_STD_VER > 11
- template <class _Allocator>
- vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, false);
- }
- }
- #endif
- template <class _Allocator>
- vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, __x);
- }
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__n, __x);
- }
- }
- template <class _Allocator>
- template <class _InputIterator>
- vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value>::type*)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- for (; __first != __last; ++__first)
- push_back(*__first);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- if (__begin_ != nullptr)
- __storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- template <class _Allocator>
- template <class _InputIterator>
- vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
- typename enable_if<__is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value>::type*)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- for (; __first != __last; ++__first)
- push_back(*__first);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- if (__begin_ != nullptr)
- __storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- template <class _Allocator>
- template <class _ForwardIterator>
- vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__first, __last);
- }
- }
- template <class _Allocator>
- template <class _ForwardIterator>
- vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
- typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__first, __last);
- }
- }
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _Allocator>
- vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0)
- {
- size_type __n = static_cast<size_type>(__il.size());
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__il.begin(), __il.end());
- }
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, static_cast<__storage_allocator>(__a))
- {
- size_type __n = static_cast<size_type>(__il.size());
- if (__n > 0)
- {
- allocate(__n);
- __construct_at_end(__il.begin(), __il.end());
- }
- }
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _Allocator>
- vector<bool, _Allocator>::~vector()
- {
- if (__begin_ != nullptr)
- __storage_traits::deallocate(__alloc(), __begin_, __cap());
- __invalidate_all_iterators();
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(const vector& __v)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
- {
- if (__v.size() > 0)
- {
- allocate(__v.size());
- __construct_at_end(__v.begin(), __v.end());
- }
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, __a)
- {
- if (__v.size() > 0)
- {
- allocate(__v.size());
- __construct_at_end(__v.begin(), __v.end());
- }
- }
- template <class _Allocator>
- vector<bool, _Allocator>&
- vector<bool, _Allocator>::operator=(const vector& __v)
- {
- if (this != &__v)
- {
- __copy_assign_alloc(__v);
- if (__v.__size_)
- {
- if (__v.__size_ > capacity())
- {
- deallocate();
- allocate(__v.__size_);
- }
- _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
- }
- __size_ = __v.__size_;
- }
- return *this;
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<bool, _Allocator>::vector(vector&& __v)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
- #endif
- : __begin_(__v.__begin_),
- __size_(__v.__size_),
- __cap_alloc_(__v.__cap_alloc_)
- {
- __v.__begin_ = nullptr;
- __v.__size_ = 0;
- __v.__cap() = 0;
- }
- template <class _Allocator>
- vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
- : __begin_(nullptr),
- __size_(0),
- __cap_alloc_(0, __a)
- {
- if (__a == allocator_type(__v.__alloc()))
- {
- this->__begin_ = __v.__begin_;
- this->__size_ = __v.__size_;
- this->__cap() = __v.__cap();
- __v.__begin_ = nullptr;
- __v.__cap() = __v.__size_ = 0;
- }
- else if (__v.size() > 0)
- {
- allocate(__v.size());
- __construct_at_end(__v.begin(), __v.end());
- }
- }
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- vector<bool, _Allocator>&
- vector<bool, _Allocator>::operator=(vector&& __v)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
- {
- __move_assign(__v, integral_constant<bool,
- __storage_traits::propagate_on_container_move_assignment::value>());
- return *this;
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
- {
- if (__alloc() != __c.__alloc())
- assign(__c.begin(), __c.end());
- else
- __move_assign(__c, true_type());
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- deallocate();
- __move_assign_alloc(__c);
- this->__begin_ = __c.__begin_;
- this->__size_ = __c.__size_;
- this->__cap() = __c.__cap();
- __c.__begin_ = nullptr;
- __c.__cap() = __c.__size_ = 0;
- }
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Allocator>
- void
- vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
- {
- __size_ = 0;
- if (__n > 0)
- {
- size_type __c = capacity();
- if (__n <= __c)
- __size_ = __n;
- else
- {
- vector __v(__alloc());
- __v.reserve(__recommend(__n));
- __v.__size_ = __n;
- swap(__v);
- }
- _VSTD::fill_n(begin(), __n, __x);
- }
- }
- template <class _Allocator>
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator<_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
- void
- >::type
- vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
- {
- clear();
- for (; __first != __last; ++__first)
- push_back(*__first);
- }
- template <class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
- {
- clear();
- difference_type __n = _VSTD::distance(__first, __last);
- if (__n)
- {
- if (__n > capacity())
- {
- deallocate();
- allocate(__n);
- }
- __construct_at_end(__first, __last);
- }
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::reserve(size_type __n)
- {
- if (__n > capacity())
- {
- vector __v(this->__alloc());
- __v.allocate(__n);
- __v.__construct_at_end(this->begin(), this->end());
- swap(__v);
- __invalidate_all_iterators();
- }
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
- {
- if (__external_cap_to_internal(size()) > __cap())
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- vector(*this, allocator_type(__alloc())).swap(*this);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::reference
- vector<bool, _Allocator>::at(size_type __n)
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return (*this)[__n];
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::const_reference
- vector<bool, _Allocator>::at(size_type __n) const
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return (*this)[__n];
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::push_back(const value_type& __x)
- {
- if (this->__size_ == this->capacity())
- reserve(__recommend(this->__size_ + 1));
- ++this->__size_;
- back() = __x;
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::iterator
- vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
- {
- iterator __r;
- if (size() < capacity())
- {
- const_iterator __old_end = end();
- ++__size_;
- _VSTD::copy_backward(__position, __old_end, end());
- __r = __const_iterator_cast(__position);
- }
- else
- {
- vector __v(__alloc());
- __v.reserve(__recommend(__size_ + 1));
- __v.__size_ = __size_ + 1;
- __r = _VSTD::copy(cbegin(), __position, __v.begin());
- _VSTD::copy_backward(__position, cend(), __v.end());
- swap(__v);
- }
- *__r = __x;
- return __r;
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::iterator
- vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
- {
- iterator __r;
- size_type __c = capacity();
- if (__n <= __c && size() <= __c - __n)
- {
- const_iterator __old_end = end();
- __size_ += __n;
- _VSTD::copy_backward(__position, __old_end, end());
- __r = __const_iterator_cast(__position);
- }
- else
- {
- vector __v(__alloc());
- __v.reserve(__recommend(__size_ + __n));
- __v.__size_ = __size_ + __n;
- __r = _VSTD::copy(cbegin(), __position, __v.begin());
- _VSTD::copy_backward(__position, cend(), __v.end());
- swap(__v);
- }
- _VSTD::fill_n(__r, __n, __x);
- return __r;
- }
- template <class _Allocator>
- template <class _InputIterator>
- typename enable_if
- <
- __is_input_iterator <_InputIterator>::value &&
- !__is_forward_iterator<_InputIterator>::value,
- typename vector<bool, _Allocator>::iterator
- >::type
- vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
- {
- difference_type __off = __position - begin();
- iterator __p = __const_iterator_cast(__position);
- iterator __old_end = end();
- for (; size() != capacity() && __first != __last; ++__first)
- {
- ++this->__size_;
- back() = *__first;
- }
- vector __v(__alloc());
- if (__first != __last)
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- __v.assign(__first, __last);
- difference_type __old_size = static_cast<difference_type>(__old_end - begin());
- difference_type __old_p = __p - begin();
- reserve(__recommend(size() + __v.size()));
- __p = begin() + __old_p;
- __old_end = begin() + __old_size;
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- erase(__old_end, end());
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __p = _VSTD::rotate(__p, __old_end, end());
- insert(__p, __v.begin(), __v.end());
- return begin() + __off;
- }
- template <class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- typename vector<bool, _Allocator>::iterator
- >::type
- vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
- {
- difference_type __n = _VSTD::distance(__first, __last);
- iterator __r;
- size_type __c = capacity();
- if (__n <= __c && size() <= __c - __n)
- {
- const_iterator __old_end = end();
- __size_ += __n;
- _VSTD::copy_backward(__position, __old_end, end());
- __r = __const_iterator_cast(__position);
- }
- else
- {
- vector __v(__alloc());
- __v.reserve(__recommend(__size_ + __n));
- __v.__size_ = __size_ + __n;
- __r = _VSTD::copy(cbegin(), __position, __v.begin());
- _VSTD::copy_backward(__position, cend(), __v.end());
- swap(__v);
- }
- _VSTD::copy(__first, __last, __r);
- return __r;
- }
- template <class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename vector<bool, _Allocator>::iterator
- vector<bool, _Allocator>::erase(const_iterator __position)
- {
- iterator __r = __const_iterator_cast(__position);
- _VSTD::copy(__position + 1, this->cend(), __r);
- --__size_;
- return __r;
- }
- template <class _Allocator>
- typename vector<bool, _Allocator>::iterator
- vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
- {
- iterator __r = __const_iterator_cast(__first);
- difference_type __d = __last - __first;
- _VSTD::copy(__last, this->cend(), __r);
- __size_ -= __d;
- return __r;
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::swap(vector& __x)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
- #endif
- {
- _VSTD::swap(this->__begin_, __x.__begin_);
- _VSTD::swap(this->__size_, __x.__size_);
- _VSTD::swap(this->__cap(), __x.__cap());
- __swap_allocator(this->__alloc(), __x.__alloc(),
- integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
- {
- size_type __cs = size();
- if (__cs < __sz)
- {
- iterator __r;
- size_type __c = capacity();
- size_type __n = __sz - __cs;
- if (__n <= __c && __cs <= __c - __n)
- {
- __r = end();
- __size_ += __n;
- }
- else
- {
- vector __v(__alloc());
- __v.reserve(__recommend(__size_ + __n));
- __v.__size_ = __size_ + __n;
- __r = _VSTD::copy(cbegin(), cend(), __v.begin());
- swap(__v);
- }
- _VSTD::fill_n(__r, __n, __x);
- }
- else
- __size_ = __sz;
- }
- template <class _Allocator>
- void
- vector<bool, _Allocator>::flip() _NOEXCEPT
- {
- // do middle whole words
- size_type __n = __size_;
- __storage_pointer __p = __begin_;
- for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
- *__p = ~*__p;
- // do last partial word
- if (__n > 0)
- {
- __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
- __storage_type __b = *__p & __m;
- *__p &= ~__m;
- *__p |= ~__b & __m;
- }
- }
- template <class _Allocator>
- bool
- vector<bool, _Allocator>::__invariants() const
- {
- if (this->__begin_ == nullptr)
- {
- if (this->__size_ != 0 || this->__cap() != 0)
- return false;
- }
- else
- {
- if (this->__cap() == 0)
- return false;
- if (this->__size_ > this->capacity())
- return false;
- }
- return true;
- }
- template <class _Allocator>
- size_t
- vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
- {
- size_t __h = 0;
- // do middle whole words
- size_type __n = __size_;
- __storage_pointer __p = __begin_;
- for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
- __h ^= *__p;
- // do last partial word
- if (__n > 0)
- {
- const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
- __h ^= *__p & __m;
- }
- return __h;
- }
- template <class _Allocator>
- struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
- : public unary_function<vector<bool, _Allocator>, size_t>
- {
- _LIBCPP_INLINE_VISIBILITY
- size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
- {return __vec.__hash_code();}
- };
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
- return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- return !(__x == __y);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- return __y < __x;
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- return !(__x < __y);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
- {
- return !(__y < __x);
- }
- template <class _Tp, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
- _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
- {
- __x.swap(__y);
- }
- _LIBCPP_END_NAMESPACE_STD
- #endif // _LIBCPP_VECTOR
|