vector 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_VECTOR
  10. #define _LIBCPP_VECTOR
  11. /*
  12. vector synopsis
  13. namespace std
  14. {
  15. template <class T, class Allocator = allocator<T> >
  16. class vector
  17. {
  18. public:
  19. typedef T value_type;
  20. typedef Allocator allocator_type;
  21. typedef typename allocator_type::reference reference;
  22. typedef typename allocator_type::const_reference const_reference;
  23. typedef implementation-defined iterator;
  24. typedef implementation-defined const_iterator;
  25. typedef typename allocator_type::size_type size_type;
  26. typedef typename allocator_type::difference_type difference_type;
  27. typedef typename allocator_type::pointer pointer;
  28. typedef typename allocator_type::const_pointer const_pointer;
  29. typedef std::reverse_iterator<iterator> reverse_iterator;
  30. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  31. vector()
  32. noexcept(is_nothrow_default_constructible<allocator_type>::value);
  33. explicit vector(const allocator_type&);
  34. explicit vector(size_type n);
  35. explicit vector(size_type n, const allocator_type&); // C++14
  36. vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
  37. template <class InputIterator>
  38. vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
  39. vector(const vector& x);
  40. vector(vector&& x)
  41. noexcept(is_nothrow_move_constructible<allocator_type>::value);
  42. vector(initializer_list<value_type> il);
  43. vector(initializer_list<value_type> il, const allocator_type& a);
  44. ~vector();
  45. vector& operator=(const vector& x);
  46. vector& operator=(vector&& x)
  47. noexcept(
  48. allocator_type::propagate_on_container_move_assignment::value ||
  49. allocator_type::is_always_equal::value); // C++17
  50. vector& operator=(initializer_list<value_type> il);
  51. template <class InputIterator>
  52. void assign(InputIterator first, InputIterator last);
  53. void assign(size_type n, const value_type& u);
  54. void assign(initializer_list<value_type> il);
  55. allocator_type get_allocator() const noexcept;
  56. iterator begin() noexcept;
  57. const_iterator begin() const noexcept;
  58. iterator end() noexcept;
  59. const_iterator end() const noexcept;
  60. reverse_iterator rbegin() noexcept;
  61. const_reverse_iterator rbegin() const noexcept;
  62. reverse_iterator rend() noexcept;
  63. const_reverse_iterator rend() const noexcept;
  64. const_iterator cbegin() const noexcept;
  65. const_iterator cend() const noexcept;
  66. const_reverse_iterator crbegin() const noexcept;
  67. const_reverse_iterator crend() const noexcept;
  68. size_type size() const noexcept;
  69. size_type max_size() const noexcept;
  70. size_type capacity() const noexcept;
  71. bool empty() const noexcept;
  72. void reserve(size_type n);
  73. void shrink_to_fit() noexcept;
  74. reference operator[](size_type n);
  75. const_reference operator[](size_type n) const;
  76. reference at(size_type n);
  77. const_reference at(size_type n) const;
  78. reference front();
  79. const_reference front() const;
  80. reference back();
  81. const_reference back() const;
  82. value_type* data() noexcept;
  83. const value_type* data() const noexcept;
  84. void push_back(const value_type& x);
  85. void push_back(value_type&& x);
  86. template <class... Args>
  87. reference emplace_back(Args&&... args); // reference in C++17
  88. void pop_back();
  89. template <class... Args> iterator emplace(const_iterator position, Args&&... args);
  90. iterator insert(const_iterator position, const value_type& x);
  91. iterator insert(const_iterator position, value_type&& x);
  92. iterator insert(const_iterator position, size_type n, const value_type& x);
  93. template <class InputIterator>
  94. iterator insert(const_iterator position, InputIterator first, InputIterator last);
  95. iterator insert(const_iterator position, initializer_list<value_type> il);
  96. iterator erase(const_iterator position);
  97. iterator erase(const_iterator first, const_iterator last);
  98. void clear() noexcept;
  99. void resize(size_type sz);
  100. void resize(size_type sz, const value_type& c);
  101. void swap(vector&)
  102. noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
  103. allocator_traits<allocator_type>::is_always_equal::value); // C++17
  104. bool __invariants() const;
  105. };
  106. template <class Allocator = allocator<T> >
  107. class vector<bool, Allocator>
  108. {
  109. public:
  110. typedef bool value_type;
  111. typedef Allocator allocator_type;
  112. typedef implementation-defined iterator;
  113. typedef implementation-defined const_iterator;
  114. typedef typename allocator_type::size_type size_type;
  115. typedef typename allocator_type::difference_type difference_type;
  116. typedef iterator pointer;
  117. typedef const_iterator const_pointer;
  118. typedef std::reverse_iterator<iterator> reverse_iterator;
  119. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  120. class reference
  121. {
  122. public:
  123. reference(const reference&) noexcept;
  124. operator bool() const noexcept;
  125. reference& operator=(bool x) noexcept;
  126. reference& operator=(const reference& x) noexcept;
  127. iterator operator&() const noexcept;
  128. void flip() noexcept;
  129. };
  130. class const_reference
  131. {
  132. public:
  133. const_reference(const reference&) noexcept;
  134. operator bool() const noexcept;
  135. const_iterator operator&() const noexcept;
  136. };
  137. vector()
  138. noexcept(is_nothrow_default_constructible<allocator_type>::value);
  139. explicit vector(const allocator_type&);
  140. explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
  141. vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
  142. template <class InputIterator>
  143. vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
  144. vector(const vector& x);
  145. vector(vector&& x)
  146. noexcept(is_nothrow_move_constructible<allocator_type>::value);
  147. vector(initializer_list<value_type> il);
  148. vector(initializer_list<value_type> il, const allocator_type& a);
  149. ~vector();
  150. vector& operator=(const vector& x);
  151. vector& operator=(vector&& x)
  152. noexcept(
  153. allocator_type::propagate_on_container_move_assignment::value ||
  154. allocator_type::is_always_equal::value); // C++17
  155. vector& operator=(initializer_list<value_type> il);
  156. template <class InputIterator>
  157. void assign(InputIterator first, InputIterator last);
  158. void assign(size_type n, const value_type& u);
  159. void assign(initializer_list<value_type> il);
  160. allocator_type get_allocator() const noexcept;
  161. iterator begin() noexcept;
  162. const_iterator begin() const noexcept;
  163. iterator end() noexcept;
  164. const_iterator end() const noexcept;
  165. reverse_iterator rbegin() noexcept;
  166. const_reverse_iterator rbegin() const noexcept;
  167. reverse_iterator rend() noexcept;
  168. const_reverse_iterator rend() const noexcept;
  169. const_iterator cbegin() const noexcept;
  170. const_iterator cend() const noexcept;
  171. const_reverse_iterator crbegin() const noexcept;
  172. const_reverse_iterator crend() const noexcept;
  173. size_type size() const noexcept;
  174. size_type max_size() const noexcept;
  175. size_type capacity() const noexcept;
  176. bool empty() const noexcept;
  177. void reserve(size_type n);
  178. void shrink_to_fit() noexcept;
  179. reference operator[](size_type n);
  180. const_reference operator[](size_type n) const;
  181. reference at(size_type n);
  182. const_reference at(size_type n) const;
  183. reference front();
  184. const_reference front() const;
  185. reference back();
  186. const_reference back() const;
  187. void push_back(const value_type& x);
  188. template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17
  189. void pop_back();
  190. template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
  191. iterator insert(const_iterator position, const value_type& x);
  192. iterator insert(const_iterator position, size_type n, const value_type& x);
  193. template <class InputIterator>
  194. iterator insert(const_iterator position, InputIterator first, InputIterator last);
  195. iterator insert(const_iterator position, initializer_list<value_type> il);
  196. iterator erase(const_iterator position);
  197. iterator erase(const_iterator first, const_iterator last);
  198. void clear() noexcept;
  199. void resize(size_type sz);
  200. void resize(size_type sz, value_type x);
  201. void swap(vector&)
  202. noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
  203. allocator_traits<allocator_type>::is_always_equal::value); // C++17
  204. void flip() noexcept;
  205. bool __invariants() const;
  206. };
  207. template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  208. vector(InputIterator, InputIterator, Allocator = Allocator())
  209. -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
  210. template <class Allocator> struct hash<std::vector<bool, Allocator>>;
  211. template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  212. template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  213. template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  214. template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  215. template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  216. template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
  217. template <class T, class Allocator>
  218. void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
  219. noexcept(noexcept(x.swap(y)));
  220. template <class T, class Allocator, class U>
  221. typename vector<T, Allocator>::size_type
  222. erase(vector<T, Allocator>& c, const U& value); // C++20
  223. template <class T, class Allocator, class Predicate>
  224. typename vector<T, Allocator>::size_type
  225. erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
  226. template<class T>
  227. inline constexpr bool is-vector-bool-reference = see below; // exposition only, since C++23
  228. template<class T, class charT> requires is-vector-bool-reference<T> // Since C++23
  229. struct formatter<T, charT>;
  230. } // std
  231. */
  232. #include <__algorithm/copy.h>
  233. #include <__algorithm/equal.h>
  234. #include <__algorithm/fill_n.h>
  235. #include <__algorithm/lexicographical_compare.h>
  236. #include <__algorithm/remove.h>
  237. #include <__algorithm/remove_if.h>
  238. #include <__algorithm/rotate.h>
  239. #include <__algorithm/unwrap_iter.h>
  240. #include <__assert> // all public C++ headers provide the assertion handler
  241. #include <__bit_reference>
  242. #include <__concepts/same_as.h>
  243. #include <__config>
  244. #include <__debug>
  245. #include <__format/enable_insertable.h>
  246. #include <__format/formatter.h>
  247. #include <__functional/hash.h>
  248. #include <__functional/unary_function.h>
  249. #include <__iterator/advance.h>
  250. #include <__iterator/iterator_traits.h>
  251. #include <__iterator/reverse_iterator.h>
  252. #include <__iterator/wrap_iter.h>
  253. #include <__memory/allocate_at_least.h>
  254. #include <__memory/pointer_traits.h>
  255. #include <__memory/swap_allocator.h>
  256. #include <__memory/temp_value.h>
  257. #include <__memory/uninitialized_algorithms.h>
  258. #include <__memory_resource/polymorphic_allocator.h>
  259. #include <__split_buffer>
  260. #include <__type_traits/is_allocator.h>
  261. #include <__type_traits/noexcept_move_assign_container.h>
  262. #include <__utility/exception_guard.h>
  263. #include <__utility/forward.h>
  264. #include <__utility/move.h>
  265. #include <__utility/swap.h>
  266. #include <climits>
  267. #include <cstdlib>
  268. #include <cstring>
  269. #include <iosfwd> // for forward declaration of vector
  270. #include <limits>
  271. #include <stdexcept>
  272. #include <type_traits>
  273. #include <version>
  274. // standard-mandated includes
  275. // [iterator.range]
  276. #include <__iterator/access.h>
  277. #include <__iterator/data.h>
  278. #include <__iterator/empty.h>
  279. #include <__iterator/reverse_access.h>
  280. #include <__iterator/size.h>
  281. // [vector.syn]
  282. #include <compare>
  283. #include <initializer_list>
  284. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  285. # pragma GCC system_header
  286. #endif
  287. _LIBCPP_PUSH_MACROS
  288. #include <__undef_macros>
  289. _LIBCPP_BEGIN_NAMESPACE_STD
  290. template <class _Tp, class _Allocator /* = allocator<_Tp> */>
  291. class _LIBCPP_TEMPLATE_VIS vector
  292. {
  293. private:
  294. typedef allocator<_Tp> __default_allocator_type;
  295. public:
  296. typedef vector __self;
  297. typedef _Tp value_type;
  298. typedef _Allocator allocator_type;
  299. typedef allocator_traits<allocator_type> __alloc_traits;
  300. typedef value_type& reference;
  301. typedef const value_type& const_reference;
  302. typedef typename __alloc_traits::size_type size_type;
  303. typedef typename __alloc_traits::difference_type difference_type;
  304. typedef typename __alloc_traits::pointer pointer;
  305. typedef typename __alloc_traits::const_pointer const_pointer;
  306. #if _YNDX_LIBCPP_MAKE_VECTOR_ITERATOR_POINTERS == 1
  307. typedef pointer iterator;
  308. typedef const_pointer const_iterator;
  309. #else
  310. // TODO: Implement iterator bounds checking without requiring the global database.
  311. typedef __wrap_iter<pointer> iterator;
  312. typedef __wrap_iter<const_pointer> const_iterator;
  313. #endif
  314. typedef std::reverse_iterator<iterator> reverse_iterator;
  315. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  316. static_assert((is_same<typename allocator_type::value_type, value_type>::value),
  317. "Allocator::value_type must be same type as value_type");
  318. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  319. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  320. "original allocator");
  321. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  322. vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
  323. {
  324. std::__debug_db_insert_c(this);
  325. }
  326. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
  327. #if _LIBCPP_STD_VER <= 14
  328. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
  329. #else
  330. _NOEXCEPT
  331. #endif
  332. : __end_cap_(nullptr, __a)
  333. {
  334. std::__debug_db_insert_c(this);
  335. }
  336. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
  337. #if _LIBCPP_STD_VER > 11
  338. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a);
  339. #endif
  340. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
  341. template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
  342. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  343. vector(size_type __n, const value_type& __x, const allocator_type& __a)
  344. : __end_cap_(nullptr, __a)
  345. {
  346. std::__debug_db_insert_c(this);
  347. if (__n > 0)
  348. {
  349. __vallocate(__n);
  350. __construct_at_end(__n, __x);
  351. }
  352. }
  353. template <class _InputIterator,
  354. __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  355. is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
  356. int> = 0>
  357. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
  358. template <class _InputIterator,
  359. __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  360. is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
  361. int> = 0>
  362. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  363. vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
  364. template <
  365. class _ForwardIterator,
  366. __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  367. is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
  368. int> = 0>
  369. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
  370. template <class _ForwardIterator,
  371. __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  372. is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
  373. int> = 0>
  374. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  375. vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
  376. private:
  377. class __destroy_vector {
  378. public:
  379. _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {}
  380. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
  381. __vec_.__annotate_delete();
  382. std::__debug_db_erase_c(std::addressof(__vec_));
  383. if (__vec_.__begin_ != nullptr) {
  384. __vec_.__clear();
  385. __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
  386. }
  387. }
  388. private:
  389. vector& __vec_;
  390. };
  391. public:
  392. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); }
  393. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
  394. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
  395. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  396. vector& operator=(const vector& __x);
  397. #ifndef _LIBCPP_CXX03_LANG
  398. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  399. vector(initializer_list<value_type> __il);
  400. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  401. vector(initializer_list<value_type> __il, const allocator_type& __a);
  402. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  403. vector& operator=(initializer_list<value_type> __il)
  404. {assign(__il.begin(), __il.end()); return *this;}
  405. #endif // !_LIBCPP_CXX03_LANG
  406. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  407. vector(vector&& __x)
  408. #if _LIBCPP_STD_VER > 14
  409. noexcept;
  410. #else
  411. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
  412. #endif
  413. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  414. vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
  415. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  416. vector& operator=(vector&& __x)
  417. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
  418. template <class _InputIterator,
  419. __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  420. is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
  421. int> = 0>
  422. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
  423. template <
  424. class _ForwardIterator,
  425. __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  426. is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
  427. int> = 0>
  428. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
  429. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
  430. #ifndef _LIBCPP_CXX03_LANG
  431. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  432. void assign(initializer_list<value_type> __il)
  433. {assign(__il.begin(), __il.end());}
  434. #endif
  435. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  436. allocator_type get_allocator() const _NOEXCEPT
  437. {return this->__alloc();}
  438. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT;
  439. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT;
  440. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT;
  441. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT;
  442. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  443. reverse_iterator rbegin() _NOEXCEPT
  444. {return reverse_iterator(end());}
  445. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  446. const_reverse_iterator rbegin() const _NOEXCEPT
  447. {return const_reverse_iterator(end());}
  448. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  449. reverse_iterator rend() _NOEXCEPT
  450. {return reverse_iterator(begin());}
  451. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  452. const_reverse_iterator rend() const _NOEXCEPT
  453. {return const_reverse_iterator(begin());}
  454. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  455. const_iterator cbegin() const _NOEXCEPT
  456. {return begin();}
  457. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  458. const_iterator cend() const _NOEXCEPT
  459. {return end();}
  460. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  461. const_reverse_iterator crbegin() const _NOEXCEPT
  462. {return rbegin();}
  463. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  464. const_reverse_iterator crend() const _NOEXCEPT
  465. {return rend();}
  466. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  467. size_type size() const _NOEXCEPT
  468. {return static_cast<size_type>(this->__end_ - this->__begin_);}
  469. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  470. size_type capacity() const _NOEXCEPT
  471. {return static_cast<size_type>(__end_cap() - this->__begin_);}
  472. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  473. bool empty() const _NOEXCEPT
  474. {return this->__begin_ == this->__end_;}
  475. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
  476. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
  477. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
  478. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT;
  479. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
  480. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
  481. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
  482. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT
  483. {
  484. _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
  485. return *this->__begin_;
  486. }
  487. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT
  488. {
  489. _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
  490. return *this->__begin_;
  491. }
  492. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT
  493. {
  494. _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
  495. return *(this->__end_ - 1);
  496. }
  497. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT
  498. {
  499. _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
  500. return *(this->__end_ - 1);
  501. }
  502. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  503. value_type* data() _NOEXCEPT
  504. {return std::__to_address(this->__begin_);}
  505. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  506. const value_type* data() const _NOEXCEPT
  507. {return std::__to_address(this->__begin_);}
  508. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
  509. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
  510. template <class... _Args>
  511. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  512. #if _LIBCPP_STD_VER > 14
  513. reference emplace_back(_Args&&... __args);
  514. #else
  515. void emplace_back(_Args&&... __args);
  516. #endif
  517. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  518. void pop_back();
  519. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
  520. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
  521. template <class... _Args>
  522. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
  523. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  524. iterator insert(const_iterator __position, size_type __n, const_reference __x);
  525. template <class _InputIterator,
  526. __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  527. is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
  528. int> = 0>
  529. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
  530. insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
  531. template <
  532. class _ForwardIterator,
  533. __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  534. is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
  535. int> = 0>
  536. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
  537. insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
  538. #ifndef _LIBCPP_CXX03_LANG
  539. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  540. iterator insert(const_iterator __position, initializer_list<value_type> __il)
  541. {return insert(__position, __il.begin(), __il.end());}
  542. #endif
  543. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
  544. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
  545. _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  546. void clear() _NOEXCEPT
  547. {
  548. size_type __old_size = size();
  549. __clear();
  550. __annotate_shrink(__old_size);
  551. std::__debug_db_invalidate_all(this);
  552. }
  553. #if _YNDX_LIBCXX_ENABLE_VECTOR_POD_RESIZE_UNINITIALIZED
  554. void resize_uninitialized(size_type __sz);
  555. #endif
  556. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
  557. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
  558. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
  559. #if _LIBCPP_STD_VER >= 14
  560. _NOEXCEPT;
  561. #else
  562. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  563. __is_nothrow_swappable<allocator_type>::value);
  564. #endif
  565. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
  566. #ifdef _LIBCPP_ENABLE_DEBUG_MODE
  567. bool __dereferenceable(const const_iterator* __i) const;
  568. bool __decrementable(const const_iterator* __i) const;
  569. bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
  570. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
  571. #endif // _LIBCPP_ENABLE_DEBUG_MODE
  572. private:
  573. pointer __begin_ = nullptr;
  574. pointer __end_ = nullptr;
  575. __compressed_pair<pointer, allocator_type> __end_cap_ =
  576. __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
  577. _LIBCPP_HIDE_FROM_ABI void __invalidate_iterators_past(pointer __new_last);
  578. // Allocate space for __n objects
  579. // throws length_error if __n > max_size()
  580. // throws (probably bad_alloc) if memory run out
  581. // Precondition: __begin_ == __end_ == __end_cap() == 0
  582. // Precondition: __n > 0
  583. // Postcondition: capacity() >= __n
  584. // Postcondition: size() == 0
  585. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
  586. if (__n > max_size())
  587. __throw_length_error();
  588. auto __allocation = std::__allocate_at_least(__alloc(), __n);
  589. __begin_ = __allocation.ptr;
  590. __end_ = __allocation.ptr;
  591. __end_cap() = __begin_ + __allocation.count;
  592. __annotate_new(0);
  593. }
  594. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
  595. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
  596. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
  597. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  598. void __construct_at_end(size_type __n, const_reference __x);
  599. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value, int> = 0>
  600. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
  601. __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
  602. void __append_uninitialized(size_type __n);
  603. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
  604. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
  605. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  606. iterator __make_iter(pointer __p) _NOEXCEPT;
  607. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  608. const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
  609. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
  610. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
  611. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_range(pointer __from_s, pointer __from_e, pointer __to);
  612. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
  613. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
  614. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
  615. _NOEXCEPT_(__alloc_traits::is_always_equal::value);
  616. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  617. void __destruct_at_end(pointer __new_last) _NOEXCEPT
  618. {
  619. if (!__libcpp_is_constant_evaluated())
  620. __invalidate_iterators_past(__new_last);
  621. size_type __old_size = size();
  622. __base_destruct_at_end(__new_last);
  623. __annotate_shrink(__old_size);
  624. }
  625. template <class _Up>
  626. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  627. inline void __push_back_slow_path(_Up&& __x);
  628. template <class... _Args>
  629. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  630. inline void __emplace_back_slow_path(_Args&&... __args);
  631. // The following functions are no-ops outside of AddressSanitizer mode.
  632. // We call annotatations only for the default Allocator because other allocators
  633. // may not meet the AddressSanitizer alignment constraints.
  634. // See the documentation for __sanitizer_annotate_contiguous_container for more details.
  635. #ifndef _LIBCPP_HAS_NO_ASAN
  636. _LIBCPP_CONSTEXPR_SINCE_CXX20
  637. void __annotate_contiguous_container(const void *__beg, const void *__end,
  638. const void *__old_mid,
  639. const void *__new_mid) const
  640. {
  641. if (!__libcpp_is_constant_evaluated() && __beg && is_same<allocator_type, __default_allocator_type>::value)
  642. __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
  643. }
  644. #else
  645. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  646. void __annotate_contiguous_container(const void*, const void*, const void*,
  647. const void*) const _NOEXCEPT {}
  648. #endif
  649. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  650. void __annotate_new(size_type __current_size) const _NOEXCEPT {
  651. __annotate_contiguous_container(data(), data() + capacity(),
  652. data() + capacity(), data() + __current_size);
  653. }
  654. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  655. void __annotate_delete() const _NOEXCEPT {
  656. __annotate_contiguous_container(data(), data() + capacity(),
  657. data() + size(), data() + capacity());
  658. }
  659. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  660. void __annotate_increase(size_type __n) const _NOEXCEPT
  661. {
  662. __annotate_contiguous_container(data(), data() + capacity(),
  663. data() + size(), data() + size() + __n);
  664. }
  665. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  666. void __annotate_shrink(size_type __old_size) const _NOEXCEPT
  667. {
  668. __annotate_contiguous_container(data(), data() + capacity(),
  669. data() + __old_size, data() + size());
  670. }
  671. struct _ConstructTransaction {
  672. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  673. explicit _ConstructTransaction(vector &__v, size_type __n)
  674. : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
  675. #ifndef _LIBCPP_HAS_NO_ASAN
  676. __v_.__annotate_increase(__n);
  677. #endif
  678. }
  679. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
  680. __v_.__end_ = __pos_;
  681. #ifndef _LIBCPP_HAS_NO_ASAN
  682. if (__pos_ != __new_end_) {
  683. __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
  684. }
  685. #endif
  686. }
  687. vector &__v_;
  688. pointer __pos_;
  689. const_pointer const __new_end_;
  690. private:
  691. _ConstructTransaction(_ConstructTransaction const&) = delete;
  692. _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
  693. };
  694. template <class ..._Args>
  695. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  696. void __construct_one_at_end(_Args&& ...__args) {
  697. _ConstructTransaction __tx(*this, 1);
  698. __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_),
  699. std::forward<_Args>(__args)...);
  700. ++__tx.__pos_;
  701. }
  702. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  703. allocator_type& __alloc() _NOEXCEPT
  704. {return this->__end_cap_.second();}
  705. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  706. const allocator_type& __alloc() const _NOEXCEPT
  707. {return this->__end_cap_.second();}
  708. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  709. pointer& __end_cap() _NOEXCEPT
  710. {return this->__end_cap_.first();}
  711. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  712. const pointer& __end_cap() const _NOEXCEPT
  713. {return this->__end_cap_.first();}
  714. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  715. void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
  716. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  717. void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
  718. pointer __soon_to_be_end = this->__end_;
  719. while (__new_last != __soon_to_be_end)
  720. __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
  721. this->__end_ = __new_last;
  722. }
  723. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  724. void __copy_assign_alloc(const vector& __c)
  725. {__copy_assign_alloc(__c, integral_constant<bool,
  726. __alloc_traits::propagate_on_container_copy_assignment::value>());}
  727. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  728. void __move_assign_alloc(vector& __c)
  729. _NOEXCEPT_(
  730. !__alloc_traits::propagate_on_container_move_assignment::value ||
  731. is_nothrow_move_assignable<allocator_type>::value)
  732. {__move_assign_alloc(__c, integral_constant<bool,
  733. __alloc_traits::propagate_on_container_move_assignment::value>());}
  734. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  735. void __throw_length_error() const {
  736. std::__throw_length_error("vector");
  737. }
  738. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  739. void __throw_out_of_range() const {
  740. std::__throw_out_of_range("vector");
  741. }
  742. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  743. void __copy_assign_alloc(const vector& __c, true_type)
  744. {
  745. if (__alloc() != __c.__alloc())
  746. {
  747. __clear();
  748. __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
  749. this->__begin_ = this->__end_ = __end_cap() = nullptr;
  750. }
  751. __alloc() = __c.__alloc();
  752. }
  753. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  754. void __copy_assign_alloc(const vector&, false_type)
  755. {}
  756. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  757. void __move_assign_alloc(vector& __c, true_type)
  758. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  759. {
  760. __alloc() = std::move(__c.__alloc());
  761. }
  762. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
  763. void __move_assign_alloc(vector&, false_type)
  764. _NOEXCEPT
  765. {}
  766. };
  767. #if _LIBCPP_STD_VER >= 17
  768. template<class _InputIterator,
  769. class _Alloc = allocator<__iter_value_type<_InputIterator>>,
  770. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  771. class = enable_if_t<__is_allocator<_Alloc>::value>
  772. >
  773. vector(_InputIterator, _InputIterator)
  774. -> vector<__iter_value_type<_InputIterator>, _Alloc>;
  775. template<class _InputIterator,
  776. class _Alloc,
  777. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  778. class = enable_if_t<__is_allocator<_Alloc>::value>
  779. >
  780. vector(_InputIterator, _InputIterator, _Alloc)
  781. -> vector<__iter_value_type<_InputIterator>, _Alloc>;
  782. #endif
  783. template <class _Tp, class _Allocator>
  784. _LIBCPP_CONSTEXPR_SINCE_CXX20
  785. void
  786. vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
  787. {
  788. __annotate_delete();
  789. using _RevIter = std::reverse_iterator<pointer>;
  790. __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept(
  791. __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
  792. .base();
  793. std::swap(this->__begin_, __v.__begin_);
  794. std::swap(this->__end_, __v.__end_);
  795. std::swap(this->__end_cap(), __v.__end_cap());
  796. __v.__first_ = __v.__begin_;
  797. __annotate_new(size());
  798. std::__debug_db_invalidate_all(this);
  799. }
  800. template <class _Tp, class _Allocator>
  801. _LIBCPP_CONSTEXPR_SINCE_CXX20
  802. typename vector<_Tp, _Allocator>::pointer
  803. vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
  804. {
  805. __annotate_delete();
  806. pointer __r = __v.__begin_;
  807. using _RevIter = std::reverse_iterator<pointer>;
  808. __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept(
  809. __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
  810. .base();
  811. __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
  812. std::swap(this->__begin_, __v.__begin_);
  813. std::swap(this->__end_, __v.__end_);
  814. std::swap(this->__end_cap(), __v.__end_cap());
  815. __v.__first_ = __v.__begin_;
  816. __annotate_new(size());
  817. std::__debug_db_invalidate_all(this);
  818. return __r;
  819. }
  820. template <class _Tp, class _Allocator>
  821. _LIBCPP_CONSTEXPR_SINCE_CXX20
  822. void
  823. vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
  824. {
  825. if (this->__begin_ != nullptr)
  826. {
  827. clear();
  828. __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
  829. this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
  830. }
  831. }
  832. template <class _Tp, class _Allocator>
  833. _LIBCPP_CONSTEXPR_SINCE_CXX20
  834. typename vector<_Tp, _Allocator>::size_type
  835. vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
  836. {
  837. return std::min<size_type>(__alloc_traits::max_size(this->__alloc()),
  838. numeric_limits<difference_type>::max());
  839. }
  840. // Precondition: __new_size > capacity()
  841. template <class _Tp, class _Allocator>
  842. _LIBCPP_CONSTEXPR_SINCE_CXX20
  843. inline _LIBCPP_HIDE_FROM_ABI
  844. typename vector<_Tp, _Allocator>::size_type
  845. vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
  846. {
  847. const size_type __ms = max_size();
  848. if (__new_size > __ms)
  849. this->__throw_length_error();
  850. const size_type __cap = capacity();
  851. if (__cap >= __ms / 2)
  852. return __ms;
  853. return std::max<size_type>(2 * __cap, __new_size);
  854. }
  855. // Default constructs __n objects starting at __end_
  856. // throws if construction throws
  857. // Precondition: __n > 0
  858. // Precondition: size() + __n <= capacity()
  859. // Postcondition: size() == size() + __n
  860. template <class _Tp, class _Allocator>
  861. _LIBCPP_CONSTEXPR_SINCE_CXX20
  862. void
  863. vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
  864. {
  865. _ConstructTransaction __tx(*this, __n);
  866. const_pointer __new_end = __tx.__new_end_;
  867. for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
  868. __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
  869. }
  870. }
  871. // Copy constructs __n objects starting at __end_ from __x
  872. // throws if construction throws
  873. // Precondition: __n > 0
  874. // Precondition: size() + __n <= capacity()
  875. // Postcondition: size() == old size() + __n
  876. // Postcondition: [i] == __x for all i in [size() - __n, __n)
  877. template <class _Tp, class _Allocator>
  878. _LIBCPP_CONSTEXPR_SINCE_CXX20
  879. inline
  880. void
  881. vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
  882. {
  883. _ConstructTransaction __tx(*this, __n);
  884. const_pointer __new_end = __tx.__new_end_;
  885. for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
  886. __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
  887. }
  888. }
  889. template <class _Tp, class _Allocator>
  890. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value, int> >
  891. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  892. vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
  893. {
  894. _ConstructTransaction __tx(*this, __n);
  895. __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
  896. }
  897. template <class _Tp, class _Allocator>
  898. void
  899. vector<_Tp, _Allocator>::__append_uninitialized(size_type __n)
  900. {
  901. if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) {
  902. __annotate_increase(__n);
  903. this->__end_ += __n;
  904. }
  905. else
  906. {
  907. allocator_type& __a = this->__alloc();
  908. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
  909. __v.__uninitialized_at_end(__n);
  910. __swap_out_circular_buffer(__v);
  911. }
  912. }
  913. // Default constructs __n objects starting at __end_
  914. // throws if construction throws
  915. // Postcondition: size() == size() + __n
  916. // Exception safety: strong.
  917. template <class _Tp, class _Allocator>
  918. _LIBCPP_CONSTEXPR_SINCE_CXX20
  919. void
  920. vector<_Tp, _Allocator>::__append(size_type __n)
  921. {
  922. if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
  923. this->__construct_at_end(__n);
  924. else
  925. {
  926. allocator_type& __a = this->__alloc();
  927. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
  928. __v.__construct_at_end(__n);
  929. __swap_out_circular_buffer(__v);
  930. }
  931. }
  932. // Default constructs __n objects starting at __end_
  933. // throws if construction throws
  934. // Postcondition: size() == size() + __n
  935. // Exception safety: strong.
  936. template <class _Tp, class _Allocator>
  937. _LIBCPP_CONSTEXPR_SINCE_CXX20
  938. void
  939. vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
  940. {
  941. if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
  942. this->__construct_at_end(__n, __x);
  943. else
  944. {
  945. allocator_type& __a = this->__alloc();
  946. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
  947. __v.__construct_at_end(__n, __x);
  948. __swap_out_circular_buffer(__v);
  949. }
  950. }
  951. template <class _Tp, class _Allocator>
  952. _LIBCPP_CONSTEXPR_SINCE_CXX20
  953. vector<_Tp, _Allocator>::vector(size_type __n)
  954. {
  955. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  956. std::__debug_db_insert_c(this);
  957. if (__n > 0)
  958. {
  959. __vallocate(__n);
  960. __construct_at_end(__n);
  961. }
  962. __guard.__complete();
  963. }
  964. #if _LIBCPP_STD_VER > 11
  965. template <class _Tp, class _Allocator>
  966. _LIBCPP_CONSTEXPR_SINCE_CXX20
  967. vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
  968. : __end_cap_(nullptr, __a)
  969. {
  970. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  971. std::__debug_db_insert_c(this);
  972. if (__n > 0)
  973. {
  974. __vallocate(__n);
  975. __construct_at_end(__n);
  976. }
  977. __guard.__complete();
  978. }
  979. #endif
  980. template <class _Tp, class _Allocator>
  981. _LIBCPP_CONSTEXPR_SINCE_CXX20
  982. vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
  983. {
  984. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  985. std::__debug_db_insert_c(this);
  986. if (__n > 0)
  987. {
  988. __vallocate(__n);
  989. __construct_at_end(__n, __x);
  990. }
  991. __guard.__complete();
  992. }
  993. template <class _Tp, class _Allocator>
  994. template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  995. is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
  996. int> >
  997. _LIBCPP_CONSTEXPR_SINCE_CXX20
  998. vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
  999. {
  1000. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1001. std::__debug_db_insert_c(this);
  1002. for (; __first != __last; ++__first)
  1003. emplace_back(*__first);
  1004. __guard.__complete();
  1005. }
  1006. template <class _Tp, class _Allocator>
  1007. template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  1008. is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
  1009. int> >
  1010. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1011. vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
  1012. : __end_cap_(nullptr, __a)
  1013. {
  1014. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1015. std::__debug_db_insert_c(this);
  1016. for (; __first != __last; ++__first)
  1017. emplace_back(*__first);
  1018. __guard.__complete();
  1019. }
  1020. template <class _Tp, class _Allocator>
  1021. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  1022. is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
  1023. int> >
  1024. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1025. vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
  1026. {
  1027. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1028. std::__debug_db_insert_c(this);
  1029. size_type __n = static_cast<size_type>(std::distance(__first, __last));
  1030. if (__n > 0)
  1031. {
  1032. __vallocate(__n);
  1033. __construct_at_end(__first, __last, __n);
  1034. }
  1035. __guard.__complete();
  1036. }
  1037. template <class _Tp, class _Allocator>
  1038. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  1039. is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
  1040. int> >
  1041. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1042. vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
  1043. : __end_cap_(nullptr, __a)
  1044. {
  1045. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1046. std::__debug_db_insert_c(this);
  1047. size_type __n = static_cast<size_type>(std::distance(__first, __last));
  1048. if (__n > 0)
  1049. {
  1050. __vallocate(__n);
  1051. __construct_at_end(__first, __last, __n);
  1052. }
  1053. __guard.__complete();
  1054. }
  1055. template <class _Tp, class _Allocator>
  1056. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1057. vector<_Tp, _Allocator>::vector(const vector& __x)
  1058. : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
  1059. {
  1060. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1061. std::__debug_db_insert_c(this);
  1062. size_type __n = __x.size();
  1063. if (__n > 0)
  1064. {
  1065. __vallocate(__n);
  1066. __construct_at_end(__x.__begin_, __x.__end_, __n);
  1067. }
  1068. __guard.__complete();
  1069. }
  1070. template <class _Tp, class _Allocator>
  1071. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1072. vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
  1073. : __end_cap_(nullptr, __a)
  1074. {
  1075. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1076. std::__debug_db_insert_c(this);
  1077. size_type __n = __x.size();
  1078. if (__n > 0)
  1079. {
  1080. __vallocate(__n);
  1081. __construct_at_end(__x.__begin_, __x.__end_, __n);
  1082. }
  1083. __guard.__complete();
  1084. }
  1085. template <class _Tp, class _Allocator>
  1086. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1087. inline _LIBCPP_HIDE_FROM_ABI
  1088. vector<_Tp, _Allocator>::vector(vector&& __x)
  1089. #if _LIBCPP_STD_VER > 14
  1090. noexcept
  1091. #else
  1092. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
  1093. #endif
  1094. : __end_cap_(nullptr, std::move(__x.__alloc()))
  1095. {
  1096. std::__debug_db_insert_c(this);
  1097. std::__debug_db_swap(this, std::addressof(__x));
  1098. this->__begin_ = __x.__begin_;
  1099. this->__end_ = __x.__end_;
  1100. this->__end_cap() = __x.__end_cap();
  1101. __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
  1102. }
  1103. template <class _Tp, class _Allocator>
  1104. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1105. inline _LIBCPP_HIDE_FROM_ABI
  1106. vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
  1107. : __end_cap_(nullptr, __a)
  1108. {
  1109. std::__debug_db_insert_c(this);
  1110. if (__a == __x.__alloc())
  1111. {
  1112. this->__begin_ = __x.__begin_;
  1113. this->__end_ = __x.__end_;
  1114. this->__end_cap() = __x.__end_cap();
  1115. __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
  1116. std::__debug_db_swap(this, std::addressof(__x));
  1117. }
  1118. else
  1119. {
  1120. typedef move_iterator<iterator> _Ip;
  1121. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1122. assign(_Ip(__x.begin()), _Ip(__x.end()));
  1123. __guard.__complete();
  1124. }
  1125. }
  1126. #ifndef _LIBCPP_CXX03_LANG
  1127. template <class _Tp, class _Allocator>
  1128. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1129. inline _LIBCPP_HIDE_FROM_ABI
  1130. vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
  1131. {
  1132. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1133. std::__debug_db_insert_c(this);
  1134. if (__il.size() > 0)
  1135. {
  1136. __vallocate(__il.size());
  1137. __construct_at_end(__il.begin(), __il.end(), __il.size());
  1138. }
  1139. __guard.__complete();
  1140. }
  1141. template <class _Tp, class _Allocator>
  1142. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1143. inline _LIBCPP_HIDE_FROM_ABI
  1144. vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
  1145. : __end_cap_(nullptr, __a)
  1146. {
  1147. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  1148. std::__debug_db_insert_c(this);
  1149. if (__il.size() > 0)
  1150. {
  1151. __vallocate(__il.size());
  1152. __construct_at_end(__il.begin(), __il.end(), __il.size());
  1153. }
  1154. __guard.__complete();
  1155. }
  1156. #endif // _LIBCPP_CXX03_LANG
  1157. template <class _Tp, class _Allocator>
  1158. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1159. inline _LIBCPP_HIDE_FROM_ABI
  1160. vector<_Tp, _Allocator>&
  1161. vector<_Tp, _Allocator>::operator=(vector&& __x)
  1162. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
  1163. {
  1164. __move_assign(__x, integral_constant<bool,
  1165. __alloc_traits::propagate_on_container_move_assignment::value>());
  1166. return *this;
  1167. }
  1168. template <class _Tp, class _Allocator>
  1169. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1170. void
  1171. vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
  1172. _NOEXCEPT_(__alloc_traits::is_always_equal::value)
  1173. {
  1174. if (__alloc() != __c.__alloc())
  1175. {
  1176. typedef move_iterator<iterator> _Ip;
  1177. assign(_Ip(__c.begin()), _Ip(__c.end()));
  1178. }
  1179. else
  1180. __move_assign(__c, true_type());
  1181. }
  1182. template <class _Tp, class _Allocator>
  1183. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1184. void
  1185. vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
  1186. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  1187. {
  1188. __vdeallocate();
  1189. __move_assign_alloc(__c); // this can throw
  1190. this->__begin_ = __c.__begin_;
  1191. this->__end_ = __c.__end_;
  1192. this->__end_cap() = __c.__end_cap();
  1193. __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
  1194. std::__debug_db_swap(this, std::addressof(__c));
  1195. }
  1196. template <class _Tp, class _Allocator>
  1197. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1198. inline _LIBCPP_HIDE_FROM_ABI
  1199. vector<_Tp, _Allocator>&
  1200. vector<_Tp, _Allocator>::operator=(const vector& __x)
  1201. {
  1202. if (this != std::addressof(__x))
  1203. {
  1204. __copy_assign_alloc(__x);
  1205. assign(__x.__begin_, __x.__end_);
  1206. }
  1207. return *this;
  1208. }
  1209. template <class _Tp, class _Allocator>
  1210. template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  1211. is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
  1212. int> >
  1213. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  1214. vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
  1215. {
  1216. clear();
  1217. for (; __first != __last; ++__first)
  1218. emplace_back(*__first);
  1219. }
  1220. template <class _Tp, class _Allocator>
  1221. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  1222. is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
  1223. int> >
  1224. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  1225. vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
  1226. {
  1227. size_type __new_size = static_cast<size_type>(std::distance(__first, __last));
  1228. if (__new_size <= capacity())
  1229. {
  1230. _ForwardIterator __mid = __last;
  1231. bool __growing = false;
  1232. if (__new_size > size())
  1233. {
  1234. __growing = true;
  1235. __mid = __first;
  1236. std::advance(__mid, size());
  1237. }
  1238. pointer __m = std::copy(__first, __mid, this->__begin_);
  1239. if (__growing)
  1240. __construct_at_end(__mid, __last, __new_size - size());
  1241. else
  1242. this->__destruct_at_end(__m);
  1243. }
  1244. else
  1245. {
  1246. __vdeallocate();
  1247. __vallocate(__recommend(__new_size));
  1248. __construct_at_end(__first, __last, __new_size);
  1249. }
  1250. std::__debug_db_invalidate_all(this);
  1251. }
  1252. template <class _Tp, class _Allocator>
  1253. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1254. void
  1255. vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
  1256. {
  1257. if (__n <= capacity())
  1258. {
  1259. size_type __s = size();
  1260. std::fill_n(this->__begin_, std::min(__n, __s), __u);
  1261. if (__n > __s)
  1262. __construct_at_end(__n - __s, __u);
  1263. else
  1264. this->__destruct_at_end(this->__begin_ + __n);
  1265. }
  1266. else
  1267. {
  1268. __vdeallocate();
  1269. __vallocate(__recommend(static_cast<size_type>(__n)));
  1270. __construct_at_end(__n, __u);
  1271. }
  1272. std::__debug_db_invalidate_all(this);
  1273. }
  1274. // We need to save the make_iter function and replace all constructor calls with it
  1275. // Made to support pointer iterators
  1276. template <class _Tp, class _Allocator>
  1277. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1278. inline _LIBCPP_INLINE_VISIBILITY
  1279. typename vector<_Tp, _Allocator>::iterator
  1280. vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
  1281. {
  1282. #if _YNDX_LIBCPP_MAKE_STRING_ITERATOR_POINTERS == 1
  1283. return iterator(__p);
  1284. #else
  1285. return iterator(this, __p);
  1286. #endif
  1287. }
  1288. template <class _Tp, class _Allocator>
  1289. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1290. inline _LIBCPP_INLINE_VISIBILITY
  1291. typename vector<_Tp, _Allocator>::const_iterator
  1292. vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
  1293. {
  1294. #if _YNDX_LIBCPP_MAKE_STRING_ITERATOR_POINTERS == 1
  1295. return const_iterator(__p);
  1296. #else
  1297. return const_iterator(this, __p);
  1298. #endif
  1299. }
  1300. template <class _Tp, class _Allocator>
  1301. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1302. inline _LIBCPP_HIDE_FROM_ABI
  1303. typename vector<_Tp, _Allocator>::iterator
  1304. vector<_Tp, _Allocator>::begin() _NOEXCEPT
  1305. {
  1306. return __make_iter(this->__begin_);
  1307. }
  1308. template <class _Tp, class _Allocator>
  1309. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1310. inline _LIBCPP_HIDE_FROM_ABI
  1311. typename vector<_Tp, _Allocator>::const_iterator
  1312. vector<_Tp, _Allocator>::begin() const _NOEXCEPT
  1313. {
  1314. return __make_iter(this->__begin_);
  1315. }
  1316. template <class _Tp, class _Allocator>
  1317. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1318. inline _LIBCPP_HIDE_FROM_ABI
  1319. typename vector<_Tp, _Allocator>::iterator
  1320. vector<_Tp, _Allocator>::end() _NOEXCEPT
  1321. {
  1322. return __make_iter(this->__end_);
  1323. }
  1324. template <class _Tp, class _Allocator>
  1325. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1326. inline _LIBCPP_HIDE_FROM_ABI
  1327. typename vector<_Tp, _Allocator>::const_iterator
  1328. vector<_Tp, _Allocator>::end() const _NOEXCEPT
  1329. {
  1330. return __make_iter(this->__end_);
  1331. }
  1332. template <class _Tp, class _Allocator>
  1333. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1334. inline _LIBCPP_HIDE_FROM_ABI
  1335. typename vector<_Tp, _Allocator>::reference
  1336. vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
  1337. {
  1338. _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
  1339. return this->__begin_[__n];
  1340. }
  1341. template <class _Tp, class _Allocator>
  1342. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1343. inline _LIBCPP_HIDE_FROM_ABI
  1344. typename vector<_Tp, _Allocator>::const_reference
  1345. vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
  1346. {
  1347. _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
  1348. return this->__begin_[__n];
  1349. }
  1350. template <class _Tp, class _Allocator>
  1351. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1352. typename vector<_Tp, _Allocator>::reference
  1353. vector<_Tp, _Allocator>::at(size_type __n)
  1354. {
  1355. if (__n >= size())
  1356. this->__throw_out_of_range();
  1357. return this->__begin_[__n];
  1358. }
  1359. template <class _Tp, class _Allocator>
  1360. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1361. typename vector<_Tp, _Allocator>::const_reference
  1362. vector<_Tp, _Allocator>::at(size_type __n) const
  1363. {
  1364. if (__n >= size())
  1365. this->__throw_out_of_range();
  1366. return this->__begin_[__n];
  1367. }
  1368. template <class _Tp, class _Allocator>
  1369. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1370. void
  1371. vector<_Tp, _Allocator>::reserve(size_type __n)
  1372. {
  1373. if (__n > capacity())
  1374. {
  1375. if (__n > max_size())
  1376. this->__throw_length_error();
  1377. allocator_type& __a = this->__alloc();
  1378. __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
  1379. __swap_out_circular_buffer(__v);
  1380. }
  1381. }
  1382. template <class _Tp, class _Allocator>
  1383. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1384. void
  1385. vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
  1386. {
  1387. if (capacity() > size())
  1388. {
  1389. #ifndef _LIBCPP_NO_EXCEPTIONS
  1390. try
  1391. {
  1392. #endif // _LIBCPP_NO_EXCEPTIONS
  1393. allocator_type& __a = this->__alloc();
  1394. __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
  1395. __swap_out_circular_buffer(__v);
  1396. #ifndef _LIBCPP_NO_EXCEPTIONS
  1397. }
  1398. catch (...)
  1399. {
  1400. }
  1401. #endif // _LIBCPP_NO_EXCEPTIONS
  1402. }
  1403. }
  1404. template <class _Tp, class _Allocator>
  1405. template <class _Up>
  1406. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1407. void
  1408. vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
  1409. {
  1410. allocator_type& __a = this->__alloc();
  1411. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
  1412. // __v.push_back(std::forward<_Up>(__x));
  1413. __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
  1414. __v.__end_++;
  1415. __swap_out_circular_buffer(__v);
  1416. }
  1417. template <class _Tp, class _Allocator>
  1418. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1419. inline _LIBCPP_HIDE_FROM_ABI
  1420. void
  1421. vector<_Tp, _Allocator>::push_back(const_reference __x)
  1422. {
  1423. if (this->__end_ != this->__end_cap())
  1424. {
  1425. __construct_one_at_end(__x);
  1426. }
  1427. else
  1428. __push_back_slow_path(__x);
  1429. }
  1430. template <class _Tp, class _Allocator>
  1431. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1432. inline _LIBCPP_HIDE_FROM_ABI
  1433. void
  1434. vector<_Tp, _Allocator>::push_back(value_type&& __x)
  1435. {
  1436. if (this->__end_ < this->__end_cap())
  1437. {
  1438. __construct_one_at_end(std::move(__x));
  1439. }
  1440. else
  1441. __push_back_slow_path(std::move(__x));
  1442. }
  1443. template <class _Tp, class _Allocator>
  1444. template <class... _Args>
  1445. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1446. void
  1447. vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
  1448. {
  1449. allocator_type& __a = this->__alloc();
  1450. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
  1451. // __v.emplace_back(std::forward<_Args>(__args)...);
  1452. __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
  1453. __v.__end_++;
  1454. __swap_out_circular_buffer(__v);
  1455. }
  1456. template <class _Tp, class _Allocator>
  1457. template <class... _Args>
  1458. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1459. inline
  1460. #if _LIBCPP_STD_VER > 14
  1461. typename vector<_Tp, _Allocator>::reference
  1462. #else
  1463. void
  1464. #endif
  1465. vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
  1466. {
  1467. if (this->__end_ < this->__end_cap())
  1468. {
  1469. __construct_one_at_end(std::forward<_Args>(__args)...);
  1470. }
  1471. else
  1472. __emplace_back_slow_path(std::forward<_Args>(__args)...);
  1473. #if _LIBCPP_STD_VER > 14
  1474. return this->back();
  1475. #endif
  1476. }
  1477. template <class _Tp, class _Allocator>
  1478. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1479. inline
  1480. void
  1481. vector<_Tp, _Allocator>::pop_back()
  1482. {
  1483. _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
  1484. this->__destruct_at_end(this->__end_ - 1);
  1485. }
  1486. template <class _Tp, class _Allocator>
  1487. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1488. inline _LIBCPP_HIDE_FROM_ABI
  1489. typename vector<_Tp, _Allocator>::iterator
  1490. vector<_Tp, _Allocator>::erase(const_iterator __position)
  1491. {
  1492. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1493. "vector::erase(iterator) called with an iterator not referring to this vector");
  1494. _LIBCPP_ASSERT(__position != end(),
  1495. "vector::erase(iterator) called with a non-dereferenceable iterator");
  1496. difference_type __ps = __position - cbegin();
  1497. pointer __p = this->__begin_ + __ps;
  1498. this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
  1499. if (!__libcpp_is_constant_evaluated())
  1500. this->__invalidate_iterators_past(__p - 1);
  1501. return __make_iter(__p);
  1502. }
  1503. template <class _Tp, class _Allocator>
  1504. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1505. typename vector<_Tp, _Allocator>::iterator
  1506. vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
  1507. {
  1508. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__first)) == this,
  1509. "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
  1510. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__last)) == this,
  1511. "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
  1512. _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
  1513. pointer __p = this->__begin_ + (__first - begin());
  1514. if (__first != __last) {
  1515. this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
  1516. if (!__libcpp_is_constant_evaluated())
  1517. this->__invalidate_iterators_past(__p - 1);
  1518. }
  1519. return __make_iter(__p);
  1520. }
  1521. template <class _Tp, class _Allocator>
  1522. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1523. void
  1524. vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
  1525. {
  1526. pointer __old_last = this->__end_;
  1527. difference_type __n = __old_last - __to;
  1528. {
  1529. pointer __i = __from_s + __n;
  1530. _ConstructTransaction __tx(*this, __from_e - __i);
  1531. for (pointer __pos = __tx.__pos_; __i < __from_e;
  1532. ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
  1533. __alloc_traits::construct(this->__alloc(),
  1534. std::__to_address(__pos),
  1535. std::move(*__i));
  1536. }
  1537. }
  1538. std::move_backward(__from_s, __from_s + __n, __old_last);
  1539. }
  1540. template <class _Tp, class _Allocator>
  1541. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1542. typename vector<_Tp, _Allocator>::iterator
  1543. vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
  1544. {
  1545. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1546. "vector::insert(iterator, x) called with an iterator not referring to this vector");
  1547. pointer __p = this->__begin_ + (__position - begin());
  1548. // We can't compare unrelated pointers inside constant expressions
  1549. if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap())
  1550. {
  1551. if (__p == this->__end_)
  1552. {
  1553. __construct_one_at_end(__x);
  1554. }
  1555. else
  1556. {
  1557. __move_range(__p, this->__end_, __p + 1);
  1558. const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
  1559. if (__p <= __xr && __xr < this->__end_)
  1560. ++__xr;
  1561. *__p = *__xr;
  1562. }
  1563. }
  1564. else
  1565. {
  1566. allocator_type& __a = this->__alloc();
  1567. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
  1568. __v.push_back(__x);
  1569. __p = __swap_out_circular_buffer(__v, __p);
  1570. }
  1571. return __make_iter(__p);
  1572. }
  1573. template <class _Tp, class _Allocator>
  1574. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1575. typename vector<_Tp, _Allocator>::iterator
  1576. vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
  1577. {
  1578. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1579. "vector::insert(iterator, x) called with an iterator not referring to this vector");
  1580. pointer __p = this->__begin_ + (__position - begin());
  1581. if (this->__end_ < this->__end_cap())
  1582. {
  1583. if (__p == this->__end_)
  1584. {
  1585. __construct_one_at_end(std::move(__x));
  1586. }
  1587. else
  1588. {
  1589. __move_range(__p, this->__end_, __p + 1);
  1590. *__p = std::move(__x);
  1591. }
  1592. }
  1593. else
  1594. {
  1595. allocator_type& __a = this->__alloc();
  1596. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
  1597. __v.push_back(std::move(__x));
  1598. __p = __swap_out_circular_buffer(__v, __p);
  1599. }
  1600. return __make_iter(__p);
  1601. }
  1602. template <class _Tp, class _Allocator>
  1603. template <class... _Args>
  1604. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1605. typename vector<_Tp, _Allocator>::iterator
  1606. vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
  1607. {
  1608. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1609. "vector::emplace(iterator, x) called with an iterator not referring to this vector");
  1610. pointer __p = this->__begin_ + (__position - begin());
  1611. if (this->__end_ < this->__end_cap())
  1612. {
  1613. if (__p == this->__end_)
  1614. {
  1615. __construct_one_at_end(std::forward<_Args>(__args)...);
  1616. }
  1617. else
  1618. {
  1619. __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
  1620. __move_range(__p, this->__end_, __p + 1);
  1621. *__p = std::move(__tmp.get());
  1622. }
  1623. }
  1624. else
  1625. {
  1626. allocator_type& __a = this->__alloc();
  1627. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
  1628. __v.emplace_back(std::forward<_Args>(__args)...);
  1629. __p = __swap_out_circular_buffer(__v, __p);
  1630. }
  1631. return __make_iter(__p);
  1632. }
  1633. template <class _Tp, class _Allocator>
  1634. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1635. typename vector<_Tp, _Allocator>::iterator
  1636. vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
  1637. {
  1638. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1639. "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
  1640. pointer __p = this->__begin_ + (__position - begin());
  1641. if (__n > 0)
  1642. {
  1643. // We can't compare unrelated pointers inside constant expressions
  1644. if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_))
  1645. {
  1646. size_type __old_n = __n;
  1647. pointer __old_last = this->__end_;
  1648. if (__n > static_cast<size_type>(this->__end_ - __p))
  1649. {
  1650. size_type __cx = __n - (this->__end_ - __p);
  1651. __construct_at_end(__cx, __x);
  1652. __n -= __cx;
  1653. }
  1654. if (__n > 0)
  1655. {
  1656. __move_range(__p, __old_last, __p + __old_n);
  1657. const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
  1658. if (__p <= __xr && __xr < this->__end_)
  1659. __xr += __old_n;
  1660. std::fill_n(__p, __n, *__xr);
  1661. }
  1662. }
  1663. else
  1664. {
  1665. allocator_type& __a = this->__alloc();
  1666. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
  1667. __v.__construct_at_end(__n, __x);
  1668. __p = __swap_out_circular_buffer(__v, __p);
  1669. }
  1670. }
  1671. return __make_iter(__p);
  1672. }
  1673. template <class _Tp, class _Allocator>
  1674. template <class _InputIterator, __enable_if_t<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
  1675. is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
  1676. int> >
  1677. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
  1678. vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
  1679. {
  1680. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1681. "vector::insert(iterator, range) called with an iterator not referring to this vector");
  1682. difference_type __off = __position - begin();
  1683. pointer __p = this->__begin_ + __off;
  1684. allocator_type& __a = this->__alloc();
  1685. pointer __old_last = this->__end_;
  1686. for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
  1687. {
  1688. __construct_one_at_end(*__first);
  1689. }
  1690. __split_buffer<value_type, allocator_type&> __v(__a);
  1691. if (__first != __last)
  1692. {
  1693. #ifndef _LIBCPP_NO_EXCEPTIONS
  1694. try
  1695. {
  1696. #endif // _LIBCPP_NO_EXCEPTIONS
  1697. __v.__construct_at_end(__first, __last);
  1698. difference_type __old_size = __old_last - this->__begin_;
  1699. difference_type __old_p = __p - this->__begin_;
  1700. reserve(__recommend(size() + __v.size()));
  1701. __p = this->__begin_ + __old_p;
  1702. __old_last = this->__begin_ + __old_size;
  1703. #ifndef _LIBCPP_NO_EXCEPTIONS
  1704. }
  1705. catch (...)
  1706. {
  1707. erase(__make_iter(__old_last), end());
  1708. throw;
  1709. }
  1710. #endif // _LIBCPP_NO_EXCEPTIONS
  1711. }
  1712. __p = std::rotate(__p, __old_last, this->__end_);
  1713. insert(__make_iter(__p), std::make_move_iterator(__v.begin()),
  1714. std::make_move_iterator(__v.end()));
  1715. return begin() + __off;
  1716. }
  1717. template <class _Tp, class _Allocator>
  1718. template <class _ForwardIterator, __enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
  1719. is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
  1720. int> >
  1721. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
  1722. vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
  1723. {
  1724. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__position)) == this,
  1725. "vector::insert(iterator, range) called with an iterator not referring to this vector");
  1726. pointer __p = this->__begin_ + (__position - begin());
  1727. difference_type __n = std::distance(__first, __last);
  1728. if (__n > 0)
  1729. {
  1730. if (__n <= this->__end_cap() - this->__end_)
  1731. {
  1732. size_type __old_n = __n;
  1733. pointer __old_last = this->__end_;
  1734. _ForwardIterator __m = __last;
  1735. difference_type __dx = this->__end_ - __p;
  1736. if (__n > __dx)
  1737. {
  1738. __m = __first;
  1739. difference_type __diff = this->__end_ - __p;
  1740. std::advance(__m, __diff);
  1741. __construct_at_end(__m, __last, __n - __diff);
  1742. __n = __dx;
  1743. }
  1744. if (__n > 0)
  1745. {
  1746. __move_range(__p, __old_last, __p + __old_n);
  1747. std::copy(__first, __m, __p);
  1748. }
  1749. }
  1750. else
  1751. {
  1752. allocator_type& __a = this->__alloc();
  1753. __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
  1754. __v.__construct_at_end(__first, __last);
  1755. __p = __swap_out_circular_buffer(__v, __p);
  1756. }
  1757. }
  1758. return __make_iter(__p);
  1759. }
  1760. template <class _Tp, class _Allocator>
  1761. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1762. void
  1763. vector<_Tp, _Allocator>::resize(size_type __sz)
  1764. {
  1765. size_type __cs = size();
  1766. if (__cs < __sz)
  1767. this->__append(__sz - __cs);
  1768. else if (__cs > __sz)
  1769. this->__destruct_at_end(this->__begin_ + __sz);
  1770. }
  1771. #if _YNDX_LIBCXX_ENABLE_VECTOR_POD_RESIZE_UNINITIALIZED
  1772. template <class _Tp, class _Allocator>
  1773. void
  1774. vector<_Tp, _Allocator>::resize_uninitialized(size_type __sz)
  1775. {
  1776. size_type __cs = size();
  1777. if (__cs < __sz)
  1778. this->__append_uninitialized(__sz - __cs);
  1779. else if (__cs > __sz) {
  1780. this->__end_ = this->__begin_ + __sz;
  1781. __annotate_shrink(__cs);
  1782. }
  1783. }
  1784. #endif
  1785. template <class _Tp, class _Allocator>
  1786. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1787. void
  1788. vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
  1789. {
  1790. size_type __cs = size();
  1791. if (__cs < __sz)
  1792. this->__append(__sz - __cs, __x);
  1793. else if (__cs > __sz)
  1794. this->__destruct_at_end(this->__begin_ + __sz);
  1795. }
  1796. template <class _Tp, class _Allocator>
  1797. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1798. void
  1799. vector<_Tp, _Allocator>::swap(vector& __x)
  1800. #if _LIBCPP_STD_VER >= 14
  1801. _NOEXCEPT
  1802. #else
  1803. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  1804. __is_nothrow_swappable<allocator_type>::value)
  1805. #endif
  1806. {
  1807. _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
  1808. this->__alloc() == __x.__alloc(),
  1809. "vector::swap: Either propagate_on_container_swap must be true"
  1810. " or the allocators must compare equal");
  1811. std::swap(this->__begin_, __x.__begin_);
  1812. std::swap(this->__end_, __x.__end_);
  1813. std::swap(this->__end_cap(), __x.__end_cap());
  1814. std::__swap_allocator(this->__alloc(), __x.__alloc(),
  1815. integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
  1816. std::__debug_db_swap(this, std::addressof(__x));
  1817. }
  1818. template <class _Tp, class _Allocator>
  1819. _LIBCPP_CONSTEXPR_SINCE_CXX20
  1820. bool
  1821. vector<_Tp, _Allocator>::__invariants() const
  1822. {
  1823. if (this->__begin_ == nullptr)
  1824. {
  1825. if (this->__end_ != nullptr || this->__end_cap() != nullptr)
  1826. return false;
  1827. }
  1828. else
  1829. {
  1830. if (this->__begin_ > this->__end_)
  1831. return false;
  1832. if (this->__begin_ == this->__end_cap())
  1833. return false;
  1834. if (this->__end_ > this->__end_cap())
  1835. return false;
  1836. }
  1837. return true;
  1838. }
  1839. #ifdef _LIBCPP_ENABLE_DEBUG_MODE
  1840. template <class _Tp, class _Allocator>
  1841. bool
  1842. vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
  1843. {
  1844. return this->__begin_ <= __i->base() && __i->base() < this->__end_;
  1845. }
  1846. template <class _Tp, class _Allocator>
  1847. bool
  1848. vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
  1849. {
  1850. return this->__begin_ < __i->base() && __i->base() <= this->__end_;
  1851. }
  1852. template <class _Tp, class _Allocator>
  1853. bool
  1854. vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
  1855. {
  1856. const_pointer __p = __i->base() + __n;
  1857. return this->__begin_ <= __p && __p <= this->__end_;
  1858. }
  1859. template <class _Tp, class _Allocator>
  1860. bool
  1861. vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  1862. {
  1863. const_pointer __p = __i->base() + __n;
  1864. return this->__begin_ <= __p && __p < this->__end_;
  1865. }
  1866. #endif // _LIBCPP_ENABLE_DEBUG_MODE
  1867. template <class _Tp, class _Allocator>
  1868. inline _LIBCPP_HIDE_FROM_ABI
  1869. void
  1870. vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
  1871. #ifdef _LIBCPP_ENABLE_DEBUG_MODE
  1872. __c_node* __c = __get_db()->__find_c_and_lock(this);
  1873. for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
  1874. --__p;
  1875. const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
  1876. if (__i->base() > __new_last) {
  1877. (*__p)->__c_ = nullptr;
  1878. if (--__c->end_ != __p)
  1879. std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
  1880. }
  1881. }
  1882. __get_db()->unlock();
  1883. #else
  1884. ((void)__new_last);
  1885. #endif
  1886. }
  1887. #if _YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION == 1
  1888. // vector<bool>
  1889. template <class _Allocator> class vector<bool, _Allocator>;
  1890. template <class _Allocator> struct hash<vector<bool, _Allocator> >;
  1891. template <class _Allocator>
  1892. struct __has_storage_type<vector<bool, _Allocator> >
  1893. {
  1894. static const bool value = true;
  1895. };
  1896. template <class _Allocator>
  1897. class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
  1898. {
  1899. public:
  1900. typedef vector __self;
  1901. typedef bool value_type;
  1902. typedef _Allocator allocator_type;
  1903. typedef allocator_traits<allocator_type> __alloc_traits;
  1904. typedef typename __alloc_traits::size_type size_type;
  1905. typedef typename __alloc_traits::difference_type difference_type;
  1906. typedef size_type __storage_type;
  1907. typedef __bit_iterator<vector, false> pointer;
  1908. typedef __bit_iterator<vector, true> const_pointer;
  1909. typedef pointer iterator;
  1910. typedef const_pointer const_iterator;
  1911. typedef std::reverse_iterator<iterator> reverse_iterator;
  1912. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  1913. private:
  1914. typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
  1915. typedef allocator_traits<__storage_allocator> __storage_traits;
  1916. typedef typename __storage_traits::pointer __storage_pointer;
  1917. typedef typename __storage_traits::const_pointer __const_storage_pointer;
  1918. __storage_pointer __begin_;
  1919. size_type __size_;
  1920. __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
  1921. public:
  1922. typedef __bit_reference<vector> reference;
  1923. #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
  1924. using const_reference = bool;
  1925. #else
  1926. typedef __bit_const_reference<vector> const_reference;
  1927. #endif
  1928. private:
  1929. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1930. size_type& __cap() _NOEXCEPT
  1931. {return __cap_alloc_.first();}
  1932. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1933. const size_type& __cap() const _NOEXCEPT
  1934. {return __cap_alloc_.first();}
  1935. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1936. __storage_allocator& __alloc() _NOEXCEPT
  1937. {return __cap_alloc_.second();}
  1938. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1939. const __storage_allocator& __alloc() const _NOEXCEPT
  1940. {return __cap_alloc_.second();}
  1941. static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
  1942. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1943. static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
  1944. {return __n * __bits_per_word;}
  1945. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1946. static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
  1947. {return (__n - 1) / __bits_per_word + 1;}
  1948. public:
  1949. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1950. vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
  1951. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
  1952. #if _LIBCPP_STD_VER <= 14
  1953. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
  1954. #else
  1955. _NOEXCEPT;
  1956. #endif
  1957. private:
  1958. class __destroy_vector {
  1959. public:
  1960. _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {}
  1961. _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
  1962. if (__vec_.__begin_ != nullptr)
  1963. __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
  1964. std::__debug_db_invalidate_all(this);
  1965. }
  1966. private:
  1967. vector& __vec_;
  1968. };
  1969. public:
  1970. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); }
  1971. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
  1972. #if _LIBCPP_STD_VER > 11
  1973. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
  1974. #endif
  1975. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
  1976. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v, const allocator_type& __a);
  1977. template <class _InputIterator>
  1978. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last,
  1979. typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
  1980. template <class _InputIterator>
  1981. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
  1982. typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
  1983. template <class _ForwardIterator>
  1984. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last,
  1985. typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
  1986. template <class _ForwardIterator>
  1987. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
  1988. typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
  1989. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
  1990. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
  1991. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
  1992. #ifndef _LIBCPP_CXX03_LANG
  1993. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
  1994. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il, const allocator_type& __a);
  1995. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  1996. vector& operator=(initializer_list<value_type> __il)
  1997. {assign(__il.begin(), __il.end()); return *this;}
  1998. #endif // !_LIBCPP_CXX03_LANG
  1999. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2000. vector(vector&& __v)
  2001. #if _LIBCPP_STD_VER > 14
  2002. noexcept;
  2003. #else
  2004. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
  2005. #endif
  2006. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
  2007. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2008. vector& operator=(vector&& __v)
  2009. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
  2010. template <class _InputIterator>
  2011. typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2012. void
  2013. >::type
  2014. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
  2015. template <class _ForwardIterator>
  2016. typename enable_if
  2017. <
  2018. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2019. void
  2020. >::type
  2021. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
  2022. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
  2023. #ifndef _LIBCPP_CXX03_LANG
  2024. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2025. void assign(initializer_list<value_type> __il)
  2026. {assign(__il.begin(), __il.end());}
  2027. #endif
  2028. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT
  2029. {return allocator_type(this->__alloc());}
  2030. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
  2031. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2032. size_type capacity() const _NOEXCEPT
  2033. {return __internal_cap_to_external(__cap());}
  2034. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2035. size_type size() const _NOEXCEPT
  2036. {return __size_;}
  2037. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2038. bool empty() const _NOEXCEPT
  2039. {return __size_ == 0;}
  2040. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
  2041. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
  2042. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2043. iterator begin() _NOEXCEPT
  2044. {return __make_iter(0);}
  2045. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2046. const_iterator begin() const _NOEXCEPT
  2047. {return __make_iter(0);}
  2048. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2049. iterator end() _NOEXCEPT
  2050. {return __make_iter(__size_);}
  2051. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2052. const_iterator end() const _NOEXCEPT
  2053. {return __make_iter(__size_);}
  2054. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2055. reverse_iterator rbegin() _NOEXCEPT
  2056. {return reverse_iterator(end());}
  2057. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2058. const_reverse_iterator rbegin() const _NOEXCEPT
  2059. {return const_reverse_iterator(end());}
  2060. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2061. reverse_iterator rend() _NOEXCEPT
  2062. {return reverse_iterator(begin());}
  2063. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2064. const_reverse_iterator rend() const _NOEXCEPT
  2065. {return const_reverse_iterator(begin());}
  2066. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2067. const_iterator cbegin() const _NOEXCEPT
  2068. {return __make_iter(0);}
  2069. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2070. const_iterator cend() const _NOEXCEPT
  2071. {return __make_iter(__size_);}
  2072. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2073. const_reverse_iterator crbegin() const _NOEXCEPT
  2074. {return rbegin();}
  2075. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2076. const_reverse_iterator crend() const _NOEXCEPT
  2077. {return rend();}
  2078. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) {return __make_ref(__n);}
  2079. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {return __make_ref(__n);}
  2080. _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
  2081. _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
  2082. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() {return __make_ref(0);}
  2083. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {return __make_ref(0);}
  2084. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() {return __make_ref(__size_ - 1);}
  2085. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const {return __make_ref(__size_ - 1);}
  2086. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
  2087. #if _LIBCPP_STD_VER > 11
  2088. template <class... _Args>
  2089. #if _LIBCPP_STD_VER > 14
  2090. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
  2091. #else
  2092. _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
  2093. #endif
  2094. {
  2095. push_back ( value_type ( std::forward<_Args>(__args)... ));
  2096. #if _LIBCPP_STD_VER > 14
  2097. return this->back();
  2098. #endif
  2099. }
  2100. #endif
  2101. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {--__size_;}
  2102. #if _LIBCPP_STD_VER > 11
  2103. template <class... _Args>
  2104. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args)
  2105. { return insert ( __position, value_type ( std::forward<_Args>(__args)... )); }
  2106. #endif
  2107. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
  2108. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
  2109. template <class _InputIterator>
  2110. typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2111. iterator
  2112. >::type
  2113. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
  2114. template <class _ForwardIterator>
  2115. typename enable_if
  2116. <
  2117. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2118. iterator
  2119. >::type
  2120. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
  2121. #ifndef _LIBCPP_CXX03_LANG
  2122. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2123. iterator insert(const_iterator __position, initializer_list<value_type> __il)
  2124. {return insert(__position, __il.begin(), __il.end());}
  2125. #endif
  2126. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
  2127. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
  2128. _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2129. void clear() _NOEXCEPT {__size_ = 0;}
  2130. _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
  2131. #if _LIBCPP_STD_VER >= 14
  2132. _NOEXCEPT;
  2133. #else
  2134. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  2135. __is_nothrow_swappable<allocator_type>::value);
  2136. #endif
  2137. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT { std::swap(__x, __y); }
  2138. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
  2139. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
  2140. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
  2141. private:
  2142. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  2143. void __throw_length_error() const {
  2144. std::__throw_length_error("vector");
  2145. }
  2146. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  2147. void __throw_out_of_range() const {
  2148. std::__throw_out_of_range("vector");
  2149. }
  2150. // Allocate space for __n objects
  2151. // throws length_error if __n > max_size()
  2152. // throws (probably bad_alloc) if memory run out
  2153. // Precondition: __begin_ == __end_ == __cap() == 0
  2154. // Precondition: __n > 0
  2155. // Postcondition: capacity() >= __n
  2156. // Postcondition: size() == 0
  2157. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
  2158. if (__n > max_size())
  2159. __throw_length_error();
  2160. auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
  2161. __begin_ = __allocation.ptr;
  2162. __size_ = 0;
  2163. __cap() = __allocation.count;
  2164. if (__libcpp_is_constant_evaluated()) {
  2165. for (size_type __i = 0; __i != __cap(); ++__i)
  2166. std::__construct_at(std::__to_address(__begin_) + __i);
  2167. }
  2168. }
  2169. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
  2170. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2171. static size_type __align_it(size_type __new_size) _NOEXCEPT
  2172. {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
  2173. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
  2174. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
  2175. template <class _ForwardIterator>
  2176. typename enable_if
  2177. <
  2178. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2179. void
  2180. >::type
  2181. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
  2182. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
  2183. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2184. reference __make_ref(size_type __pos) _NOEXCEPT
  2185. {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
  2186. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2187. const_reference __make_ref(size_type __pos) const _NOEXCEPT {
  2188. return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
  2189. __storage_type(1) << __pos % __bits_per_word);
  2190. }
  2191. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2192. iterator __make_iter(size_type __pos) _NOEXCEPT
  2193. {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
  2194. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2195. const_iterator __make_iter(size_type __pos) const _NOEXCEPT
  2196. {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
  2197. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2198. iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
  2199. {return begin() + (__p - cbegin());}
  2200. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2201. void __copy_assign_alloc(const vector& __v)
  2202. {__copy_assign_alloc(__v, integral_constant<bool,
  2203. __storage_traits::propagate_on_container_copy_assignment::value>());}
  2204. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2205. void __copy_assign_alloc(const vector& __c, true_type)
  2206. {
  2207. if (__alloc() != __c.__alloc())
  2208. __vdeallocate();
  2209. __alloc() = __c.__alloc();
  2210. }
  2211. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2212. void __copy_assign_alloc(const vector&, false_type)
  2213. {}
  2214. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
  2215. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
  2216. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
  2217. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2218. void __move_assign_alloc(vector& __c)
  2219. _NOEXCEPT_(
  2220. !__storage_traits::propagate_on_container_move_assignment::value ||
  2221. is_nothrow_move_assignable<allocator_type>::value)
  2222. {__move_assign_alloc(__c, integral_constant<bool,
  2223. __storage_traits::propagate_on_container_move_assignment::value>());}
  2224. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2225. void __move_assign_alloc(vector& __c, true_type)
  2226. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  2227. {
  2228. __alloc() = std::move(__c.__alloc());
  2229. }
  2230. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2231. void __move_assign_alloc(vector&, false_type)
  2232. _NOEXCEPT
  2233. {}
  2234. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
  2235. friend class __bit_reference<vector>;
  2236. friend class __bit_const_reference<vector>;
  2237. friend class __bit_iterator<vector, false>;
  2238. friend class __bit_iterator<vector, true>;
  2239. friend struct __bit_array<vector>;
  2240. friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
  2241. };
  2242. template <class _Allocator>
  2243. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2244. vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
  2245. {
  2246. if (this->__begin_ != nullptr)
  2247. {
  2248. __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
  2249. std::__debug_db_invalidate_all(this);
  2250. this->__begin_ = nullptr;
  2251. this->__size_ = this->__cap() = 0;
  2252. }
  2253. }
  2254. template <class _Allocator>
  2255. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2256. typename vector<bool, _Allocator>::size_type
  2257. vector<bool, _Allocator>::max_size() const _NOEXCEPT
  2258. {
  2259. size_type __amax = __storage_traits::max_size(__alloc());
  2260. size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
  2261. if (__nmax / __bits_per_word <= __amax)
  2262. return __nmax;
  2263. return __internal_cap_to_external(__amax);
  2264. }
  2265. // Precondition: __new_size > capacity()
  2266. template <class _Allocator>
  2267. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2268. typename vector<bool, _Allocator>::size_type
  2269. vector<bool, _Allocator>::__recommend(size_type __new_size) const
  2270. {
  2271. const size_type __ms = max_size();
  2272. if (__new_size > __ms)
  2273. this->__throw_length_error();
  2274. const size_type __cap = capacity();
  2275. if (__cap >= __ms / 2)
  2276. return __ms;
  2277. return std::max(2 * __cap, __align_it(__new_size));
  2278. }
  2279. // Default constructs __n objects starting at __end_
  2280. // Precondition: __n > 0
  2281. // Precondition: size() + __n <= capacity()
  2282. // Postcondition: size() == size() + __n
  2283. template <class _Allocator>
  2284. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2285. void
  2286. vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
  2287. {
  2288. size_type __old_size = this->__size_;
  2289. this->__size_ += __n;
  2290. if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
  2291. {
  2292. if (this->__size_ <= __bits_per_word)
  2293. this->__begin_[0] = __storage_type(0);
  2294. else
  2295. this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
  2296. }
  2297. std::fill_n(__make_iter(__old_size), __n, __x);
  2298. }
  2299. template <class _Allocator>
  2300. template <class _ForwardIterator>
  2301. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2302. typename enable_if
  2303. <
  2304. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2305. void
  2306. >::type
  2307. vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
  2308. {
  2309. size_type __old_size = this->__size_;
  2310. this->__size_ += std::distance(__first, __last);
  2311. if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
  2312. {
  2313. if (this->__size_ <= __bits_per_word)
  2314. this->__begin_[0] = __storage_type(0);
  2315. else
  2316. this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
  2317. }
  2318. std::copy(__first, __last, __make_iter(__old_size));
  2319. }
  2320. template <class _Allocator>
  2321. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2322. vector<bool, _Allocator>::vector()
  2323. _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
  2324. : __begin_(nullptr),
  2325. __size_(0),
  2326. __cap_alloc_(0, __default_init_tag())
  2327. {
  2328. }
  2329. template <class _Allocator>
  2330. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2331. vector<bool, _Allocator>::vector(const allocator_type& __a)
  2332. #if _LIBCPP_STD_VER <= 14
  2333. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
  2334. #else
  2335. _NOEXCEPT
  2336. #endif
  2337. : __begin_(nullptr),
  2338. __size_(0),
  2339. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2340. {
  2341. }
  2342. template <class _Allocator>
  2343. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2344. vector<bool, _Allocator>::vector(size_type __n)
  2345. : __begin_(nullptr),
  2346. __size_(0),
  2347. __cap_alloc_(0, __default_init_tag())
  2348. {
  2349. if (__n > 0)
  2350. {
  2351. __vallocate(__n);
  2352. __construct_at_end(__n, false);
  2353. }
  2354. }
  2355. #if _LIBCPP_STD_VER > 11
  2356. template <class _Allocator>
  2357. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2358. vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
  2359. : __begin_(nullptr),
  2360. __size_(0),
  2361. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2362. {
  2363. if (__n > 0)
  2364. {
  2365. __vallocate(__n);
  2366. __construct_at_end(__n, false);
  2367. }
  2368. }
  2369. #endif
  2370. template <class _Allocator>
  2371. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2372. vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
  2373. : __begin_(nullptr),
  2374. __size_(0),
  2375. __cap_alloc_(0, __default_init_tag())
  2376. {
  2377. if (__n > 0)
  2378. {
  2379. __vallocate(__n);
  2380. __construct_at_end(__n, __x);
  2381. }
  2382. }
  2383. template <class _Allocator>
  2384. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2385. vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
  2386. : __begin_(nullptr),
  2387. __size_(0),
  2388. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2389. {
  2390. if (__n > 0)
  2391. {
  2392. __vallocate(__n);
  2393. __construct_at_end(__n, __x);
  2394. }
  2395. }
  2396. template <class _Allocator>
  2397. template <class _InputIterator>
  2398. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2399. vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
  2400. typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
  2401. : __begin_(nullptr),
  2402. __size_(0),
  2403. __cap_alloc_(0, __default_init_tag())
  2404. {
  2405. #ifndef _LIBCPP_NO_EXCEPTIONS
  2406. try
  2407. {
  2408. #endif // _LIBCPP_NO_EXCEPTIONS
  2409. for (; __first != __last; ++__first)
  2410. push_back(*__first);
  2411. #ifndef _LIBCPP_NO_EXCEPTIONS
  2412. }
  2413. catch (...)
  2414. {
  2415. if (__begin_ != nullptr)
  2416. __storage_traits::deallocate(__alloc(), __begin_, __cap());
  2417. std::__debug_db_invalidate_all(this);
  2418. throw;
  2419. }
  2420. #endif // _LIBCPP_NO_EXCEPTIONS
  2421. }
  2422. template <class _Allocator>
  2423. template <class _InputIterator>
  2424. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2425. vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
  2426. typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
  2427. : __begin_(nullptr),
  2428. __size_(0),
  2429. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2430. {
  2431. #ifndef _LIBCPP_NO_EXCEPTIONS
  2432. try
  2433. {
  2434. #endif // _LIBCPP_NO_EXCEPTIONS
  2435. for (; __first != __last; ++__first)
  2436. push_back(*__first);
  2437. #ifndef _LIBCPP_NO_EXCEPTIONS
  2438. }
  2439. catch (...)
  2440. {
  2441. if (__begin_ != nullptr)
  2442. __storage_traits::deallocate(__alloc(), __begin_, __cap());
  2443. std::__debug_db_invalidate_all(this);
  2444. throw;
  2445. }
  2446. #endif // _LIBCPP_NO_EXCEPTIONS
  2447. }
  2448. template <class _Allocator>
  2449. template <class _ForwardIterator>
  2450. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2451. vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
  2452. typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
  2453. : __begin_(nullptr),
  2454. __size_(0),
  2455. __cap_alloc_(0, __default_init_tag())
  2456. {
  2457. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  2458. size_type __n = static_cast<size_type>(std::distance(__first, __last));
  2459. if (__n > 0)
  2460. {
  2461. __vallocate(__n);
  2462. __construct_at_end(__first, __last);
  2463. }
  2464. __guard.__complete();
  2465. }
  2466. template <class _Allocator>
  2467. template <class _ForwardIterator>
  2468. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2469. vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
  2470. typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
  2471. : __begin_(nullptr),
  2472. __size_(0),
  2473. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2474. {
  2475. auto __guard = std::__make_exception_guard(__destroy_vector(*this));
  2476. size_type __n = static_cast<size_type>(std::distance(__first, __last));
  2477. if (__n > 0)
  2478. {
  2479. __vallocate(__n);
  2480. __construct_at_end(__first, __last);
  2481. }
  2482. __guard.__complete();
  2483. }
  2484. #ifndef _LIBCPP_CXX03_LANG
  2485. template <class _Allocator>
  2486. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2487. vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
  2488. : __begin_(nullptr),
  2489. __size_(0),
  2490. __cap_alloc_(0, __default_init_tag())
  2491. {
  2492. size_type __n = static_cast<size_type>(__il.size());
  2493. if (__n > 0)
  2494. {
  2495. __vallocate(__n);
  2496. __construct_at_end(__il.begin(), __il.end());
  2497. }
  2498. }
  2499. template <class _Allocator>
  2500. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2501. vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
  2502. : __begin_(nullptr),
  2503. __size_(0),
  2504. __cap_alloc_(0, static_cast<__storage_allocator>(__a))
  2505. {
  2506. size_type __n = static_cast<size_type>(__il.size());
  2507. if (__n > 0)
  2508. {
  2509. __vallocate(__n);
  2510. __construct_at_end(__il.begin(), __il.end());
  2511. }
  2512. }
  2513. #endif // _LIBCPP_CXX03_LANG
  2514. template <class _Allocator>
  2515. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2516. vector<bool, _Allocator>::vector(const vector& __v)
  2517. : __begin_(nullptr),
  2518. __size_(0),
  2519. __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
  2520. {
  2521. if (__v.size() > 0)
  2522. {
  2523. __vallocate(__v.size());
  2524. __construct_at_end(__v.begin(), __v.end());
  2525. }
  2526. }
  2527. template <class _Allocator>
  2528. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2529. vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
  2530. : __begin_(nullptr),
  2531. __size_(0),
  2532. __cap_alloc_(0, __a)
  2533. {
  2534. if (__v.size() > 0)
  2535. {
  2536. __vallocate(__v.size());
  2537. __construct_at_end(__v.begin(), __v.end());
  2538. }
  2539. }
  2540. template <class _Allocator>
  2541. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2542. vector<bool, _Allocator>&
  2543. vector<bool, _Allocator>::operator=(const vector& __v)
  2544. {
  2545. if (this != std::addressof(__v))
  2546. {
  2547. __copy_assign_alloc(__v);
  2548. if (__v.__size_)
  2549. {
  2550. if (__v.__size_ > capacity())
  2551. {
  2552. __vdeallocate();
  2553. __vallocate(__v.__size_);
  2554. }
  2555. std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
  2556. }
  2557. __size_ = __v.__size_;
  2558. }
  2559. return *this;
  2560. }
  2561. template <class _Allocator>
  2562. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
  2563. #if _LIBCPP_STD_VER > 14
  2564. _NOEXCEPT
  2565. #else
  2566. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
  2567. #endif
  2568. : __begin_(__v.__begin_),
  2569. __size_(__v.__size_),
  2570. __cap_alloc_(std::move(__v.__cap_alloc_)) {
  2571. __v.__begin_ = nullptr;
  2572. __v.__size_ = 0;
  2573. __v.__cap() = 0;
  2574. }
  2575. template <class _Allocator>
  2576. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2577. vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
  2578. : __begin_(nullptr),
  2579. __size_(0),
  2580. __cap_alloc_(0, __a)
  2581. {
  2582. if (__a == allocator_type(__v.__alloc()))
  2583. {
  2584. this->__begin_ = __v.__begin_;
  2585. this->__size_ = __v.__size_;
  2586. this->__cap() = __v.__cap();
  2587. __v.__begin_ = nullptr;
  2588. __v.__cap() = __v.__size_ = 0;
  2589. }
  2590. else if (__v.size() > 0)
  2591. {
  2592. __vallocate(__v.size());
  2593. __construct_at_end(__v.begin(), __v.end());
  2594. }
  2595. }
  2596. template <class _Allocator>
  2597. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2598. vector<bool, _Allocator>&
  2599. vector<bool, _Allocator>::operator=(vector&& __v)
  2600. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
  2601. {
  2602. __move_assign(__v, integral_constant<bool,
  2603. __storage_traits::propagate_on_container_move_assignment::value>());
  2604. return *this;
  2605. }
  2606. template <class _Allocator>
  2607. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2608. vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
  2609. {
  2610. if (__alloc() != __c.__alloc())
  2611. assign(__c.begin(), __c.end());
  2612. else
  2613. __move_assign(__c, true_type());
  2614. }
  2615. template <class _Allocator>
  2616. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2617. vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
  2618. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  2619. {
  2620. __vdeallocate();
  2621. __move_assign_alloc(__c);
  2622. this->__begin_ = __c.__begin_;
  2623. this->__size_ = __c.__size_;
  2624. this->__cap() = __c.__cap();
  2625. __c.__begin_ = nullptr;
  2626. __c.__cap() = __c.__size_ = 0;
  2627. }
  2628. template <class _Allocator>
  2629. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2630. vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
  2631. {
  2632. __size_ = 0;
  2633. if (__n > 0)
  2634. {
  2635. size_type __c = capacity();
  2636. if (__n <= __c)
  2637. __size_ = __n;
  2638. else
  2639. {
  2640. vector __v(get_allocator());
  2641. __v.reserve(__recommend(__n));
  2642. __v.__size_ = __n;
  2643. swap(__v);
  2644. }
  2645. std::fill_n(begin(), __n, __x);
  2646. }
  2647. std::__debug_db_invalidate_all(this);
  2648. }
  2649. template <class _Allocator>
  2650. template <class _InputIterator>
  2651. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2652. void
  2653. >::type
  2654. vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
  2655. {
  2656. clear();
  2657. for (; __first != __last; ++__first)
  2658. push_back(*__first);
  2659. }
  2660. template <class _Allocator>
  2661. template <class _ForwardIterator>
  2662. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2663. typename enable_if
  2664. <
  2665. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2666. void
  2667. >::type
  2668. vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
  2669. {
  2670. clear();
  2671. difference_type __ns = std::distance(__first, __last);
  2672. _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
  2673. const size_t __n = static_cast<size_type>(__ns);
  2674. if (__n)
  2675. {
  2676. if (__n > capacity())
  2677. {
  2678. __vdeallocate();
  2679. __vallocate(__n);
  2680. }
  2681. __construct_at_end(__first, __last);
  2682. }
  2683. }
  2684. template <class _Allocator>
  2685. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2686. vector<bool, _Allocator>::reserve(size_type __n)
  2687. {
  2688. if (__n > capacity())
  2689. {
  2690. if (__n > max_size())
  2691. this->__throw_length_error();
  2692. vector __v(this->get_allocator());
  2693. __v.__vallocate(__n);
  2694. __v.__construct_at_end(this->begin(), this->end());
  2695. swap(__v);
  2696. std::__debug_db_invalidate_all(this);
  2697. }
  2698. }
  2699. template <class _Allocator>
  2700. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2701. vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
  2702. {
  2703. if (__external_cap_to_internal(size()) > __cap())
  2704. {
  2705. #ifndef _LIBCPP_NO_EXCEPTIONS
  2706. try
  2707. {
  2708. #endif // _LIBCPP_NO_EXCEPTIONS
  2709. vector(*this, allocator_type(__alloc())).swap(*this);
  2710. #ifndef _LIBCPP_NO_EXCEPTIONS
  2711. }
  2712. catch (...)
  2713. {
  2714. }
  2715. #endif // _LIBCPP_NO_EXCEPTIONS
  2716. }
  2717. }
  2718. template <class _Allocator>
  2719. typename vector<bool, _Allocator>::reference
  2720. vector<bool, _Allocator>::at(size_type __n)
  2721. {
  2722. if (__n >= size())
  2723. this->__throw_out_of_range();
  2724. return (*this)[__n];
  2725. }
  2726. template <class _Allocator>
  2727. typename vector<bool, _Allocator>::const_reference
  2728. vector<bool, _Allocator>::at(size_type __n) const
  2729. {
  2730. if (__n >= size())
  2731. this->__throw_out_of_range();
  2732. return (*this)[__n];
  2733. }
  2734. template <class _Allocator>
  2735. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2736. vector<bool, _Allocator>::push_back(const value_type& __x)
  2737. {
  2738. if (this->__size_ == this->capacity())
  2739. reserve(__recommend(this->__size_ + 1));
  2740. ++this->__size_;
  2741. back() = __x;
  2742. }
  2743. template <class _Allocator>
  2744. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
  2745. vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
  2746. {
  2747. iterator __r;
  2748. if (size() < capacity())
  2749. {
  2750. const_iterator __old_end = end();
  2751. ++__size_;
  2752. std::copy_backward(__position, __old_end, end());
  2753. __r = __const_iterator_cast(__position);
  2754. }
  2755. else
  2756. {
  2757. vector __v(get_allocator());
  2758. __v.reserve(__recommend(__size_ + 1));
  2759. __v.__size_ = __size_ + 1;
  2760. __r = std::copy(cbegin(), __position, __v.begin());
  2761. std::copy_backward(__position, cend(), __v.end());
  2762. swap(__v);
  2763. }
  2764. *__r = __x;
  2765. return __r;
  2766. }
  2767. template <class _Allocator>
  2768. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
  2769. vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
  2770. {
  2771. iterator __r;
  2772. size_type __c = capacity();
  2773. if (__n <= __c && size() <= __c - __n)
  2774. {
  2775. const_iterator __old_end = end();
  2776. __size_ += __n;
  2777. std::copy_backward(__position, __old_end, end());
  2778. __r = __const_iterator_cast(__position);
  2779. }
  2780. else
  2781. {
  2782. vector __v(get_allocator());
  2783. __v.reserve(__recommend(__size_ + __n));
  2784. __v.__size_ = __size_ + __n;
  2785. __r = std::copy(cbegin(), __position, __v.begin());
  2786. std::copy_backward(__position, cend(), __v.end());
  2787. swap(__v);
  2788. }
  2789. std::fill_n(__r, __n, __x);
  2790. return __r;
  2791. }
  2792. template <class _Allocator>
  2793. template <class _InputIterator>
  2794. _LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2795. typename vector<bool, _Allocator>::iterator
  2796. >::type
  2797. vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
  2798. {
  2799. difference_type __off = __position - begin();
  2800. iterator __p = __const_iterator_cast(__position);
  2801. iterator __old_end = end();
  2802. for (; size() != capacity() && __first != __last; ++__first)
  2803. {
  2804. ++this->__size_;
  2805. back() = *__first;
  2806. }
  2807. vector __v(get_allocator());
  2808. if (__first != __last)
  2809. {
  2810. #ifndef _LIBCPP_NO_EXCEPTIONS
  2811. try
  2812. {
  2813. #endif // _LIBCPP_NO_EXCEPTIONS
  2814. __v.assign(__first, __last);
  2815. difference_type __old_size = static_cast<difference_type>(__old_end - begin());
  2816. difference_type __old_p = __p - begin();
  2817. reserve(__recommend(size() + __v.size()));
  2818. __p = begin() + __old_p;
  2819. __old_end = begin() + __old_size;
  2820. #ifndef _LIBCPP_NO_EXCEPTIONS
  2821. }
  2822. catch (...)
  2823. {
  2824. erase(__old_end, end());
  2825. throw;
  2826. }
  2827. #endif // _LIBCPP_NO_EXCEPTIONS
  2828. }
  2829. __p = std::rotate(__p, __old_end, end());
  2830. insert(__p, __v.begin(), __v.end());
  2831. return begin() + __off;
  2832. }
  2833. template <class _Allocator>
  2834. template <class _ForwardIterator>
  2835. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2836. typename enable_if
  2837. <
  2838. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2839. typename vector<bool, _Allocator>::iterator
  2840. >::type
  2841. vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
  2842. {
  2843. const difference_type __n_signed = std::distance(__first, __last);
  2844. _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
  2845. const size_type __n = static_cast<size_type>(__n_signed);
  2846. iterator __r;
  2847. size_type __c = capacity();
  2848. if (__n <= __c && size() <= __c - __n)
  2849. {
  2850. const_iterator __old_end = end();
  2851. __size_ += __n;
  2852. std::copy_backward(__position, __old_end, end());
  2853. __r = __const_iterator_cast(__position);
  2854. }
  2855. else
  2856. {
  2857. vector __v(get_allocator());
  2858. __v.reserve(__recommend(__size_ + __n));
  2859. __v.__size_ = __size_ + __n;
  2860. __r = std::copy(cbegin(), __position, __v.begin());
  2861. std::copy_backward(__position, cend(), __v.end());
  2862. swap(__v);
  2863. }
  2864. std::copy(__first, __last, __r);
  2865. return __r;
  2866. }
  2867. template <class _Allocator>
  2868. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2869. typename vector<bool, _Allocator>::iterator
  2870. vector<bool, _Allocator>::erase(const_iterator __position)
  2871. {
  2872. iterator __r = __const_iterator_cast(__position);
  2873. std::copy(__position + 1, this->cend(), __r);
  2874. --__size_;
  2875. return __r;
  2876. }
  2877. template <class _Allocator>
  2878. _LIBCPP_CONSTEXPR_SINCE_CXX20
  2879. typename vector<bool, _Allocator>::iterator
  2880. vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
  2881. {
  2882. iterator __r = __const_iterator_cast(__first);
  2883. difference_type __d = __last - __first;
  2884. std::copy(__last, this->cend(), __r);
  2885. __size_ -= __d;
  2886. return __r;
  2887. }
  2888. template <class _Allocator>
  2889. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2890. vector<bool, _Allocator>::swap(vector& __x)
  2891. #if _LIBCPP_STD_VER >= 14
  2892. _NOEXCEPT
  2893. #else
  2894. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  2895. __is_nothrow_swappable<allocator_type>::value)
  2896. #endif
  2897. {
  2898. std::swap(this->__begin_, __x.__begin_);
  2899. std::swap(this->__size_, __x.__size_);
  2900. std::swap(this->__cap(), __x.__cap());
  2901. std::__swap_allocator(this->__alloc(), __x.__alloc(),
  2902. integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
  2903. }
  2904. template <class _Allocator>
  2905. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2906. vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
  2907. {
  2908. size_type __cs = size();
  2909. if (__cs < __sz)
  2910. {
  2911. iterator __r;
  2912. size_type __c = capacity();
  2913. size_type __n = __sz - __cs;
  2914. if (__n <= __c && __cs <= __c - __n)
  2915. {
  2916. __r = end();
  2917. __size_ += __n;
  2918. }
  2919. else
  2920. {
  2921. vector __v(get_allocator());
  2922. __v.reserve(__recommend(__size_ + __n));
  2923. __v.__size_ = __size_ + __n;
  2924. __r = std::copy(cbegin(), cend(), __v.begin());
  2925. swap(__v);
  2926. }
  2927. std::fill_n(__r, __n, __x);
  2928. }
  2929. else
  2930. __size_ = __sz;
  2931. }
  2932. template <class _Allocator>
  2933. _LIBCPP_CONSTEXPR_SINCE_CXX20 void
  2934. vector<bool, _Allocator>::flip() _NOEXCEPT
  2935. {
  2936. // do middle whole words
  2937. size_type __n = __size_;
  2938. __storage_pointer __p = __begin_;
  2939. for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
  2940. *__p = ~*__p;
  2941. // do last partial word
  2942. if (__n > 0)
  2943. {
  2944. __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
  2945. __storage_type __b = *__p & __m;
  2946. *__p &= ~__m;
  2947. *__p |= ~__b & __m;
  2948. }
  2949. }
  2950. template <class _Allocator>
  2951. _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
  2952. vector<bool, _Allocator>::__invariants() const
  2953. {
  2954. if (this->__begin_ == nullptr)
  2955. {
  2956. if (this->__size_ != 0 || this->__cap() != 0)
  2957. return false;
  2958. }
  2959. else
  2960. {
  2961. if (this->__cap() == 0)
  2962. return false;
  2963. if (this->__size_ > this->capacity())
  2964. return false;
  2965. }
  2966. return true;
  2967. }
  2968. template <class _Allocator>
  2969. _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
  2970. vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
  2971. {
  2972. size_t __h = 0;
  2973. // do middle whole words
  2974. size_type __n = __size_;
  2975. __storage_pointer __p = __begin_;
  2976. for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
  2977. __h ^= *__p;
  2978. // do last partial word
  2979. if (__n > 0)
  2980. {
  2981. const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
  2982. __h ^= *__p & __m;
  2983. }
  2984. return __h;
  2985. }
  2986. template <class _Allocator>
  2987. struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
  2988. : public __unary_function<vector<bool, _Allocator>, size_t>
  2989. {
  2990. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
  2991. size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
  2992. {return __vec.__hash_code();}
  2993. };
  2994. #else // _YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION
  2995. // Hash function implementation for uncompressed std::vector<bool> which returns the same result.
  2996. template <class _Allocator>
  2997. struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
  2998. : public unary_function<vector<bool, _Allocator>, size_t>
  2999. {
  3000. _LIBCPP_INLINE_VISIBILITY
  3001. size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
  3002. {
  3003. size_t __h = 0;
  3004. size_t __idx = 0;
  3005. size_t __n = __vec.size();
  3006. constexpr size_t __bits_per_word = sizeof(typename allocator_traits<_Allocator>::size_type) * CHAR_BIT;
  3007. static_assert(sizeof(typename allocator_traits<_Allocator>::size_type) <= sizeof(size_t), "size_type constraint violated");
  3008. for (;__idx + __bits_per_word <= __n;) {
  3009. for (size_t __bit = 0; __bit < __bits_per_word; __bit++, __idx++) {
  3010. __h ^= static_cast<size_t>(__vec[__idx]) << __bit;
  3011. }
  3012. }
  3013. for (size_t __bit = 0; __idx < __n; __bit++, __idx++) {
  3014. __h ^= static_cast<size_t>(__vec[__idx]) << __bit;
  3015. }
  3016. return __h;
  3017. }
  3018. };
  3019. #endif // _YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION
  3020. template <class _Tp, class _Allocator>
  3021. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3022. inline _LIBCPP_HIDE_FROM_ABI
  3023. bool
  3024. operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3025. {
  3026. const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
  3027. return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
  3028. }
  3029. template <class _Tp, class _Allocator>
  3030. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3031. inline _LIBCPP_HIDE_FROM_ABI
  3032. bool
  3033. operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3034. {
  3035. return !(__x == __y);
  3036. }
  3037. template <class _Tp, class _Allocator>
  3038. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3039. inline _LIBCPP_HIDE_FROM_ABI
  3040. bool
  3041. operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3042. {
  3043. return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
  3044. }
  3045. template <class _Tp, class _Allocator>
  3046. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3047. inline _LIBCPP_HIDE_FROM_ABI
  3048. bool
  3049. operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3050. {
  3051. return __y < __x;
  3052. }
  3053. template <class _Tp, class _Allocator>
  3054. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3055. inline _LIBCPP_HIDE_FROM_ABI
  3056. bool
  3057. operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3058. {
  3059. return !(__x < __y);
  3060. }
  3061. template <class _Tp, class _Allocator>
  3062. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3063. inline _LIBCPP_HIDE_FROM_ABI
  3064. bool
  3065. operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
  3066. {
  3067. return !(__y < __x);
  3068. }
  3069. template <class _Tp, class _Allocator>
  3070. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3071. inline _LIBCPP_HIDE_FROM_ABI
  3072. void
  3073. swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
  3074. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  3075. {
  3076. __x.swap(__y);
  3077. }
  3078. #if _LIBCPP_STD_VER > 17
  3079. template <class _Tp, class _Allocator, class _Up>
  3080. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3081. inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
  3082. erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
  3083. auto __old_size = __c.size();
  3084. __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
  3085. return __old_size - __c.size();
  3086. }
  3087. template <class _Tp, class _Allocator, class _Predicate>
  3088. _LIBCPP_CONSTEXPR_SINCE_CXX20
  3089. inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
  3090. erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
  3091. auto __old_size = __c.size();
  3092. __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
  3093. return __old_size - __c.size();
  3094. }
  3095. template <>
  3096. inline constexpr bool __format::__enable_insertable<vector<char>> = true;
  3097. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  3098. template <>
  3099. inline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
  3100. #endif
  3101. #endif // _LIBCPP_STD_VER > 17
  3102. #if _LIBCPP_STD_VER > 20
  3103. template <class _Tp, class CharT>
  3104. // Since is-vector-bool-reference is only used once it's inlined here.
  3105. requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
  3106. struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_Tp, CharT> {
  3107. private:
  3108. formatter<bool, CharT> __underlying_;
  3109. public:
  3110. template <class _ParseContext>
  3111. _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
  3112. return __underlying_.parse(__ctx);
  3113. }
  3114. template <class _FormatContext>
  3115. _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
  3116. return __underlying_.format(__ref, __ctx);
  3117. }
  3118. };
  3119. #endif // _LIBCPP_STD_VER > 20
  3120. _LIBCPP_END_NAMESPACE_STD
  3121. #if _LIBCPP_STD_VER > 14
  3122. _LIBCPP_BEGIN_NAMESPACE_STD
  3123. namespace pmr {
  3124. template <class _ValueT>
  3125. using vector = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
  3126. } // namespace pmr
  3127. _LIBCPP_END_NAMESPACE_STD
  3128. #endif
  3129. _LIBCPP_POP_MACROS
  3130. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  3131. # include <algorithm>
  3132. # include <atomic>
  3133. # include <concepts>
  3134. # include <typeinfo>
  3135. # include <utility>
  3136. #endif
  3137. #endif // _LIBCPP_VECTOR