string 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529
  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_STRING
  10. #define _LIBCPP_STRING
  11. /*
  12. string synopsis
  13. namespace std
  14. {
  15. template <class stateT>
  16. class fpos
  17. {
  18. private:
  19. stateT st;
  20. public:
  21. fpos(streamoff = streamoff());
  22. operator streamoff() const;
  23. stateT state() const;
  24. void state(stateT);
  25. fpos& operator+=(streamoff);
  26. fpos operator+ (streamoff) const;
  27. fpos& operator-=(streamoff);
  28. fpos operator- (streamoff) const;
  29. };
  30. template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
  31. template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
  32. template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
  33. template <class charT>
  34. struct char_traits
  35. {
  36. typedef charT char_type;
  37. typedef ... int_type;
  38. typedef streamoff off_type;
  39. typedef streampos pos_type;
  40. typedef mbstate_t state_type;
  41. static void assign(char_type& c1, const char_type& c2) noexcept;
  42. static constexpr bool eq(char_type c1, char_type c2) noexcept;
  43. static constexpr bool lt(char_type c1, char_type c2) noexcept;
  44. static int compare(const char_type* s1, const char_type* s2, size_t n);
  45. static size_t length(const char_type* s);
  46. static const char_type* find(const char_type* s, size_t n, const char_type& a);
  47. static char_type* move(char_type* s1, const char_type* s2, size_t n);
  48. static char_type* copy(char_type* s1, const char_type* s2, size_t n);
  49. static char_type* assign(char_type* s, size_t n, char_type a);
  50. static constexpr int_type not_eof(int_type c) noexcept;
  51. static constexpr char_type to_char_type(int_type c) noexcept;
  52. static constexpr int_type to_int_type(char_type c) noexcept;
  53. static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
  54. static constexpr int_type eof() noexcept;
  55. };
  56. template <> struct char_traits<char>;
  57. template <> struct char_traits<wchar_t>;
  58. template <> struct char_traits<char8_t>; // C++20
  59. template <> struct char_traits<char16_t>;
  60. template <> struct char_traits<char32_t>;
  61. template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
  62. class basic_string
  63. {
  64. public:
  65. // types:
  66. typedef traits traits_type;
  67. typedef typename traits_type::char_type value_type;
  68. typedef Allocator allocator_type;
  69. typedef typename allocator_type::size_type size_type;
  70. typedef typename allocator_type::difference_type difference_type;
  71. typedef typename allocator_type::reference reference;
  72. typedef typename allocator_type::const_reference const_reference;
  73. typedef typename allocator_type::pointer pointer;
  74. typedef typename allocator_type::const_pointer const_pointer;
  75. typedef implementation-defined iterator;
  76. typedef implementation-defined const_iterator;
  77. typedef std::reverse_iterator<iterator> reverse_iterator;
  78. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  79. static const size_type npos = -1;
  80. basic_string()
  81. noexcept(is_nothrow_default_constructible<allocator_type>::value);
  82. explicit basic_string(const allocator_type& a);
  83. basic_string(const basic_string& str);
  84. basic_string(basic_string&& str)
  85. noexcept(is_nothrow_move_constructible<allocator_type>::value);
  86. basic_string(const basic_string& str, size_type pos,
  87. const allocator_type& a = allocator_type());
  88. basic_string(const basic_string& str, size_type pos, size_type n,
  89. const Allocator& a = Allocator());
  90. template<class T>
  91. basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
  92. template <class T>
  93. explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
  94. basic_string(const value_type* s, const allocator_type& a = allocator_type());
  95. basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
  96. basic_string(nullptr_t) = delete; // C++2b
  97. basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
  98. template<class InputIterator>
  99. basic_string(InputIterator begin, InputIterator end,
  100. const allocator_type& a = allocator_type());
  101. basic_string(initializer_list<value_type>, const Allocator& = Allocator());
  102. basic_string(const basic_string&, const Allocator&);
  103. basic_string(basic_string&&, const Allocator&);
  104. ~basic_string();
  105. operator basic_string_view<charT, traits>() const noexcept;
  106. basic_string& operator=(const basic_string& str);
  107. template <class T>
  108. basic_string& operator=(const T& t); // C++17
  109. basic_string& operator=(basic_string&& str)
  110. noexcept(
  111. allocator_type::propagate_on_container_move_assignment::value ||
  112. allocator_type::is_always_equal::value ); // C++17
  113. basic_string& operator=(const value_type* s);
  114. basic_string& operator=(nullptr_t) = delete; // C++2b
  115. basic_string& operator=(value_type c);
  116. basic_string& operator=(initializer_list<value_type>);
  117. iterator begin() noexcept;
  118. const_iterator begin() const noexcept;
  119. iterator end() noexcept;
  120. const_iterator end() const noexcept;
  121. reverse_iterator rbegin() noexcept;
  122. const_reverse_iterator rbegin() const noexcept;
  123. reverse_iterator rend() noexcept;
  124. const_reverse_iterator rend() const noexcept;
  125. const_iterator cbegin() const noexcept;
  126. const_iterator cend() const noexcept;
  127. const_reverse_iterator crbegin() const noexcept;
  128. const_reverse_iterator crend() const noexcept;
  129. size_type size() const noexcept;
  130. size_type length() const noexcept;
  131. size_type max_size() const noexcept;
  132. size_type capacity() const noexcept;
  133. void resize(size_type n, value_type c);
  134. void resize(size_type n);
  135. template<class Operation>
  136. constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
  137. void reserve(size_type res_arg);
  138. void reserve(); // deprecated in C++20
  139. void shrink_to_fit();
  140. void clear() noexcept;
  141. bool empty() const noexcept;
  142. const_reference operator[](size_type pos) const;
  143. reference operator[](size_type pos);
  144. const_reference at(size_type n) const;
  145. reference at(size_type n);
  146. basic_string& operator+=(const basic_string& str);
  147. template <class T>
  148. basic_string& operator+=(const T& t); // C++17
  149. basic_string& operator+=(const value_type* s);
  150. basic_string& operator+=(value_type c);
  151. basic_string& operator+=(initializer_list<value_type>);
  152. basic_string& append(const basic_string& str);
  153. template <class T>
  154. basic_string& append(const T& t); // C++17
  155. basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
  156. template <class T>
  157. basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
  158. basic_string& append(const value_type* s, size_type n);
  159. basic_string& append(const value_type* s);
  160. basic_string& append(size_type n, value_type c);
  161. template<class InputIterator>
  162. basic_string& append(InputIterator first, InputIterator last);
  163. basic_string& append(initializer_list<value_type>);
  164. void push_back(value_type c);
  165. void pop_back();
  166. reference front();
  167. const_reference front() const;
  168. reference back();
  169. const_reference back() const;
  170. basic_string& assign(const basic_string& str);
  171. template <class T>
  172. basic_string& assign(const T& t); // C++17
  173. basic_string& assign(basic_string&& str);
  174. basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
  175. template <class T>
  176. basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
  177. basic_string& assign(const value_type* s, size_type n);
  178. basic_string& assign(const value_type* s);
  179. basic_string& assign(size_type n, value_type c);
  180. template<class InputIterator>
  181. basic_string& assign(InputIterator first, InputIterator last);
  182. basic_string& assign(initializer_list<value_type>);
  183. basic_string& insert(size_type pos1, const basic_string& str);
  184. template <class T>
  185. basic_string& insert(size_type pos1, const T& t);
  186. basic_string& insert(size_type pos1, const basic_string& str,
  187. size_type pos2, size_type n);
  188. template <class T>
  189. basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
  190. basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
  191. basic_string& insert(size_type pos, const value_type* s);
  192. basic_string& insert(size_type pos, size_type n, value_type c);
  193. iterator insert(const_iterator p, value_type c);
  194. iterator insert(const_iterator p, size_type n, value_type c);
  195. template<class InputIterator>
  196. iterator insert(const_iterator p, InputIterator first, InputIterator last);
  197. iterator insert(const_iterator p, initializer_list<value_type>);
  198. basic_string& erase(size_type pos = 0, size_type n = npos);
  199. iterator erase(const_iterator position);
  200. iterator erase(const_iterator first, const_iterator last);
  201. basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
  202. template <class T>
  203. basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
  204. basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
  205. size_type pos2, size_type n2=npos); // C++14
  206. template <class T>
  207. basic_string& replace(size_type pos1, size_type n1, const T& t,
  208. size_type pos2, size_type n); // C++17
  209. basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
  210. basic_string& replace(size_type pos, size_type n1, const value_type* s);
  211. basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
  212. basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
  213. template <class T>
  214. basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
  215. basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
  216. basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
  217. basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
  218. template<class InputIterator>
  219. basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
  220. basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
  221. size_type copy(value_type* s, size_type n, size_type pos = 0) const;
  222. basic_string substr(size_type pos = 0, size_type n = npos) const;
  223. void swap(basic_string& str)
  224. noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
  225. allocator_traits<allocator_type>::is_always_equal::value); // C++17
  226. const value_type* c_str() const noexcept;
  227. const value_type* data() const noexcept;
  228. value_type* data() noexcept; // C++17
  229. allocator_type get_allocator() const noexcept;
  230. size_type find(const basic_string& str, size_type pos = 0) const noexcept;
  231. template <class T>
  232. size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
  233. size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
  234. size_type find(const value_type* s, size_type pos = 0) const noexcept;
  235. size_type find(value_type c, size_type pos = 0) const noexcept;
  236. size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
  237. template <class T>
  238. size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
  239. size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
  240. size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
  241. size_type rfind(value_type c, size_type pos = npos) const noexcept;
  242. size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
  243. template <class T>
  244. size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
  245. size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
  246. size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
  247. size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
  248. size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
  249. template <class T>
  250. size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension
  251. size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
  252. size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
  253. size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
  254. size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
  255. template <class T>
  256. size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
  257. size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
  258. size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
  259. size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
  260. size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
  261. template <class T>
  262. size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
  263. size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
  264. size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
  265. size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
  266. int compare(const basic_string& str) const noexcept;
  267. template <class T>
  268. int compare(const T& t) const noexcept; // C++17, noexcept as an extension
  269. int compare(size_type pos1, size_type n1, const basic_string& str) const;
  270. template <class T>
  271. int compare(size_type pos1, size_type n1, const T& t) const; // C++17
  272. int compare(size_type pos1, size_type n1, const basic_string& str,
  273. size_type pos2, size_type n2=npos) const; // C++14
  274. template <class T>
  275. int compare(size_type pos1, size_type n1, const T& t,
  276. size_type pos2, size_type n2=npos) const; // C++17
  277. int compare(const value_type* s) const noexcept;
  278. int compare(size_type pos1, size_type n1, const value_type* s) const;
  279. int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
  280. bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
  281. bool starts_with(charT c) const noexcept; // C++20
  282. bool starts_with(const charT* s) const; // C++20
  283. bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
  284. bool ends_with(charT c) const noexcept; // C++20
  285. bool ends_with(const charT* s) const; // C++20
  286. constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
  287. constexpr bool contains(charT c) const noexcept; // C++2b
  288. constexpr bool contains(const charT* s) const; // C++2b
  289. bool __invariants() const;
  290. };
  291. template<class InputIterator,
  292. class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  293. basic_string(InputIterator, InputIterator, Allocator = Allocator())
  294. -> basic_string<typename iterator_traits<InputIterator>::value_type,
  295. char_traits<typename iterator_traits<InputIterator>::value_type>,
  296. Allocator>; // C++17
  297. template<class charT, class traits, class Allocator>
  298. basic_string<charT, traits, Allocator>
  299. operator+(const basic_string<charT, traits, Allocator>& lhs,
  300. const basic_string<charT, traits, Allocator>& rhs);
  301. template<class charT, class traits, class Allocator>
  302. basic_string<charT, traits, Allocator>
  303. operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
  304. template<class charT, class traits, class Allocator>
  305. basic_string<charT, traits, Allocator>
  306. operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
  307. template<class charT, class traits, class Allocator>
  308. basic_string<charT, traits, Allocator>
  309. operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
  310. template<class charT, class traits, class Allocator>
  311. basic_string<charT, traits, Allocator>
  312. operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
  313. template<class charT, class traits, class Allocator>
  314. bool operator==(const basic_string<charT, traits, Allocator>& lhs,
  315. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  316. template<class charT, class traits, class Allocator>
  317. bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  318. template<class charT, class traits, class Allocator>
  319. bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
  320. template<class charT, class traits, class Allocator>
  321. bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
  322. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  323. template<class charT, class traits, class Allocator>
  324. bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  325. template<class charT, class traits, class Allocator>
  326. bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
  327. template<class charT, class traits, class Allocator>
  328. bool operator< (const basic_string<charT, traits, Allocator>& lhs,
  329. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  330. template<class charT, class traits, class Allocator>
  331. bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
  332. template<class charT, class traits, class Allocator>
  333. bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  334. template<class charT, class traits, class Allocator>
  335. bool operator> (const basic_string<charT, traits, Allocator>& lhs,
  336. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  337. template<class charT, class traits, class Allocator>
  338. bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
  339. template<class charT, class traits, class Allocator>
  340. bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  341. template<class charT, class traits, class Allocator>
  342. bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
  343. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  344. template<class charT, class traits, class Allocator>
  345. bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
  346. template<class charT, class traits, class Allocator>
  347. bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  348. template<class charT, class traits, class Allocator>
  349. bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
  350. const basic_string<charT, traits, Allocator>& rhs) noexcept;
  351. template<class charT, class traits, class Allocator>
  352. bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
  353. template<class charT, class traits, class Allocator>
  354. bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
  355. template<class charT, class traits, class Allocator>
  356. void swap(basic_string<charT, traits, Allocator>& lhs,
  357. basic_string<charT, traits, Allocator>& rhs)
  358. noexcept(noexcept(lhs.swap(rhs)));
  359. template<class charT, class traits, class Allocator>
  360. basic_istream<charT, traits>&
  361. operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
  362. template<class charT, class traits, class Allocator>
  363. basic_ostream<charT, traits>&
  364. operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
  365. template<class charT, class traits, class Allocator>
  366. basic_istream<charT, traits>&
  367. getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
  368. charT delim);
  369. template<class charT, class traits, class Allocator>
  370. basic_istream<charT, traits>&
  371. getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
  372. template<class charT, class traits, class Allocator, class U>
  373. typename basic_string<charT, traits, Allocator>::size_type
  374. erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
  375. template<class charT, class traits, class Allocator, class Predicate>
  376. typename basic_string<charT, traits, Allocator>::size_type
  377. erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
  378. typedef basic_string<char> string;
  379. typedef basic_string<wchar_t> wstring;
  380. typedef basic_string<char8_t> u8string; // C++20
  381. typedef basic_string<char16_t> u16string;
  382. typedef basic_string<char32_t> u32string;
  383. int stoi (const string& str, size_t* idx = nullptr, int base = 10);
  384. long stol (const string& str, size_t* idx = nullptr, int base = 10);
  385. unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10);
  386. long long stoll (const string& str, size_t* idx = nullptr, int base = 10);
  387. unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
  388. float stof (const string& str, size_t* idx = nullptr);
  389. double stod (const string& str, size_t* idx = nullptr);
  390. long double stold(const string& str, size_t* idx = nullptr);
  391. string to_string(int val);
  392. string to_string(unsigned val);
  393. string to_string(long val);
  394. string to_string(unsigned long val);
  395. string to_string(long long val);
  396. string to_string(unsigned long long val);
  397. string to_string(float val);
  398. string to_string(double val);
  399. string to_string(long double val);
  400. int stoi (const wstring& str, size_t* idx = nullptr, int base = 10);
  401. long stol (const wstring& str, size_t* idx = nullptr, int base = 10);
  402. unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
  403. long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
  404. unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
  405. float stof (const wstring& str, size_t* idx = nullptr);
  406. double stod (const wstring& str, size_t* idx = nullptr);
  407. long double stold(const wstring& str, size_t* idx = nullptr);
  408. wstring to_wstring(int val);
  409. wstring to_wstring(unsigned val);
  410. wstring to_wstring(long val);
  411. wstring to_wstring(unsigned long val);
  412. wstring to_wstring(long long val);
  413. wstring to_wstring(unsigned long long val);
  414. wstring to_wstring(float val);
  415. wstring to_wstring(double val);
  416. wstring to_wstring(long double val);
  417. template <> struct hash<string>;
  418. template <> struct hash<u8string>; // C++20
  419. template <> struct hash<u16string>;
  420. template <> struct hash<u32string>;
  421. template <> struct hash<wstring>;
  422. basic_string<char> operator "" s( const char *str, size_t len ); // C++14
  423. basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
  424. basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
  425. basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
  426. basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
  427. } // std
  428. */
  429. #include <__algorithm/max.h>
  430. #include <__algorithm/min.h>
  431. #include <__algorithm/remove.h>
  432. #include <__algorithm/remove_if.h>
  433. #include <__assert>
  434. #include <__config>
  435. #include <__debug>
  436. #include <__ios/fpos.h>
  437. #include <__iterator/wrap_iter.h>
  438. #include <compare>
  439. #include <cstdio> // EOF
  440. #include <cstdlib>
  441. #include <cstring>
  442. #include <initializer_list>
  443. #include <iosfwd>
  444. #include <iterator>
  445. #include <limits>
  446. #include <memory>
  447. #include <stdexcept>
  448. #include <string_view>
  449. #include <type_traits>
  450. #include <utility>
  451. #include <version>
  452. // TODO: remove these headers
  453. #include <__functional/binary_function.h>
  454. #include <__functional/invoke.h>
  455. #include <__functional/operations.h>
  456. #include <__functional/reference_wrapper.h>
  457. #include <__functional/unary_function.h>
  458. #include <__functional/weak_result_type.h>
  459. #include <new>
  460. #include <typeinfo>
  461. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  462. # include <cwchar>
  463. #endif
  464. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  465. # include <cstdint>
  466. #endif
  467. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  468. # pragma GCC system_header
  469. #endif
  470. _LIBCPP_PUSH_MACROS
  471. #include <__undef_macros>
  472. #ifdef _LIBCPP_COMPILER_MSVC
  473. #pragma warning ( push )
  474. #pragma warning ( disable : 4455 )
  475. #endif
  476. _LIBCPP_BEGIN_NAMESPACE_STD
  477. // basic_string
  478. template<class _CharT, class _Traits, class _Allocator>
  479. basic_string<_CharT, _Traits, _Allocator>
  480. operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
  481. const basic_string<_CharT, _Traits, _Allocator>& __y);
  482. template<class _CharT, class _Traits, class _Allocator>
  483. basic_string<_CharT, _Traits, _Allocator>
  484. operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
  485. template<class _CharT, class _Traits, class _Allocator>
  486. basic_string<_CharT, _Traits, _Allocator>
  487. operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
  488. template<class _CharT, class _Traits, class _Allocator>
  489. inline _LIBCPP_INLINE_VISIBILITY
  490. basic_string<_CharT, _Traits, _Allocator>
  491. operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
  492. template<class _CharT, class _Traits, class _Allocator>
  493. basic_string<_CharT, _Traits, _Allocator>
  494. operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
  495. _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
  496. template <class _Iter>
  497. struct __string_is_trivial_iterator : public false_type {};
  498. template <class _Tp>
  499. struct __string_is_trivial_iterator<_Tp*>
  500. : public is_arithmetic<_Tp> {};
  501. template <class _Iter>
  502. struct __string_is_trivial_iterator<__wrap_iter<_Iter> >
  503. : public __string_is_trivial_iterator<_Iter> {};
  504. template <class _CharT, class _Traits, class _Tp>
  505. struct __can_be_converted_to_string_view : public _BoolConstant<
  506. is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
  507. !is_convertible<const _Tp&, const _CharT*>::value
  508. > {};
  509. #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  510. template <class _CharT, size_t = sizeof(_CharT)>
  511. struct __padding
  512. {
  513. unsigned char __xx[sizeof(_CharT)-1];
  514. };
  515. template <class _CharT>
  516. struct __padding<_CharT, 1>
  517. {
  518. };
  519. #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  520. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  521. typedef basic_string<char8_t> u8string;
  522. #endif
  523. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  524. typedef basic_string<char16_t> u16string;
  525. typedef basic_string<char32_t> u32string;
  526. #endif
  527. template<class _CharT, class _Traits, class _Allocator>
  528. class
  529. _LIBCPP_TEMPLATE_VIS
  530. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  531. _LIBCPP_PREFERRED_NAME(u8string)
  532. #endif
  533. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  534. _LIBCPP_PREFERRED_NAME(u16string)
  535. _LIBCPP_PREFERRED_NAME(u32string)
  536. #endif
  537. basic_string
  538. {
  539. static_assert(sizeof(_CharT) <= 4, "libc++ implementation of std::basic_string does not support extra-wide character types");
  540. public:
  541. typedef basic_string __self;
  542. typedef basic_string_view<_CharT, _Traits> __self_view;
  543. typedef _Traits traits_type;
  544. typedef _CharT value_type;
  545. typedef _Allocator allocator_type;
  546. typedef allocator_traits<allocator_type> __alloc_traits;
  547. typedef typename __alloc_traits::size_type size_type;
  548. typedef typename __alloc_traits::difference_type difference_type;
  549. typedef value_type& reference;
  550. typedef const value_type& const_reference;
  551. typedef typename __alloc_traits::pointer pointer;
  552. typedef typename __alloc_traits::const_pointer const_pointer;
  553. static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
  554. static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
  555. static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
  556. static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
  557. "traits_type::char_type must be the same type as CharT");
  558. static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
  559. "Allocator::value_type must be same type as value_type");
  560. #if _YNDX_LIBCPP_MAKE_STRING_ITERATOR_POINTERS == 1
  561. typedef pointer iterator;
  562. typedef const_pointer const_iterator;
  563. #else
  564. typedef __wrap_iter<pointer> iterator;
  565. typedef __wrap_iter<const_pointer> const_iterator;
  566. #endif
  567. typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
  568. typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
  569. private:
  570. #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  571. struct __long
  572. {
  573. pointer __data_;
  574. size_type __size_;
  575. size_type __cap_;
  576. };
  577. #ifdef _LIBCPP_BIG_ENDIAN
  578. static const size_type __short_mask = 0x01;
  579. static const size_type __long_mask = 0x1ul;
  580. #else // _LIBCPP_BIG_ENDIAN
  581. static const size_type __short_mask = 0x80;
  582. static const size_type __long_mask = ~(size_type(~0) >> 1);
  583. #endif // _LIBCPP_BIG_ENDIAN
  584. enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
  585. (sizeof(__long) - 1)/sizeof(value_type) : 2};
  586. struct __short
  587. {
  588. value_type __data_[__min_cap];
  589. struct
  590. : __padding<value_type>
  591. {
  592. unsigned char __size_;
  593. };
  594. };
  595. #else
  596. struct __long
  597. {
  598. size_type __cap_;
  599. size_type __size_;
  600. pointer __data_;
  601. };
  602. #ifdef _LIBCPP_BIG_ENDIAN
  603. static const size_type __short_mask = 0x80;
  604. static const size_type __long_mask = ~(size_type(~0) >> 1);
  605. #else // _LIBCPP_BIG_ENDIAN
  606. static const size_type __short_mask = 0x01;
  607. static const size_type __long_mask = 0x1ul;
  608. #endif // _LIBCPP_BIG_ENDIAN
  609. enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
  610. (sizeof(__long) - 1)/sizeof(value_type) : 2};
  611. struct __short
  612. {
  613. union
  614. {
  615. unsigned char __size_;
  616. value_type __lx;
  617. };
  618. value_type __data_[__min_cap];
  619. };
  620. #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  621. union __ulx{__long __lx; __short __lxx;};
  622. enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
  623. struct __raw
  624. {
  625. size_type __words[__n_words];
  626. };
  627. struct __rep
  628. {
  629. union
  630. {
  631. __long __l;
  632. __short __s;
  633. __raw __r;
  634. };
  635. };
  636. __compressed_pair<__rep, allocator_type> __r_;
  637. public:
  638. _LIBCPP_TEMPLATE_DATA_VIS
  639. static const size_type npos = numeric_limits<size_type>::max();
  640. _LIBCPP_INLINE_VISIBILITY basic_string()
  641. _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
  642. _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
  643. #if _LIBCPP_STD_VER <= 14
  644. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
  645. #else
  646. _NOEXCEPT;
  647. #endif
  648. basic_string(const basic_string& __str);
  649. basic_string(const basic_string& __str, const allocator_type& __a);
  650. #ifndef _LIBCPP_CXX03_LANG
  651. _LIBCPP_INLINE_VISIBILITY
  652. basic_string(basic_string&& __str)
  653. #if _LIBCPP_STD_VER <= 14
  654. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
  655. #else
  656. _NOEXCEPT;
  657. #endif
  658. #if _LIBCPP_STD_VER > 17
  659. basic_string(nullptr_t) = delete;
  660. #endif
  661. _LIBCPP_INLINE_VISIBILITY
  662. basic_string(basic_string&& __str, const allocator_type& __a);
  663. #endif // _LIBCPP_CXX03_LANG
  664. template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
  665. _LIBCPP_INLINE_VISIBILITY
  666. basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
  667. _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
  668. __init(__s, traits_type::length(__s));
  669. _VSTD::__debug_db_insert_c(this);
  670. }
  671. template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
  672. _LIBCPP_INLINE_VISIBILITY
  673. basic_string(const _CharT* __s, const _Allocator& __a);
  674. _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
  675. basic_string(nullptr_t, size_t) = delete;
  676. _LIBCPP_INLINE_VISIBILITY
  677. basic_string(const _CharT* __s, size_type __n);
  678. _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
  679. basic_string(nullptr_t, size_t, const _Allocator&) = delete;
  680. _LIBCPP_INLINE_VISIBILITY
  681. basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
  682. _LIBCPP_INLINE_VISIBILITY
  683. basic_string(size_type __n, _CharT __c);
  684. template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
  685. _LIBCPP_INLINE_VISIBILITY
  686. basic_string(size_type __n, _CharT __c, const _Allocator& __a);
  687. basic_string(const basic_string& __str, size_type __pos, size_type __n,
  688. const _Allocator& __a = _Allocator());
  689. _LIBCPP_INLINE_VISIBILITY
  690. basic_string(const basic_string& __str, size_type __pos,
  691. const _Allocator& __a = _Allocator());
  692. template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
  693. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  694. basic_string(const _Tp& __t, size_type __pos, size_type __n,
  695. const allocator_type& __a = allocator_type());
  696. template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
  697. !__is_same_uncvref<_Tp, basic_string>::value> >
  698. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  699. explicit basic_string(const _Tp& __t);
  700. template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
  701. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  702. explicit basic_string(const _Tp& __t, const allocator_type& __a);
  703. template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
  704. _LIBCPP_INLINE_VISIBILITY
  705. basic_string(_InputIterator __first, _InputIterator __last);
  706. template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
  707. _LIBCPP_INLINE_VISIBILITY
  708. basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
  709. #ifndef _LIBCPP_CXX03_LANG
  710. _LIBCPP_INLINE_VISIBILITY
  711. basic_string(initializer_list<_CharT> __il);
  712. _LIBCPP_INLINE_VISIBILITY
  713. basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
  714. #endif // _LIBCPP_CXX03_LANG
  715. inline ~basic_string();
  716. _LIBCPP_INLINE_VISIBILITY
  717. operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
  718. basic_string& operator=(const basic_string& __str);
  719. basic_string& operator=(nullptr_t) = delete;
  720. template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
  721. basic_string& operator=(const _Tp& __t)
  722. {__self_view __sv = __t; return assign(__sv);}
  723. #ifndef _LIBCPP_CXX03_LANG
  724. _LIBCPP_INLINE_VISIBILITY
  725. basic_string& operator=(basic_string&& __str)
  726. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
  727. _LIBCPP_INLINE_VISIBILITY
  728. basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
  729. #endif
  730. _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
  731. #if _LIBCPP_STD_VER > 20
  732. basic_string& operator=(nullptr_t) = delete;
  733. #endif
  734. basic_string& operator=(value_type __c);
  735. #if _LIBCPP_DEBUG_LEVEL == 2
  736. _LIBCPP_INLINE_VISIBILITY
  737. iterator begin() _NOEXCEPT
  738. {return iterator(this, __get_pointer());}
  739. _LIBCPP_INLINE_VISIBILITY
  740. const_iterator begin() const _NOEXCEPT
  741. {return const_iterator(this, __get_pointer());}
  742. _LIBCPP_INLINE_VISIBILITY
  743. iterator end() _NOEXCEPT
  744. {return iterator(this, __get_pointer() + size());}
  745. _LIBCPP_INLINE_VISIBILITY
  746. const_iterator end() const _NOEXCEPT
  747. {return const_iterator(this, __get_pointer() + size());}
  748. #else
  749. _LIBCPP_INLINE_VISIBILITY
  750. iterator begin() _NOEXCEPT
  751. {return iterator(__get_pointer());}
  752. _LIBCPP_INLINE_VISIBILITY
  753. const_iterator begin() const _NOEXCEPT
  754. {return const_iterator(__get_pointer());}
  755. _LIBCPP_INLINE_VISIBILITY
  756. iterator end() _NOEXCEPT
  757. {return iterator(__get_pointer() + size());}
  758. _LIBCPP_INLINE_VISIBILITY
  759. const_iterator end() const _NOEXCEPT
  760. {return const_iterator(__get_pointer() + size());}
  761. #endif // _LIBCPP_DEBUG_LEVEL == 2
  762. _LIBCPP_INLINE_VISIBILITY
  763. reverse_iterator rbegin() _NOEXCEPT
  764. {return reverse_iterator(end());}
  765. _LIBCPP_INLINE_VISIBILITY
  766. const_reverse_iterator rbegin() const _NOEXCEPT
  767. {return const_reverse_iterator(end());}
  768. _LIBCPP_INLINE_VISIBILITY
  769. reverse_iterator rend() _NOEXCEPT
  770. {return reverse_iterator(begin());}
  771. _LIBCPP_INLINE_VISIBILITY
  772. const_reverse_iterator rend() const _NOEXCEPT
  773. {return const_reverse_iterator(begin());}
  774. _LIBCPP_INLINE_VISIBILITY
  775. const_iterator cbegin() const _NOEXCEPT
  776. {return begin();}
  777. _LIBCPP_INLINE_VISIBILITY
  778. const_iterator cend() const _NOEXCEPT
  779. {return end();}
  780. _LIBCPP_INLINE_VISIBILITY
  781. const_reverse_iterator crbegin() const _NOEXCEPT
  782. {return rbegin();}
  783. _LIBCPP_INLINE_VISIBILITY
  784. const_reverse_iterator crend() const _NOEXCEPT
  785. {return rend();}
  786. _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
  787. {return __is_long() ? __get_long_size() : __get_short_size();}
  788. _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
  789. _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
  790. _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
  791. {return (__is_long() ? __get_long_cap()
  792. : static_cast<size_type>(__min_cap)) - 1;}
  793. #if _YNDX_LIBCXX_ENABLE_STRING_RESIZE_UNINITIALIZED == 1
  794. inline void resize_uninitialized(size_type __n)
  795. {
  796. __resize_default_init(__n);
  797. }
  798. #endif
  799. void resize(size_type __n, value_type __c);
  800. _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
  801. void reserve(size_type __requested_capacity);
  802. #if _LIBCPP_STD_VER > 20
  803. template <class _Op>
  804. _LIBCPP_HIDE_FROM_ABI constexpr
  805. void resize_and_overwrite(size_type __n, _Op __op) {
  806. __resize_default_init(__n);
  807. __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
  808. }
  809. #endif
  810. _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
  811. _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
  812. void reserve() _NOEXCEPT {shrink_to_fit();}
  813. _LIBCPP_INLINE_VISIBILITY
  814. void shrink_to_fit() _NOEXCEPT;
  815. _LIBCPP_INLINE_VISIBILITY
  816. void clear() _NOEXCEPT;
  817. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  818. bool empty() const _NOEXCEPT {return size() == 0;}
  819. _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
  820. _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
  821. const_reference at(size_type __n) const;
  822. reference at(size_type __n);
  823. _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
  824. template <class _Tp>
  825. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  826. __enable_if_t
  827. <
  828. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  829. && !__is_same_uncvref<_Tp, basic_string >::value,
  830. basic_string&
  831. >
  832. operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
  833. _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
  834. _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
  835. #ifndef _LIBCPP_CXX03_LANG
  836. _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
  837. #endif // _LIBCPP_CXX03_LANG
  838. _LIBCPP_INLINE_VISIBILITY
  839. basic_string& append(const basic_string& __str);
  840. template <class _Tp>
  841. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  842. __enable_if_t<
  843. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  844. && !__is_same_uncvref<_Tp, basic_string>::value,
  845. basic_string&
  846. >
  847. append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
  848. basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
  849. template <class _Tp>
  850. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  851. __enable_if_t
  852. <
  853. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  854. && !__is_same_uncvref<_Tp, basic_string>::value,
  855. basic_string&
  856. >
  857. append(const _Tp& __t, size_type __pos, size_type __n=npos);
  858. basic_string& append(const value_type* __s, size_type __n);
  859. basic_string& append(const value_type* __s);
  860. basic_string& append(size_type __n, value_type __c);
  861. _LIBCPP_INLINE_VISIBILITY
  862. void __append_default_init(size_type __n);
  863. template<class _InputIterator>
  864. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  865. __enable_if_t
  866. <
  867. __is_exactly_cpp17_input_iterator<_InputIterator>::value,
  868. basic_string&
  869. >
  870. _LIBCPP_INLINE_VISIBILITY
  871. append(_InputIterator __first, _InputIterator __last) {
  872. const basic_string __temp(__first, __last, __alloc());
  873. append(__temp.data(), __temp.size());
  874. return *this;
  875. }
  876. template<class _ForwardIterator>
  877. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  878. __enable_if_t
  879. <
  880. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  881. basic_string&
  882. >
  883. _LIBCPP_INLINE_VISIBILITY
  884. append(_ForwardIterator __first, _ForwardIterator __last);
  885. #ifndef _LIBCPP_CXX03_LANG
  886. _LIBCPP_INLINE_VISIBILITY
  887. basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
  888. #endif // _LIBCPP_CXX03_LANG
  889. void push_back(value_type __c);
  890. _LIBCPP_INLINE_VISIBILITY
  891. void pop_back();
  892. _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
  893. _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
  894. _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
  895. _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
  896. template <class _Tp>
  897. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  898. __enable_if_t
  899. <
  900. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  901. basic_string&
  902. >
  903. assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
  904. _LIBCPP_INLINE_VISIBILITY
  905. basic_string& assign(const basic_string& __str) { return *this = __str; }
  906. #ifndef _LIBCPP_CXX03_LANG
  907. _LIBCPP_INLINE_VISIBILITY
  908. basic_string& assign(basic_string&& __str)
  909. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
  910. {*this = _VSTD::move(__str); return *this;}
  911. #endif
  912. basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
  913. template <class _Tp>
  914. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  915. __enable_if_t
  916. <
  917. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  918. && !__is_same_uncvref<_Tp, basic_string>::value,
  919. basic_string&
  920. >
  921. assign(const _Tp & __t, size_type __pos, size_type __n=npos);
  922. basic_string& assign(const value_type* __s, size_type __n);
  923. basic_string& assign(const value_type* __s);
  924. basic_string& assign(size_type __n, value_type __c);
  925. template<class _InputIterator>
  926. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  927. __enable_if_t
  928. <
  929. __is_exactly_cpp17_input_iterator<_InputIterator>::value,
  930. basic_string&
  931. >
  932. assign(_InputIterator __first, _InputIterator __last);
  933. template<class _ForwardIterator>
  934. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  935. __enable_if_t
  936. <
  937. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  938. basic_string&
  939. >
  940. assign(_ForwardIterator __first, _ForwardIterator __last);
  941. #ifndef _LIBCPP_CXX03_LANG
  942. _LIBCPP_INLINE_VISIBILITY
  943. basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
  944. #endif // _LIBCPP_CXX03_LANG
  945. _LIBCPP_INLINE_VISIBILITY
  946. basic_string& insert(size_type __pos1, const basic_string& __str);
  947. template <class _Tp>
  948. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  949. __enable_if_t
  950. <
  951. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  952. basic_string&
  953. >
  954. insert(size_type __pos1, const _Tp& __t)
  955. { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
  956. template <class _Tp>
  957. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  958. __enable_if_t
  959. <
  960. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
  961. basic_string&
  962. >
  963. insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
  964. basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
  965. basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
  966. basic_string& insert(size_type __pos, const value_type* __s);
  967. basic_string& insert(size_type __pos, size_type __n, value_type __c);
  968. iterator insert(const_iterator __pos, value_type __c);
  969. _LIBCPP_INLINE_VISIBILITY
  970. iterator insert(const_iterator __pos, size_type __n, value_type __c);
  971. template<class _InputIterator>
  972. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  973. __enable_if_t
  974. <
  975. __is_exactly_cpp17_input_iterator<_InputIterator>::value,
  976. iterator
  977. >
  978. insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
  979. template<class _ForwardIterator>
  980. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  981. __enable_if_t
  982. <
  983. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  984. iterator
  985. >
  986. insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
  987. #ifndef _LIBCPP_CXX03_LANG
  988. _LIBCPP_INLINE_VISIBILITY
  989. iterator insert(const_iterator __pos, initializer_list<value_type> __il)
  990. {return insert(__pos, __il.begin(), __il.end());}
  991. #endif // _LIBCPP_CXX03_LANG
  992. basic_string& erase(size_type __pos = 0, size_type __n = npos);
  993. _LIBCPP_INLINE_VISIBILITY
  994. iterator erase(const_iterator __pos);
  995. _LIBCPP_INLINE_VISIBILITY
  996. iterator erase(const_iterator __first, const_iterator __last);
  997. _LIBCPP_INLINE_VISIBILITY
  998. basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
  999. template <class _Tp>
  1000. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1001. __enable_if_t
  1002. <
  1003. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1004. basic_string&
  1005. >
  1006. replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
  1007. basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
  1008. template <class _Tp>
  1009. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1010. __enable_if_t
  1011. <
  1012. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
  1013. basic_string&
  1014. >
  1015. replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
  1016. basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
  1017. basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
  1018. basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
  1019. _LIBCPP_INLINE_VISIBILITY
  1020. basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
  1021. template <class _Tp>
  1022. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1023. __enable_if_t
  1024. <
  1025. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1026. basic_string&
  1027. >
  1028. replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
  1029. _LIBCPP_INLINE_VISIBILITY
  1030. basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
  1031. _LIBCPP_INLINE_VISIBILITY
  1032. basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
  1033. _LIBCPP_INLINE_VISIBILITY
  1034. basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
  1035. template<class _InputIterator>
  1036. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1037. __enable_if_t
  1038. <
  1039. __is_cpp17_input_iterator<_InputIterator>::value,
  1040. basic_string&
  1041. >
  1042. replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
  1043. #ifndef _LIBCPP_CXX03_LANG
  1044. _LIBCPP_INLINE_VISIBILITY
  1045. basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
  1046. {return replace(__i1, __i2, __il.begin(), __il.end());}
  1047. #endif // _LIBCPP_CXX03_LANG
  1048. size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
  1049. _LIBCPP_INLINE_VISIBILITY
  1050. basic_string substr(size_type __pos = 0, size_type __n = npos) const;
  1051. _LIBCPP_INLINE_VISIBILITY
  1052. void swap(basic_string& __str)
  1053. #if _LIBCPP_STD_VER >= 14
  1054. _NOEXCEPT;
  1055. #else
  1056. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  1057. __is_nothrow_swappable<allocator_type>::value);
  1058. #endif
  1059. _LIBCPP_INLINE_VISIBILITY
  1060. const value_type* c_str() const _NOEXCEPT {return data();}
  1061. _LIBCPP_INLINE_VISIBILITY
  1062. const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
  1063. #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
  1064. _LIBCPP_INLINE_VISIBILITY
  1065. value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
  1066. #endif
  1067. _LIBCPP_INLINE_VISIBILITY
  1068. allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
  1069. _LIBCPP_INLINE_VISIBILITY
  1070. size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
  1071. template <class _Tp>
  1072. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1073. __enable_if_t
  1074. <
  1075. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1076. size_type
  1077. >
  1078. find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
  1079. size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1080. _LIBCPP_INLINE_VISIBILITY
  1081. size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
  1082. size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
  1083. _LIBCPP_INLINE_VISIBILITY
  1084. size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
  1085. template <class _Tp>
  1086. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1087. __enable_if_t
  1088. <
  1089. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1090. size_type
  1091. >
  1092. rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
  1093. size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1094. _LIBCPP_INLINE_VISIBILITY
  1095. size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
  1096. size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
  1097. _LIBCPP_INLINE_VISIBILITY
  1098. size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
  1099. template <class _Tp>
  1100. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1101. __enable_if_t
  1102. <
  1103. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1104. size_type
  1105. >
  1106. find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
  1107. size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1108. _LIBCPP_INLINE_VISIBILITY
  1109. size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
  1110. _LIBCPP_INLINE_VISIBILITY
  1111. size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
  1112. _LIBCPP_INLINE_VISIBILITY
  1113. size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
  1114. template <class _Tp>
  1115. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1116. __enable_if_t
  1117. <
  1118. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1119. size_type
  1120. >
  1121. find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
  1122. size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1123. _LIBCPP_INLINE_VISIBILITY
  1124. size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
  1125. _LIBCPP_INLINE_VISIBILITY
  1126. size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
  1127. _LIBCPP_INLINE_VISIBILITY
  1128. size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
  1129. template <class _Tp>
  1130. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1131. __enable_if_t
  1132. <
  1133. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1134. size_type
  1135. >
  1136. find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
  1137. size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1138. _LIBCPP_INLINE_VISIBILITY
  1139. size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
  1140. _LIBCPP_INLINE_VISIBILITY
  1141. size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
  1142. _LIBCPP_INLINE_VISIBILITY
  1143. size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
  1144. template <class _Tp>
  1145. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1146. __enable_if_t
  1147. <
  1148. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1149. size_type
  1150. >
  1151. find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
  1152. size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
  1153. _LIBCPP_INLINE_VISIBILITY
  1154. size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
  1155. _LIBCPP_INLINE_VISIBILITY
  1156. size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
  1157. _LIBCPP_INLINE_VISIBILITY
  1158. int compare(const basic_string& __str) const _NOEXCEPT;
  1159. template <class _Tp>
  1160. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1161. __enable_if_t
  1162. <
  1163. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1164. int
  1165. >
  1166. compare(const _Tp &__t) const _NOEXCEPT;
  1167. template <class _Tp>
  1168. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  1169. __enable_if_t
  1170. <
  1171. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  1172. int
  1173. >
  1174. compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
  1175. _LIBCPP_INLINE_VISIBILITY
  1176. int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
  1177. int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
  1178. template <class _Tp>
  1179. inline _LIBCPP_INLINE_VISIBILITY
  1180. __enable_if_t
  1181. <
  1182. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
  1183. int
  1184. >
  1185. compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
  1186. int compare(const value_type* __s) const _NOEXCEPT;
  1187. int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
  1188. int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
  1189. //WARN: disabled std guards in order to allow using these options without switching to new std
  1190. //#if _LIBCPP_STD_VER > 17
  1191. constexpr _LIBCPP_INLINE_VISIBILITY
  1192. bool starts_with(__self_view __sv) const noexcept
  1193. { return __self_view(data(), size()).starts_with(__sv); }
  1194. constexpr _LIBCPP_INLINE_VISIBILITY
  1195. bool starts_with(value_type __c) const noexcept
  1196. { return !empty() && _Traits::eq(front(), __c); }
  1197. constexpr _LIBCPP_INLINE_VISIBILITY
  1198. bool starts_with(const value_type* __s) const noexcept
  1199. { return starts_with(__self_view(__s)); }
  1200. constexpr _LIBCPP_INLINE_VISIBILITY
  1201. bool ends_with(__self_view __sv) const noexcept
  1202. { return __self_view(data(), size()).ends_with( __sv); }
  1203. constexpr _LIBCPP_INLINE_VISIBILITY
  1204. bool ends_with(value_type __c) const noexcept
  1205. { return !empty() && _Traits::eq(back(), __c); }
  1206. constexpr _LIBCPP_INLINE_VISIBILITY
  1207. bool ends_with(const value_type* __s) const noexcept
  1208. { return ends_with(__self_view(__s)); }
  1209. //#endif
  1210. #if _LIBCPP_STD_VER >= 20
  1211. constexpr _LIBCPP_INLINE_VISIBILITY
  1212. bool contains(__self_view __sv) const noexcept
  1213. { return __self_view(data(), size()).contains(__sv); }
  1214. constexpr _LIBCPP_INLINE_VISIBILITY
  1215. bool contains(value_type __c) const noexcept
  1216. { return __self_view(data(), size()).contains(__c); }
  1217. constexpr _LIBCPP_INLINE_VISIBILITY
  1218. bool contains(const value_type* __s) const
  1219. { return __self_view(data(), size()).contains(__s); }
  1220. #endif
  1221. _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
  1222. _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
  1223. _LIBCPP_INLINE_VISIBILITY void __shrink_or_extend(size_type __target_capacity);
  1224. _LIBCPP_INLINE_VISIBILITY
  1225. bool __is_long() const _NOEXCEPT
  1226. {return bool(__r_.first().__s.__size_ & __short_mask);}
  1227. #if _LIBCPP_DEBUG_LEVEL == 2
  1228. bool __dereferenceable(const const_iterator* __i) const;
  1229. bool __decrementable(const const_iterator* __i) const;
  1230. bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
  1231. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
  1232. #endif // _LIBCPP_DEBUG_LEVEL == 2
  1233. private:
  1234. _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
  1235. // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
  1236. return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
  1237. }
  1238. _LIBCPP_INLINE_VISIBILITY
  1239. allocator_type& __alloc() _NOEXCEPT
  1240. {return __r_.second();}
  1241. _LIBCPP_INLINE_VISIBILITY
  1242. const allocator_type& __alloc() const _NOEXCEPT
  1243. {return __r_.second();}
  1244. #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  1245. _LIBCPP_INLINE_VISIBILITY
  1246. void __set_short_size(size_type __s) _NOEXCEPT
  1247. # ifdef _LIBCPP_BIG_ENDIAN
  1248. {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
  1249. # else
  1250. {__r_.first().__s.__size_ = (unsigned char)(__s);}
  1251. # endif
  1252. _LIBCPP_INLINE_VISIBILITY
  1253. size_type __get_short_size() const _NOEXCEPT
  1254. # ifdef _LIBCPP_BIG_ENDIAN
  1255. {return __r_.first().__s.__size_ >> 1;}
  1256. # else
  1257. {return __r_.first().__s.__size_;}
  1258. # endif
  1259. #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  1260. _LIBCPP_INLINE_VISIBILITY
  1261. void __set_short_size(size_type __s) _NOEXCEPT
  1262. # ifdef _LIBCPP_BIG_ENDIAN
  1263. {__r_.first().__s.__size_ = (unsigned char)(__s);}
  1264. # else
  1265. {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
  1266. # endif
  1267. _LIBCPP_INLINE_VISIBILITY
  1268. size_type __get_short_size() const _NOEXCEPT
  1269. # ifdef _LIBCPP_BIG_ENDIAN
  1270. {return __r_.first().__s.__size_;}
  1271. # else
  1272. {return __r_.first().__s.__size_ >> 1;}
  1273. # endif
  1274. #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  1275. _LIBCPP_INLINE_VISIBILITY
  1276. void __set_long_size(size_type __s) _NOEXCEPT
  1277. {__r_.first().__l.__size_ = __s;}
  1278. _LIBCPP_INLINE_VISIBILITY
  1279. size_type __get_long_size() const _NOEXCEPT
  1280. {return __r_.first().__l.__size_;}
  1281. _LIBCPP_INLINE_VISIBILITY
  1282. void __set_size(size_type __s) _NOEXCEPT
  1283. {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
  1284. _LIBCPP_INLINE_VISIBILITY
  1285. void __set_long_cap(size_type __s) _NOEXCEPT
  1286. {__r_.first().__l.__cap_ = __long_mask | __s;}
  1287. _LIBCPP_INLINE_VISIBILITY
  1288. size_type __get_long_cap() const _NOEXCEPT
  1289. {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
  1290. _LIBCPP_INLINE_VISIBILITY
  1291. void __set_long_pointer(pointer __p) _NOEXCEPT
  1292. {__r_.first().__l.__data_ = __p;}
  1293. _LIBCPP_INLINE_VISIBILITY
  1294. pointer __get_long_pointer() _NOEXCEPT
  1295. {return __r_.first().__l.__data_;}
  1296. _LIBCPP_INLINE_VISIBILITY
  1297. const_pointer __get_long_pointer() const _NOEXCEPT
  1298. {return __r_.first().__l.__data_;}
  1299. _LIBCPP_INLINE_VISIBILITY
  1300. pointer __get_short_pointer() _NOEXCEPT
  1301. {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
  1302. _LIBCPP_INLINE_VISIBILITY
  1303. const_pointer __get_short_pointer() const _NOEXCEPT
  1304. {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
  1305. _LIBCPP_INLINE_VISIBILITY
  1306. pointer __get_pointer() _NOEXCEPT
  1307. {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
  1308. _LIBCPP_INLINE_VISIBILITY
  1309. const_pointer __get_pointer() const _NOEXCEPT
  1310. {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
  1311. _LIBCPP_INLINE_VISIBILITY
  1312. void __zero() _NOEXCEPT
  1313. {
  1314. size_type (&__a)[__n_words] = __r_.first().__r.__words;
  1315. for (unsigned __i = 0; __i < __n_words; ++__i)
  1316. __a[__i] = 0;
  1317. }
  1318. template <size_type __a> static
  1319. _LIBCPP_INLINE_VISIBILITY
  1320. size_type __align_it(size_type __s) _NOEXCEPT
  1321. {return (__s + (__a-1)) & ~(__a-1);}
  1322. enum {__alignment = 16};
  1323. static _LIBCPP_INLINE_VISIBILITY
  1324. size_type __recommend(size_type __s) _NOEXCEPT
  1325. {
  1326. if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
  1327. size_type __guess = __align_it<sizeof(value_type) < __alignment ?
  1328. __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
  1329. if (__guess == __min_cap) ++__guess;
  1330. return __guess;
  1331. }
  1332. inline
  1333. void __init(const value_type* __s, size_type __sz, size_type __reserve);
  1334. inline
  1335. void __init(const value_type* __s, size_type __sz);
  1336. inline
  1337. void __init(size_type __n, value_type __c);
  1338. // Slow path for the (inlined) copy constructor for 'long' strings.
  1339. // Always externally instantiated and not inlined.
  1340. // Requires that __s is zero terminated.
  1341. // The main reason for this function to exist is because for unstable, we
  1342. // want to allow inlining of the copy constructor. However, we don't want
  1343. // to call the __init() functions as those are marked as inline which may
  1344. // result in over-aggressive inlining by the compiler, where our aim is
  1345. // to only inline the fast path code directly in the ctor.
  1346. void __init_copy_ctor_external(const value_type* __s, size_type __sz);
  1347. template <class _InputIterator>
  1348. inline
  1349. __enable_if_t
  1350. <
  1351. __is_exactly_cpp17_input_iterator<_InputIterator>::value
  1352. >
  1353. __init(_InputIterator __first, _InputIterator __last);
  1354. template <class _ForwardIterator>
  1355. inline
  1356. __enable_if_t
  1357. <
  1358. __is_cpp17_forward_iterator<_ForwardIterator>::value
  1359. >
  1360. __init(_ForwardIterator __first, _ForwardIterator __last);
  1361. void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
  1362. size_type __n_copy, size_type __n_del, size_type __n_add = 0);
  1363. void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
  1364. size_type __n_copy, size_type __n_del,
  1365. size_type __n_add, const value_type* __p_new_stuff);
  1366. // __assign_no_alias is invoked for assignment operations where we
  1367. // have proof that the input does not alias the current instance.
  1368. // For example, operator=(basic_string) performs a 'self' check.
  1369. template <bool __is_short>
  1370. basic_string& __assign_no_alias(const value_type* __s, size_type __n);
  1371. _LIBCPP_INLINE_VISIBILITY
  1372. void __erase_to_end(size_type __pos);
  1373. // __erase_external_with_move is invoked for erase() invocations where
  1374. // `n ~= npos`, likely requiring memory moves on the string data.
  1375. void __erase_external_with_move(size_type __pos, size_type __n);
  1376. _LIBCPP_INLINE_VISIBILITY
  1377. void __copy_assign_alloc(const basic_string& __str)
  1378. {__copy_assign_alloc(__str, integral_constant<bool,
  1379. __alloc_traits::propagate_on_container_copy_assignment::value>());}
  1380. _LIBCPP_INLINE_VISIBILITY
  1381. void __copy_assign_alloc(const basic_string& __str, true_type)
  1382. {
  1383. if (__alloc() == __str.__alloc())
  1384. __alloc() = __str.__alloc();
  1385. else
  1386. {
  1387. if (!__str.__is_long())
  1388. {
  1389. __clear_and_shrink();
  1390. __alloc() = __str.__alloc();
  1391. }
  1392. else
  1393. {
  1394. allocator_type __a = __str.__alloc();
  1395. pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
  1396. __clear_and_shrink();
  1397. __alloc() = _VSTD::move(__a);
  1398. __set_long_pointer(__p);
  1399. __set_long_cap(__str.__get_long_cap());
  1400. __set_long_size(__str.size());
  1401. }
  1402. }
  1403. }
  1404. _LIBCPP_INLINE_VISIBILITY
  1405. void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
  1406. {}
  1407. #ifndef _LIBCPP_CXX03_LANG
  1408. _LIBCPP_INLINE_VISIBILITY
  1409. void __move_assign(basic_string& __str, false_type)
  1410. _NOEXCEPT_(__alloc_traits::is_always_equal::value);
  1411. _LIBCPP_INLINE_VISIBILITY
  1412. void __move_assign(basic_string& __str, true_type)
  1413. #if _LIBCPP_STD_VER > 14
  1414. _NOEXCEPT;
  1415. #else
  1416. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
  1417. #endif
  1418. #endif
  1419. _LIBCPP_INLINE_VISIBILITY
  1420. void
  1421. __move_assign_alloc(basic_string& __str)
  1422. _NOEXCEPT_(
  1423. !__alloc_traits::propagate_on_container_move_assignment::value ||
  1424. is_nothrow_move_assignable<allocator_type>::value)
  1425. {__move_assign_alloc(__str, integral_constant<bool,
  1426. __alloc_traits::propagate_on_container_move_assignment::value>());}
  1427. _LIBCPP_INLINE_VISIBILITY
  1428. void __move_assign_alloc(basic_string& __c, true_type)
  1429. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  1430. {
  1431. __alloc() = _VSTD::move(__c.__alloc());
  1432. }
  1433. _LIBCPP_INLINE_VISIBILITY
  1434. void __move_assign_alloc(basic_string&, false_type)
  1435. _NOEXCEPT
  1436. {}
  1437. basic_string& __assign_external(const value_type* __s);
  1438. basic_string& __assign_external(const value_type* __s, size_type __n);
  1439. // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
  1440. inline basic_string& __assign_short(const value_type* __s, size_type __n) {
  1441. pointer __p = __is_long()
  1442. ? (__set_long_size(__n), __get_long_pointer())
  1443. : (__set_short_size(__n), __get_short_pointer());
  1444. traits_type::move(_VSTD::__to_address(__p), __s, __n);
  1445. traits_type::assign(__p[__n], value_type());
  1446. return *this;
  1447. }
  1448. _LIBCPP_HIDE_FROM_ABI basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
  1449. __set_size(__newsz);
  1450. __invalidate_iterators_past(__newsz);
  1451. traits_type::assign(__p[__newsz], value_type());
  1452. return *this;
  1453. }
  1454. _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
  1455. _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
  1456. template<class _Tp>
  1457. _LIBCPP_INLINE_VISIBILITY
  1458. bool __addr_in_range(_Tp&& __t) const {
  1459. const volatile void *__p = _VSTD::addressof(__t);
  1460. return data() <= __p && __p <= data() + size();
  1461. }
  1462. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  1463. void __throw_length_error() const {
  1464. _VSTD::__throw_length_error("basic_string");
  1465. }
  1466. _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
  1467. void __throw_out_of_range() const {
  1468. _VSTD::__throw_out_of_range("basic_string");
  1469. }
  1470. friend basic_string operator+<>(const basic_string&, const basic_string&);
  1471. friend basic_string operator+<>(const value_type*, const basic_string&);
  1472. friend basic_string operator+<>(value_type, const basic_string&);
  1473. friend basic_string operator+<>(const basic_string&, const value_type*);
  1474. friend basic_string operator+<>(const basic_string&, value_type);
  1475. };
  1476. // These declarations must appear before any functions are implicitly used
  1477. // so that they have the correct visibility specifier.
  1478. #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
  1479. _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
  1480. # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1481. _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
  1482. # endif
  1483. #else
  1484. _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
  1485. # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1486. _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
  1487. # endif
  1488. #endif
  1489. #if _LIBCPP_STD_VER >= 17
  1490. template<class _InputIterator,
  1491. class _CharT = __iter_value_type<_InputIterator>,
  1492. class _Allocator = allocator<_CharT>,
  1493. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1494. class = enable_if_t<__is_allocator<_Allocator>::value>
  1495. >
  1496. basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
  1497. -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
  1498. template<class _CharT,
  1499. class _Traits,
  1500. class _Allocator = allocator<_CharT>,
  1501. class = enable_if_t<__is_allocator<_Allocator>::value>
  1502. >
  1503. explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
  1504. -> basic_string<_CharT, _Traits, _Allocator>;
  1505. template<class _CharT,
  1506. class _Traits,
  1507. class _Allocator = allocator<_CharT>,
  1508. class = enable_if_t<__is_allocator<_Allocator>::value>,
  1509. class _Sz = typename allocator_traits<_Allocator>::size_type
  1510. >
  1511. basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
  1512. -> basic_string<_CharT, _Traits, _Allocator>;
  1513. #endif
  1514. template <class _CharT, class _Traits, class _Allocator>
  1515. inline
  1516. void
  1517. basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
  1518. {
  1519. #if _LIBCPP_DEBUG_LEVEL == 2
  1520. if (!__libcpp_is_constant_evaluated())
  1521. __get_db()->__invalidate_all(this);
  1522. #endif
  1523. }
  1524. template <class _CharT, class _Traits, class _Allocator>
  1525. inline
  1526. void
  1527. basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
  1528. {
  1529. #if _LIBCPP_DEBUG_LEVEL == 2
  1530. if (!__libcpp_is_constant_evaluated()) {
  1531. __c_node* __c = __get_db()->__find_c_and_lock(this);
  1532. if (__c)
  1533. {
  1534. const_pointer __new_last = __get_pointer() + __pos;
  1535. for (__i_node** __p = __c->end_; __p != __c->beg_; )
  1536. {
  1537. --__p;
  1538. const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
  1539. if (__i->base() > __new_last)
  1540. {
  1541. (*__p)->__c_ = nullptr;
  1542. if (--__c->end_ != __p)
  1543. _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
  1544. }
  1545. }
  1546. __get_db()->unlock();
  1547. }
  1548. }
  1549. #else
  1550. (void)__pos;
  1551. #endif // _LIBCPP_DEBUG_LEVEL == 2
  1552. }
  1553. template <class _CharT, class _Traits, class _Allocator>
  1554. inline
  1555. basic_string<_CharT, _Traits, _Allocator>::basic_string()
  1556. _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
  1557. : __r_(__default_init_tag(), __default_init_tag())
  1558. {
  1559. _VSTD::__debug_db_insert_c(this);
  1560. __zero();
  1561. }
  1562. template <class _CharT, class _Traits, class _Allocator>
  1563. inline
  1564. basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
  1565. #if _LIBCPP_STD_VER <= 14
  1566. _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
  1567. #else
  1568. _NOEXCEPT
  1569. #endif
  1570. : __r_(__default_init_tag(), __a)
  1571. {
  1572. _VSTD::__debug_db_insert_c(this);
  1573. __zero();
  1574. }
  1575. template <class _CharT, class _Traits, class _Allocator>
  1576. void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
  1577. size_type __sz,
  1578. size_type __reserve)
  1579. {
  1580. if (__reserve > max_size())
  1581. __throw_length_error();
  1582. pointer __p;
  1583. if (__fits_in_sso(__reserve))
  1584. {
  1585. __set_short_size(__sz);
  1586. __p = __get_short_pointer();
  1587. }
  1588. else
  1589. {
  1590. size_type __cap = __recommend(__reserve);
  1591. __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1592. __set_long_pointer(__p);
  1593. __set_long_cap(__cap+1);
  1594. __set_long_size(__sz);
  1595. }
  1596. traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
  1597. traits_type::assign(__p[__sz], value_type());
  1598. }
  1599. template <class _CharT, class _Traits, class _Allocator>
  1600. void
  1601. basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
  1602. {
  1603. if (__sz > max_size())
  1604. __throw_length_error();
  1605. pointer __p;
  1606. if (__fits_in_sso(__sz))
  1607. {
  1608. __set_short_size(__sz);
  1609. __p = __get_short_pointer();
  1610. }
  1611. else
  1612. {
  1613. size_type __cap = __recommend(__sz);
  1614. __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1615. __set_long_pointer(__p);
  1616. __set_long_cap(__cap+1);
  1617. __set_long_size(__sz);
  1618. }
  1619. traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
  1620. traits_type::assign(__p[__sz], value_type());
  1621. }
  1622. template <class _CharT, class _Traits, class _Allocator>
  1623. template <class>
  1624. basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
  1625. : __r_(__default_init_tag(), __a)
  1626. {
  1627. _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
  1628. __init(__s, traits_type::length(__s));
  1629. _VSTD::__debug_db_insert_c(this);
  1630. }
  1631. template <class _CharT, class _Traits, class _Allocator>
  1632. inline
  1633. basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
  1634. : __r_(__default_init_tag(), __default_init_tag())
  1635. {
  1636. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
  1637. __init(__s, __n);
  1638. _VSTD::__debug_db_insert_c(this);
  1639. }
  1640. template <class _CharT, class _Traits, class _Allocator>
  1641. inline
  1642. basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
  1643. : __r_(__default_init_tag(), __a)
  1644. {
  1645. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
  1646. __init(__s, __n);
  1647. _VSTD::__debug_db_insert_c(this);
  1648. }
  1649. template <class _CharT, class _Traits, class _Allocator>
  1650. basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
  1651. : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
  1652. {
  1653. if (!__str.__is_long())
  1654. __r_.first().__r = __str.__r_.first().__r;
  1655. else
  1656. __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
  1657. __str.__get_long_size());
  1658. _VSTD::__debug_db_insert_c(this);
  1659. }
  1660. template <class _CharT, class _Traits, class _Allocator>
  1661. basic_string<_CharT, _Traits, _Allocator>::basic_string(
  1662. const basic_string& __str, const allocator_type& __a)
  1663. : __r_(__default_init_tag(), __a)
  1664. {
  1665. if (!__str.__is_long())
  1666. __r_.first().__r = __str.__r_.first().__r;
  1667. else
  1668. __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
  1669. __str.__get_long_size());
  1670. _VSTD::__debug_db_insert_c(this);
  1671. }
  1672. template <class _CharT, class _Traits, class _Allocator>
  1673. void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
  1674. const value_type* __s, size_type __sz) {
  1675. pointer __p;
  1676. if (__fits_in_sso(__sz)) {
  1677. __p = __get_short_pointer();
  1678. __set_short_size(__sz);
  1679. } else {
  1680. if (__sz > max_size())
  1681. __throw_length_error();
  1682. size_t __cap = __recommend(__sz);
  1683. __p = __alloc_traits::allocate(__alloc(), __cap + 1);
  1684. __set_long_pointer(__p);
  1685. __set_long_cap(__cap + 1);
  1686. __set_long_size(__sz);
  1687. }
  1688. traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
  1689. }
  1690. #ifndef _LIBCPP_CXX03_LANG
  1691. template <class _CharT, class _Traits, class _Allocator>
  1692. inline
  1693. basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
  1694. #if _LIBCPP_STD_VER <= 14
  1695. _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
  1696. #else
  1697. _NOEXCEPT
  1698. #endif
  1699. : __r_(_VSTD::move(__str.__r_))
  1700. {
  1701. __str.__zero();
  1702. _VSTD::__debug_db_insert_c(this);
  1703. #if _LIBCPP_DEBUG_LEVEL == 2
  1704. if (!__libcpp_is_constant_evaluated() && __is_long())
  1705. __get_db()->swap(this, &__str);
  1706. #endif
  1707. }
  1708. template <class _CharT, class _Traits, class _Allocator>
  1709. inline
  1710. basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
  1711. : __r_(__default_init_tag(), __a)
  1712. {
  1713. if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
  1714. __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
  1715. else
  1716. {
  1717. __r_.first().__r = __str.__r_.first().__r;
  1718. __str.__zero();
  1719. }
  1720. _VSTD::__debug_db_insert_c(this);
  1721. #if _LIBCPP_DEBUG_LEVEL == 2
  1722. if (!__libcpp_is_constant_evaluated() && __is_long())
  1723. __get_db()->swap(this, &__str);
  1724. #endif
  1725. }
  1726. #endif // _LIBCPP_CXX03_LANG
  1727. template <class _CharT, class _Traits, class _Allocator>
  1728. void
  1729. basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
  1730. {
  1731. if (__n > max_size())
  1732. __throw_length_error();
  1733. pointer __p;
  1734. if (__fits_in_sso(__n))
  1735. {
  1736. __set_short_size(__n);
  1737. __p = __get_short_pointer();
  1738. }
  1739. else
  1740. {
  1741. size_type __cap = __recommend(__n);
  1742. __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1743. __set_long_pointer(__p);
  1744. __set_long_cap(__cap+1);
  1745. __set_long_size(__n);
  1746. }
  1747. traits_type::assign(_VSTD::__to_address(__p), __n, __c);
  1748. traits_type::assign(__p[__n], value_type());
  1749. }
  1750. template <class _CharT, class _Traits, class _Allocator>
  1751. inline
  1752. basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
  1753. : __r_(__default_init_tag(), __default_init_tag())
  1754. {
  1755. __init(__n, __c);
  1756. _VSTD::__debug_db_insert_c(this);
  1757. }
  1758. template <class _CharT, class _Traits, class _Allocator>
  1759. template <class>
  1760. basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
  1761. : __r_(__default_init_tag(), __a)
  1762. {
  1763. __init(__n, __c);
  1764. _VSTD::__debug_db_insert_c(this);
  1765. }
  1766. template <class _CharT, class _Traits, class _Allocator>
  1767. basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
  1768. size_type __pos, size_type __n,
  1769. const _Allocator& __a)
  1770. : __r_(__default_init_tag(), __a)
  1771. {
  1772. size_type __str_sz = __str.size();
  1773. if (__pos > __str_sz)
  1774. __throw_out_of_range();
  1775. __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
  1776. _VSTD::__debug_db_insert_c(this);
  1777. }
  1778. template <class _CharT, class _Traits, class _Allocator>
  1779. inline
  1780. basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
  1781. const _Allocator& __a)
  1782. : __r_(__default_init_tag(), __a)
  1783. {
  1784. size_type __str_sz = __str.size();
  1785. if (__pos > __str_sz)
  1786. __throw_out_of_range();
  1787. __init(__str.data() + __pos, __str_sz - __pos);
  1788. _VSTD::__debug_db_insert_c(this);
  1789. }
  1790. template <class _CharT, class _Traits, class _Allocator>
  1791. template <class _Tp, class>
  1792. basic_string<_CharT, _Traits, _Allocator>::basic_string(
  1793. const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
  1794. : __r_(__default_init_tag(), __a)
  1795. {
  1796. __self_view __sv0 = __t;
  1797. __self_view __sv = __sv0.substr(__pos, __n);
  1798. __init(__sv.data(), __sv.size());
  1799. _VSTD::__debug_db_insert_c(this);
  1800. }
  1801. template <class _CharT, class _Traits, class _Allocator>
  1802. template <class _Tp, class>
  1803. basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
  1804. : __r_(__default_init_tag(), __default_init_tag())
  1805. {
  1806. __self_view __sv = __t;
  1807. __init(__sv.data(), __sv.size());
  1808. _VSTD::__debug_db_insert_c(this);
  1809. }
  1810. template <class _CharT, class _Traits, class _Allocator>
  1811. template <class _Tp, class>
  1812. basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
  1813. : __r_(__default_init_tag(), __a)
  1814. {
  1815. __self_view __sv = __t;
  1816. __init(__sv.data(), __sv.size());
  1817. _VSTD::__debug_db_insert_c(this);
  1818. }
  1819. template <class _CharT, class _Traits, class _Allocator>
  1820. template <class _InputIterator>
  1821. __enable_if_t
  1822. <
  1823. __is_exactly_cpp17_input_iterator<_InputIterator>::value
  1824. >
  1825. basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
  1826. {
  1827. __zero();
  1828. #ifndef _LIBCPP_NO_EXCEPTIONS
  1829. try
  1830. {
  1831. #endif // _LIBCPP_NO_EXCEPTIONS
  1832. for (; __first != __last; ++__first)
  1833. push_back(*__first);
  1834. #ifndef _LIBCPP_NO_EXCEPTIONS
  1835. }
  1836. catch (...)
  1837. {
  1838. if (__is_long())
  1839. __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
  1840. throw;
  1841. }
  1842. #endif // _LIBCPP_NO_EXCEPTIONS
  1843. }
  1844. template <class _CharT, class _Traits, class _Allocator>
  1845. template <class _ForwardIterator>
  1846. __enable_if_t
  1847. <
  1848. __is_cpp17_forward_iterator<_ForwardIterator>::value
  1849. >
  1850. basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
  1851. {
  1852. size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
  1853. if (__sz > max_size())
  1854. __throw_length_error();
  1855. pointer __p;
  1856. if (__fits_in_sso(__sz))
  1857. {
  1858. __set_short_size(__sz);
  1859. __p = __get_short_pointer();
  1860. }
  1861. else
  1862. {
  1863. size_type __cap = __recommend(__sz);
  1864. __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1865. __set_long_pointer(__p);
  1866. __set_long_cap(__cap+1);
  1867. __set_long_size(__sz);
  1868. }
  1869. #ifndef _LIBCPP_NO_EXCEPTIONS
  1870. try
  1871. {
  1872. #endif // _LIBCPP_NO_EXCEPTIONS
  1873. for (; __first != __last; ++__first, (void) ++__p)
  1874. traits_type::assign(*__p, *__first);
  1875. traits_type::assign(*__p, value_type());
  1876. #ifndef _LIBCPP_NO_EXCEPTIONS
  1877. }
  1878. catch (...)
  1879. {
  1880. if (__is_long())
  1881. __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
  1882. throw;
  1883. }
  1884. #endif // _LIBCPP_NO_EXCEPTIONS
  1885. }
  1886. template <class _CharT, class _Traits, class _Allocator>
  1887. template<class _InputIterator, class>
  1888. inline
  1889. basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
  1890. : __r_(__default_init_tag(), __default_init_tag())
  1891. {
  1892. __init(__first, __last);
  1893. _VSTD::__debug_db_insert_c(this);
  1894. }
  1895. template <class _CharT, class _Traits, class _Allocator>
  1896. template<class _InputIterator, class>
  1897. inline
  1898. basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
  1899. const allocator_type& __a)
  1900. : __r_(__default_init_tag(), __a)
  1901. {
  1902. __init(__first, __last);
  1903. _VSTD::__debug_db_insert_c(this);
  1904. }
  1905. #ifndef _LIBCPP_CXX03_LANG
  1906. template <class _CharT, class _Traits, class _Allocator>
  1907. inline
  1908. basic_string<_CharT, _Traits, _Allocator>::basic_string(
  1909. initializer_list<_CharT> __il)
  1910. : __r_(__default_init_tag(), __default_init_tag())
  1911. {
  1912. __init(__il.begin(), __il.end());
  1913. _VSTD::__debug_db_insert_c(this);
  1914. }
  1915. template <class _CharT, class _Traits, class _Allocator>
  1916. inline
  1917. basic_string<_CharT, _Traits, _Allocator>::basic_string(
  1918. initializer_list<_CharT> __il, const _Allocator& __a)
  1919. : __r_(__default_init_tag(), __a)
  1920. {
  1921. __init(__il.begin(), __il.end());
  1922. _VSTD::__debug_db_insert_c(this);
  1923. }
  1924. #endif // _LIBCPP_CXX03_LANG
  1925. template <class _CharT, class _Traits, class _Allocator>
  1926. basic_string<_CharT, _Traits, _Allocator>::~basic_string()
  1927. {
  1928. #if _LIBCPP_DEBUG_LEVEL == 2
  1929. if (!__libcpp_is_constant_evaluated())
  1930. __get_db()->__erase_c(this);
  1931. #endif
  1932. if (__is_long())
  1933. __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
  1934. }
  1935. template <class _CharT, class _Traits, class _Allocator>
  1936. void
  1937. basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
  1938. (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
  1939. size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
  1940. {
  1941. size_type __ms = max_size();
  1942. if (__delta_cap > __ms - __old_cap - 1)
  1943. __throw_length_error();
  1944. pointer __old_p = __get_pointer();
  1945. size_type __cap = __old_cap < __ms / 2 - __alignment ?
  1946. __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
  1947. __ms - 1;
  1948. pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1949. __invalidate_all_iterators();
  1950. if (__n_copy != 0)
  1951. traits_type::copy(_VSTD::__to_address(__p),
  1952. _VSTD::__to_address(__old_p), __n_copy);
  1953. if (__n_add != 0)
  1954. traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
  1955. size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
  1956. if (__sec_cp_sz != 0)
  1957. traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
  1958. _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
  1959. if (__old_cap+1 != __min_cap)
  1960. __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
  1961. __set_long_pointer(__p);
  1962. __set_long_cap(__cap+1);
  1963. __old_sz = __n_copy + __n_add + __sec_cp_sz;
  1964. __set_long_size(__old_sz);
  1965. traits_type::assign(__p[__old_sz], value_type());
  1966. }
  1967. template <class _CharT, class _Traits, class _Allocator>
  1968. void
  1969. basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
  1970. size_type __n_copy, size_type __n_del, size_type __n_add)
  1971. {
  1972. size_type __ms = max_size();
  1973. if (__delta_cap > __ms - __old_cap)
  1974. __throw_length_error();
  1975. pointer __old_p = __get_pointer();
  1976. size_type __cap = __old_cap < __ms / 2 - __alignment ?
  1977. __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
  1978. __ms - 1;
  1979. pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
  1980. __invalidate_all_iterators();
  1981. if (__n_copy != 0)
  1982. traits_type::copy(_VSTD::__to_address(__p),
  1983. _VSTD::__to_address(__old_p), __n_copy);
  1984. size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
  1985. if (__sec_cp_sz != 0)
  1986. traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
  1987. _VSTD::__to_address(__old_p) + __n_copy + __n_del,
  1988. __sec_cp_sz);
  1989. if (__old_cap+1 != __min_cap)
  1990. __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
  1991. __set_long_pointer(__p);
  1992. __set_long_cap(__cap+1);
  1993. }
  1994. // assign
  1995. template <class _CharT, class _Traits, class _Allocator>
  1996. template <bool __is_short>
  1997. basic_string<_CharT, _Traits, _Allocator>&
  1998. basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
  1999. const value_type* __s, size_type __n) {
  2000. size_type __cap = __is_short ? __min_cap : __get_long_cap();
  2001. if (__n < __cap) {
  2002. pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
  2003. __is_short ? __set_short_size(__n) : __set_long_size(__n);
  2004. traits_type::copy(_VSTD::__to_address(__p), __s, __n);
  2005. traits_type::assign(__p[__n], value_type());
  2006. __invalidate_iterators_past(__n);
  2007. } else {
  2008. size_type __sz = __is_short ? __get_short_size() : __get_long_size();
  2009. __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
  2010. }
  2011. return *this;
  2012. }
  2013. template <class _CharT, class _Traits, class _Allocator>
  2014. basic_string<_CharT, _Traits, _Allocator>&
  2015. basic_string<_CharT, _Traits, _Allocator>::__assign_external(
  2016. const value_type* __s, size_type __n) {
  2017. size_type __cap = capacity();
  2018. if (__cap >= __n) {
  2019. value_type* __p = _VSTD::__to_address(__get_pointer());
  2020. traits_type::move(__p, __s, __n);
  2021. return __null_terminate_at(__p, __n);
  2022. } else {
  2023. size_type __sz = size();
  2024. __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
  2025. return *this;
  2026. }
  2027. }
  2028. template <class _CharT, class _Traits, class _Allocator>
  2029. basic_string<_CharT, _Traits, _Allocator>&
  2030. basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
  2031. {
  2032. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
  2033. return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __fits_in_sso(__n))
  2034. ? __assign_short(__s, __n)
  2035. : __assign_external(__s, __n);
  2036. }
  2037. template <class _CharT, class _Traits, class _Allocator>
  2038. basic_string<_CharT, _Traits, _Allocator>&
  2039. basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
  2040. {
  2041. size_type __cap = capacity();
  2042. if (__cap < __n)
  2043. {
  2044. size_type __sz = size();
  2045. __grow_by(__cap, __n - __cap, __sz, 0, __sz);
  2046. }
  2047. value_type* __p = _VSTD::__to_address(__get_pointer());
  2048. traits_type::assign(__p, __n, __c);
  2049. return __null_terminate_at(__p, __n);
  2050. }
  2051. template <class _CharT, class _Traits, class _Allocator>
  2052. basic_string<_CharT, _Traits, _Allocator>&
  2053. basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
  2054. {
  2055. pointer __p;
  2056. if (__is_long())
  2057. {
  2058. __p = __get_long_pointer();
  2059. __set_long_size(1);
  2060. }
  2061. else
  2062. {
  2063. __p = __get_short_pointer();
  2064. __set_short_size(1);
  2065. }
  2066. traits_type::assign(*__p, __c);
  2067. traits_type::assign(*++__p, value_type());
  2068. __invalidate_iterators_past(1);
  2069. return *this;
  2070. }
  2071. template <class _CharT, class _Traits, class _Allocator>
  2072. basic_string<_CharT, _Traits, _Allocator>&
  2073. basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
  2074. {
  2075. if (this != &__str) {
  2076. __copy_assign_alloc(__str);
  2077. if (!__is_long()) {
  2078. if (!__str.__is_long()) {
  2079. __r_.first().__r = __str.__r_.first().__r;
  2080. } else {
  2081. return __assign_no_alias<true>(__str.data(), __str.size());
  2082. }
  2083. } else {
  2084. return __assign_no_alias<false>(__str.data(), __str.size());
  2085. }
  2086. }
  2087. return *this;
  2088. }
  2089. #ifndef _LIBCPP_CXX03_LANG
  2090. template <class _CharT, class _Traits, class _Allocator>
  2091. inline
  2092. void
  2093. basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
  2094. _NOEXCEPT_(__alloc_traits::is_always_equal::value)
  2095. {
  2096. if (__alloc() != __str.__alloc())
  2097. assign(__str);
  2098. else
  2099. __move_assign(__str, true_type());
  2100. }
  2101. template <class _CharT, class _Traits, class _Allocator>
  2102. inline
  2103. void
  2104. basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
  2105. #if _LIBCPP_STD_VER > 14
  2106. _NOEXCEPT
  2107. #else
  2108. _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
  2109. #endif
  2110. {
  2111. if (__is_long()) {
  2112. __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
  2113. __get_long_cap());
  2114. #if _LIBCPP_STD_VER <= 14
  2115. if (!is_nothrow_move_assignable<allocator_type>::value) {
  2116. __set_short_size(0);
  2117. traits_type::assign(__get_short_pointer()[0], value_type());
  2118. }
  2119. #endif
  2120. }
  2121. __move_assign_alloc(__str);
  2122. __r_.first() = __str.__r_.first();
  2123. __str.__set_short_size(0);
  2124. traits_type::assign(__str.__get_short_pointer()[0], value_type());
  2125. }
  2126. template <class _CharT, class _Traits, class _Allocator>
  2127. inline
  2128. basic_string<_CharT, _Traits, _Allocator>&
  2129. basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
  2130. _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
  2131. {
  2132. __move_assign(__str, integral_constant<bool,
  2133. __alloc_traits::propagate_on_container_move_assignment::value>());
  2134. return *this;
  2135. }
  2136. #endif
  2137. template <class _CharT, class _Traits, class _Allocator>
  2138. template<class _InputIterator>
  2139. __enable_if_t
  2140. <
  2141. __is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2142. basic_string<_CharT, _Traits, _Allocator>&
  2143. >
  2144. basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
  2145. {
  2146. const basic_string __temp(__first, __last, __alloc());
  2147. assign(__temp.data(), __temp.size());
  2148. return *this;
  2149. }
  2150. template <class _CharT, class _Traits, class _Allocator>
  2151. template<class _ForwardIterator>
  2152. __enable_if_t
  2153. <
  2154. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2155. basic_string<_CharT, _Traits, _Allocator>&
  2156. >
  2157. basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
  2158. {
  2159. size_type __cap = capacity();
  2160. size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
  2161. static_cast<size_type>(_VSTD::distance(__first, __last)) : 0;
  2162. if (__string_is_trivial_iterator<_ForwardIterator>::value &&
  2163. (__cap >= __n || !__addr_in_range(*__first)))
  2164. {
  2165. if (__cap < __n)
  2166. {
  2167. size_type __sz = size();
  2168. __grow_by(__cap, __n - __cap, __sz, 0, __sz);
  2169. }
  2170. pointer __p = __get_pointer();
  2171. for (; __first != __last; ++__p, (void) ++__first)
  2172. traits_type::assign(*__p, *__first);
  2173. traits_type::assign(*__p, value_type());
  2174. __set_size(__n);
  2175. __invalidate_iterators_past(__n);
  2176. }
  2177. else
  2178. {
  2179. const basic_string __temp(__first, __last, __alloc());
  2180. assign(__temp.data(), __temp.size());
  2181. }
  2182. return *this;
  2183. }
  2184. template <class _CharT, class _Traits, class _Allocator>
  2185. basic_string<_CharT, _Traits, _Allocator>&
  2186. basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
  2187. {
  2188. size_type __sz = __str.size();
  2189. if (__pos > __sz)
  2190. __throw_out_of_range();
  2191. return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
  2192. }
  2193. template <class _CharT, class _Traits, class _Allocator>
  2194. template <class _Tp>
  2195. __enable_if_t
  2196. <
  2197. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  2198. && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
  2199. basic_string<_CharT, _Traits, _Allocator>&
  2200. >
  2201. basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
  2202. {
  2203. __self_view __sv = __t;
  2204. size_type __sz = __sv.size();
  2205. if (__pos > __sz)
  2206. __throw_out_of_range();
  2207. return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
  2208. }
  2209. template <class _CharT, class _Traits, class _Allocator>
  2210. basic_string<_CharT, _Traits, _Allocator>&
  2211. basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
  2212. return __assign_external(__s, traits_type::length(__s));
  2213. }
  2214. template <class _CharT, class _Traits, class _Allocator>
  2215. basic_string<_CharT, _Traits, _Allocator>&
  2216. basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
  2217. {
  2218. _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
  2219. return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
  2220. ? (__fits_in_sso(traits_type::length(__s))
  2221. ? __assign_short(__s, traits_type::length(__s))
  2222. : __assign_external(__s, traits_type::length(__s)))
  2223. : __assign_external(__s);
  2224. }
  2225. // append
  2226. template <class _CharT, class _Traits, class _Allocator>
  2227. basic_string<_CharT, _Traits, _Allocator>&
  2228. basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
  2229. {
  2230. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
  2231. size_type __cap = capacity();
  2232. size_type __sz = size();
  2233. if (__cap - __sz >= __n)
  2234. {
  2235. if (__n)
  2236. {
  2237. value_type* __p = _VSTD::__to_address(__get_pointer());
  2238. traits_type::copy(__p + __sz, __s, __n);
  2239. __sz += __n;
  2240. __set_size(__sz);
  2241. traits_type::assign(__p[__sz], value_type());
  2242. }
  2243. }
  2244. else
  2245. __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
  2246. return *this;
  2247. }
  2248. template <class _CharT, class _Traits, class _Allocator>
  2249. basic_string<_CharT, _Traits, _Allocator>&
  2250. basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
  2251. {
  2252. if (__n)
  2253. {
  2254. size_type __cap = capacity();
  2255. size_type __sz = size();
  2256. if (__cap - __sz < __n)
  2257. __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
  2258. pointer __p = __get_pointer();
  2259. traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
  2260. __sz += __n;
  2261. __set_size(__sz);
  2262. traits_type::assign(__p[__sz], value_type());
  2263. }
  2264. return *this;
  2265. }
  2266. template <class _CharT, class _Traits, class _Allocator>
  2267. inline void
  2268. basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
  2269. {
  2270. if (__n)
  2271. {
  2272. size_type __cap = capacity();
  2273. size_type __sz = size();
  2274. if (__cap - __sz < __n)
  2275. __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
  2276. pointer __p = __get_pointer();
  2277. __sz += __n;
  2278. __set_size(__sz);
  2279. traits_type::assign(__p[__sz], value_type());
  2280. }
  2281. }
  2282. template <class _CharT, class _Traits, class _Allocator>
  2283. void
  2284. basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
  2285. {
  2286. bool __is_short = !__is_long();
  2287. size_type __cap;
  2288. size_type __sz;
  2289. if (__is_short)
  2290. {
  2291. __cap = __min_cap - 1;
  2292. __sz = __get_short_size();
  2293. }
  2294. else
  2295. {
  2296. __cap = __get_long_cap() - 1;
  2297. __sz = __get_long_size();
  2298. }
  2299. if (__sz == __cap)
  2300. {
  2301. __grow_by(__cap, 1, __sz, __sz, 0);
  2302. __is_short = false; // the string is always long after __grow_by
  2303. }
  2304. pointer __p;
  2305. if (__is_short)
  2306. {
  2307. __p = __get_short_pointer() + __sz;
  2308. __set_short_size(__sz+1);
  2309. }
  2310. else
  2311. {
  2312. __p = __get_long_pointer() + __sz;
  2313. __set_long_size(__sz+1);
  2314. }
  2315. traits_type::assign(*__p, __c);
  2316. traits_type::assign(*++__p, value_type());
  2317. }
  2318. template <class _CharT, class _Traits, class _Allocator>
  2319. template<class _ForwardIterator>
  2320. __enable_if_t
  2321. <
  2322. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2323. basic_string<_CharT, _Traits, _Allocator>&
  2324. >
  2325. basic_string<_CharT, _Traits, _Allocator>::append(
  2326. _ForwardIterator __first, _ForwardIterator __last)
  2327. {
  2328. size_type __sz = size();
  2329. size_type __cap = capacity();
  2330. size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
  2331. if (__n)
  2332. {
  2333. if (__string_is_trivial_iterator<_ForwardIterator>::value &&
  2334. !__addr_in_range(*__first))
  2335. {
  2336. if (__cap - __sz < __n)
  2337. __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
  2338. pointer __p = __get_pointer() + __sz;
  2339. for (; __first != __last; ++__p, (void) ++__first)
  2340. traits_type::assign(*__p, *__first);
  2341. traits_type::assign(*__p, value_type());
  2342. __set_size(__sz + __n);
  2343. }
  2344. else
  2345. {
  2346. const basic_string __temp(__first, __last, __alloc());
  2347. append(__temp.data(), __temp.size());
  2348. }
  2349. }
  2350. return *this;
  2351. }
  2352. template <class _CharT, class _Traits, class _Allocator>
  2353. inline
  2354. basic_string<_CharT, _Traits, _Allocator>&
  2355. basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
  2356. {
  2357. return append(__str.data(), __str.size());
  2358. }
  2359. template <class _CharT, class _Traits, class _Allocator>
  2360. basic_string<_CharT, _Traits, _Allocator>&
  2361. basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
  2362. {
  2363. size_type __sz = __str.size();
  2364. if (__pos > __sz)
  2365. __throw_out_of_range();
  2366. return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
  2367. }
  2368. template <class _CharT, class _Traits, class _Allocator>
  2369. template <class _Tp>
  2370. __enable_if_t
  2371. <
  2372. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
  2373. basic_string<_CharT, _Traits, _Allocator>&
  2374. >
  2375. basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
  2376. {
  2377. __self_view __sv = __t;
  2378. size_type __sz = __sv.size();
  2379. if (__pos > __sz)
  2380. __throw_out_of_range();
  2381. return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
  2382. }
  2383. template <class _CharT, class _Traits, class _Allocator>
  2384. basic_string<_CharT, _Traits, _Allocator>&
  2385. basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
  2386. {
  2387. _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
  2388. return append(__s, traits_type::length(__s));
  2389. }
  2390. // insert
  2391. template <class _CharT, class _Traits, class _Allocator>
  2392. basic_string<_CharT, _Traits, _Allocator>&
  2393. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
  2394. {
  2395. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
  2396. size_type __sz = size();
  2397. if (__pos > __sz)
  2398. __throw_out_of_range();
  2399. size_type __cap = capacity();
  2400. if (__cap - __sz >= __n)
  2401. {
  2402. if (__n)
  2403. {
  2404. value_type* __p = _VSTD::__to_address(__get_pointer());
  2405. size_type __n_move = __sz - __pos;
  2406. if (__n_move != 0)
  2407. {
  2408. if (__p + __pos <= __s && __s < __p + __sz)
  2409. __s += __n;
  2410. traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
  2411. }
  2412. traits_type::move(__p + __pos, __s, __n);
  2413. __sz += __n;
  2414. __set_size(__sz);
  2415. traits_type::assign(__p[__sz], value_type());
  2416. }
  2417. }
  2418. else
  2419. __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
  2420. return *this;
  2421. }
  2422. template <class _CharT, class _Traits, class _Allocator>
  2423. basic_string<_CharT, _Traits, _Allocator>&
  2424. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
  2425. {
  2426. size_type __sz = size();
  2427. if (__pos > __sz)
  2428. __throw_out_of_range();
  2429. if (__n)
  2430. {
  2431. size_type __cap = capacity();
  2432. value_type* __p;
  2433. if (__cap - __sz >= __n)
  2434. {
  2435. __p = _VSTD::__to_address(__get_pointer());
  2436. size_type __n_move = __sz - __pos;
  2437. if (__n_move != 0)
  2438. traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
  2439. }
  2440. else
  2441. {
  2442. __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
  2443. __p = _VSTD::__to_address(__get_long_pointer());
  2444. }
  2445. traits_type::assign(__p + __pos, __n, __c);
  2446. __sz += __n;
  2447. __set_size(__sz);
  2448. traits_type::assign(__p[__sz], value_type());
  2449. }
  2450. return *this;
  2451. }
  2452. template <class _CharT, class _Traits, class _Allocator>
  2453. template<class _InputIterator>
  2454. __enable_if_t
  2455. <
  2456. __is_exactly_cpp17_input_iterator<_InputIterator>::value,
  2457. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2458. >
  2459. basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
  2460. {
  2461. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
  2462. "string::insert(iterator, range) called with an iterator not"
  2463. " referring to this string");
  2464. const basic_string __temp(__first, __last, __alloc());
  2465. return insert(__pos, __temp.data(), __temp.data() + __temp.size());
  2466. }
  2467. template <class _CharT, class _Traits, class _Allocator>
  2468. template<class _ForwardIterator>
  2469. __enable_if_t
  2470. <
  2471. __is_cpp17_forward_iterator<_ForwardIterator>::value,
  2472. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2473. >
  2474. basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
  2475. {
  2476. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
  2477. "string::insert(iterator, range) called with an iterator not"
  2478. " referring to this string");
  2479. size_type __ip = static_cast<size_type>(__pos - begin());
  2480. size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
  2481. if (__n)
  2482. {
  2483. if (__string_is_trivial_iterator<_ForwardIterator>::value &&
  2484. !__addr_in_range(*__first))
  2485. {
  2486. size_type __sz = size();
  2487. size_type __cap = capacity();
  2488. value_type* __p;
  2489. if (__cap - __sz >= __n)
  2490. {
  2491. __p = _VSTD::__to_address(__get_pointer());
  2492. size_type __n_move = __sz - __ip;
  2493. if (__n_move != 0)
  2494. traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
  2495. }
  2496. else
  2497. {
  2498. __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
  2499. __p = _VSTD::__to_address(__get_long_pointer());
  2500. }
  2501. __sz += __n;
  2502. __set_size(__sz);
  2503. traits_type::assign(__p[__sz], value_type());
  2504. for (__p += __ip; __first != __last; ++__p, (void) ++__first)
  2505. traits_type::assign(*__p, *__first);
  2506. }
  2507. else
  2508. {
  2509. const basic_string __temp(__first, __last, __alloc());
  2510. return insert(__pos, __temp.data(), __temp.data() + __temp.size());
  2511. }
  2512. }
  2513. return begin() + __ip;
  2514. }
  2515. template <class _CharT, class _Traits, class _Allocator>
  2516. inline
  2517. basic_string<_CharT, _Traits, _Allocator>&
  2518. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
  2519. {
  2520. return insert(__pos1, __str.data(), __str.size());
  2521. }
  2522. template <class _CharT, class _Traits, class _Allocator>
  2523. basic_string<_CharT, _Traits, _Allocator>&
  2524. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
  2525. size_type __pos2, size_type __n)
  2526. {
  2527. size_type __str_sz = __str.size();
  2528. if (__pos2 > __str_sz)
  2529. __throw_out_of_range();
  2530. return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
  2531. }
  2532. template <class _CharT, class _Traits, class _Allocator>
  2533. template <class _Tp>
  2534. __enable_if_t
  2535. <
  2536. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
  2537. basic_string<_CharT, _Traits, _Allocator>&
  2538. >
  2539. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
  2540. size_type __pos2, size_type __n)
  2541. {
  2542. __self_view __sv = __t;
  2543. size_type __str_sz = __sv.size();
  2544. if (__pos2 > __str_sz)
  2545. __throw_out_of_range();
  2546. return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
  2547. }
  2548. template <class _CharT, class _Traits, class _Allocator>
  2549. basic_string<_CharT, _Traits, _Allocator>&
  2550. basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
  2551. {
  2552. _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
  2553. return insert(__pos, __s, traits_type::length(__s));
  2554. }
  2555. template <class _CharT, class _Traits, class _Allocator>
  2556. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2557. basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
  2558. {
  2559. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
  2560. "string::insert(iterator, character) called with an iterator not"
  2561. " referring to this string");
  2562. size_type __ip = static_cast<size_type>(__pos - begin());
  2563. size_type __sz = size();
  2564. size_type __cap = capacity();
  2565. value_type* __p;
  2566. if (__cap == __sz)
  2567. {
  2568. __grow_by(__cap, 1, __sz, __ip, 0, 1);
  2569. __p = _VSTD::__to_address(__get_long_pointer());
  2570. }
  2571. else
  2572. {
  2573. __p = _VSTD::__to_address(__get_pointer());
  2574. size_type __n_move = __sz - __ip;
  2575. if (__n_move != 0)
  2576. traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
  2577. }
  2578. traits_type::assign(__p[__ip], __c);
  2579. traits_type::assign(__p[++__sz], value_type());
  2580. __set_size(__sz);
  2581. return begin() + static_cast<difference_type>(__ip);
  2582. }
  2583. template <class _CharT, class _Traits, class _Allocator>
  2584. inline
  2585. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2586. basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
  2587. {
  2588. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
  2589. "string::insert(iterator, n, value) called with an iterator not"
  2590. " referring to this string");
  2591. difference_type __p = __pos - begin();
  2592. insert(static_cast<size_type>(__p), __n, __c);
  2593. return begin() + __p;
  2594. }
  2595. // replace
  2596. template <class _CharT, class _Traits, class _Allocator>
  2597. basic_string<_CharT, _Traits, _Allocator>&
  2598. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
  2599. _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
  2600. {
  2601. _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
  2602. size_type __sz = size();
  2603. if (__pos > __sz)
  2604. __throw_out_of_range();
  2605. __n1 = _VSTD::min(__n1, __sz - __pos);
  2606. size_type __cap = capacity();
  2607. if (__cap - __sz + __n1 >= __n2)
  2608. {
  2609. value_type* __p = _VSTD::__to_address(__get_pointer());
  2610. if (__n1 != __n2)
  2611. {
  2612. size_type __n_move = __sz - __pos - __n1;
  2613. if (__n_move != 0)
  2614. {
  2615. if (__n1 > __n2)
  2616. {
  2617. traits_type::move(__p + __pos, __s, __n2);
  2618. traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
  2619. return __null_terminate_at(__p, __sz + (__n2 - __n1));
  2620. }
  2621. if (__p + __pos < __s && __s < __p + __sz)
  2622. {
  2623. if (__p + __pos + __n1 <= __s)
  2624. __s += __n2 - __n1;
  2625. else // __p + __pos < __s < __p + __pos + __n1
  2626. {
  2627. traits_type::move(__p + __pos, __s, __n1);
  2628. __pos += __n1;
  2629. __s += __n2;
  2630. __n2 -= __n1;
  2631. __n1 = 0;
  2632. }
  2633. }
  2634. traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
  2635. }
  2636. }
  2637. traits_type::move(__p + __pos, __s, __n2);
  2638. return __null_terminate_at(__p, __sz + (__n2 - __n1));
  2639. }
  2640. else
  2641. __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
  2642. return *this;
  2643. }
  2644. template <class _CharT, class _Traits, class _Allocator>
  2645. basic_string<_CharT, _Traits, _Allocator>&
  2646. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
  2647. {
  2648. size_type __sz = size();
  2649. if (__pos > __sz)
  2650. __throw_out_of_range();
  2651. __n1 = _VSTD::min(__n1, __sz - __pos);
  2652. size_type __cap = capacity();
  2653. value_type* __p;
  2654. if (__cap - __sz + __n1 >= __n2)
  2655. {
  2656. __p = _VSTD::__to_address(__get_pointer());
  2657. if (__n1 != __n2)
  2658. {
  2659. size_type __n_move = __sz - __pos - __n1;
  2660. if (__n_move != 0)
  2661. traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
  2662. }
  2663. }
  2664. else
  2665. {
  2666. __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
  2667. __p = _VSTD::__to_address(__get_long_pointer());
  2668. }
  2669. traits_type::assign(__p + __pos, __n2, __c);
  2670. return __null_terminate_at(__p, __sz - (__n1 - __n2));
  2671. }
  2672. template <class _CharT, class _Traits, class _Allocator>
  2673. template<class _InputIterator>
  2674. __enable_if_t
  2675. <
  2676. __is_cpp17_input_iterator<_InputIterator>::value,
  2677. basic_string<_CharT, _Traits, _Allocator>&
  2678. >
  2679. basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
  2680. _InputIterator __j1, _InputIterator __j2)
  2681. {
  2682. const basic_string __temp(__j1, __j2, __alloc());
  2683. return replace(__i1, __i2, __temp);
  2684. }
  2685. template <class _CharT, class _Traits, class _Allocator>
  2686. inline
  2687. basic_string<_CharT, _Traits, _Allocator>&
  2688. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
  2689. {
  2690. return replace(__pos1, __n1, __str.data(), __str.size());
  2691. }
  2692. template <class _CharT, class _Traits, class _Allocator>
  2693. basic_string<_CharT, _Traits, _Allocator>&
  2694. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
  2695. size_type __pos2, size_type __n2)
  2696. {
  2697. size_type __str_sz = __str.size();
  2698. if (__pos2 > __str_sz)
  2699. __throw_out_of_range();
  2700. return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
  2701. }
  2702. template <class _CharT, class _Traits, class _Allocator>
  2703. template <class _Tp>
  2704. __enable_if_t
  2705. <
  2706. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
  2707. basic_string<_CharT, _Traits, _Allocator>&
  2708. >
  2709. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
  2710. size_type __pos2, size_type __n2)
  2711. {
  2712. __self_view __sv = __t;
  2713. size_type __str_sz = __sv.size();
  2714. if (__pos2 > __str_sz)
  2715. __throw_out_of_range();
  2716. return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
  2717. }
  2718. template <class _CharT, class _Traits, class _Allocator>
  2719. basic_string<_CharT, _Traits, _Allocator>&
  2720. basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
  2721. {
  2722. _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
  2723. return replace(__pos, __n1, __s, traits_type::length(__s));
  2724. }
  2725. template <class _CharT, class _Traits, class _Allocator>
  2726. inline
  2727. basic_string<_CharT, _Traits, _Allocator>&
  2728. basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
  2729. {
  2730. return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
  2731. __str.data(), __str.size());
  2732. }
  2733. template <class _CharT, class _Traits, class _Allocator>
  2734. inline
  2735. basic_string<_CharT, _Traits, _Allocator>&
  2736. basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
  2737. {
  2738. return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
  2739. }
  2740. template <class _CharT, class _Traits, class _Allocator>
  2741. inline
  2742. basic_string<_CharT, _Traits, _Allocator>&
  2743. basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
  2744. {
  2745. return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
  2746. }
  2747. template <class _CharT, class _Traits, class _Allocator>
  2748. inline
  2749. basic_string<_CharT, _Traits, _Allocator>&
  2750. basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
  2751. {
  2752. return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
  2753. }
  2754. // erase
  2755. // 'externally instantiated' erase() implementation, called when __n != npos.
  2756. // Does not check __pos against size()
  2757. template <class _CharT, class _Traits, class _Allocator>
  2758. void
  2759. basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
  2760. size_type __pos, size_type __n)
  2761. {
  2762. if (__n)
  2763. {
  2764. size_type __sz = size();
  2765. value_type* __p = _VSTD::__to_address(__get_pointer());
  2766. __n = _VSTD::min(__n, __sz - __pos);
  2767. size_type __n_move = __sz - __pos - __n;
  2768. if (__n_move != 0)
  2769. traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
  2770. __null_terminate_at(__p, __sz - __n);
  2771. }
  2772. }
  2773. template <class _CharT, class _Traits, class _Allocator>
  2774. basic_string<_CharT, _Traits, _Allocator>&
  2775. basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
  2776. size_type __n) {
  2777. if (__pos > size())
  2778. __throw_out_of_range();
  2779. if (__n == npos) {
  2780. __erase_to_end(__pos);
  2781. } else {
  2782. __erase_external_with_move(__pos, __n);
  2783. }
  2784. return *this;
  2785. }
  2786. template <class _CharT, class _Traits, class _Allocator>
  2787. inline
  2788. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2789. basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
  2790. {
  2791. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
  2792. "string::erase(iterator) called with an iterator not"
  2793. " referring to this string");
  2794. _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator");
  2795. iterator __b = begin();
  2796. size_type __r = static_cast<size_type>(__pos - __b);
  2797. erase(__r, 1);
  2798. return __b + static_cast<difference_type>(__r);
  2799. }
  2800. template <class _CharT, class _Traits, class _Allocator>
  2801. inline
  2802. typename basic_string<_CharT, _Traits, _Allocator>::iterator
  2803. basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
  2804. {
  2805. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
  2806. "string::erase(iterator, iterator) called with an iterator not"
  2807. " referring to this string");
  2808. _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
  2809. iterator __b = begin();
  2810. size_type __r = static_cast<size_type>(__first - __b);
  2811. erase(__r, static_cast<size_type>(__last - __first));
  2812. return __b + static_cast<difference_type>(__r);
  2813. }
  2814. template <class _CharT, class _Traits, class _Allocator>
  2815. inline
  2816. void
  2817. basic_string<_CharT, _Traits, _Allocator>::pop_back()
  2818. {
  2819. _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
  2820. __erase_to_end(size() - 1);
  2821. }
  2822. template <class _CharT, class _Traits, class _Allocator>
  2823. inline
  2824. void
  2825. basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
  2826. {
  2827. __invalidate_all_iterators();
  2828. if (__is_long())
  2829. {
  2830. traits_type::assign(*__get_long_pointer(), value_type());
  2831. __set_long_size(0);
  2832. }
  2833. else
  2834. {
  2835. traits_type::assign(*__get_short_pointer(), value_type());
  2836. __set_short_size(0);
  2837. }
  2838. }
  2839. template <class _CharT, class _Traits, class _Allocator>
  2840. inline
  2841. void
  2842. basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
  2843. {
  2844. __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos);
  2845. }
  2846. template <class _CharT, class _Traits, class _Allocator>
  2847. void
  2848. basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
  2849. {
  2850. size_type __sz = size();
  2851. if (__n > __sz)
  2852. append(__n - __sz, __c);
  2853. else
  2854. __erase_to_end(__n);
  2855. }
  2856. template <class _CharT, class _Traits, class _Allocator>
  2857. inline void
  2858. basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
  2859. {
  2860. size_type __sz = size();
  2861. if (__n > __sz) {
  2862. __append_default_init(__n - __sz);
  2863. } else
  2864. __erase_to_end(__n);
  2865. }
  2866. template <class _CharT, class _Traits, class _Allocator>
  2867. inline
  2868. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  2869. basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
  2870. {
  2871. size_type __m = __alloc_traits::max_size(__alloc());
  2872. #ifdef _LIBCPP_BIG_ENDIAN
  2873. return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
  2874. #else
  2875. return __m - __alignment;
  2876. #endif
  2877. }
  2878. template <class _CharT, class _Traits, class _Allocator>
  2879. void
  2880. basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
  2881. {
  2882. if (__requested_capacity > max_size())
  2883. __throw_length_error();
  2884. // Make sure reserve(n) never shrinks. This is technically only required in C++20
  2885. // and later (since P0966R1), however we provide consistent behavior in all Standard
  2886. // modes because this function is instantiated in the shared library.
  2887. if (__requested_capacity <= capacity())
  2888. return;
  2889. size_type __target_capacity = _VSTD::max(__requested_capacity, size());
  2890. __target_capacity = __recommend(__target_capacity);
  2891. if (__target_capacity == capacity()) return;
  2892. __shrink_or_extend(__target_capacity);
  2893. }
  2894. template <class _CharT, class _Traits, class _Allocator>
  2895. inline
  2896. void
  2897. basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
  2898. {
  2899. size_type __target_capacity = __recommend(size());
  2900. if (__target_capacity == capacity()) return;
  2901. __shrink_or_extend(__target_capacity);
  2902. }
  2903. template <class _CharT, class _Traits, class _Allocator>
  2904. inline
  2905. void
  2906. basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
  2907. {
  2908. size_type __cap = capacity();
  2909. size_type __sz = size();
  2910. pointer __new_data, __p;
  2911. bool __was_long, __now_long;
  2912. if (__target_capacity == __min_cap - 1)
  2913. {
  2914. __was_long = true;
  2915. __now_long = false;
  2916. __new_data = __get_short_pointer();
  2917. __p = __get_long_pointer();
  2918. }
  2919. else
  2920. {
  2921. if (__target_capacity > __cap)
  2922. __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
  2923. else
  2924. {
  2925. #ifndef _LIBCPP_NO_EXCEPTIONS
  2926. try
  2927. {
  2928. #endif // _LIBCPP_NO_EXCEPTIONS
  2929. __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
  2930. #ifndef _LIBCPP_NO_EXCEPTIONS
  2931. }
  2932. catch (...)
  2933. {
  2934. return;
  2935. }
  2936. #else // _LIBCPP_NO_EXCEPTIONS
  2937. if (__new_data == nullptr)
  2938. return;
  2939. #endif // _LIBCPP_NO_EXCEPTIONS
  2940. }
  2941. __now_long = true;
  2942. __was_long = __is_long();
  2943. __p = __get_pointer();
  2944. }
  2945. traits_type::copy(_VSTD::__to_address(__new_data),
  2946. _VSTD::__to_address(__p), size()+1);
  2947. if (__was_long)
  2948. __alloc_traits::deallocate(__alloc(), __p, __cap+1);
  2949. if (__now_long)
  2950. {
  2951. __set_long_cap(__target_capacity+1);
  2952. __set_long_size(__sz);
  2953. __set_long_pointer(__new_data);
  2954. }
  2955. else
  2956. __set_short_size(__sz);
  2957. __invalidate_all_iterators();
  2958. }
  2959. template <class _CharT, class _Traits, class _Allocator>
  2960. inline
  2961. typename basic_string<_CharT, _Traits, _Allocator>::const_reference
  2962. basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
  2963. {
  2964. _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
  2965. return *(data() + __pos);
  2966. }
  2967. template <class _CharT, class _Traits, class _Allocator>
  2968. inline
  2969. typename basic_string<_CharT, _Traits, _Allocator>::reference
  2970. basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
  2971. {
  2972. _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
  2973. return *(__get_pointer() + __pos);
  2974. }
  2975. template <class _CharT, class _Traits, class _Allocator>
  2976. typename basic_string<_CharT, _Traits, _Allocator>::const_reference
  2977. basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
  2978. {
  2979. if (__n >= size())
  2980. __throw_out_of_range();
  2981. return (*this)[__n];
  2982. }
  2983. template <class _CharT, class _Traits, class _Allocator>
  2984. typename basic_string<_CharT, _Traits, _Allocator>::reference
  2985. basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
  2986. {
  2987. if (__n >= size())
  2988. __throw_out_of_range();
  2989. return (*this)[__n];
  2990. }
  2991. template <class _CharT, class _Traits, class _Allocator>
  2992. inline
  2993. typename basic_string<_CharT, _Traits, _Allocator>::reference
  2994. basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
  2995. {
  2996. _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
  2997. return *__get_pointer();
  2998. }
  2999. template <class _CharT, class _Traits, class _Allocator>
  3000. inline
  3001. typename basic_string<_CharT, _Traits, _Allocator>::const_reference
  3002. basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
  3003. {
  3004. _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
  3005. return *data();
  3006. }
  3007. template <class _CharT, class _Traits, class _Allocator>
  3008. inline
  3009. typename basic_string<_CharT, _Traits, _Allocator>::reference
  3010. basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
  3011. {
  3012. _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
  3013. return *(__get_pointer() + size() - 1);
  3014. }
  3015. template <class _CharT, class _Traits, class _Allocator>
  3016. inline
  3017. typename basic_string<_CharT, _Traits, _Allocator>::const_reference
  3018. basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
  3019. {
  3020. _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
  3021. return *(data() + size() - 1);
  3022. }
  3023. template <class _CharT, class _Traits, class _Allocator>
  3024. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3025. basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
  3026. {
  3027. size_type __sz = size();
  3028. if (__pos > __sz)
  3029. __throw_out_of_range();
  3030. size_type __rlen = _VSTD::min(__n, __sz - __pos);
  3031. traits_type::copy(__s, data() + __pos, __rlen);
  3032. return __rlen;
  3033. }
  3034. template <class _CharT, class _Traits, class _Allocator>
  3035. inline
  3036. basic_string<_CharT, _Traits, _Allocator>
  3037. basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
  3038. {
  3039. return basic_string(*this, __pos, __n, __alloc());
  3040. }
  3041. template <class _CharT, class _Traits, class _Allocator>
  3042. inline
  3043. void
  3044. basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
  3045. #if _LIBCPP_STD_VER >= 14
  3046. _NOEXCEPT
  3047. #else
  3048. _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
  3049. __is_nothrow_swappable<allocator_type>::value)
  3050. #endif
  3051. {
  3052. #if _LIBCPP_DEBUG_LEVEL == 2
  3053. if (!__libcpp_is_constant_evaluated()) {
  3054. if (!__is_long())
  3055. __get_db()->__invalidate_all(this);
  3056. if (!__str.__is_long())
  3057. __get_db()->__invalidate_all(&__str);
  3058. __get_db()->swap(this, &__str);
  3059. }
  3060. #endif
  3061. _LIBCPP_ASSERT(
  3062. __alloc_traits::propagate_on_container_swap::value ||
  3063. __alloc_traits::is_always_equal::value ||
  3064. __alloc() == __str.__alloc(), "swapping non-equal allocators");
  3065. _VSTD::swap(__r_.first(), __str.__r_.first());
  3066. _VSTD::__swap_allocator(__alloc(), __str.__alloc());
  3067. }
  3068. // find
  3069. template <class _Traits>
  3070. struct _LIBCPP_HIDDEN __traits_eq
  3071. {
  3072. typedef typename _Traits::char_type char_type;
  3073. _LIBCPP_INLINE_VISIBILITY
  3074. bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
  3075. {return _Traits::eq(__x, __y);}
  3076. };
  3077. template<class _CharT, class _Traits, class _Allocator>
  3078. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3079. basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
  3080. size_type __pos,
  3081. size_type __n) const _NOEXCEPT
  3082. {
  3083. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
  3084. return __str_find<value_type, size_type, traits_type, npos>
  3085. (data(), size(), __s, __pos, __n);
  3086. }
  3087. template<class _CharT, class _Traits, class _Allocator>
  3088. inline
  3089. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3090. basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
  3091. size_type __pos) const _NOEXCEPT
  3092. {
  3093. return __str_find<value_type, size_type, traits_type, npos>
  3094. (data(), size(), __str.data(), __pos, __str.size());
  3095. }
  3096. template<class _CharT, class _Traits, class _Allocator>
  3097. template <class _Tp>
  3098. __enable_if_t
  3099. <
  3100. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3101. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3102. >
  3103. basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
  3104. size_type __pos) const _NOEXCEPT
  3105. {
  3106. __self_view __sv = __t;
  3107. return __str_find<value_type, size_type, traits_type, npos>
  3108. (data(), size(), __sv.data(), __pos, __sv.size());
  3109. }
  3110. template<class _CharT, class _Traits, class _Allocator>
  3111. inline
  3112. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3113. basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
  3114. size_type __pos) const _NOEXCEPT
  3115. {
  3116. _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
  3117. return __str_find<value_type, size_type, traits_type, npos>
  3118. (data(), size(), __s, __pos, traits_type::length(__s));
  3119. }
  3120. template<class _CharT, class _Traits, class _Allocator>
  3121. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3122. basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
  3123. size_type __pos) const _NOEXCEPT
  3124. {
  3125. return __str_find<value_type, size_type, traits_type, npos>
  3126. (data(), size(), __c, __pos);
  3127. }
  3128. // rfind
  3129. template<class _CharT, class _Traits, class _Allocator>
  3130. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3131. basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
  3132. size_type __pos,
  3133. size_type __n) const _NOEXCEPT
  3134. {
  3135. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
  3136. return __str_rfind<value_type, size_type, traits_type, npos>
  3137. (data(), size(), __s, __pos, __n);
  3138. }
  3139. template<class _CharT, class _Traits, class _Allocator>
  3140. inline
  3141. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3142. basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
  3143. size_type __pos) const _NOEXCEPT
  3144. {
  3145. return __str_rfind<value_type, size_type, traits_type, npos>
  3146. (data(), size(), __str.data(), __pos, __str.size());
  3147. }
  3148. template<class _CharT, class _Traits, class _Allocator>
  3149. template <class _Tp>
  3150. __enable_if_t
  3151. <
  3152. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3153. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3154. >
  3155. basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
  3156. size_type __pos) const _NOEXCEPT
  3157. {
  3158. __self_view __sv = __t;
  3159. return __str_rfind<value_type, size_type, traits_type, npos>
  3160. (data(), size(), __sv.data(), __pos, __sv.size());
  3161. }
  3162. template<class _CharT, class _Traits, class _Allocator>
  3163. inline
  3164. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3165. basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
  3166. size_type __pos) const _NOEXCEPT
  3167. {
  3168. _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
  3169. return __str_rfind<value_type, size_type, traits_type, npos>
  3170. (data(), size(), __s, __pos, traits_type::length(__s));
  3171. }
  3172. template<class _CharT, class _Traits, class _Allocator>
  3173. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3174. basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
  3175. size_type __pos) const _NOEXCEPT
  3176. {
  3177. return __str_rfind<value_type, size_type, traits_type, npos>
  3178. (data(), size(), __c, __pos);
  3179. }
  3180. // find_first_of
  3181. template<class _CharT, class _Traits, class _Allocator>
  3182. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3183. basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
  3184. size_type __pos,
  3185. size_type __n) const _NOEXCEPT
  3186. {
  3187. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
  3188. return __str_find_first_of<value_type, size_type, traits_type, npos>
  3189. (data(), size(), __s, __pos, __n);
  3190. }
  3191. template<class _CharT, class _Traits, class _Allocator>
  3192. inline
  3193. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3194. basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
  3195. size_type __pos) const _NOEXCEPT
  3196. {
  3197. return __str_find_first_of<value_type, size_type, traits_type, npos>
  3198. (data(), size(), __str.data(), __pos, __str.size());
  3199. }
  3200. template<class _CharT, class _Traits, class _Allocator>
  3201. template <class _Tp>
  3202. __enable_if_t
  3203. <
  3204. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3205. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3206. >
  3207. basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
  3208. size_type __pos) const _NOEXCEPT
  3209. {
  3210. __self_view __sv = __t;
  3211. return __str_find_first_of<value_type, size_type, traits_type, npos>
  3212. (data(), size(), __sv.data(), __pos, __sv.size());
  3213. }
  3214. template<class _CharT, class _Traits, class _Allocator>
  3215. inline
  3216. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3217. basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
  3218. size_type __pos) const _NOEXCEPT
  3219. {
  3220. _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
  3221. return __str_find_first_of<value_type, size_type, traits_type, npos>
  3222. (data(), size(), __s, __pos, traits_type::length(__s));
  3223. }
  3224. template<class _CharT, class _Traits, class _Allocator>
  3225. inline
  3226. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3227. basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
  3228. size_type __pos) const _NOEXCEPT
  3229. {
  3230. return find(__c, __pos);
  3231. }
  3232. // find_last_of
  3233. template<class _CharT, class _Traits, class _Allocator>
  3234. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3235. basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
  3236. size_type __pos,
  3237. size_type __n) const _NOEXCEPT
  3238. {
  3239. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
  3240. return __str_find_last_of<value_type, size_type, traits_type, npos>
  3241. (data(), size(), __s, __pos, __n);
  3242. }
  3243. template<class _CharT, class _Traits, class _Allocator>
  3244. inline
  3245. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3246. basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
  3247. size_type __pos) const _NOEXCEPT
  3248. {
  3249. return __str_find_last_of<value_type, size_type, traits_type, npos>
  3250. (data(), size(), __str.data(), __pos, __str.size());
  3251. }
  3252. template<class _CharT, class _Traits, class _Allocator>
  3253. template <class _Tp>
  3254. __enable_if_t
  3255. <
  3256. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3257. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3258. >
  3259. basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
  3260. size_type __pos) const _NOEXCEPT
  3261. {
  3262. __self_view __sv = __t;
  3263. return __str_find_last_of<value_type, size_type, traits_type, npos>
  3264. (data(), size(), __sv.data(), __pos, __sv.size());
  3265. }
  3266. template<class _CharT, class _Traits, class _Allocator>
  3267. inline
  3268. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3269. basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
  3270. size_type __pos) const _NOEXCEPT
  3271. {
  3272. _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
  3273. return __str_find_last_of<value_type, size_type, traits_type, npos>
  3274. (data(), size(), __s, __pos, traits_type::length(__s));
  3275. }
  3276. template<class _CharT, class _Traits, class _Allocator>
  3277. inline
  3278. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3279. basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
  3280. size_type __pos) const _NOEXCEPT
  3281. {
  3282. return rfind(__c, __pos);
  3283. }
  3284. // find_first_not_of
  3285. template<class _CharT, class _Traits, class _Allocator>
  3286. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3287. basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
  3288. size_type __pos,
  3289. size_type __n) const _NOEXCEPT
  3290. {
  3291. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
  3292. return __str_find_first_not_of<value_type, size_type, traits_type, npos>
  3293. (data(), size(), __s, __pos, __n);
  3294. }
  3295. template<class _CharT, class _Traits, class _Allocator>
  3296. inline
  3297. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3298. basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
  3299. size_type __pos) const _NOEXCEPT
  3300. {
  3301. return __str_find_first_not_of<value_type, size_type, traits_type, npos>
  3302. (data(), size(), __str.data(), __pos, __str.size());
  3303. }
  3304. template<class _CharT, class _Traits, class _Allocator>
  3305. template <class _Tp>
  3306. __enable_if_t
  3307. <
  3308. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3309. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3310. >
  3311. basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
  3312. size_type __pos) const _NOEXCEPT
  3313. {
  3314. __self_view __sv = __t;
  3315. return __str_find_first_not_of<value_type, size_type, traits_type, npos>
  3316. (data(), size(), __sv.data(), __pos, __sv.size());
  3317. }
  3318. template<class _CharT, class _Traits, class _Allocator>
  3319. inline
  3320. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3321. basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
  3322. size_type __pos) const _NOEXCEPT
  3323. {
  3324. _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
  3325. return __str_find_first_not_of<value_type, size_type, traits_type, npos>
  3326. (data(), size(), __s, __pos, traits_type::length(__s));
  3327. }
  3328. template<class _CharT, class _Traits, class _Allocator>
  3329. inline
  3330. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3331. basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
  3332. size_type __pos) const _NOEXCEPT
  3333. {
  3334. return __str_find_first_not_of<value_type, size_type, traits_type, npos>
  3335. (data(), size(), __c, __pos);
  3336. }
  3337. // find_last_not_of
  3338. template<class _CharT, class _Traits, class _Allocator>
  3339. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3340. basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
  3341. size_type __pos,
  3342. size_type __n) const _NOEXCEPT
  3343. {
  3344. _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
  3345. return __str_find_last_not_of<value_type, size_type, traits_type, npos>
  3346. (data(), size(), __s, __pos, __n);
  3347. }
  3348. template<class _CharT, class _Traits, class _Allocator>
  3349. inline
  3350. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3351. basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
  3352. size_type __pos) const _NOEXCEPT
  3353. {
  3354. return __str_find_last_not_of<value_type, size_type, traits_type, npos>
  3355. (data(), size(), __str.data(), __pos, __str.size());
  3356. }
  3357. template<class _CharT, class _Traits, class _Allocator>
  3358. template <class _Tp>
  3359. __enable_if_t
  3360. <
  3361. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3362. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3363. >
  3364. basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
  3365. size_type __pos) const _NOEXCEPT
  3366. {
  3367. __self_view __sv = __t;
  3368. return __str_find_last_not_of<value_type, size_type, traits_type, npos>
  3369. (data(), size(), __sv.data(), __pos, __sv.size());
  3370. }
  3371. template<class _CharT, class _Traits, class _Allocator>
  3372. inline
  3373. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3374. basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
  3375. size_type __pos) const _NOEXCEPT
  3376. {
  3377. _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
  3378. return __str_find_last_not_of<value_type, size_type, traits_type, npos>
  3379. (data(), size(), __s, __pos, traits_type::length(__s));
  3380. }
  3381. template<class _CharT, class _Traits, class _Allocator>
  3382. inline
  3383. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3384. basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
  3385. size_type __pos) const _NOEXCEPT
  3386. {
  3387. return __str_find_last_not_of<value_type, size_type, traits_type, npos>
  3388. (data(), size(), __c, __pos);
  3389. }
  3390. // compare
  3391. template <class _CharT, class _Traits, class _Allocator>
  3392. template <class _Tp>
  3393. __enable_if_t
  3394. <
  3395. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3396. int
  3397. >
  3398. basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT
  3399. {
  3400. __self_view __sv = __t;
  3401. size_t __lhs_sz = size();
  3402. size_t __rhs_sz = __sv.size();
  3403. int __result = traits_type::compare(data(), __sv.data(),
  3404. _VSTD::min(__lhs_sz, __rhs_sz));
  3405. if (__result != 0)
  3406. return __result;
  3407. if (__lhs_sz < __rhs_sz)
  3408. return -1;
  3409. if (__lhs_sz > __rhs_sz)
  3410. return 1;
  3411. return 0;
  3412. }
  3413. template <class _CharT, class _Traits, class _Allocator>
  3414. inline
  3415. int
  3416. basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
  3417. {
  3418. return compare(__self_view(__str));
  3419. }
  3420. template <class _CharT, class _Traits, class _Allocator>
  3421. int
  3422. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3423. size_type __n1,
  3424. const value_type* __s,
  3425. size_type __n2) const
  3426. {
  3427. _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
  3428. size_type __sz = size();
  3429. if (__pos1 > __sz || __n2 == npos)
  3430. __throw_out_of_range();
  3431. size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
  3432. int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
  3433. if (__r == 0)
  3434. {
  3435. if (__rlen < __n2)
  3436. __r = -1;
  3437. else if (__rlen > __n2)
  3438. __r = 1;
  3439. }
  3440. return __r;
  3441. }
  3442. template <class _CharT, class _Traits, class _Allocator>
  3443. template <class _Tp>
  3444. __enable_if_t
  3445. <
  3446. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
  3447. int
  3448. >
  3449. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3450. size_type __n1,
  3451. const _Tp& __t) const
  3452. {
  3453. __self_view __sv = __t;
  3454. return compare(__pos1, __n1, __sv.data(), __sv.size());
  3455. }
  3456. template <class _CharT, class _Traits, class _Allocator>
  3457. inline
  3458. int
  3459. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3460. size_type __n1,
  3461. const basic_string& __str) const
  3462. {
  3463. return compare(__pos1, __n1, __str.data(), __str.size());
  3464. }
  3465. template <class _CharT, class _Traits, class _Allocator>
  3466. template <class _Tp>
  3467. __enable_if_t
  3468. <
  3469. __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
  3470. && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
  3471. int
  3472. >
  3473. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3474. size_type __n1,
  3475. const _Tp& __t,
  3476. size_type __pos2,
  3477. size_type __n2) const
  3478. {
  3479. __self_view __sv = __t;
  3480. return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
  3481. }
  3482. template <class _CharT, class _Traits, class _Allocator>
  3483. int
  3484. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3485. size_type __n1,
  3486. const basic_string& __str,
  3487. size_type __pos2,
  3488. size_type __n2) const
  3489. {
  3490. return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
  3491. }
  3492. template <class _CharT, class _Traits, class _Allocator>
  3493. int
  3494. basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
  3495. {
  3496. _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
  3497. return compare(0, npos, __s, traits_type::length(__s));
  3498. }
  3499. template <class _CharT, class _Traits, class _Allocator>
  3500. int
  3501. basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
  3502. size_type __n1,
  3503. const value_type* __s) const
  3504. {
  3505. _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
  3506. return compare(__pos1, __n1, __s, traits_type::length(__s));
  3507. }
  3508. // __invariants
  3509. template<class _CharT, class _Traits, class _Allocator>
  3510. inline
  3511. bool
  3512. basic_string<_CharT, _Traits, _Allocator>::__invariants() const
  3513. {
  3514. if (size() > capacity())
  3515. return false;
  3516. if (capacity() < __min_cap - 1)
  3517. return false;
  3518. if (data() == nullptr)
  3519. return false;
  3520. if (data()[size()] != value_type())
  3521. return false;
  3522. return true;
  3523. }
  3524. // __clear_and_shrink
  3525. template<class _CharT, class _Traits, class _Allocator>
  3526. inline
  3527. void
  3528. basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
  3529. {
  3530. clear();
  3531. if(__is_long())
  3532. {
  3533. __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
  3534. __set_long_cap(0);
  3535. __set_short_size(0);
  3536. traits_type::assign(*__get_short_pointer(), value_type());
  3537. }
  3538. }
  3539. // operator==
  3540. template<class _CharT, class _Traits, class _Allocator>
  3541. inline _LIBCPP_INLINE_VISIBILITY
  3542. bool
  3543. operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3544. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3545. {
  3546. size_t __lhs_sz = __lhs.size();
  3547. return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
  3548. __rhs.data(),
  3549. __lhs_sz) == 0;
  3550. }
  3551. template<class _Allocator>
  3552. inline _LIBCPP_INLINE_VISIBILITY
  3553. bool
  3554. operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
  3555. const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
  3556. {
  3557. size_t __lhs_sz = __lhs.size();
  3558. if (__lhs_sz != __rhs.size())
  3559. return false;
  3560. const char* __lp = __lhs.data();
  3561. const char* __rp = __rhs.data();
  3562. if (__lhs.__is_long())
  3563. return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
  3564. for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
  3565. if (*__lp != *__rp)
  3566. return false;
  3567. return true;
  3568. }
  3569. template<class _CharT, class _Traits, class _Allocator>
  3570. inline _LIBCPP_INLINE_VISIBILITY
  3571. bool
  3572. operator==(const _CharT* __lhs,
  3573. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3574. {
  3575. typedef basic_string<_CharT, _Traits, _Allocator> _String;
  3576. _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
  3577. size_t __lhs_len = _Traits::length(__lhs);
  3578. if (__lhs_len != __rhs.size()) return false;
  3579. return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
  3580. }
  3581. template<class _CharT, class _Traits, class _Allocator>
  3582. inline _LIBCPP_INLINE_VISIBILITY
  3583. bool
  3584. operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  3585. const _CharT* __rhs) _NOEXCEPT
  3586. {
  3587. typedef basic_string<_CharT, _Traits, _Allocator> _String;
  3588. _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
  3589. size_t __rhs_len = _Traits::length(__rhs);
  3590. if (__rhs_len != __lhs.size()) return false;
  3591. return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
  3592. }
  3593. template<class _CharT, class _Traits, class _Allocator>
  3594. inline _LIBCPP_INLINE_VISIBILITY
  3595. bool
  3596. operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  3597. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3598. {
  3599. return !(__lhs == __rhs);
  3600. }
  3601. template<class _CharT, class _Traits, class _Allocator>
  3602. inline _LIBCPP_INLINE_VISIBILITY
  3603. bool
  3604. operator!=(const _CharT* __lhs,
  3605. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3606. {
  3607. return !(__lhs == __rhs);
  3608. }
  3609. template<class _CharT, class _Traits, class _Allocator>
  3610. inline _LIBCPP_INLINE_VISIBILITY
  3611. bool
  3612. operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3613. const _CharT* __rhs) _NOEXCEPT
  3614. {
  3615. return !(__lhs == __rhs);
  3616. }
  3617. // operator<
  3618. template<class _CharT, class _Traits, class _Allocator>
  3619. inline _LIBCPP_INLINE_VISIBILITY
  3620. bool
  3621. operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3622. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3623. {
  3624. return __lhs.compare(__rhs) < 0;
  3625. }
  3626. template<class _CharT, class _Traits, class _Allocator>
  3627. inline _LIBCPP_INLINE_VISIBILITY
  3628. bool
  3629. operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3630. const _CharT* __rhs) _NOEXCEPT
  3631. {
  3632. return __lhs.compare(__rhs) < 0;
  3633. }
  3634. template<class _CharT, class _Traits, class _Allocator>
  3635. inline _LIBCPP_INLINE_VISIBILITY
  3636. bool
  3637. operator< (const _CharT* __lhs,
  3638. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3639. {
  3640. return __rhs.compare(__lhs) > 0;
  3641. }
  3642. // operator>
  3643. template<class _CharT, class _Traits, class _Allocator>
  3644. inline _LIBCPP_INLINE_VISIBILITY
  3645. bool
  3646. operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3647. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3648. {
  3649. return __rhs < __lhs;
  3650. }
  3651. template<class _CharT, class _Traits, class _Allocator>
  3652. inline _LIBCPP_INLINE_VISIBILITY
  3653. bool
  3654. operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3655. const _CharT* __rhs) _NOEXCEPT
  3656. {
  3657. return __rhs < __lhs;
  3658. }
  3659. template<class _CharT, class _Traits, class _Allocator>
  3660. inline _LIBCPP_INLINE_VISIBILITY
  3661. bool
  3662. operator> (const _CharT* __lhs,
  3663. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3664. {
  3665. return __rhs < __lhs;
  3666. }
  3667. // operator<=
  3668. template<class _CharT, class _Traits, class _Allocator>
  3669. inline _LIBCPP_INLINE_VISIBILITY
  3670. bool
  3671. operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3672. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3673. {
  3674. return !(__rhs < __lhs);
  3675. }
  3676. template<class _CharT, class _Traits, class _Allocator>
  3677. inline _LIBCPP_INLINE_VISIBILITY
  3678. bool
  3679. operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3680. const _CharT* __rhs) _NOEXCEPT
  3681. {
  3682. return !(__rhs < __lhs);
  3683. }
  3684. template<class _CharT, class _Traits, class _Allocator>
  3685. inline _LIBCPP_INLINE_VISIBILITY
  3686. bool
  3687. operator<=(const _CharT* __lhs,
  3688. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3689. {
  3690. return !(__rhs < __lhs);
  3691. }
  3692. // operator>=
  3693. template<class _CharT, class _Traits, class _Allocator>
  3694. inline _LIBCPP_INLINE_VISIBILITY
  3695. bool
  3696. operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3697. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3698. {
  3699. return !(__lhs < __rhs);
  3700. }
  3701. template<class _CharT, class _Traits, class _Allocator>
  3702. inline _LIBCPP_INLINE_VISIBILITY
  3703. bool
  3704. operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3705. const _CharT* __rhs) _NOEXCEPT
  3706. {
  3707. return !(__lhs < __rhs);
  3708. }
  3709. template<class _CharT, class _Traits, class _Allocator>
  3710. inline _LIBCPP_INLINE_VISIBILITY
  3711. bool
  3712. operator>=(const _CharT* __lhs,
  3713. const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
  3714. {
  3715. return !(__lhs < __rhs);
  3716. }
  3717. // operator +
  3718. template<class _CharT, class _Traits, class _Allocator>
  3719. basic_string<_CharT, _Traits, _Allocator>
  3720. operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3721. const basic_string<_CharT, _Traits, _Allocator>& __rhs)
  3722. {
  3723. using _String = basic_string<_CharT, _Traits, _Allocator>;
  3724. _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
  3725. typename _String::size_type __lhs_sz = __lhs.size();
  3726. typename _String::size_type __rhs_sz = __rhs.size();
  3727. __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
  3728. __r.append(__rhs.data(), __rhs_sz);
  3729. return __r;
  3730. }
  3731. template<class _CharT, class _Traits, class _Allocator>
  3732. basic_string<_CharT, _Traits, _Allocator>
  3733. operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  3734. {
  3735. using _String = basic_string<_CharT, _Traits, _Allocator>;
  3736. _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
  3737. typename _String::size_type __lhs_sz = _Traits::length(__lhs);
  3738. typename _String::size_type __rhs_sz = __rhs.size();
  3739. __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
  3740. __r.append(__rhs.data(), __rhs_sz);
  3741. return __r;
  3742. }
  3743. template<class _CharT, class _Traits, class _Allocator>
  3744. basic_string<_CharT, _Traits, _Allocator>
  3745. operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  3746. {
  3747. using _String = basic_string<_CharT, _Traits, _Allocator>;
  3748. _String __r(_String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
  3749. typename _String::size_type __rhs_sz = __rhs.size();
  3750. __r.__init(&__lhs, 1, 1 + __rhs_sz);
  3751. __r.append(__rhs.data(), __rhs_sz);
  3752. return __r;
  3753. }
  3754. template<class _CharT, class _Traits, class _Allocator>
  3755. inline
  3756. basic_string<_CharT, _Traits, _Allocator>
  3757. operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
  3758. {
  3759. using _String = basic_string<_CharT, _Traits, _Allocator>;
  3760. _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
  3761. typename _String::size_type __lhs_sz = __lhs.size();
  3762. typename _String::size_type __rhs_sz = _Traits::length(__rhs);
  3763. __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
  3764. __r.append(__rhs, __rhs_sz);
  3765. return __r;
  3766. }
  3767. template<class _CharT, class _Traits, class _Allocator>
  3768. basic_string<_CharT, _Traits, _Allocator>
  3769. operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
  3770. {
  3771. using _String = basic_string<_CharT, _Traits, _Allocator>;
  3772. _String __r(_String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
  3773. typename _String::size_type __lhs_sz = __lhs.size();
  3774. __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
  3775. __r.push_back(__rhs);
  3776. return __r;
  3777. }
  3778. #ifndef _LIBCPP_CXX03_LANG
  3779. template<class _CharT, class _Traits, class _Allocator>
  3780. inline _LIBCPP_INLINE_VISIBILITY
  3781. basic_string<_CharT, _Traits, _Allocator>
  3782. operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
  3783. {
  3784. return _VSTD::move(__lhs.append(__rhs));
  3785. }
  3786. template<class _CharT, class _Traits, class _Allocator>
  3787. inline _LIBCPP_INLINE_VISIBILITY
  3788. basic_string<_CharT, _Traits, _Allocator>
  3789. operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
  3790. {
  3791. return _VSTD::move(__rhs.insert(0, __lhs));
  3792. }
  3793. template<class _CharT, class _Traits, class _Allocator>
  3794. inline _LIBCPP_INLINE_VISIBILITY
  3795. basic_string<_CharT, _Traits, _Allocator>
  3796. operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
  3797. {
  3798. return _VSTD::move(__lhs.append(__rhs));
  3799. }
  3800. template<class _CharT, class _Traits, class _Allocator>
  3801. inline _LIBCPP_INLINE_VISIBILITY
  3802. basic_string<_CharT, _Traits, _Allocator>
  3803. operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
  3804. {
  3805. return _VSTD::move(__rhs.insert(0, __lhs));
  3806. }
  3807. template<class _CharT, class _Traits, class _Allocator>
  3808. inline _LIBCPP_INLINE_VISIBILITY
  3809. basic_string<_CharT, _Traits, _Allocator>
  3810. operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
  3811. {
  3812. __rhs.insert(__rhs.begin(), __lhs);
  3813. return _VSTD::move(__rhs);
  3814. }
  3815. template<class _CharT, class _Traits, class _Allocator>
  3816. inline _LIBCPP_INLINE_VISIBILITY
  3817. basic_string<_CharT, _Traits, _Allocator>
  3818. operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
  3819. {
  3820. return _VSTD::move(__lhs.append(__rhs));
  3821. }
  3822. template<class _CharT, class _Traits, class _Allocator>
  3823. inline _LIBCPP_INLINE_VISIBILITY
  3824. basic_string<_CharT, _Traits, _Allocator>
  3825. operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
  3826. {
  3827. __lhs.push_back(__rhs);
  3828. return _VSTD::move(__lhs);
  3829. }
  3830. #endif // _LIBCPP_CXX03_LANG
  3831. // swap
  3832. template<class _CharT, class _Traits, class _Allocator>
  3833. inline _LIBCPP_INLINE_VISIBILITY
  3834. void
  3835. swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
  3836. basic_string<_CharT, _Traits, _Allocator>& __rhs)
  3837. _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
  3838. {
  3839. __lhs.swap(__rhs);
  3840. }
  3841. _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);
  3842. _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10);
  3843. _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
  3844. _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
  3845. _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
  3846. _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr);
  3847. _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr);
  3848. _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr);
  3849. _LIBCPP_FUNC_VIS string to_string(int __val);
  3850. _LIBCPP_FUNC_VIS string to_string(unsigned __val);
  3851. _LIBCPP_FUNC_VIS string to_string(long __val);
  3852. _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
  3853. _LIBCPP_FUNC_VIS string to_string(long long __val);
  3854. _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
  3855. _LIBCPP_FUNC_VIS string to_string(float __val);
  3856. _LIBCPP_FUNC_VIS string to_string(double __val);
  3857. _LIBCPP_FUNC_VIS string to_string(long double __val);
  3858. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  3859. _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
  3860. _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
  3861. _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
  3862. _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
  3863. _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
  3864. _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr);
  3865. _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr);
  3866. _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr);
  3867. _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
  3868. _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
  3869. _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
  3870. _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
  3871. _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
  3872. _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
  3873. _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
  3874. _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
  3875. _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
  3876. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  3877. template<class _CharT, class _Traits, class _Allocator>
  3878. _LIBCPP_TEMPLATE_DATA_VIS
  3879. const typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3880. basic_string<_CharT, _Traits, _Allocator>::npos;
  3881. template <class _CharT, class _Allocator>
  3882. struct _LIBCPP_TEMPLATE_VIS
  3883. hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
  3884. : public unary_function<
  3885. basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
  3886. {
  3887. size_t
  3888. operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
  3889. { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
  3890. };
  3891. template<class _CharT, class _Traits, class _Allocator>
  3892. basic_ostream<_CharT, _Traits>&
  3893. operator<<(basic_ostream<_CharT, _Traits>& __os,
  3894. const basic_string<_CharT, _Traits, _Allocator>& __str);
  3895. template<class _CharT, class _Traits, class _Allocator>
  3896. basic_istream<_CharT, _Traits>&
  3897. operator>>(basic_istream<_CharT, _Traits>& __is,
  3898. basic_string<_CharT, _Traits, _Allocator>& __str);
  3899. template<class _CharT, class _Traits, class _Allocator>
  3900. basic_istream<_CharT, _Traits>&
  3901. getline(basic_istream<_CharT, _Traits>& __is,
  3902. basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
  3903. template<class _CharT, class _Traits, class _Allocator>
  3904. inline _LIBCPP_INLINE_VISIBILITY
  3905. basic_istream<_CharT, _Traits>&
  3906. getline(basic_istream<_CharT, _Traits>& __is,
  3907. basic_string<_CharT, _Traits, _Allocator>& __str);
  3908. template<class _CharT, class _Traits, class _Allocator>
  3909. inline _LIBCPP_INLINE_VISIBILITY
  3910. basic_istream<_CharT, _Traits>&
  3911. getline(basic_istream<_CharT, _Traits>&& __is,
  3912. basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
  3913. template<class _CharT, class _Traits, class _Allocator>
  3914. inline _LIBCPP_INLINE_VISIBILITY
  3915. basic_istream<_CharT, _Traits>&
  3916. getline(basic_istream<_CharT, _Traits>&& __is,
  3917. basic_string<_CharT, _Traits, _Allocator>& __str);
  3918. #if _LIBCPP_STD_VER > 17
  3919. template <class _CharT, class _Traits, class _Allocator, class _Up>
  3920. inline _LIBCPP_INLINE_VISIBILITY
  3921. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3922. erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
  3923. auto __old_size = __str.size();
  3924. __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
  3925. return __old_size - __str.size();
  3926. }
  3927. template <class _CharT, class _Traits, class _Allocator, class _Predicate>
  3928. inline _LIBCPP_INLINE_VISIBILITY
  3929. typename basic_string<_CharT, _Traits, _Allocator>::size_type
  3930. erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
  3931. _Predicate __pred) {
  3932. auto __old_size = __str.size();
  3933. __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
  3934. __str.end());
  3935. return __old_size - __str.size();
  3936. }
  3937. #endif
  3938. #if _LIBCPP_DEBUG_LEVEL == 2
  3939. template<class _CharT, class _Traits, class _Allocator>
  3940. bool
  3941. basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
  3942. {
  3943. return data() <= _VSTD::__to_address(__i->base()) &&
  3944. _VSTD::__to_address(__i->base()) < data() + size();
  3945. }
  3946. template<class _CharT, class _Traits, class _Allocator>
  3947. bool
  3948. basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
  3949. {
  3950. return data() < _VSTD::__to_address(__i->base()) &&
  3951. _VSTD::__to_address(__i->base()) <= data() + size();
  3952. }
  3953. template<class _CharT, class _Traits, class _Allocator>
  3954. bool
  3955. basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
  3956. {
  3957. const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
  3958. return data() <= __p && __p <= data() + size();
  3959. }
  3960. template<class _CharT, class _Traits, class _Allocator>
  3961. bool
  3962. basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  3963. {
  3964. const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
  3965. return data() <= __p && __p < data() + size();
  3966. }
  3967. #endif // _LIBCPP_DEBUG_LEVEL == 2
  3968. #if _LIBCPP_STD_VER > 11
  3969. // Literal suffixes for basic_string [basic.string.literals]
  3970. inline namespace literals
  3971. {
  3972. inline namespace string_literals
  3973. {
  3974. inline _LIBCPP_INLINE_VISIBILITY
  3975. basic_string<char> operator "" s( const char *__str, size_t __len )
  3976. {
  3977. return basic_string<char> (__str, __len);
  3978. }
  3979. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  3980. inline _LIBCPP_INLINE_VISIBILITY
  3981. basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
  3982. {
  3983. return basic_string<wchar_t> (__str, __len);
  3984. }
  3985. #endif
  3986. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  3987. inline _LIBCPP_INLINE_VISIBILITY
  3988. basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
  3989. {
  3990. return basic_string<char8_t> (__str, __len);
  3991. }
  3992. #endif
  3993. inline _LIBCPP_INLINE_VISIBILITY
  3994. basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
  3995. {
  3996. return basic_string<char16_t> (__str, __len);
  3997. }
  3998. inline _LIBCPP_INLINE_VISIBILITY
  3999. basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
  4000. {
  4001. return basic_string<char32_t> (__str, __len);
  4002. }
  4003. } // namespace string_literals
  4004. } // namespace literals
  4005. #endif
  4006. _LIBCPP_END_NAMESPACE_STD
  4007. #ifdef _LIBCPP_COMPILER_MSVC
  4008. #pragma warning ( pop )
  4009. #endif
  4010. _LIBCPP_POP_MACROS
  4011. #endif // _LIBCPP_STRING