vector 110 KB

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