string 165 KB

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