1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330 |
- // -*- C++ -*-
- //===--------------------------- string -----------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is distributed under the University of Illinois Open Source
- // License. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP_STRING
- #define _LIBCPP_STRING
- /*
- string synopsis
- namespace std
- {
- template <class stateT>
- class fpos
- {
- private:
- stateT st;
- public:
- fpos(streamoff = streamoff());
- operator streamoff() const;
- stateT state() const;
- void state(stateT);
- fpos& operator+=(streamoff);
- fpos operator+ (streamoff) const;
- fpos& operator-=(streamoff);
- fpos operator- (streamoff) const;
- };
- template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
- template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
- template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
- template <class charT>
- struct char_traits
- {
- typedef charT char_type;
- typedef ... int_type;
- typedef streamoff off_type;
- typedef streampos pos_type;
- typedef mbstate_t state_type;
- static void assign(char_type& c1, const char_type& c2) noexcept;
- static constexpr bool eq(char_type c1, char_type c2) noexcept;
- static constexpr bool lt(char_type c1, char_type c2) noexcept;
- static int compare(const char_type* s1, const char_type* s2, size_t n);
- static size_t length(const char_type* s);
- static const char_type* find(const char_type* s, size_t n, const char_type& a);
- static char_type* move(char_type* s1, const char_type* s2, size_t n);
- static char_type* copy(char_type* s1, const char_type* s2, size_t n);
- static char_type* assign(char_type* s, size_t n, char_type a);
- static constexpr int_type not_eof(int_type c) noexcept;
- static constexpr char_type to_char_type(int_type c) noexcept;
- static constexpr int_type to_int_type(char_type c) noexcept;
- static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
- static constexpr int_type eof() noexcept;
- };
- template <> struct char_traits<char>;
- template <> struct char_traits<wchar_t>;
- template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
- class basic_string
- {
- public:
- // types:
- typedef traits traits_type;
- typedef typename traits_type::char_type value_type;
- typedef Allocator allocator_type;
- typedef typename allocator_type::size_type size_type;
- typedef typename allocator_type::difference_type difference_type;
- typedef typename allocator_type::reference reference;
- typedef typename allocator_type::const_reference const_reference;
- typedef typename allocator_type::pointer pointer;
- typedef typename allocator_type::const_pointer const_pointer;
- typedef implementation-defined iterator;
- typedef implementation-defined const_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- static const size_type npos = -1;
- basic_string()
- noexcept(is_nothrow_default_constructible<allocator_type>::value);
- explicit basic_string(const allocator_type& a);
- basic_string(const basic_string& str);
- basic_string(basic_string&& str)
- noexcept(is_nothrow_move_constructible<allocator_type>::value);
- basic_string(const basic_string& str, size_type pos,
- const allocator_type& a = allocator_type());
- basic_string(const basic_string& str, size_type pos, size_type n,
- const Allocator& a = Allocator());
- basic_string(const value_type* s, const allocator_type& a = allocator_type());
- basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
- basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
- template<class InputIterator>
- basic_string(InputIterator begin, InputIterator end,
- const allocator_type& a = allocator_type());
- basic_string(initializer_list<value_type>, const Allocator& = Allocator());
- basic_string(const basic_string&, const Allocator&);
- basic_string(basic_string&&, const Allocator&);
- ~basic_string();
- basic_string& operator=(const basic_string& str);
- basic_string& operator=(basic_string&& str)
- noexcept(
- allocator_type::propagate_on_container_move_assignment::value ||
- allocator_type::is_always_equal::value ); // C++17
- basic_string& operator=(const value_type* s);
- basic_string& operator=(value_type c);
- basic_string& operator=(initializer_list<value_type>);
- iterator begin() noexcept;
- const_iterator begin() const noexcept;
- iterator end() noexcept;
- const_iterator end() const noexcept;
- reverse_iterator rbegin() noexcept;
- const_reverse_iterator rbegin() const noexcept;
- reverse_iterator rend() noexcept;
- const_reverse_iterator rend() const noexcept;
- const_iterator cbegin() const noexcept;
- const_iterator cend() const noexcept;
- const_reverse_iterator crbegin() const noexcept;
- const_reverse_iterator crend() const noexcept;
- size_type size() const noexcept;
- size_type length() const noexcept;
- size_type max_size() const noexcept;
- size_type capacity() const noexcept;
- void resize(size_type n, value_type c);
- void resize(size_type n);
- void reserve(size_type res_arg = 0);
- void shrink_to_fit();
- void clear() noexcept;
- bool empty() const noexcept;
- const_reference operator[](size_type pos) const;
- reference operator[](size_type pos);
- const_reference at(size_type n) const;
- reference at(size_type n);
- basic_string& operator+=(const basic_string& str);
- basic_string& operator+=(const value_type* s);
- basic_string& operator+=(value_type c);
- basic_string& operator+=(initializer_list<value_type>);
- basic_string& append(const basic_string& str);
- basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
- basic_string& append(const value_type* s, size_type n);
- basic_string& append(const value_type* s);
- basic_string& append(size_type n, value_type c);
- template<class InputIterator>
- basic_string& append(InputIterator first, InputIterator last);
- basic_string& append(initializer_list<value_type>);
- void push_back(value_type c);
- void pop_back();
- reference front();
- const_reference front() const;
- reference back();
- const_reference back() const;
- basic_string& assign(const basic_string& str);
- basic_string& assign(basic_string&& str);
- basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
- basic_string& assign(const value_type* s, size_type n);
- basic_string& assign(const value_type* s);
- basic_string& assign(size_type n, value_type c);
- template<class InputIterator>
- basic_string& assign(InputIterator first, InputIterator last);
- basic_string& assign(initializer_list<value_type>);
- basic_string& insert(size_type pos1, const basic_string& str);
- basic_string& insert(size_type pos1, const basic_string& str,
- size_type pos2, size_type n);
- basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
- basic_string& insert(size_type pos, const value_type* s);
- basic_string& insert(size_type pos, size_type n, value_type c);
- iterator insert(const_iterator p, value_type c);
- iterator insert(const_iterator p, size_type n, value_type c);
- template<class InputIterator>
- iterator insert(const_iterator p, InputIterator first, InputIterator last);
- iterator insert(const_iterator p, initializer_list<value_type>);
- basic_string& erase(size_type pos = 0, size_type n = npos);
- iterator erase(const_iterator position);
- iterator erase(const_iterator first, const_iterator last);
- basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
- basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
- size_type pos2, size_type n2=npos); // C++14
- basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
- basic_string& replace(size_type pos, size_type n1, const value_type* s);
- basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
- basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
- basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
- basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
- basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
- template<class InputIterator>
- basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
- basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
- size_type copy(value_type* s, size_type n, size_type pos = 0) const;
- basic_string substr(size_type pos = 0, size_type n = npos) const;
- void swap(basic_string& str)
- noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
- allocator_traits<allocator_type>::is_always_equal::value); // C++17
- const value_type* c_str() const noexcept;
- const value_type* data() const noexcept;
- value_type* data() noexcept; // C++17
- allocator_type get_allocator() const noexcept;
- size_type find(const basic_string& str, size_type pos = 0) const noexcept;
- size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type find(const value_type* s, size_type pos = 0) const noexcept;
- size_type find(value_type c, size_type pos = 0) const noexcept;
- size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
- size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
- size_type rfind(value_type c, size_type pos = npos) const noexcept;
- size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
- size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
- size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
- size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
- size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
- size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
- size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
- size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
- size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
- size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
- size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
- size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
- size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
- int compare(const basic_string& str) const noexcept;
- int compare(size_type pos1, size_type n1, const basic_string& str) const;
- int compare(size_type pos1, size_type n1, const basic_string& str,
- size_type pos2, size_type n2=npos) const; // C++14
- int compare(const value_type* s) const noexcept;
- int compare(size_type pos1, size_type n1, const value_type* s) const;
- int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
- bool __invariants() const;
- };
- template<class charT, class traits, class Allocator>
- basic_string<charT, traits, Allocator>
- operator+(const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs);
- template<class charT, class traits, class Allocator>
- basic_string<charT, traits, Allocator>
- operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
- template<class charT, class traits, class Allocator>
- basic_string<charT, traits, Allocator>
- operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
- template<class charT, class traits, class Allocator>
- basic_string<charT, traits, Allocator>
- operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
- template<class charT, class traits, class Allocator>
- basic_string<charT, traits, Allocator>
- operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
- template<class charT, class traits, class Allocator>
- bool operator==(const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator< (const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator> (const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
- template<class charT, class traits, class Allocator>
- bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
- template<class charT, class traits, class Allocator>
- void swap(basic_string<charT, traits, Allocator>& lhs,
- basic_string<charT, traits, Allocator>& rhs)
- noexcept(noexcept(lhs.swap(rhs)));
- template<class charT, class traits, class Allocator>
- basic_istream<charT, traits>&
- operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
- template<class charT, class traits, class Allocator>
- basic_ostream<charT, traits>&
- operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
- template<class charT, class traits, class Allocator>
- basic_istream<charT, traits>&
- getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
- charT delim);
- template<class charT, class traits, class Allocator>
- basic_istream<charT, traits>&
- getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
- typedef basic_string<char> string;
- typedef basic_string<wchar_t> wstring;
- typedef basic_string<char16_t> u16string;
- typedef basic_string<char32_t> u32string;
- int stoi (const string& str, size_t* idx = 0, int base = 10);
- long stol (const string& str, size_t* idx = 0, int base = 10);
- unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
- long long stoll (const string& str, size_t* idx = 0, int base = 10);
- unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
- float stof (const string& str, size_t* idx = 0);
- double stod (const string& str, size_t* idx = 0);
- long double stold(const string& str, size_t* idx = 0);
- string to_string(int val);
- string to_string(unsigned val);
- string to_string(long val);
- string to_string(unsigned long val);
- string to_string(long long val);
- string to_string(unsigned long long val);
- string to_string(float val);
- string to_string(double val);
- string to_string(long double val);
- int stoi (const wstring& str, size_t* idx = 0, int base = 10);
- long stol (const wstring& str, size_t* idx = 0, int base = 10);
- unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
- long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
- unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
- float stof (const wstring& str, size_t* idx = 0);
- double stod (const wstring& str, size_t* idx = 0);
- long double stold(const wstring& str, size_t* idx = 0);
- wstring to_wstring(int val);
- wstring to_wstring(unsigned val);
- wstring to_wstring(long val);
- wstring to_wstring(unsigned long val);
- wstring to_wstring(long long val);
- wstring to_wstring(unsigned long long val);
- wstring to_wstring(float val);
- wstring to_wstring(double val);
- wstring to_wstring(long double val);
- template <> struct hash<string>;
- template <> struct hash<u16string>;
- template <> struct hash<u32string>;
- template <> struct hash<wstring>;
- basic_string<char> operator "" s( const char *str, size_t len ); // C++14
- basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
- basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
- basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
- } // std
- */
- #include <__config>
- #include <iosfwd>
- #include <cstring>
- #include <cstdio> // For EOF.
- #include <cwchar>
- #include <algorithm>
- #include <iterator>
- #include <utility>
- #include <memory>
- #include <stdexcept>
- #include <type_traits>
- #include <initializer_list>
- #include <__functional_base>
- #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
- #include <cstdint>
- #endif
- #if defined(_LIBCPP_NO_EXCEPTIONS)
- #include <cassert>
- #endif
- #include <__undef_min_max>
- #include <__debug>
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- #pragma GCC system_header
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- // fpos
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- template <class _StateT>
- class _LIBCPP_TYPE_VIS_ONLY fpos
- {
- private:
- _StateT __st_;
- streamoff __off_;
- public:
- _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
- _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
- _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
- _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
- _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
- _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
- _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
- _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
- };
- template <class _StateT>
- inline _LIBCPP_INLINE_VISIBILITY
- streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
- {return streamoff(__x) - streamoff(__y);}
- template <class _StateT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
- {return streamoff(__x) == streamoff(__y);}
- template <class _StateT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
- {return streamoff(__x) != streamoff(__y);}
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- // char_traits
- template <class _CharT>
- struct _LIBCPP_TYPE_VIS_ONLY char_traits
- {
- typedef _CharT char_type;
- typedef int int_type;
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef streamoff off_type;
- typedef streampos pos_type;
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef mbstate_t state_type;
- static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
- {__c1 = __c2;}
- static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 < __c2;}
- static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static size_t length(const char_type* __s);
- _LIBCPP_INLINE_VISIBILITY
- static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
- static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* assign(char_type* __s, size_t __n, char_type __a);
- static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
- {return eq_int_type(__c, eof()) ? ~eof() : __c;}
- static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
- {return char_type(__c);}
- static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
- {return int_type(__c);}
- static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(EOF);}
- };
- template <class _CharT>
- int
- char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- {
- if (lt(*__s1, *__s2))
- return -1;
- if (lt(*__s2, *__s1))
- return 1;
- }
- return 0;
- }
- template <class _CharT>
- inline
- size_t
- char_traits<_CharT>::length(const char_type* __s)
- {
- size_t __len = 0;
- for (; !eq(*__s, char_type(0)); ++__s)
- ++__len;
- return __len;
- }
- template <class _CharT>
- inline
- const _CharT*
- char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
- {
- for (; __n; --__n)
- {
- if (eq(*__s, __a))
- return __s;
- ++__s;
- }
- return 0;
- }
- template <class _CharT>
- _CharT*
- char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
- {
- char_type* __r = __s1;
- if (__s1 < __s2)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- }
- else if (__s2 < __s1)
- {
- __s1 += __n;
- __s2 += __n;
- for (; __n; --__n)
- assign(*--__s1, *--__s2);
- }
- return __r;
- }
- template <class _CharT>
- inline
- _CharT*
- char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
- {
- _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
- char_type* __r = __s1;
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- return __r;
- }
- template <class _CharT>
- inline
- _CharT*
- char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
- {
- char_type* __r = __s;
- for (; __n; --__n, ++__s)
- assign(*__s, __a);
- return __r;
- }
- // char_traits<char>
- template <>
- struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
- {
- typedef char char_type;
- typedef int int_type;
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef streamoff off_type;
- typedef streampos pos_type;
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef mbstate_t state_type;
- static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
- {__c1 = __c2;}
- static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
- {return (unsigned char)__c1 < (unsigned char)__c2;}
- static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
- static inline size_t length(const char_type* __s) {return strlen(__s);}
- static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
- {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);}
- static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
- {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
- static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
- {
- _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
- return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
- }
- static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
- {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
- static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
- {return eq_int_type(__c, eof()) ? ~eof() : __c;}
- static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
- {return char_type(__c);}
- static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
- {return int_type((unsigned char)__c);}
- static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(EOF);}
- };
- // char_traits<wchar_t>
- template <>
- struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
- {
- typedef wchar_t char_type;
- typedef wint_t int_type;
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef streamoff off_type;
- typedef streampos pos_type;
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef mbstate_t state_type;
- static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
- {__c1 = __c2;}
- static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 < __c2;}
- static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
- static inline size_t length(const char_type* __s)
- {return wcslen(__s);}
- static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
- {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);}
- static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
- {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
- static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
- {
- _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
- return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
- }
- static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
- {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
- static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
- {return eq_int_type(__c, eof()) ? ~eof() : __c;}
- static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
- {return char_type(__c);}
- static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
- {return int_type(__c);}
- static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(WEOF);}
- };
- #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
- template <>
- struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
- {
- typedef char16_t char_type;
- typedef uint_least16_t int_type;
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef streamoff off_type;
- typedef u16streampos pos_type;
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef mbstate_t state_type;
- static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
- {__c1 = __c2;}
- static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 < __c2;}
- _LIBCPP_INLINE_VISIBILITY
- static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static size_t length(const char_type* __s);
- _LIBCPP_INLINE_VISIBILITY
- static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* assign(char_type* __s, size_t __n, char_type __a);
- static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
- {return eq_int_type(__c, eof()) ? ~eof() : __c;}
- static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
- {return char_type(__c);}
- static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
- {return int_type(__c);}
- static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(0xFFFF);}
- };
- inline
- int
- char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- {
- if (lt(*__s1, *__s2))
- return -1;
- if (lt(*__s2, *__s1))
- return 1;
- }
- return 0;
- }
- inline
- size_t
- char_traits<char16_t>::length(const char_type* __s)
- {
- size_t __len = 0;
- for (; !eq(*__s, char_type(0)); ++__s)
- ++__len;
- return __len;
- }
- inline
- const char16_t*
- char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
- {
- for (; __n; --__n)
- {
- if (eq(*__s, __a))
- return __s;
- ++__s;
- }
- return 0;
- }
- inline
- char16_t*
- char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
- {
- char_type* __r = __s1;
- if (__s1 < __s2)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- }
- else if (__s2 < __s1)
- {
- __s1 += __n;
- __s2 += __n;
- for (; __n; --__n)
- assign(*--__s1, *--__s2);
- }
- return __r;
- }
- inline
- char16_t*
- char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
- {
- _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
- char_type* __r = __s1;
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- return __r;
- }
- inline
- char16_t*
- char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
- {
- char_type* __r = __s;
- for (; __n; --__n, ++__s)
- assign(*__s, __a);
- return __r;
- }
- template <>
- struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
- {
- typedef char32_t char_type;
- typedef uint_least32_t int_type;
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef streamoff off_type;
- typedef u32streampos pos_type;
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- typedef mbstate_t state_type;
- static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
- {__c1 = __c2;}
- static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
- {return __c1 < __c2;}
- _LIBCPP_INLINE_VISIBILITY
- static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static size_t length(const char_type* __s);
- _LIBCPP_INLINE_VISIBILITY
- static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
- _LIBCPP_INLINE_VISIBILITY
- static char_type* assign(char_type* __s, size_t __n, char_type __a);
- static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
- {return eq_int_type(__c, eof()) ? ~eof() : __c;}
- static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
- {return char_type(__c);}
- static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
- {return int_type(__c);}
- static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
- {return __c1 == __c2;}
- static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
- {return int_type(0xFFFFFFFF);}
- };
- inline
- int
- char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- {
- if (lt(*__s1, *__s2))
- return -1;
- if (lt(*__s2, *__s1))
- return 1;
- }
- return 0;
- }
- inline
- size_t
- char_traits<char32_t>::length(const char_type* __s)
- {
- size_t __len = 0;
- for (; !eq(*__s, char_type(0)); ++__s)
- ++__len;
- return __len;
- }
- inline
- const char32_t*
- char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
- {
- for (; __n; --__n)
- {
- if (eq(*__s, __a))
- return __s;
- ++__s;
- }
- return 0;
- }
- inline
- char32_t*
- char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
- {
- char_type* __r = __s1;
- if (__s1 < __s2)
- {
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- }
- else if (__s2 < __s1)
- {
- __s1 += __n;
- __s2 += __n;
- for (; __n; --__n)
- assign(*--__s1, *--__s2);
- }
- return __r;
- }
- inline
- char32_t*
- char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
- {
- _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
- char_type* __r = __s1;
- for (; __n; --__n, ++__s1, ++__s2)
- assign(*__s1, *__s2);
- return __r;
- }
- inline
- char32_t*
- char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
- {
- char_type* __r = __s;
- for (; __n; --__n, ++__s)
- assign(*__s, __a);
- return __r;
- }
- #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
- // helper fns for basic_string
- // __str_find
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find(const _CharT *__p, _SizeT __sz,
- _CharT __c, _SizeT __pos) _NOEXCEPT
- {
- if (__pos >= __sz)
- return __npos;
- const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
- if (__r == 0)
- return __npos;
- return static_cast<_SizeT>(__r - __p);
- }
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- if (__pos > __sz || __sz - __pos < __n)
- return __npos;
- if (__n == 0)
- return __pos;
- const _CharT* __r =
- _VSTD::__search(__p + __pos, __p + __sz,
- __s, __s + __n, _Traits::eq,
- random_access_iterator_tag(), random_access_iterator_tag()).first;
- if (__r == __p + __sz)
- return __npos;
- return static_cast<_SizeT>(__r - __p);
- }
- // __str_rfind
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_rfind(const _CharT *__p, _SizeT __sz,
- _CharT __c, _SizeT __pos) _NOEXCEPT
- {
- if (__sz < 1)
- return __npos;
- if (__pos < __sz)
- ++__pos;
- else
- __pos = __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __p;)
- {
- if (_Traits::eq(*--__ps, __c))
- return static_cast<_SizeT>(__ps - __p);
- }
- return __npos;
- }
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_rfind(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- __pos = _VSTD::min(__pos, __sz);
- if (__n < __sz - __pos)
- __pos += __n;
- else
- __pos = __sz;
- const _CharT* __r = _VSTD::__find_end(
- __p, __p + __pos, __s, __s + __n, _Traits::eq,
- random_access_iterator_tag(), random_access_iterator_tag());
- if (__n > 0 && __r == __p + __pos)
- return __npos;
- return static_cast<_SizeT>(__r - __p);
- }
- // __str_find_first_of
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_first_of(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- if (__pos >= __sz || __n == 0)
- return __npos;
- const _CharT* __r = _VSTD::__find_first_of_ce
- (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
- if (__r == __p + __sz)
- return __npos;
- return static_cast<_SizeT>(__r - __p);
- }
- // __str_find_last_of
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_last_of(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- if (__n != 0)
- {
- if (__pos < __sz)
- ++__pos;
- else
- __pos = __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __p;)
- {
- const _CharT* __r = _Traits::find(__s, __n, *--__ps);
- if (__r)
- return static_cast<_SizeT>(__ps - __p);
- }
- }
- return __npos;
- }
- // __str_find_first_not_of
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- if (__pos < __sz)
- {
- const _CharT* __pe = __p + __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
- if (_Traits::find(__s, __n, *__ps) == 0)
- return static_cast<_SizeT>(__ps - __p);
- }
- return __npos;
- }
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
- _CharT __c, _SizeT __pos) _NOEXCEPT
- {
- if (__pos < __sz)
- {
- const _CharT* __pe = __p + __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
- if (!_Traits::eq(*__ps, __c))
- return static_cast<_SizeT>(__ps - __p);
- }
- return __npos;
- }
- // __str_find_last_not_of
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
- {
- if (__pos < __sz)
- ++__pos;
- else
- __pos = __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __p;)
- if (_Traits::find(__s, __n, *--__ps) == 0)
- return static_cast<_SizeT>(__ps - __p);
- return __npos;
- }
- template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
- inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
- __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
- _CharT __c, _SizeT __pos) _NOEXCEPT
- {
- if (__pos < __sz)
- ++__pos;
- else
- __pos = __sz;
- for (const _CharT* __ps = __p + __pos; __ps != __p;)
- if (!_Traits::eq(*--__ps, __c))
- return static_cast<_SizeT>(__ps - __p);
- return __npos;
- }
- template<class _Ptr>
- size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
- {
- typedef typename iterator_traits<_Ptr>::value_type value_type;
- return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
- }
- // basic_string
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
- const basic_string<_CharT, _Traits, _Allocator>& __y);
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
- template <bool>
- class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
- {
- protected:
- void __throw_length_error() const;
- void __throw_out_of_range() const;
- };
- template <bool __b>
- void
- __basic_string_common<__b>::__throw_length_error() const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- throw length_error("basic_string");
- #else
- assert(!"basic_string length_error");
- #endif
- }
- template <bool __b>
- void
- __basic_string_common<__b>::__throw_out_of_range() const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- throw out_of_range("basic_string");
- #else
- assert(!"basic_string out_of_range");
- #endif
- }
- #ifdef _LIBCPP_MSVC
- #pragma warning( push )
- #pragma warning( disable: 4231 )
- #endif // _LIBCPP_MSVC
- _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
- #ifdef _LIBCPP_MSVC
- #pragma warning( pop )
- #endif // _LIBCPP_MSVC
- #ifdef _LIBCPP_NO_EXCEPTIONS
- template <class _Iter>
- struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
- #elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
- template <class _Iter>
- struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
- #else
- template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
- struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
- noexcept(++(declval<_Iter&>())) &&
- is_nothrow_assignable<_Iter&, _Iter>::value &&
- noexcept(declval<_Iter>() == declval<_Iter>()) &&
- noexcept(*declval<_Iter>())
- )) {};
- template <class _Iter>
- struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
- #endif
- template <class _Iter>
- struct __libcpp_string_gets_noexcept_iterator
- : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
- #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- template <class _CharT, size_t = sizeof(_CharT)>
- struct __padding
- {
- unsigned char __xx[sizeof(_CharT)-1];
- };
- template <class _CharT>
- struct __padding<_CharT, 1>
- {
- };
- #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- template<class _CharT, class _Traits, class _Allocator>
- class _LIBCPP_TYPE_VIS_ONLY basic_string
- : private __basic_string_common<true>
- {
- public:
- typedef basic_string __self;
- typedef _Traits traits_type;
- typedef typename traits_type::char_type value_type;
- typedef _Allocator allocator_type;
- typedef allocator_traits<allocator_type> __alloc_traits;
- typedef typename __alloc_traits::size_type size_type;
- typedef typename __alloc_traits::difference_type difference_type;
- typedef value_type& reference;
- typedef const value_type& const_reference;
- typedef typename __alloc_traits::pointer pointer;
- typedef typename __alloc_traits::const_pointer const_pointer;
- static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
- static_assert((is_same<_CharT, value_type>::value),
- "traits_type::char_type must be the same type as CharT");
- static_assert((is_same<typename allocator_type::value_type, value_type>::value),
- "Allocator::value_type must be same type as value_type");
- #if defined(_LIBCPP_RAW_ITERATORS)
- typedef pointer iterator;
- typedef const_pointer const_iterator;
- #else // defined(_LIBCPP_RAW_ITERATORS)
- typedef __wrap_iter<pointer> iterator;
- typedef __wrap_iter<const_pointer> const_iterator;
- #endif // defined(_LIBCPP_RAW_ITERATORS)
- typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
- typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
- private:
- #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- struct __long
- {
- pointer __data_;
- size_type __size_;
- size_type __cap_;
- };
- #if _LIBCPP_BIG_ENDIAN
- enum {__short_mask = 0x01};
- enum {__long_mask = 0x1ul};
- #else // _LIBCPP_BIG_ENDIAN
- enum {__short_mask = 0x80};
- enum {__long_mask = ~(size_type(~0) >> 1)};
- #endif // _LIBCPP_BIG_ENDIAN
- enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
- (sizeof(__long) - 1)/sizeof(value_type) : 2};
- struct __short
- {
- value_type __data_[__min_cap];
- struct
- : __padding<value_type>
- {
- unsigned char __size_;
- };
- };
- #else
- struct __long
- {
- size_type __cap_;
- size_type __size_;
- pointer __data_;
- };
- #if _LIBCPP_BIG_ENDIAN
- enum {__short_mask = 0x80};
- enum {__long_mask = ~(size_type(~0) >> 1)};
- #else // _LIBCPP_BIG_ENDIAN
- enum {__short_mask = 0x01};
- enum {__long_mask = 0x1ul};
- #endif // _LIBCPP_BIG_ENDIAN
- enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
- (sizeof(__long) - 1)/sizeof(value_type) : 2};
- struct __short
- {
- union
- {
- unsigned char __size_;
- value_type __lx;
- };
- value_type __data_[__min_cap];
- };
- #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- union __ulx{__long __lx; __short __lxx;};
- enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
- struct __raw
- {
- size_type __words[__n_words];
- };
- struct __rep
- {
- union
- {
- __long __l;
- __short __s;
- __raw __r;
- };
- };
- __compressed_pair<__rep, allocator_type> __r_;
- public:
- static const size_type npos = -1;
- _LIBCPP_INLINE_VISIBILITY basic_string()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
- _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
- #else
- _NOEXCEPT;
- #endif
- basic_string(const basic_string& __str);
- basic_string(const basic_string& __str, const allocator_type& __a);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- basic_string(basic_string&& __str)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
- #else
- _NOEXCEPT;
- #endif
- _LIBCPP_INLINE_VISIBILITY
- basic_string(basic_string&& __str, const allocator_type& __a);
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(const value_type* __s, const allocator_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(const value_type* __s, size_type __n);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(size_type __n, value_type __c);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(size_type __n, value_type __c, const allocator_type& __a);
- basic_string(const basic_string& __str, size_type __pos, size_type __n,
- const allocator_type& __a = allocator_type());
- _LIBCPP_INLINE_VISIBILITY
- basic_string(const basic_string& __str, size_type __pos,
- const allocator_type& __a = allocator_type());
- template<class _InputIterator>
- _LIBCPP_INLINE_VISIBILITY
- basic_string(_InputIterator __first, _InputIterator __last);
- template<class _InputIterator>
- _LIBCPP_INLINE_VISIBILITY
- basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string(initializer_list<value_type> __il);
- _LIBCPP_INLINE_VISIBILITY
- basic_string(initializer_list<value_type> __il, const allocator_type& __a);
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- ~basic_string();
- basic_string& operator=(const basic_string& __str);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- basic_string& operator=(basic_string&& __str)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
- #endif
- _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
- basic_string& operator=(value_type __c);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_INLINE_VISIBILITY
- iterator begin() _NOEXCEPT
- {return iterator(this, __get_pointer());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator begin() const _NOEXCEPT
- {return const_iterator(this, __get_pointer());}
- _LIBCPP_INLINE_VISIBILITY
- iterator end() _NOEXCEPT
- {return iterator(this, __get_pointer() + size());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator end() const _NOEXCEPT
- {return const_iterator(this, __get_pointer() + size());}
- #else
- _LIBCPP_INLINE_VISIBILITY
- iterator begin() _NOEXCEPT
- {return iterator(__get_pointer());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator begin() const _NOEXCEPT
- {return const_iterator(__get_pointer());}
- _LIBCPP_INLINE_VISIBILITY
- iterator end() _NOEXCEPT
- {return iterator(__get_pointer() + size());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator end() const _NOEXCEPT
- {return const_iterator(__get_pointer() + size());}
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rbegin() _NOEXCEPT
- {return reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rbegin() const _NOEXCEPT
- {return const_reverse_iterator(end());}
- _LIBCPP_INLINE_VISIBILITY
- reverse_iterator rend() _NOEXCEPT
- {return reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator rend() const _NOEXCEPT
- {return const_reverse_iterator(begin());}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cbegin() const _NOEXCEPT
- {return begin();}
- _LIBCPP_INLINE_VISIBILITY
- const_iterator cend() const _NOEXCEPT
- {return end();}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crbegin() const _NOEXCEPT
- {return rbegin();}
- _LIBCPP_INLINE_VISIBILITY
- const_reverse_iterator crend() const _NOEXCEPT
- {return rend();}
- _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
- {return __is_long() ? __get_long_size() : __get_short_size();}
- _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
- _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
- {return (__is_long() ? __get_long_cap()
- : static_cast<size_type>(__min_cap)) - 1;}
- void resize(size_type __n, value_type __c);
- _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
- void reserve(size_type res_arg = 0);
- _LIBCPP_INLINE_VISIBILITY
- void shrink_to_fit() _NOEXCEPT {reserve();}
- _LIBCPP_INLINE_VISIBILITY
- void clear() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
- _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
- _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
- const_reference at(size_type __n) const;
- reference at(size_type __n);
- _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
- _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
- _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& append(const basic_string& __str);
- basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
- basic_string& append(const value_type* __s, size_type __n);
- basic_string& append(const value_type* __s);
- basic_string& append(size_type __n, value_type __c);
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- basic_string&
- >::type
- append(_InputIterator __first, _InputIterator __last);
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- basic_string&
- >::type
- append(_ForwardIterator __first, _ForwardIterator __last);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- void push_back(value_type __c);
- _LIBCPP_INLINE_VISIBILITY
- void pop_back();
- _LIBCPP_INLINE_VISIBILITY reference front();
- _LIBCPP_INLINE_VISIBILITY const_reference front() const;
- _LIBCPP_INLINE_VISIBILITY reference back();
- _LIBCPP_INLINE_VISIBILITY const_reference back() const;
- _LIBCPP_INLINE_VISIBILITY
- basic_string& assign(const basic_string& __str) { return *this = __str; }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- basic_string& assign(basic_string&& str)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
- {*this = _VSTD::move(str); return *this;}
- #endif
- basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
- basic_string& assign(const value_type* __s, size_type __n);
- basic_string& assign(const value_type* __s);
- basic_string& assign(size_type __n, value_type __c);
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- basic_string&
- >::type
- assign(_InputIterator __first, _InputIterator __last);
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- basic_string&
- >::type
- assign(_ForwardIterator __first, _ForwardIterator __last);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& insert(size_type __pos1, const basic_string& __str);
- basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
- basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
- basic_string& insert(size_type __pos, const value_type* __s);
- basic_string& insert(size_type __pos, size_type __n, value_type __c);
- iterator insert(const_iterator __pos, value_type __c);
- _LIBCPP_INLINE_VISIBILITY
- iterator insert(const_iterator __pos, size_type __n, value_type __c);
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- iterator
- >::type
- insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- iterator
- >::type
- insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- iterator insert(const_iterator __pos, initializer_list<value_type> __il)
- {return insert(__pos, __il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- basic_string& erase(size_type __pos = 0, size_type __n = npos);
- _LIBCPP_INLINE_VISIBILITY
- iterator erase(const_iterator __pos);
- _LIBCPP_INLINE_VISIBILITY
- iterator erase(const_iterator __first, const_iterator __last);
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
- basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
- basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
- basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
- basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
- template<class _InputIterator>
- typename enable_if
- <
- __is_input_iterator<_InputIterator>::value,
- basic_string&
- >::type
- replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- _LIBCPP_INLINE_VISIBILITY
- basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
- {return replace(__i1, __i2, __il.begin(), __il.end());}
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
- _LIBCPP_INLINE_VISIBILITY
- basic_string substr(size_type __pos = 0, size_type __n = npos) const;
- _LIBCPP_INLINE_VISIBILITY
- void swap(basic_string& __str)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value);
- #endif
- _LIBCPP_INLINE_VISIBILITY
- const value_type* c_str() const _NOEXCEPT {return data();}
- _LIBCPP_INLINE_VISIBILITY
- const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
- #if _LIBCPP_STD_VER > 14
- _LIBCPP_INLINE_VISIBILITY
- value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
- #endif
- _LIBCPP_INLINE_VISIBILITY
- allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
- _LIBCPP_INLINE_VISIBILITY
- size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
- size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
- size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
- size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
- size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
- size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
- size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
- size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
- size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- int compare(const basic_string& __str) const _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY
- int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
- int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
- int compare(const value_type* __s) const _NOEXCEPT;
- int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
- int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
- _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
- _LIBCPP_INLINE_VISIBILITY
- bool __is_long() const _NOEXCEPT
- {return bool(__r_.first().__s.__size_ & __short_mask);}
- #if _LIBCPP_DEBUG_LEVEL >= 2
- bool __dereferenceable(const const_iterator* __i) const;
- bool __decrementable(const const_iterator* __i) const;
- bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
- bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- private:
- _LIBCPP_INLINE_VISIBILITY
- allocator_type& __alloc() _NOEXCEPT
- {return __r_.second();}
- _LIBCPP_INLINE_VISIBILITY
- const allocator_type& __alloc() const _NOEXCEPT
- {return __r_.second();}
- #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- _LIBCPP_INLINE_VISIBILITY
- void __set_short_size(size_type __s) _NOEXCEPT
- # if _LIBCPP_BIG_ENDIAN
- {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
- # else
- {__r_.first().__s.__size_ = (unsigned char)(__s);}
- # endif
- _LIBCPP_INLINE_VISIBILITY
- size_type __get_short_size() const _NOEXCEPT
- # if _LIBCPP_BIG_ENDIAN
- {return __r_.first().__s.__size_ >> 1;}
- # else
- {return __r_.first().__s.__size_;}
- # endif
- #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- _LIBCPP_INLINE_VISIBILITY
- void __set_short_size(size_type __s) _NOEXCEPT
- # if _LIBCPP_BIG_ENDIAN
- {__r_.first().__s.__size_ = (unsigned char)(__s);}
- # else
- {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
- # endif
- _LIBCPP_INLINE_VISIBILITY
- size_type __get_short_size() const _NOEXCEPT
- # if _LIBCPP_BIG_ENDIAN
- {return __r_.first().__s.__size_;}
- # else
- {return __r_.first().__s.__size_ >> 1;}
- # endif
- #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
- _LIBCPP_INLINE_VISIBILITY
- void __set_long_size(size_type __s) _NOEXCEPT
- {__r_.first().__l.__size_ = __s;}
- _LIBCPP_INLINE_VISIBILITY
- size_type __get_long_size() const _NOEXCEPT
- {return __r_.first().__l.__size_;}
- _LIBCPP_INLINE_VISIBILITY
- void __set_size(size_type __s) _NOEXCEPT
- {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
- _LIBCPP_INLINE_VISIBILITY
- void __set_long_cap(size_type __s) _NOEXCEPT
- {__r_.first().__l.__cap_ = __long_mask | __s;}
- _LIBCPP_INLINE_VISIBILITY
- size_type __get_long_cap() const _NOEXCEPT
- {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
- _LIBCPP_INLINE_VISIBILITY
- void __set_long_pointer(pointer __p) _NOEXCEPT
- {__r_.first().__l.__data_ = __p;}
- _LIBCPP_INLINE_VISIBILITY
- pointer __get_long_pointer() _NOEXCEPT
- {return __r_.first().__l.__data_;}
- _LIBCPP_INLINE_VISIBILITY
- const_pointer __get_long_pointer() const _NOEXCEPT
- {return __r_.first().__l.__data_;}
- _LIBCPP_INLINE_VISIBILITY
- pointer __get_short_pointer() _NOEXCEPT
- {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
- _LIBCPP_INLINE_VISIBILITY
- const_pointer __get_short_pointer() const _NOEXCEPT
- {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
- _LIBCPP_INLINE_VISIBILITY
- pointer __get_pointer() _NOEXCEPT
- {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
- _LIBCPP_INLINE_VISIBILITY
- const_pointer __get_pointer() const _NOEXCEPT
- {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
- _LIBCPP_INLINE_VISIBILITY
- void __zero() _NOEXCEPT
- {
- size_type (&__a)[__n_words] = __r_.first().__r.__words;
- for (unsigned __i = 0; __i < __n_words; ++__i)
- __a[__i] = 0;
- }
- template <size_type __a> static
- _LIBCPP_INLINE_VISIBILITY
- size_type __align_it(size_type __s) _NOEXCEPT
- {return (__s + (__a-1)) & ~(__a-1);}
- enum {__alignment = 16};
- static _LIBCPP_INLINE_VISIBILITY
- size_type __recommend(size_type __s) _NOEXCEPT
- {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
- __align_it<sizeof(value_type) < __alignment ?
- __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
- void __init(const value_type* __s, size_type __sz, size_type __reserve);
- void __init(const value_type* __s, size_type __sz);
- void __init(size_type __n, value_type __c);
- template <class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value,
- void
- >::type
- __init(_InputIterator __first, _InputIterator __last);
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- __init(_ForwardIterator __first, _ForwardIterator __last);
- void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
- size_type __n_copy, size_type __n_del, size_type __n_add = 0);
- void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
- size_type __n_copy, size_type __n_del,
- size_type __n_add, const value_type* __p_new_stuff);
- _LIBCPP_INLINE_VISIBILITY
- void __erase_to_end(size_type __pos);
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const basic_string& __str)
- {__copy_assign_alloc(__str, integral_constant<bool,
- __alloc_traits::propagate_on_container_copy_assignment::value>());}
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const basic_string& __str, true_type)
- {
- if (__alloc() != __str.__alloc())
- {
- clear();
- shrink_to_fit();
- }
- __alloc() = __str.__alloc();
- }
- _LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
- {}
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign(basic_string& __str, false_type)
- _NOEXCEPT_(__alloc_traits::is_always_equal::value);
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign(basic_string& __str, true_type)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT;
- #else
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
- #endif
- #endif
- _LIBCPP_INLINE_VISIBILITY
- void
- __move_assign_alloc(basic_string& __str)
- _NOEXCEPT_(
- !__alloc_traits::propagate_on_container_move_assignment::value ||
- is_nothrow_move_assignable<allocator_type>::value)
- {__move_assign_alloc(__str, integral_constant<bool,
- __alloc_traits::propagate_on_container_move_assignment::value>());}
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(basic_string& __c, true_type)
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- {
- __alloc() = _VSTD::move(__c.__alloc());
- }
- _LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(basic_string&, false_type)
- _NOEXCEPT
- {}
- _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
- _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
- friend basic_string operator+<>(const basic_string&, const basic_string&);
- friend basic_string operator+<>(const value_type*, const basic_string&);
- friend basic_string operator+<>(value_type, const basic_string&);
- friend basic_string operator+<>(const basic_string&, const value_type*);
- friend basic_string operator+<>(const basic_string&, value_type);
- };
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__invalidate_all(this);
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __pos
- #endif
- )
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __c_node* __c = __get_db()->__find_c_and_lock(this);
- if (__c)
- {
- const_pointer __new_last = __get_pointer() + __pos;
- for (__i_node** __p = __c->end_; __p != __c->beg_; )
- {
- --__p;
- const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
- if (__i->base() > __new_last)
- {
- (*__p)->__c_ = nullptr;
- if (--__c->end_ != __p)
- memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
- }
- }
- __get_db()->unlock();
- }
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string()
- _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- __zero();
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
- #else
- _NOEXCEPT
- #endif
- : __r_(__a)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- __zero();
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
- {
- if (__reserve > max_size())
- this->__throw_length_error();
- pointer __p;
- if (__reserve < __min_cap)
- {
- __set_short_size(__sz);
- __p = __get_short_pointer();
- }
- else
- {
- size_type __cap = __recommend(__reserve);
- __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- __set_long_size(__sz);
- }
- traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
- traits_type::assign(__p[__sz], value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
- {
- if (__sz > max_size())
- this->__throw_length_error();
- pointer __p;
- if (__sz < __min_cap)
- {
- __set_short_size(__sz);
- __p = __get_short_pointer();
- }
- else
- {
- size_type __cap = __recommend(__sz);
- __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- __set_long_size(__sz);
- }
- traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
- traits_type::assign(__p[__sz], value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
- {
- _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
- __init(__s, traits_type::length(__s));
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
- : __r_(__a)
- {
- _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
- __init(__s, traits_type::length(__s));
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
- __init(__s, __n);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
- : __r_(__a)
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
- __init(__s, __n);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
- : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
- {
- if (!__str.__is_long())
- __r_.first().__r = __str.__r_.first().__r;
- else
- __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
- : __r_(__a)
- {
- if (!__str.__is_long())
- __r_.first().__r = __str.__r_.first().__r;
- else
- __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
- #if _LIBCPP_STD_VER <= 14
- _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
- #else
- _NOEXCEPT
- #endif
- : __r_(_VSTD::move(__str.__r_))
- {
- __str.__zero();
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- if (__is_long())
- __get_db()->swap(this, &__str);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
- : __r_(__a)
- {
- if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
- __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
- else
- {
- __r_.first().__r = __str.__r_.first().__r;
- __str.__zero();
- }
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- if (__is_long())
- __get_db()->swap(this, &__str);
- #endif
- }
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
- {
- if (__n > max_size())
- this->__throw_length_error();
- pointer __p;
- if (__n < __min_cap)
- {
- __set_short_size(__n);
- __p = __get_short_pointer();
- }
- else
- {
- size_type __cap = __recommend(__n);
- __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- __set_long_size(__n);
- }
- traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
- traits_type::assign(__p[__n], value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
- {
- __init(__n, __c);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
- : __r_(__a)
- {
- __init(__n, __c);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
- const allocator_type& __a)
- : __r_(__a)
- {
- size_type __str_sz = __str.size();
- if (__pos > __str_sz)
- this->__throw_out_of_range();
- __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
- const allocator_type& __a)
- : __r_(__a)
- {
- size_type __str_sz = __str.size();
- if (__pos > __str_sz)
- this->__throw_out_of_range();
- __init(__str.data() + __pos, __str_sz - __pos);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- template <class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value,
- void
- >::type
- basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
- {
- __zero();
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- for (; __first != __last; ++__first)
- push_back(*__first);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- if (__is_long())
- __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
- throw;
- }
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- template <class _CharT, class _Traits, class _Allocator>
- template <class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value,
- void
- >::type
- basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
- {
- size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__sz > max_size())
- this->__throw_length_error();
- pointer __p;
- if (__sz < __min_cap)
- {
- __set_short_size(__sz);
- __p = __get_short_pointer();
- }
- else
- {
- size_type __cap = __recommend(__sz);
- __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- __set_long_size(__sz);
- }
- for (; __first != __last; ++__first, (void) ++__p)
- traits_type::assign(*__p, *__first);
- traits_type::assign(*__p, value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
- {
- __init(__first, __last);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
- const allocator_type& __a)
- : __r_(__a)
- {
- __init(__first, __last);
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
- {
- __init(__il.begin(), __il.end());
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
- : __r_(__a)
- {
- __init(__il.begin(), __il.end());
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__insert_c(this);
- #endif
- }
- #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>::~basic_string()
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- __get_db()->__erase_c(this);
- #endif
- if (__is_long())
- __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
- (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
- size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
- {
- size_type __ms = max_size();
- if (__delta_cap > __ms - __old_cap - 1)
- this->__throw_length_error();
- pointer __old_p = __get_pointer();
- size_type __cap = __old_cap < __ms / 2 - __alignment ?
- __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
- __ms - 1;
- pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __invalidate_all_iterators();
- if (__n_copy != 0)
- traits_type::copy(_VSTD::__to_raw_pointer(__p),
- _VSTD::__to_raw_pointer(__old_p), __n_copy);
- if (__n_add != 0)
- traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
- size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
- if (__sec_cp_sz != 0)
- traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
- _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
- if (__old_cap+1 != __min_cap)
- __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- __old_sz = __n_copy + __n_add + __sec_cp_sz;
- __set_long_size(__old_sz);
- traits_type::assign(__p[__old_sz], value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
- size_type __n_copy, size_type __n_del, size_type __n_add)
- {
- size_type __ms = max_size();
- if (__delta_cap > __ms - __old_cap)
- this->__throw_length_error();
- pointer __old_p = __get_pointer();
- size_type __cap = __old_cap < __ms / 2 - __alignment ?
- __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
- __ms - 1;
- pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
- __invalidate_all_iterators();
- if (__n_copy != 0)
- traits_type::copy(_VSTD::__to_raw_pointer(__p),
- _VSTD::__to_raw_pointer(__old_p), __n_copy);
- size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
- if (__sec_cp_sz != 0)
- traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
- _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
- __sec_cp_sz);
- if (__old_cap+1 != __min_cap)
- __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
- __set_long_pointer(__p);
- __set_long_cap(__cap+1);
- }
- // assign
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
- size_type __cap = capacity();
- if (__cap >= __n)
- {
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- traits_type::move(__p, __s, __n);
- traits_type::assign(__p[__n], value_type());
- __set_size(__n);
- __invalidate_iterators_past(__n);
- }
- else
- {
- size_type __sz = size();
- __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
- }
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
- {
- size_type __cap = capacity();
- if (__cap < __n)
- {
- size_type __sz = size();
- __grow_by(__cap, __n - __cap, __sz, 0, __sz);
- }
- else
- __invalidate_iterators_past(__n);
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- traits_type::assign(__p, __n, __c);
- traits_type::assign(__p[__n], value_type());
- __set_size(__n);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
- {
- pointer __p;
- if (__is_long())
- {
- __p = __get_long_pointer();
- __set_long_size(1);
- }
- else
- {
- __p = __get_short_pointer();
- __set_short_size(1);
- }
- traits_type::assign(*__p, __c);
- traits_type::assign(*++__p, value_type());
- __invalidate_iterators_past(1);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
- {
- if (this != &__str)
- {
- __copy_assign_alloc(__str);
- assign(__str.data(), __str.size());
- }
- return *this;
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
- _NOEXCEPT_(__alloc_traits::is_always_equal::value)
- {
- if (__alloc() != __str.__alloc())
- assign(__str);
- else
- __move_assign(__str, true_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
- #if _LIBCPP_STD_VER > 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
- #endif
- {
- clear();
- shrink_to_fit();
- __r_.first() = __str.__r_.first();
- __move_assign_alloc(__str);
- __str.__zero();
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
- _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
- {
- __move_assign(__str, integral_constant<bool,
- __alloc_traits::propagate_on_container_move_assignment::value>());
- return *this;
- }
- #endif
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator <_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- basic_string<_CharT, _Traits, _Allocator>&
- >::type
- basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
- {
- basic_string __temp(__first, __last, __alloc());
- assign(__temp.data(), __temp.size());
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- basic_string<_CharT, _Traits, _Allocator>&
- >::type
- basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
- {
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- size_type __cap = capacity();
- if (__cap < __n)
- {
- size_type __sz = size();
- __grow_by(__cap, __n - __cap, __sz, 0, __sz);
- }
- else
- __invalidate_iterators_past(__n);
- pointer __p = __get_pointer();
- for (; __first != __last; ++__first, ++__p)
- traits_type::assign(*__p, *__first);
- traits_type::assign(*__p, value_type());
- __set_size(__n);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
- {
- size_type __sz = __str.size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
- return assign(__s, traits_type::length(__s));
- }
- // append
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
- size_type __cap = capacity();
- size_type __sz = size();
- if (__cap - __sz >= __n)
- {
- if (__n)
- {
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- traits_type::copy(__p + __sz, __s, __n);
- __sz += __n;
- __set_size(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- }
- else
- __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
- {
- if (__n)
- {
- size_type __cap = capacity();
- size_type __sz = size();
- if (__cap - __sz < __n)
- __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
- pointer __p = __get_pointer();
- traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
- __sz += __n;
- __set_size(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
- {
- bool __is_short = !__is_long();
- size_type __cap;
- size_type __sz;
- if (__is_short)
- {
- __cap = __min_cap - 1;
- __sz = __get_short_size();
- }
- else
- {
- __cap = __get_long_cap() - 1;
- __sz = __get_long_size();
- }
- if (__sz == __cap)
- {
- __grow_by(__cap, 1, __sz, __sz, 0);
- __is_short = !__is_long();
- }
- pointer __p;
- if (__is_short)
- {
- __p = __get_short_pointer() + __sz;
- __set_short_size(__sz+1);
- }
- else
- {
- __p = __get_long_pointer() + __sz;
- __set_long_size(__sz+1);
- }
- traits_type::assign(*__p, __c);
- traits_type::assign(*++__p, value_type());
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- basic_string<_CharT, _Traits, _Allocator>&
- >::type
- basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
- {
- basic_string __temp (__first, __last, __alloc());
- append(__temp.data(), __temp.size());
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- basic_string<_CharT, _Traits, _Allocator>&
- >::type
- basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
- {
- size_type __sz = size();
- size_type __cap = capacity();
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n)
- {
- if (__cap - __sz < __n)
- __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
- pointer __p = __get_pointer() + __sz;
- for (; __first != __last; ++__p, ++__first)
- traits_type::assign(*__p, *__first);
- traits_type::assign(*__p, value_type());
- __set_size(__sz + __n);
- }
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
- {
- return append(__str.data(), __str.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
- {
- size_type __sz = __str.size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
- return append(__s, traits_type::length(__s));
- }
- // insert
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- size_type __cap = capacity();
- if (__cap - __sz >= __n)
- {
- if (__n)
- {
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- size_type __n_move = __sz - __pos;
- if (__n_move != 0)
- {
- if (__p + __pos <= __s && __s < __p + __sz)
- __s += __n;
- traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
- }
- traits_type::move(__p + __pos, __s, __n);
- __sz += __n;
- __set_size(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- }
- else
- __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
- {
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- if (__n)
- {
- size_type __cap = capacity();
- value_type* __p;
- if (__cap - __sz >= __n)
- {
- __p = _VSTD::__to_raw_pointer(__get_pointer());
- size_type __n_move = __sz - __pos;
- if (__n_move != 0)
- traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
- }
- else
- {
- __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
- __p = _VSTD::__to_raw_pointer(__get_long_pointer());
- }
- traits_type::assign(__p + __pos, __n, __c);
- __sz += __n;
- __set_size(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- typename enable_if
- <
- __is_exactly_input_iterator<_InputIterator>::value
- || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- >::type
- basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
- "string::insert(iterator, range) called with an iterator not"
- " referring to this string");
- #endif
- basic_string __temp(__first, __last, __alloc());
- return insert(__pos, __temp.data(), __temp.data() + __temp.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _ForwardIterator>
- typename enable_if
- <
- __is_forward_iterator<_ForwardIterator>::value
- && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- >::type
- basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
- "string::insert(iterator, range) called with an iterator not"
- " referring to this string");
- #endif
- size_type __ip = static_cast<size_type>(__pos - begin());
- size_type __sz = size();
- size_type __cap = capacity();
- size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
- if (__n)
- {
- value_type* __p;
- if (__cap - __sz >= __n)
- {
- __p = _VSTD::__to_raw_pointer(__get_pointer());
- size_type __n_move = __sz - __ip;
- if (__n_move != 0)
- traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
- }
- else
- {
- __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
- __p = _VSTD::__to_raw_pointer(__get_long_pointer());
- }
- __sz += __n;
- __set_size(__sz);
- traits_type::assign(__p[__sz], value_type());
- for (__p += __ip; __first != __last; ++__p, ++__first)
- traits_type::assign(*__p, *__first);
- }
- return begin() + __ip;
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
- {
- return insert(__pos1, __str.data(), __str.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
- size_type __pos2, size_type __n)
- {
- size_type __str_sz = __str.size();
- if (__pos2 > __str_sz)
- this->__throw_out_of_range();
- return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
- return insert(__pos, __s, traits_type::length(__s));
- }
- template <class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
- {
- size_type __ip = static_cast<size_type>(__pos - begin());
- size_type __sz = size();
- size_type __cap = capacity();
- value_type* __p;
- if (__cap == __sz)
- {
- __grow_by(__cap, 1, __sz, __ip, 0, 1);
- __p = _VSTD::__to_raw_pointer(__get_long_pointer());
- }
- else
- {
- __p = _VSTD::__to_raw_pointer(__get_pointer());
- size_type __n_move = __sz - __ip;
- if (__n_move != 0)
- traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
- }
- traits_type::assign(__p[__ip], __c);
- traits_type::assign(__p[++__sz], value_type());
- __set_size(__sz);
- return begin() + static_cast<difference_type>(__ip);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
- "string::insert(iterator, n, value) called with an iterator not"
- " referring to this string");
- #endif
- difference_type __p = __pos - begin();
- insert(static_cast<size_type>(__p), __n, __c);
- return begin() + __p;
- }
- // replace
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
- {
- _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- __n1 = _VSTD::min(__n1, __sz - __pos);
- size_type __cap = capacity();
- if (__cap - __sz + __n1 >= __n2)
- {
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- if (__n1 != __n2)
- {
- size_type __n_move = __sz - __pos - __n1;
- if (__n_move != 0)
- {
- if (__n1 > __n2)
- {
- traits_type::move(__p + __pos, __s, __n2);
- traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
- goto __finish;
- }
- if (__p + __pos < __s && __s < __p + __sz)
- {
- if (__p + __pos + __n1 <= __s)
- __s += __n2 - __n1;
- else // __p + __pos < __s < __p + __pos + __n1
- {
- traits_type::move(__p + __pos, __s, __n1);
- __pos += __n1;
- __s += __n2;
- __n2 -= __n1;
- __n1 = 0;
- }
- }
- traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
- }
- }
- traits_type::move(__p + __pos, __s, __n2);
- __finish:
- __sz += __n2 - __n1;
- __set_size(__sz);
- __invalidate_iterators_past(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- else
- __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
- {
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- __n1 = _VSTD::min(__n1, __sz - __pos);
- size_type __cap = capacity();
- value_type* __p;
- if (__cap - __sz + __n1 >= __n2)
- {
- __p = _VSTD::__to_raw_pointer(__get_pointer());
- if (__n1 != __n2)
- {
- size_type __n_move = __sz - __pos - __n1;
- if (__n_move != 0)
- traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
- }
- }
- else
- {
- __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
- __p = _VSTD::__to_raw_pointer(__get_long_pointer());
- }
- traits_type::assign(__p + __pos, __n2, __c);
- __sz += __n2 - __n1;
- __set_size(__sz);
- __invalidate_iterators_past(__sz);
- traits_type::assign(__p[__sz], value_type());
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- template<class _InputIterator>
- typename enable_if
- <
- __is_input_iterator<_InputIterator>::value,
- basic_string<_CharT, _Traits, _Allocator>&
- >::type
- basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
- _InputIterator __j1, _InputIterator __j2)
- {
- basic_string __temp(__j1, __j2, __alloc());
- return this->replace(__i1, __i2, __temp);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
- {
- return replace(__pos1, __n1, __str.data(), __str.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
- size_type __pos2, size_type __n2)
- {
- size_type __str_sz = __str.size();
- if (__pos2 > __str_sz)
- this->__throw_out_of_range();
- return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
- }
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
- return replace(__pos, __n1, __s, traits_type::length(__s));
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
- {
- return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
- __str.data(), __str.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
- {
- return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
- {
- return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
- {
- return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
- }
- // erase
- template <class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>&
- basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
- {
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- if (__n)
- {
- value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
- __n = _VSTD::min(__n, __sz - __pos);
- size_type __n_move = __sz - __pos - __n;
- if (__n_move != 0)
- traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
- __sz -= __n;
- __set_size(__sz);
- __invalidate_iterators_past(__sz);
- traits_type::assign(__p[__sz], value_type());
- }
- return *this;
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
- "string::erase(iterator) called with an iterator not"
- " referring to this string");
- #endif
- _LIBCPP_ASSERT(__pos != end(),
- "string::erase(iterator) called with a non-dereferenceable iterator");
- iterator __b = begin();
- size_type __r = static_cast<size_type>(__pos - __b);
- erase(__r, 1);
- return __b + static_cast<difference_type>(__r);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::iterator
- basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
- "string::erase(iterator, iterator) called with an iterator not"
- " referring to this string");
- #endif
- _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
- iterator __b = begin();
- size_type __r = static_cast<size_type>(__first - __b);
- erase(__r, static_cast<size_type>(__last - __first));
- return __b + static_cast<difference_type>(__r);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::pop_back()
- {
- _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
- size_type __sz;
- if (__is_long())
- {
- __sz = __get_long_size() - 1;
- __set_long_size(__sz);
- traits_type::assign(*(__get_long_pointer() + __sz), value_type());
- }
- else
- {
- __sz = __get_short_size() - 1;
- __set_short_size(__sz);
- traits_type::assign(*(__get_short_pointer() + __sz), value_type());
- }
- __invalidate_iterators_past(__sz);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
- {
- __invalidate_all_iterators();
- if (__is_long())
- {
- traits_type::assign(*__get_long_pointer(), value_type());
- __set_long_size(0);
- }
- else
- {
- traits_type::assign(*__get_short_pointer(), value_type());
- __set_short_size(0);
- }
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
- {
- if (__is_long())
- {
- traits_type::assign(*(__get_long_pointer() + __pos), value_type());
- __set_long_size(__pos);
- }
- else
- {
- traits_type::assign(*(__get_short_pointer() + __pos), value_type());
- __set_short_size(__pos);
- }
- __invalidate_iterators_past(__pos);
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
- {
- size_type __sz = size();
- if (__n > __sz)
- append(__n - __sz, __c);
- else
- __erase_to_end(__n);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
- {
- size_type __m = __alloc_traits::max_size(__alloc());
- #if _LIBCPP_BIG_ENDIAN
- return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
- #else
- return __m - __alignment;
- #endif
- }
- template <class _CharT, class _Traits, class _Allocator>
- void
- basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
- {
- if (__res_arg > max_size())
- this->__throw_length_error();
- size_type __cap = capacity();
- size_type __sz = size();
- __res_arg = _VSTD::max(__res_arg, __sz);
- __res_arg = __recommend(__res_arg);
- if (__res_arg != __cap)
- {
- pointer __new_data, __p;
- bool __was_long, __now_long;
- if (__res_arg == __min_cap - 1)
- {
- __was_long = true;
- __now_long = false;
- __new_data = __get_short_pointer();
- __p = __get_long_pointer();
- }
- else
- {
- if (__res_arg > __cap)
- __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
- else
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
- #endif // _LIBCPP_NO_EXCEPTIONS
- __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
- #ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- return;
- }
- #else // _LIBCPP_NO_EXCEPTIONS
- if (__new_data == nullptr)
- return;
- #endif // _LIBCPP_NO_EXCEPTIONS
- }
- __now_long = true;
- __was_long = __is_long();
- __p = __get_pointer();
- }
- traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
- _VSTD::__to_raw_pointer(__p), size()+1);
- if (__was_long)
- __alloc_traits::deallocate(__alloc(), __p, __cap+1);
- if (__now_long)
- {
- __set_long_cap(__res_arg+1);
- __set_long_size(__sz);
- __set_long_pointer(__new_data);
- }
- else
- __set_short_size(__sz);
- __invalidate_all_iterators();
- }
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::const_reference
- basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
- {
- _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
- return *(data() + __pos);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::reference
- basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
- {
- _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
- return *(__get_pointer() + __pos);
- }
- template <class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::const_reference
- basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return (*this)[__n];
- }
- template <class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::reference
- basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
- {
- if (__n >= size())
- this->__throw_out_of_range();
- return (*this)[__n];
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::reference
- basic_string<_CharT, _Traits, _Allocator>::front()
- {
- _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
- return *__get_pointer();
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::const_reference
- basic_string<_CharT, _Traits, _Allocator>::front() const
- {
- _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
- return *data();
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::reference
- basic_string<_CharT, _Traits, _Allocator>::back()
- {
- _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
- return *(__get_pointer() + size() - 1);
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::const_reference
- basic_string<_CharT, _Traits, _Allocator>::back() const
- {
- _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
- return *(data() + size() - 1);
- }
- template <class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
- {
- size_type __sz = size();
- if (__pos > __sz)
- this->__throw_out_of_range();
- size_type __rlen = _VSTD::min(__n, __sz - __pos);
- traits_type::copy(__s, data() + __pos, __rlen);
- return __rlen;
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
- {
- return basic_string(*this, __pos, __n, __alloc());
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
- #if _LIBCPP_STD_VER >= 14
- _NOEXCEPT
- #else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
- #endif
- {
- #if _LIBCPP_DEBUG_LEVEL >= 2
- if (!__is_long())
- __get_db()->__invalidate_all(this);
- if (!__str.__is_long())
- __get_db()->__invalidate_all(&__str);
- __get_db()->swap(this, &__str);
- #endif
- _VSTD::swap(__r_.first(), __str.__r_.first());
- __swap_allocator(__alloc(), __str.__alloc());
- }
- // find
- template <class _Traits>
- struct _LIBCPP_HIDDEN __traits_eq
- {
- typedef typename _Traits::char_type char_type;
- _LIBCPP_INLINE_VISIBILITY
- bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
- {return _Traits::eq(__x, __y);}
- };
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
- return _VSTD::__str_find<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
- return _VSTD::__str_find<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find<value_type, size_type, traits_type, npos>
- (data(), size(), __c, __pos);
- }
- // rfind
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
- return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
- return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
- (data(), size(), __c, __pos);
- }
- // find_first_of
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
- return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
- return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return find(__c, __pos);
- }
- // find_last_of
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
- return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
- return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return rfind(__c, __pos);
- }
- // find_first_not_of
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
- return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
- return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __c, __pos);
- }
- // find_last_not_of
- template<class _CharT, class _Traits, class _Allocator>
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
- size_type __pos,
- size_type __n) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
- return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, __n);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __str.data(), __pos, __str.size());
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
- size_type __pos) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
- return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __s, __pos, traits_type::length(__s));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
- size_type __pos) const _NOEXCEPT
- {
- return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
- (data(), size(), __c, __pos);
- }
- // compare
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
- {
- size_t __lhs_sz = size();
- size_t __rhs_sz = __str.size();
- int __result = traits_type::compare(data(), __str.data(),
- _VSTD::min(__lhs_sz, __rhs_sz));
- if (__result != 0)
- return __result;
- if (__lhs_sz < __rhs_sz)
- return -1;
- if (__lhs_sz > __rhs_sz)
- return 1;
- return 0;
- }
- template <class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
- size_type __n1,
- const basic_string& __str) const
- {
- return compare(__pos1, __n1, __str.data(), __str.size());
- }
- template <class _CharT, class _Traits, class _Allocator>
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
- size_type __n1,
- const basic_string& __str,
- size_type __pos2,
- size_type __n2) const
- {
- size_type __sz = __str.size();
- if (__pos2 > __sz)
- this->__throw_out_of_range();
- return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
- __sz - __pos2));
- }
- template <class _CharT, class _Traits, class _Allocator>
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
- return compare(0, npos, __s, traits_type::length(__s));
- }
- template <class _CharT, class _Traits, class _Allocator>
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
- size_type __n1,
- const value_type* __s) const
- {
- _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
- return compare(__pos1, __n1, __s, traits_type::length(__s));
- }
- template <class _CharT, class _Traits, class _Allocator>
- int
- basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
- size_type __n1,
- const value_type* __s,
- size_type __n2) const
- {
- _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
- size_type __sz = size();
- if (__pos1 > __sz || __n2 == npos)
- this->__throw_out_of_range();
- size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
- int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
- if (__r == 0)
- {
- if (__rlen < __n2)
- __r = -1;
- else if (__rlen > __n2)
- __r = 1;
- }
- return __r;
- }
- // __invariants
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- basic_string<_CharT, _Traits, _Allocator>::__invariants() const
- {
- if (size() > capacity())
- return false;
- if (capacity() < __min_cap - 1)
- return false;
- if (data() == 0)
- return false;
- if (data()[size()] != value_type(0))
- return false;
- return true;
- }
- // operator==
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- size_t __lhs_sz = __lhs.size();
- return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
- __rhs.data(),
- __lhs_sz) == 0;
- }
- template<class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
- const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
- {
- size_t __lhs_sz = __lhs.size();
- if (__lhs_sz != __rhs.size())
- return false;
- const char* __lp = __lhs.data();
- const char* __rp = __rhs.data();
- if (__lhs.__is_long())
- return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
- for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
- if (*__lp != *__rp)
- return false;
- return true;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator==(const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- typedef basic_string<_CharT, _Traits, _Allocator> _String;
- _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
- size_t __lhs_len = _Traits::length(__lhs);
- if (__lhs_len != __rhs.size()) return false;
- return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- typedef basic_string<_CharT, _Traits, _Allocator> _String;
- _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
- size_t __rhs_len = _Traits::length(__rhs);
- if (__rhs_len != __lhs.size()) return false;
- return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
- }
- // operator!=
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__lhs == __rhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator!=(const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__lhs == __rhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- return !(__lhs == __rhs);
- }
- // operator<
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return __lhs.compare(__rhs) < 0;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- return __lhs.compare(__rhs) < 0;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator< (const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return __rhs.compare(__lhs) > 0;
- }
- // operator>
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return __rhs < __lhs;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- return __rhs < __lhs;
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator> (const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return __rhs < __lhs;
- }
- // operator<=
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__rhs < __lhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- return !(__rhs < __lhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator<=(const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__rhs < __lhs);
- }
- // operator>=
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__lhs < __rhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const _CharT* __rhs) _NOEXCEPT
- {
- return !(__lhs < __rhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- operator>=(const _CharT* __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
- {
- return !(__lhs < __rhs);
- }
- // operator +
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
- const basic_string<_CharT, _Traits, _Allocator>& __rhs)
- {
- basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
- __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
- __r.append(__rhs.data(), __rhs_sz);
- return __r;
- }
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
- {
- basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
- __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
- __r.append(__rhs.data(), __rhs_sz);
- return __r;
- }
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
- {
- basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
- __r.__init(&__lhs, 1, 1 + __rhs_sz);
- __r.append(__rhs.data(), __rhs_sz);
- return __r;
- }
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
- {
- basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
- __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
- __r.append(__rhs, __rhs_sz);
- return __r;
- }
- template<class _CharT, class _Traits, class _Allocator>
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
- {
- basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
- typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
- __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
- __r.push_back(__rhs);
- return __r;
- }
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
- {
- return _VSTD::move(__lhs.append(__rhs));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
- {
- return _VSTD::move(__rhs.insert(0, __lhs));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
- {
- return _VSTD::move(__lhs.append(__rhs));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
- {
- return _VSTD::move(__rhs.insert(0, __lhs));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
- {
- __rhs.insert(__rhs.begin(), __lhs);
- return _VSTD::move(__rhs);
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
- {
- return _VSTD::move(__lhs.append(__rhs));
- }
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<_CharT, _Traits, _Allocator>
- operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
- {
- __lhs.push_back(__rhs);
- return _VSTD::move(__lhs);
- }
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- // swap
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- void
- swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
- basic_string<_CharT, _Traits, _Allocator>& __rhs)
- _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
- {
- __lhs.swap(__rhs);
- }
- #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
- typedef basic_string<char16_t> u16string;
- typedef basic_string<char32_t> u32string;
- #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
- _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS string to_string(int __val);
- _LIBCPP_FUNC_VIS string to_string(unsigned __val);
- _LIBCPP_FUNC_VIS string to_string(long __val);
- _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
- _LIBCPP_FUNC_VIS string to_string(long long __val);
- _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
- _LIBCPP_FUNC_VIS string to_string(float __val);
- _LIBCPP_FUNC_VIS string to_string(double __val);
- _LIBCPP_FUNC_VIS string to_string(long double __val);
- _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
- _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
- _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
- _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
- template<class _CharT, class _Traits, class _Allocator>
- const typename basic_string<_CharT, _Traits, _Allocator>::size_type
- basic_string<_CharT, _Traits, _Allocator>::npos;
- template<class _CharT, class _Traits, class _Allocator>
- struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
- : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
- {
- size_t
- operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
- };
- template<class _CharT, class _Traits, class _Allocator>
- size_t
- hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
- const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
- {
- return __do_string_hash(__val.data(), __val.data() + __val.size());
- }
- #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- template<class _CharT, class _Traits, class _Allocator>
- basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os,
- const basic_string<_CharT, _Traits, _Allocator>& __str);
- template<class _CharT, class _Traits, class _Allocator>
- basic_istream<_CharT, _Traits>&
- operator>>(basic_istream<_CharT, _Traits>& __is,
- basic_string<_CharT, _Traits, _Allocator>& __str);
- template<class _CharT, class _Traits, class _Allocator>
- basic_istream<_CharT, _Traits>&
- getline(basic_istream<_CharT, _Traits>& __is,
- basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_istream<_CharT, _Traits>&
- getline(basic_istream<_CharT, _Traits>& __is,
- basic_string<_CharT, _Traits, _Allocator>& __str);
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_istream<_CharT, _Traits>&
- getline(basic_istream<_CharT, _Traits>&& __is,
- basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
- template<class _CharT, class _Traits, class _Allocator>
- inline _LIBCPP_INLINE_VISIBILITY
- basic_istream<_CharT, _Traits>&
- getline(basic_istream<_CharT, _Traits>&& __is,
- basic_string<_CharT, _Traits, _Allocator>& __str);
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
- #if _LIBCPP_DEBUG_LEVEL >= 2
- template<class _CharT, class _Traits, class _Allocator>
- bool
- basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
- {
- return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
- _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
- }
- template<class _CharT, class _Traits, class _Allocator>
- bool
- basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
- {
- return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
- _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
- }
- template<class _CharT, class _Traits, class _Allocator>
- bool
- basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
- {
- const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
- return this->data() <= __p && __p <= this->data() + this->size();
- }
- template<class _CharT, class _Traits, class _Allocator>
- bool
- basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
- {
- const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
- return this->data() <= __p && __p < this->data() + this->size();
- }
- #endif // _LIBCPP_DEBUG_LEVEL >= 2
- #if _LIBCPP_STD_VER > 11
- // Literal suffixes for basic_string [basic.string.literals]
- inline namespace literals
- {
- inline namespace string_literals
- {
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<char> operator "" s( const char *__str, size_t __len )
- {
- return basic_string<char> (__str, __len);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
- {
- return basic_string<wchar_t> (__str, __len);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
- {
- return basic_string<char16_t> (__str, __len);
- }
- inline _LIBCPP_INLINE_VISIBILITY
- basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
- {
- return basic_string<char32_t> (__str, __len);
- }
- }
- }
- #endif
- _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
- _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
- _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
- _LIBCPP_END_NAMESPACE_STD
- #endif // _LIBCPP_STRING
|