1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003 |
- //
- // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
- // Copyright (c) 2019-2020 Krystian Stasiowski (sdkrystian at gmail dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- // Official repository: https://github.com/boostorg/static_string
- //
- #ifndef BHO_STATIC_STRING_STATIC_STRING_HPP
- #define BHO_STATIC_STRING_STATIC_STRING_HPP
- #if defined(__GNUC__) && __GNUC__ >= 8
- #pragma GCC diagnostic push
- #pragma GCC system_header
- // false positives
- #pragma GCC diagnostic ignored "-Warray-bounds"
- #pragma GCC diagnostic ignored "-Wrestrict"
- #pragma GCC diagnostic ignored "-Wstringop-overflow"
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 7
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wnoexcept-type"
- #endif
- // External include guard
- #ifndef BHO_STATIC_STRING_CONFIG_HPP
- #include <asio2/bho/static_string/config.hpp>
- #include <asio2/bho/config/workaround.hpp>
- #endif
- #include <algorithm>
- #include <cstdint>
- #include <cstdio>
- #include <cwchar>
- #include <functional>
- #include <initializer_list>
- #include <limits>
- #include <iosfwd>
- #include <type_traits>
- namespace bho {
- namespace static_strings {
- #ifndef BHO_STATIC_STRING_DOCS
- template<std::size_t N, typename CharT, typename Traits>
- class basic_static_string;
- //------------------------------------------------------------------------------
- //
- // Aliases
- //
- //------------------------------------------------------------------------------
- template<std::size_t N>
- using static_string =
- basic_static_string<N, char, std::char_traits<char>>;
- template<std::size_t N>
- using static_wstring =
- basic_static_string<N, wchar_t, std::char_traits<wchar_t>>;
- template<std::size_t N>
- using static_u16string =
- basic_static_string<N, char16_t, std::char_traits<char16_t>>;
- template<std::size_t N>
- using static_u32string =
- basic_static_string<N, char32_t, std::char_traits<char32_t>>;
- #ifdef __cpp_char8_t
- template<std::size_t N>
- using static_u8string =
- basic_static_string<N, char8_t, std::char_traits<char8_t>>;
- #endif
- //--------------------------------------------------------------------------
- //
- // Detail
- //
- //--------------------------------------------------------------------------
- namespace detail {
- // Find the smallest width integral type that can hold a value as large as N (Glen Fernandes)
- template<std::size_t N>
- using smallest_width =
- typename std::conditional<(N <= (std::numeric_limits<unsigned char>::max)()), unsigned char,
- typename std::conditional<(N <= (std::numeric_limits<unsigned short>::max)()), unsigned short,
- typename std::conditional<(N <= (std::numeric_limits<unsigned int>::max)()), unsigned int,
- typename std::conditional<(N <= (std::numeric_limits<unsigned long>::max)()), unsigned long,
- typename std::conditional<(N <= (std::numeric_limits<unsigned long long>::max)()), unsigned long long,
- std::size_t>::type>::type>::type>::type>::type;
- // std::is_nothrow_convertible is C++20
- template<typename To>
- void is_nothrow_convertible_helper(To) noexcept;
- // MSVC is unable to parse this as a single expression, so a helper is needed
- template<typename From, typename To, typename =
- decltype(is_nothrow_convertible_helper<To>(std::declval<From>()))>
- struct is_nothrow_convertible_msvc_helper
- {
- static const bool value =
- noexcept(is_nothrow_convertible_helper<To>(std::declval<From>()));
- };
- template<typename From, typename To, typename = void>
- struct is_nothrow_convertible
- : std::false_type { };
- template<typename From, typename To>
- struct is_nothrow_convertible<From, To, typename std::enable_if<
- is_nothrow_convertible_msvc_helper<From, To>::value>::type>
- : std::true_type { };
- // GCC 4.8, 4.9 workaround for void_t to make the defining-type-id dependant
- template<typename...>
- struct void_t_helper
- {
- using type = void;
- };
- // void_t for c++11
- template<typename... Ts>
- using void_t = typename void_t_helper<Ts...>::type;
- template <class T, typename CharT, typename = void>
- struct is_string_like : std::false_type {};
- template<typename T, typename CharT>
- struct is_string_like<
- T, CharT,
- void_t<
- decltype(std::declval<CharT const*&>() = std::declval<T>().data()),
- decltype(std::declval<std::size_t&>() = std::declval<T>().size())>>
- : std::true_type
- {};
- // Check if a type can be used for templated
- // overloads string_view_type
- // This will be used by overloads that accept the string_view types
- // directly and other convertible types such as std::string.
- // When no string_view type is available, then we check for the
- // data and size member functions, and use them directly for assignments.
- template<typename T, typename CharT, typename Traits, typename = void>
- struct enable_if_viewable { };
- template<typename T, typename CharT, typename Traits>
- struct enable_if_viewable<T, CharT, Traits,
- typename std::enable_if<
- #if !defined(BHO_STATIC_STRING_HAS_ANY_STRING_VIEW)
- is_string_like<T, CharT>::value
- #elif defined(BHO_STATIC_STRING_STANDALONE)
- std::is_convertible<const T&, std::basic_string_view<CharT, Traits>>::value &&
- !std::is_convertible<const T&, const CharT*>::value
- #else
- (
- std::is_convertible<const T&, basic_string_view<CharT, Traits>>::value ||
- std::is_convertible<const T&, core::basic_string_view<CharT>>::value
- ) &&
- !std::is_convertible<const T&, const CharT*>::value
- #endif
- >::type>
- {
- using type = void;
- };
- template<typename T, typename CharT, typename Traits>
- using enable_if_viewable_t = typename enable_if_viewable<T, CharT, Traits>::type;
- // The common string_view type used in private operations with enable_if_viewable_t
- // - T const& itself when no string_view type is available
- // - basic_string_view (bho::string_view or std::string_view) when in
- // standalone because core::detail::string_view is unavailable
- // - core::detail::basic_string_view otherwise because it's convertible
- // to and from most types, including std::string_view
- // After converting a parameter to a common_string_view_type reference, we
- // can use the data() and size() member functions.
- #if !defined(BHO_STATIC_STRING_HAS_ANY_STRING_VIEW)
- template<typename T, typename CharT, typename Traits>
- using common_string_view_type = T const&;
- #elif defined(BHO_STATIC_STRING_STANDALONE)
- template<typename T, typename CharT, typename Traits>
- using common_string_view_type = basic_string_view<CharT, Traits>;
- #else
- template <class T, typename CharT, typename Traits, typename = void>
- struct common_string_view_type_impl {};
- template<typename T, typename CharT, typename Traits>
- struct common_string_view_type_impl<
- T, CharT, Traits,
- typename std::enable_if<
- is_string_like<T, CharT>::value &&
- !std::is_convertible<const T&, basic_string_view<CharT, Traits>>::value &&
- !std::is_convertible<const T&, core::basic_string_view<CharT>>::value>::type>
- {
- using type = T const&;
- };
- template<typename T, typename CharT, typename Traits>
- struct common_string_view_type_impl<
- T, CharT, Traits,
- typename std::enable_if<
- std::is_convertible<const T&, basic_string_view<CharT, Traits>>::value &&
- !std::is_convertible<const T&, core::basic_string_view<CharT>>::value>::type>
- {
- using type = basic_string_view<CharT, Traits>;
- };
- template<typename T, typename CharT, typename Traits>
- struct common_string_view_type_impl<
- T, CharT, Traits,
- typename std::enable_if<
- std::is_convertible<const T&, core::basic_string_view<CharT>>::value>::type>
- {
- using type = core::basic_string_view<CharT>;
- };
- template<typename T, typename CharT, typename Traits>
- using common_string_view_type = typename common_string_view_type_impl<T, CharT, Traits>::type;
- #endif
- // Simplified check for if a type is an iterator
- template<typename T, typename = void>
- struct is_iterator : std::false_type { };
- template<typename T>
- struct is_iterator<T,
- typename std::enable_if<std::is_class<T>::value,
- void_t<typename T::iterator_category>>::type>
- : std::true_type { };
- template<typename T>
- struct is_iterator<T*, void>
- : std::true_type { };
- template<typename T, typename = void>
- struct is_input_iterator : std::false_type { };
- template<typename T>
- struct is_input_iterator<T, typename std::enable_if<is_iterator<T>::value &&
- std::is_convertible<typename std::iterator_traits<T>::iterator_category,
- std::input_iterator_tag>::value>::type>
- : std::true_type { };
- template<typename T, typename = void>
- struct is_forward_iterator : std::false_type { };
- template<typename T>
- struct is_forward_iterator<T, typename std::enable_if<is_iterator<T>::value &&
- std::is_convertible<typename std::iterator_traits<T>::iterator_category,
- std::forward_iterator_tag>::value>::type>
- : std::true_type { };
- template<typename T, typename = void>
- struct is_subtractable
- : std::false_type { };
- template<typename T>
- struct is_subtractable<T, void_t<decltype(std::declval<T&>() - std::declval<T&>())>>
- : std::true_type { };
- // constexpr distance for c++14
- template<
- typename ForwardIt,
- typename std::enable_if<!is_subtractable<ForwardIt>::value>::type* = nullptr>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- std::size_t
- distance(ForwardIt first, ForwardIt last)
- {
- std::size_t dist = 0;
- for (; first != last; ++first, ++dist);
- return dist;
- }
- template<
- typename RandomIt,
- typename std::enable_if<is_subtractable<RandomIt>::value>::type* = nullptr>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- std::size_t
- distance(RandomIt first, RandomIt last)
- {
- return last - first;
- }
- // Copy using traits, respecting iterator rules
- template<typename Traits, typename InputIt, typename CharT>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- copy_with_traits(
- InputIt first,
- InputIt last,
- CharT* out)
- {
- for (; first != last; ++first, ++out)
- Traits::assign(*out, *first);
- }
- // Optimization for using the smallest possible type
- template<std::size_t N, typename CharT, typename Traits>
- class static_string_base
- {
- private:
- using size_type = smallest_width<N>;
- using value_type = typename Traits::char_type;
- using pointer = value_type*;
- using const_pointer = const value_type*;
- public:
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- static_string_base() noexcept { };
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- pointer
- data_impl() noexcept
- {
- return data_;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_pointer
- data_impl() const noexcept
- {
- return data_;
- }
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- std::size_t
- size_impl() const noexcept
- {
- return size_;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- std::size_t
- set_size(std::size_t n) noexcept
- {
- // Functions that set size will throw
- // if the new size would exceed max_size()
- // therefore we can guarantee that this will
- // not lose data.
- return size_ = size_type(n);
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- term_impl() noexcept
- {
- Traits::assign(data_[size_], value_type());
- }
- size_type size_ = 0;
- value_type data_[N + 1]{};
- };
- // Optimization for when the size is 0
- template<typename CharT, typename Traits>
- class static_string_base<0, CharT, Traits>
- {
- private:
- using value_type = typename Traits::char_type;
- using pointer = value_type*;
- public:
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- static_string_base() noexcept { }
- // Modifying the null terminator is UB
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- pointer
- data_impl() const noexcept
- {
- return const_cast<pointer>(&null_);
- }
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- std::size_t
- size_impl() const noexcept
- {
- return 0;
- }
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- std::size_t
- set_size(std::size_t) const noexcept
- {
- return 0;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- term_impl() const noexcept { }
- private:
- static constexpr const value_type null_{};
- };
- // This is only needed in C++14 and lower.
- // see http://eel.is/c++draft/depr.static.constexpr
- #ifndef BHO_STATIC_STRING_CPP17
- template<typename CharT, typename Traits>
- constexpr
- const
- typename static_string_base<0, CharT, Traits>::value_type
- static_string_base<0, CharT, Traits>::
- null_;
- #endif
- template<typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- int
- lexicographical_compare(
- const CharT* s1,
- std::size_t n1,
- const CharT* s2,
- std::size_t n2) noexcept
- {
- if(n1 < n2)
- return Traits::compare(
- s1, s2, n1) <= 0 ? -1 : 1;
- if(n1 > n2)
- return Traits::compare(
- s1, s2, n2) >= 0 ? 1 : -1;
- return Traits::compare(s1, s2, n1);
- }
- template<typename Traits, typename Integer>
- inline
- char*
- integer_to_string(
- char* str_end,
- Integer value,
- std::true_type) noexcept
- {
- if (value == 0)
- {
- Traits::assign(*--str_end, '0');
- return str_end;
- }
- if (value < 0)
- {
- const bool is_min = value == (std::numeric_limits<Integer>::min)();
- // negation of a min value cannot be represented
- if (is_min)
- value = (std::numeric_limits<Integer>::max)();
- else
- value = -value;
- const auto last_char = str_end - 1;
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, "0123456789"[value % 10]);
- // minimum values are powers of 2, so it will
- // never terminate with a 9.
- if (is_min)
- Traits::assign(*last_char, Traits::to_char_type(
- Traits::to_int_type(*last_char) + 1));
- Traits::assign(*--str_end, '-');
- return str_end;
- }
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, "0123456789"[value % 10]);
- return str_end;
- }
- template<typename Traits, typename Integer>
- inline
- char*
- integer_to_string(
- char* str_end,
- Integer value,
- std::false_type) noexcept
- {
- if (value == 0)
- {
- Traits::assign(*--str_end, '0');
- return str_end;
- }
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, "0123456789"[value % 10]);
- return str_end;
- }
- template<typename Traits, typename Integer>
- inline
- wchar_t*
- integer_to_wstring(
- wchar_t* str_end,
- Integer value,
- std::true_type) noexcept
- {
- if (value == 0)
- {
- Traits::assign(*--str_end, L'0');
- return str_end;
- }
- if (value < 0)
- {
- const bool is_min = value == (std::numeric_limits<Integer>::min)();
- // negation of a min value cannot be represented
- if (is_min)
- value = (std::numeric_limits<Integer>::max)();
- else
- value = -value;
- const auto last_char = str_end - 1;
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, L"0123456789"[value % 10]);
- // minimum values are powers of 2, so it will
- // never terminate with a 9.
- if (is_min)
- Traits::assign(*last_char, Traits::to_char_type(
- Traits::to_int_type(*last_char) + 1));
- Traits::assign(*--str_end, L'-');
- return str_end;
- }
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, L"0123456789"[value % 10]);
- return str_end;
- }
- template<typename Traits, typename Integer>
- inline
- wchar_t*
- integer_to_wstring(
- wchar_t* str_end,
- Integer value,
- std::false_type) noexcept
- {
- if (value == 0)
- {
- Traits::assign(*--str_end, L'0');
- return str_end;
- }
- for (; value > 0; value /= 10)
- Traits::assign(*--str_end, L"0123456789"[value % 10]);
- return str_end;
- }
- template<std::size_t N, typename Integer>
- inline
- static_string<N>
- to_static_string_int_impl(Integer value) noexcept
- {
- char buffer[N];
- const auto digits_end = std::end(buffer);
- const auto digits_begin = integer_to_string<std::char_traits<char>, Integer>(
- digits_end, value, std::is_signed<Integer>{});
- return static_string<N>(digits_begin, std::distance(digits_begin, digits_end));
- }
- template<std::size_t N, typename Integer>
- inline
- static_wstring<N>
- to_static_wstring_int_impl(Integer value) noexcept
- {
- wchar_t buffer[N];
- const auto digits_end = std::end(buffer);
- const auto digits_begin = integer_to_wstring<std::char_traits<wchar_t>, Integer>(
- digits_end, value, std::is_signed<Integer>{});
- return static_wstring<N>(digits_begin, std::distance(digits_begin, digits_end));
- }
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- inline
- int
- count_digits(std::size_t value)
- {
- return value < 10 ? 1 : count_digits(value / 10) + 1;
- }
- // Ignore -Wformat-truncation, we know what
- // we are doing here. The version check does
- // not need to be extremely precise.
- #if defined(__GNUC__) && __GNUC__ >= 7
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wformat-truncation"
- #endif
- template<std::size_t N>
- inline
- static_string<N>
- to_static_string_float_impl(double value) noexcept
- {
- // we have to assume here that no reasonable implementation
- // will require more than 2^63 chars to represent a float value.
- const long long narrow =
- static_cast<long long>(N);
- // extra one needed for null terminator
- char buffer[N + 1];
- // we know that a formatting error will not occur, so
- // we assume that the result is always positive
- if (std::size_t(std::snprintf(buffer, N + 1, "%f", value)) > N)
- {
- // the + 4 is for the decimal, 'e',
- // its sign, and the sign of the integral portion
- const int reserved_count =
- (std::max)(2, count_digits(
- std::numeric_limits<double>::max_exponent10)) + 4;
- const int precision = narrow > reserved_count ?
- N - reserved_count : 0;
- // switch to scientific notation
- std::snprintf(buffer, N + 1, "%.*e", precision, value);
- }
- // this will not throw
- return static_string<N>(buffer);
- }
- template<std::size_t N>
- inline
- static_string<N>
- to_static_string_float_impl(long double value) noexcept
- {
- // we have to assume here that no reasonable implementation
- // will require more than 2^63 chars to represent a float value.
- const long long narrow =
- static_cast<long long>(N);
- // extra one needed for null terminator
- char buffer[N + 1];
- // snprintf returns the number of characters
- // that would have been written
- // we know that a formatting error will not occur, so
- // we assume that the result is always positive
- if (std::size_t(std::snprintf(buffer, N + 1, "%Lf", value)) > N)
- {
- // the + 4 is for the decimal, 'e',
- // its sign, and the sign of the integral portion
- const int reserved_count =
- (std::max)(2, count_digits(
- std::numeric_limits<long double>::max_exponent10)) + 4;
- const int precision = narrow > reserved_count ?
- N - reserved_count : 0;
- // switch to scientific notation
- std::snprintf(buffer, N + 1, "%.*Le", precision, value);
- }
- // this will not throw
- return static_string<N>(buffer);
- }
- template<std::size_t N>
- inline
- static_wstring<N>
- to_static_wstring_float_impl(double value) noexcept
- {
- // we have to assume here that no reasonable implementation
- // will require more than 2^63 chars to represent a float value.
- const long long narrow =
- static_cast<long long>(N);
- // extra one needed for null terminator
- wchar_t buffer[N + 1];
- // swprintf returns a negative number if it can't
- // fit all the characters in the buffer.
- // mingw has a non-standard swprintf, so
- // this just covers all the bases. short
- // circuit evaluation will ensure that the
- // second operand is not evaluated on conforming
- // implementations.
- const long long num_written =
- std::swprintf(buffer, N + 1, L"%f", value);
- if (num_written < 0 ||
- num_written > narrow)
- {
- // the + 4 is for the decimal, 'e',
- // its sign, and the sign of the integral portion
- const int reserved_count =
- (std::max)(2, count_digits(
- std::numeric_limits<double>::max_exponent10)) + 4;
- const int precision = narrow > reserved_count ?
- N - reserved_count : 0;
- // switch to scientific notation
- std::swprintf(buffer, N + 1, L"%.*e", precision, value);
- }
- // this will not throw
- return static_wstring<N>(buffer);
- }
- template<std::size_t N>
- inline
- static_wstring<N>
- to_static_wstring_float_impl(long double value) noexcept
- {
- // we have to assume here that no reasonable implementation
- // will require more than 2^63 chars to represent a float value.
- const long long narrow =
- static_cast<long long>(N);
- // extra one needed for null terminator
- wchar_t buffer[N + 1];
- // swprintf returns a negative number if it can't
- // fit all the characters in the buffer.
- // mingw has a non-standard swprintf, so
- // this just covers all the bases. short
- // circuit evaluation will ensure that the
- // second operand is not evaluated on conforming
- // implementations.
- const long long num_written =
- std::swprintf(buffer, N + 1, L"%Lf", value);
- if (num_written < 0 ||
- num_written > narrow)
- {
- // the + 4 is for the decimal, 'e',
- // its sign, and the sign of the integral portion
- const int reserved_count =
- (std::max)(2, count_digits(
- std::numeric_limits<long double>::max_exponent10)) + 4;
- const int precision = narrow > reserved_count ?
- N - reserved_count : 0;
- // switch to scientific notation
- std::swprintf(buffer, N + 1, L"%.*Le", precision, value);
- }
- // this will not throw
- return static_wstring<N>(buffer);
- }
- #if defined(__GNUC__) && __GNUC__ >= 7
- #pragma GCC diagnostic pop
- #endif
- template<typename Traits, typename CharT, typename ForwardIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- ForwardIterator
- find_not_of(
- ForwardIterator first,
- ForwardIterator last,
- const CharT* str,
- std::size_t n) noexcept
- {
- for (; first != last; ++first)
- if (!Traits::find(str, n, *first))
- return first;
- return last;
- }
- // constexpr search for C++14
- template<typename ForwardIt1, typename ForwardIt2, typename BinaryPredicate>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- ForwardIt1
- search(
- ForwardIt1 first,
- ForwardIt1 last,
- ForwardIt2 s_first,
- ForwardIt2 s_last,
- BinaryPredicate p)
- {
- for (; ; ++first)
- {
- ForwardIt1 it = first;
- for (ForwardIt2 s_it = s_first; ; ++it, ++s_it)
- {
- if (s_it == s_last)
- return first;
- if (it == last)
- return last;
- if (!p(*it, *s_it))
- break;
- }
- }
- }
- template<typename InputIt, typename ForwardIt, typename BinaryPredicate>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- InputIt
- find_first_of(
- InputIt first,
- InputIt last,
- ForwardIt s_first,
- ForwardIt s_last,
- BinaryPredicate p)
- {
- for (; first != last; ++first)
- for (ForwardIt it = s_first; it != s_last; ++it)
- if (p(*first, *it))
- return first;
- return last;
- }
- // KRYSTIAN TODO: add a constexpr rotate
- // Check if a pointer lies within the range {src_first, src_last)
- // without unspecified behavior, allowing it to be used
- // in a constant evaluation.
- template<typename T>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- ptr_in_range(
- const T* src_first,
- const T* src_last,
- const T* ptr)
- {
- #if defined(BHO_STATIC_STRING_CPP14) && \
- defined(BHO_STATIC_STRING_IS_CONST_EVAL)
- // Our second best option is to use is_constant_evaluated
- // and a loop that checks for equality, since equality for
- // pointer to object types is never unspecified in this case.
- if (BHO_STATIC_STRING_IS_CONST_EVAL)
- {
- for (; src_first != src_last; ++src_first)
- if (ptr == src_first)
- return true;
- return false;
- }
- #endif
- // We want to make this usable in constant expressions as much as possible
- // while retaining the guarentee that the comparison has a strict total ordering.
- // We also want this to be fast. Since different compilers have differing levels
- // of conformance, we will settle for the best option that is available.
- // We don't care about this in C++11, since this function would have
- // no applications in constant expressions.
- #if defined(BHO_STATIC_STRING_CPP14) && \
- defined(BHO_STATIC_STRING_NO_PTR_COMP_FUNCTIONS)
- // If library comparison functions don't work,
- // we can use try builtin comparison operators instead.
- return ptr >= src_first && ptr < src_last;
- #else
- // Use the library comparison functions if we can't use
- // is_constant_evaluated or if we don't need to.
- return std::greater_equal<const T*>()(ptr, src_first) &&
- std::less<const T*>()(ptr, src_last);
- #endif
- }
- // This workaround is for gcc 5,
- // which prohibits throw expressions in constexpr
- // functions, but for some reason permits them in
- // constructors.
- #ifdef BHO_STATIC_STRING_GCC5_BAD_CONSTEXPR
- template<typename Exception>
- struct throw_exception
- {
- BHO_STATIC_STRING_NORETURN
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- throw_exception(const char* msg)
- {
- BHO_STATIC_STRING_THROW(Exception(msg));
- }
- };
- #else
- template<typename Exception>
- BHO_STATIC_STRING_NORETURN
- inline
- void
- throw_exception(const char* msg)
- {
- BHO_STATIC_STRING_THROW(Exception(msg));
- }
- #endif
- } // detail
- #endif
- //--------------------------------------------------------------------------
- //
- // static_string
- //
- //--------------------------------------------------------------------------
- /** A fixed-capacity string.
- These objects behave like `std::string` except that the storage
- is not dynamically allocated but rather fixed in size, and
- stored in the object itself.
- These strings offer performance advantages when an algorithm
- can execute with a reasonable upper limit on the size of a value.
- @par Aliases
- The following alias templates are provided for convenience:
- @code
- template<std::size_t N>
- using static_string =
- basic_static_string<N, char, std::char_traits<char>>;
- @endcode
- @code
- template<std::size_t N>
- using static_wstring =
- basic_static_string<N, wchar_t, std::char_traits<wchar_t>>;
- @endcode
- @code
- template<std::size_t N>
- using static_u16string =
- basic_static_string<N, char16_t, std::char_traits<char16_t>>;
- @endcode
- @code
- template<std::size_t N>
- using static_u32string =
- basic_static_string<N, char32_t, std::char_traits<char32_t>>;
- @endcode
- Addtionally, the alias template `static_u8string` is provided in C++20
- @code
- template<std::size_t N>
- using static_u8string =
- basic_static_string<N, char8_t, std::char_traits<char8_t>>;
- @endcode
- @see to_static_string
- */
- template<std::size_t N, typename CharT,
- typename Traits = std::char_traits<CharT>>
- class basic_static_string
- #ifndef BHO_STATIC_STRING_DOCS
- : private detail::static_string_base<N, CharT, Traits>
- #endif
- {
- private:
- template<std::size_t, class, class>
- friend class basic_static_string;
- public:
- //--------------------------------------------------------------------------
- //
- // Member types
- //
- //--------------------------------------------------------------------------
- /// The traits type.
- using traits_type = Traits;
- /// The character type.
- using value_type = typename traits_type::char_type;
- /// The size type.
- using size_type = std::size_t;
- /// The difference type.
- using difference_type = std::ptrdiff_t;
- /// The pointer type.
- using pointer = value_type*;
- /// The reference type.
- using reference = value_type&;
- /// The constant pointer type.
- using const_pointer = const value_type*;
- /// The constant reference type.
- using const_reference = const value_type&;
- /// The iterator type.
- using iterator = value_type*;
- /// The constant iterator type.
- using const_iterator = const value_type*;
- /// The reverse iterator type.
- using reverse_iterator =
- std::reverse_iterator<iterator>;
- /// The constant reverse iterator type.
- using const_reverse_iterator =
- std::reverse_iterator<const_iterator>;
- #ifdef BHO_STATIC_STRING_HAS_ANY_STRING_VIEW
- /// The string view type.
- using string_view_type =
- basic_string_view<value_type, traits_type>;
- #endif
- //--------------------------------------------------------------------------
- //
- // Constants
- //
- //--------------------------------------------------------------------------
- /// Maximum size of the string excluding any null terminator
- static constexpr size_type static_capacity = N;
- /// A special index
- static constexpr size_type npos = size_type(-1);
- //--------------------------------------------------------------------------
- //
- // Construction
- //
- //--------------------------------------------------------------------------
- /** Constructor.
- Construct an empty string
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- basic_static_string() noexcept
- {
- #ifdef BHO_STATIC_STRING_CPP20
- term();
- #endif
- }
- /** Constructor.
- Construct the string with `count` copies of character `ch`.
- The behavior is undefined if `count >= npos`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- size_type count,
- value_type ch)
- {
- assign(count, ch);
- }
- /** Constructor.
- Construct with a substring (pos, other.size()) of `other`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- const basic_static_string<M, CharT, Traits>& other,
- size_type pos)
- {
- assign(other, pos);
- }
- /** Constructor.
- Construct with a substring (pos, count) of `other`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- const basic_static_string<M, CharT, Traits>& other,
- size_type pos,
- size_type count)
- {
- assign(other, pos, count);
- }
- /** Constructor.
- Construct with the first `count` characters of `s`, including nulls.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- const_pointer s,
- size_type count)
- {
- assign(s, count);
- }
- /** Constructor.
- Construct from a null terminated string.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(const_pointer s)
- {
- assign(s);
- }
- /** Constructor.
- Construct from a range of characters
- */
- template<typename InputIterator
- #ifndef BHO_STATIC_STRING_DOCS
- , typename std::enable_if<
- detail::is_input_iterator<InputIterator>
- ::value>::type* = nullptr
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- InputIterator first,
- InputIterator last)
- {
- // KRYSTIAN TODO: we can use a better algorithm if this is a forward iterator
- assign(first, last);
- }
- /** Constructor.
- Copy constructor.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(const basic_static_string& other) noexcept
- {
- assign(other);
- }
- /** Constructor.
- Copy constructor.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- const basic_static_string<M, CharT, Traits>& other)
- {
- assign(other);
- }
- /** Constructor.
- Construct from an initializer list
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(std::initializer_list<value_type> init)
- {
- assign(init.begin(), init.size());
- }
- /** Constructor.
- Construct from a object convertible to `string_view_type`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- explicit
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(const T& t)
- {
- assign(t);
- }
- /** Constructor.
- Construct from any object convertible to `string_view_type`.
- The range (pos, n) is extracted from the value
- obtained by converting `t` to `string_view_type`,
- and used to construct the string.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string(
- const T& t,
- size_type pos,
- size_type n)
- {
- assign(t, pos, n);
- }
- //--------------------------------------------------------------------------
- //
- // Assignment
- //
- //--------------------------------------------------------------------------
- /** Assign to the string.
- Replaces the contents with those of
- the string `s`.
- @par Complexity
- Linear in `s.size()`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param s The string to replace
- the contents with.
- @throw std::length_error `s.size() > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(const basic_static_string& s)
- {
- return assign(s);
- }
- /** Assign to the string.
- Replaces the contents with those of
- the string `s`.
- @par Complexity
- Linear in `s.size()`.
- @par Exception Safety
- Strong guarantee.
- @tparam M The size of the other string.
- @return `*this`
- @param s The string to replace
- the contents with.
- @throw std::length_error `s.size() > max_size()`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(const basic_static_string<M, CharT, Traits>& s)
- {
- return assign(s);
- }
- /** Assign to the string.
- Replaces the contents with those of
- `{s, s + traits_type::length(s))`.
- @par Complexity
- Linear in `count`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param s A pointer to the string to copy from.
- @throw std::length_error `traits_type::length(s) > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(const_pointer s)
- {
- return assign(s);
- }
- /** Assign to the string.
- Replaces the contents with a single copy of
- the character `ch`.
- @par Complexity
- Constant.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param ch The character to assign to.
- @throw std::length_error `count > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(value_type ch)
- {
- return assign_char(ch,
- std::integral_constant<bool, (N > 0)>{});
- }
- /** Assign to the string.
- Replaces the contents with those of the
- initializer list `ilist`.
- @par Complexity
- Linear in `init.size()`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param ilist The initializer list to copy from.
- @throw std::length_error `ilist.size() > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(std::initializer_list<value_type> ilist)
- {
- return assign(ilist);
- }
- /** Assign to the string.
- Replaces the contents with those of
- `sv`, where `sv` is `string_view_type(t)`.
- @par Complexity
- Linear in `sv.size()`.
- @par Exception Safety
- Strong guarantee.
- @note
- The view can contain null characters.
- @tparam T A type convertible to `string_view_type`.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value
- @endcode
- @return `*this`
- @param t The object to assign from.
- @throw std::length_error `sv.size() > max_size()`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator=(const T& t)
- {
- return assign(t);
- }
- /** Assign to the string.
- Replaces the contents with `count` copies of
- character `ch`.
- @par Complexity
- Linear in `count`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param count The size of the resulting string.
- @param ch The value to initialize characters
- of the string with.
- @throw std::length_error `count > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(
- size_type count,
- value_type ch);
- /** Assign to the string.
- Replaces the contents with those of
- the string `s`.
- @par Complexity
- Linear in `s.size()`.
- @par Exception Safety
- Strong guarantee.
- @tparam M The size of the other string.
- @return `*this`
- @param s The string to replace
- the contents with.
- @throw std::length_error `s.size() > max_size()`.
- */
- template<std::size_t M
- #ifndef BHO_STATIC_STRING_DOCS
- , typename std::enable_if<(M < N)>::type* = nullptr
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(const basic_static_string<M, CharT, Traits>& s)
- {
- return assign_unchecked(s.data(), s.size());
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(const basic_static_string& s) noexcept
- {
- if (data() == s.data())
- return *this;
- return assign_unchecked(s.data(), s.size());
- }
- template<std::size_t M,
- typename std::enable_if<(M > N)>::type* = nullptr>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(const basic_static_string<M, CharT, Traits>& s)
- {
- return assign(s.data(), s.size());
- }
- #endif
- /** Assign to the string.
- Replaces the contents with those of the string `sub`,
- where `sub` is `s.substr(pos, count)`.
- @par Complexity
- Linear in `sub.size()`.
- @par Exception Safety
- Strong guarantee.
- @tparam M The capacity of the other string.
- @return `*this`
- @param s The string to replace
- the contents with.
- @param pos The index at which to begin the substring.
- @param count The size of the substring. The default
- argument for this parameter is @ref npos.
- @throw std::length_error `sub.size() > max_size()`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(
- const basic_static_string<M, CharT, Traits>& s,
- size_type pos,
- size_type count = npos)
- {
- return assign(s.data() + pos, s.capped_length(pos, count));
- }
- /** Assign to the string.
- Replaces the contents with those of `{s, s + count)`.
- @par Complexity
- Linear in `count`.
- @par Exception Safety
- Strong guarantee.
- @note
- The range can contain null characters.
- @return `*this`
- @param count The number of characters to copy.
- @param s A pointer to the string to copy from.
- @throw std::length_error `count > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(
- const_pointer s,
- size_type count);
- /** Assign to the string.
- Replaces the contents with those of
- `{s, s + traits_type::length(s))`.
- @par Complexity
- Linear in `count`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param s A pointer to the string to copy from.
- @throw std::length_error `traits_type::length(s) > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(const_pointer s)
- {
- return assign(s, traits_type::length(s));
- }
- /** Assign to the string.
- Replaces the contents with the characters
- in the range `{first, last)`.
- @par Complexity
- Linear in `std::distance(first, last)`.
- @par Exception Safety
- Strong guarantee.
- @tparam InputIterator The type of the iterators.
- @par Constraints
- `InputIterator` satisfies __InputIterator__.
- @return `*this`
- @param first An iterator referring to the
- first character to assign.
- @param last An iterator past the end
- of the range to assign from.
- @throw std::length_error `std::distance(first, last) > max_size()`.
- */
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- #ifdef BHO_STATIC_STRING_DOCS
- basic_static_string&
- #else
- typename std::enable_if<
- detail::is_input_iterator<InputIterator>::value,
- basic_static_string&>::type
- #endif
- assign(
- InputIterator first,
- InputIterator last);
- /** Assign to the string.
- Replaces the contents with those of the
- initializer list `ilist`.
- @par Complexity
- Linear in `init.size()`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param ilist The initializer list to copy from.
- @throw std::length_error `ilist.size() > max_size()`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(
- std::initializer_list<value_type> ilist)
- {
- return assign(ilist.begin(), ilist.end());
- }
- /** Assign to the string.
- Replaces the contents with those of
- `sv`, where `sv` is `string_view_type(t)`.
- @par Complexity
- Linear in `sv.size()`.
- @par Exception Safety
- Strong guarantee.
- @note
- The view can contain null characters.
- @tparam T A type convertible to `string_view_type`.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value
- @endcode
- @return `*this`
- @param t The object to assign from.
- @throw std::length_error `sv.size() > max_size()`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign(const T& t)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return assign(sv.data(), sv.size());
- }
- /** Assign to the string.
- Replaces the contents with those of the substring `sv`,
- where `sv` is `string_view_type(t).substr(pos, count)`.
- @par Complexity
- Linear in `sv.size()`.
- @par Exception Safety
- Strong guarantee.
- @note
- The view can contain null characters.
- @tparam T A type convertible to `string_view_type`.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value
- @endcode
- @return `*this`
- @param t The object to assign from.
- @param pos The index at which to begin the substring.
- @param count The size of the substring. The default
- argument for this parameter is @ref npos.
- @throw std::length_error `sv.size() > max_size()`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- basic_static_string&
- assign(
- const T& t,
- size_type pos,
- size_type count = npos)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- if( pos > sv.size() )
- detail::throw_exception<std::out_of_range>(
- "pos >= t.size()");
- std::size_t rlen = (std::min)( count, sv.size() - pos );
- return assign(sv.data() + pos, rlen);
- }
- //--------------------------------------------------------------------------
- //
- // Element access
- //
- //--------------------------------------------------------------------------
- /** Access a character with bounds checking.
- Returns a reference to the character at
- index `pos`.
- @par Complexity
- Constant.
- @par Exception Safety
- Strong guarantee.
- @param pos The index to access.
- @throw std::out_of_range `pos >= size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- reference
- at(size_type pos)
- {
- if (pos >= size())
- detail::throw_exception<std::out_of_range>(
- "pos >= size()");
- return data()[pos];
- }
- /** Access a character with bounds checking.
- Returns a reference to the character at
- index `pos`.
- @par Complexity
- Constant.
- @par Exception Safety
- Strong guarantee.
- @param pos The index to access.
- @throw std::out_of_range `pos >= size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_reference
- at(size_type pos) const
- {
- if (pos >= size())
- detail::throw_exception<std::out_of_range>(
- "pos >= size()");
- return data()[pos];
- }
- /** Access a character.
- Returns a reference to the character at
- index `pos`.
- @par Complexity
- Constant.
- @par Precondition
- `pos >= size`
- @param pos The index to access.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- reference
- operator[](size_type pos) noexcept
- {
- return data()[pos];
- }
- /** Access a character.
- Returns a reference to the character at
- index `pos`.
- @par Complexity
- Constant.
- @par Precondition
- `pos >= size`
- @param pos The index to access.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_reference
- operator[](size_type pos) const noexcept
- {
- return data()[pos];
- }
- /** Return the first character.
- Returns a reference to the first character.
- @par Complexity
- Constant.
- @par Precondition
- `not empty()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- reference
- front() noexcept
- {
- return data()[0];
- }
- /** Return the first character.
- Returns a reference to the first character.
- @par Complexity
- Constant.
- @par Precondition
- `not empty()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_reference
- front() const noexcept
- {
- return data()[0];
- }
- /** Return the last character.
- Returns a reference to the last character.
- @par Complexity
- Constant.
- @par Precondition
- `not empty()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- reference
- back() noexcept
- {
- return data()[size() - 1];
- }
- /** Return the last character.
- Returns a reference to the last character.
- @par Complexity
- Constant.
- @par Precondition
- `not empty()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_reference
- back() const noexcept
- {
- return data()[size() - 1];
- }
- /** Return a pointer to the string.
- Returns a pointer to the underlying array
- serving as storage. The value returned is such that
- the range `{data(), data() + size())` is always a
- valid range, even if the container is empty.
- @par Complexity
- Constant.
- @note The value returned from this function
- is never never a null pointer value.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- pointer
- data() noexcept
- {
- return this->data_impl();
- }
- /** Return a pointer to the string.
- Returns a pointer to the underlying array
- serving as storage. The value returned is such that
- the range `{data(), data() + size())` is always a
- valid range, even if the container is empty.
- @par Complexity
- Constant.
- @note The value returned from this function
- is never never a null pointer value.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_pointer
- data() const noexcept
- {
- return this->data_impl();
- }
- /** Return a pointer to the string.
- Returns a pointer to the underlying array
- serving as storage. The value returned is such that
- the range `{c_str(), c_str() + size())` is always a
- valid range, even if the container is empty.
- @par Complexity
- Constant.
- @note The value returned from this function
- is never never a null pointer value.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_pointer
- c_str() const noexcept
- {
- return data();
- }
- #ifdef BHO_STATIC_STRING_DOCS
- /** Convert to a string view referring to the string.
- Returns a string view referring to the
- underlying character string.
- @par Complexity
- Constant.
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- operator string_view_type() const noexcept
- {
- return string_view_type(data(), size());
- }
- #else
- #ifdef BHO_STATIC_STRING_HAS_STD_STRING_VIEW
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- operator std::basic_string_view<CharT, Traits>() const noexcept
- {
- return std::basic_string_view<CharT, Traits>(data(), size());
- }
- #endif
- #ifndef BHO_STATIC_STRING_STANDALONE
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- operator ::bho::basic_string_view<CharT, Traits>() const noexcept
- {
- return ::bho::basic_string_view<CharT, Traits>(data(), size());
- }
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- operator ::bho::core::basic_string_view<CharT>() const noexcept
- {
- return ::bho::core::basic_string_view<CharT>(data(), size());
- }
- #endif
- #endif
- //--------------------------------------------------------------------------
- //
- // Iterators
- //
- //--------------------------------------------------------------------------
- /// Return an iterator to the beginning.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- begin() noexcept
- {
- return data();
- }
- /// Return an iterator to the beginning.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_iterator
- begin() const noexcept
- {
- return data();
- }
- /// Return an iterator to the beginning.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_iterator
- cbegin() const noexcept
- {
- return data();
- }
- /// Return an iterator to the end.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- end() noexcept
- {
- return data() + size();
- }
- /// Return an iterator to the end.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_iterator
- end() const noexcept
- {
- return data() + size();
- }
- /// Return an iterator to the end.
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- const_iterator
- cend() const noexcept
- {
- return data() + size();
- }
- /// Return a reverse iterator to the beginning.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- reverse_iterator
- rbegin() noexcept
- {
- return reverse_iterator{end()};
- }
- /// Return a reverse iterator to the beginning.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- const_reverse_iterator
- rbegin() const noexcept
- {
- return const_reverse_iterator{cend()};
- }
- /// Return a reverse iterator to the beginning.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- const_reverse_iterator
- crbegin() const noexcept
- {
- return const_reverse_iterator{cend()};
- }
- /// Return a reverse iterator to the end.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- reverse_iterator
- rend() noexcept
- {
- return reverse_iterator{begin()};
- }
- /// Return a reverse iterator to the end.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- const_reverse_iterator
- rend() const noexcept
- {
- return const_reverse_iterator{cbegin()};
- }
- /// Return a reverse iterator to the end.
- BHO_STATIC_STRING_CPP17_CONSTEXPR
- const_reverse_iterator
- crend() const noexcept
- {
- return const_reverse_iterator{cbegin()};
- }
- //--------------------------------------------------------------------------
- //
- // Capacity
- //
- //--------------------------------------------------------------------------
- /** Return if the string is empty.
- Returns whether the string contains no characters.
- @par Complexity
- Constant.
- @return `size() == 0`
- */
- BHO_STATIC_STRING_NODISCARD
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- bool
- empty() const noexcept
- {
- return size() == 0;
- }
- /** Return the size of the string.
- Returns the number of characters stored in the
- string, excluding the null terminator.
- @par Complexity
- Constant.
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- size_type
- size() const noexcept
- {
- return this->size_impl();
- }
- /** Return the size of the string.
- Returns the number of characters stored in the
- string, excluding the null terminator.
- @par Complexity
- Constant.
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- size_type
- length() const noexcept
- {
- return size();
- }
- /** Return the number of characters that can be stored.
- Returns the maximum size of the string, excluding the
- null terminator. The returned value is always `N`.
- @par Complexity
- Constant.
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- size_type
- max_size() const noexcept
- {
- return N;
- }
- /** Increase the capacity.
- This function has no effect.
- @throw std::length_error `n > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- reserve(size_type n)
- {
- if (n > max_size())
- detail::throw_exception<std::length_error>(
- "n > max_size()");
- }
- /** Return the number of characters that can be stored.
- Returns the maximum size of the string, excluding the
- null terminator. The returned value is always `N`.
- @par Complexity
- Constant.
- */
- BHO_STATIC_STRING_CPP11_CONSTEXPR
- size_type
- capacity() const noexcept
- {
- return max_size();
- }
- /** Request the removal of unused capacity.
- This function has no effect.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- shrink_to_fit() noexcept { }
- //--------------------------------------------------------------------------
- //
- // Operations
- //
- //--------------------------------------------------------------------------
- /** Clear the contents.
- Erases all characters from the string. After this
- call, @ref size() returns zero.
- @par Complexity
- Linear in @ref size().
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- clear() noexcept
- {
- this->set_size(0);
- term();
- }
- /** Insert into the string.
- Inserts `count` copies of `ch` at the position `index`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param index The index to insert at.
- @param count The number of characters to insert.
- @param ch The character to insert.
- @throw std::length_error `size() + count > max_size()`
- @throw std::out_of_range `index > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- size_type count,
- value_type ch)
- {
- if (index > size())
- detail::throw_exception<std::out_of_range>(
- "index > size()");
- insert(begin() + index, count, ch);
- return *this;
- }
- /** Insert into the string.
- Inserts the null-terminated character string pointed to by `s`
- of length `count` at the position `index` where `count`
- is `traits_type::length(s)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param index The index to insert at.
- @param s The string to insert.
- @throw std::length_error `size() + count > max_size()`
- @throw std::out_of_range `index > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const_pointer s)
- {
- return insert(index, s, traits_type::length(s));
- }
- /** Insert into the string.
- Inserts `count` characters of the string pointed to by `s`
- at the position `index`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param index The index to insert at.
- @param s The string to insert.
- @param count The length of the string to insert.
- @throw std::length_error `size() + count > max_size()`
- @throw std::out_of_range `index > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const_pointer s,
- size_type count)
- {
- if (index > size())
- detail::throw_exception<std::out_of_range>(
- "index > size()");
- insert(data() + index, s, s + count);
- return *this;
- }
- /** Insert into the string.
- Inserts the string `str`
- at the position `index`.
- @par Exception Safety
- Strong guarantee.
- @note The insertion is done unchecked when
- the capacity of `str` differs from that of the
- string the function is called on.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam M The size of the input string.
- @return `*this`
- @param index The index to insert at.
- @param str The string to insert.
- @throw std::length_error `size() + str.size() > max_size()`
- @throw std::out_of_range `index > size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const basic_static_string<M, CharT, Traits>& str)
- {
- return insert_unchecked(index, str.data(), str.size());
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const basic_static_string& str)
- {
- return insert(index, str.data(), str.size());
- }
- #endif
- /** Insert into the string.
- Inserts a string, obtained by `str.substr(index_str, count)`
- at the position `index`.
- @par Exception Safety
- Strong guarantee.
- @note The insertion is done unchecked when
- the capacity of `str` differs from that of the
- string the function is called on.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam M The size of the input string.
- @return `*this`
- @param index The index to insert at.
- @param str The string from which to insert.
- @param index_str The index in `str` to start inserting from.
- @param count The number of characters to insert.
- The default argument for this parameter is @ref npos.
- @throw std::length_error `size() + str.substr(index_str, count).size() > max_size()`
- @throw std::out_of_range `index > size()`
- @throw std::out_of_range `index_str > str.size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const basic_static_string<M, CharT, Traits>& str,
- size_type index_str,
- size_type count = npos)
- {
- return insert_unchecked(index, str.data() + index_str, str.capped_length(index_str, count));
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const basic_static_string& str,
- size_type index_str,
- size_type count = npos)
- {
- return insert(index, str.data() + index_str, str.capped_length(index_str, count));
- }
- #endif
- /** Insert into the string.
- Inserts the character `ch` before the character pointed by `pos`.
- @par Precondition
- `pos` shall be vaild within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return An iterator which refers to the first inserted character
- or `pos` if no characters were inserted
- @param pos The index to insert at.
- @param ch The character to insert.
- @throw std::length_error `size() + 1 > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- insert(
- const_iterator pos,
- value_type ch)
- {
- return insert(pos, 1, ch);
- }
- /** Insert into the string.
- Inserts `count` copies of `ch` before the character pointed by `pos`.
- @par Precondition
- `pos` shall be valid within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return An iterator which refers to the first inserted character
- or `pos` if no characters were inserted
- @param pos The position to insert at.
- @param count The number of characters to insert.
- @param ch The character to insert.
- @throw std::length_error `size() + count > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- insert(
- const_iterator pos,
- size_type count,
- value_type ch);
- /** Insert into the string.
- Inserts characters from the range `{first, last)` before the
- character pointed to by `pos`.
- @par Precondition
- `pos` shall be valid within `{data(), data() + size()}`,
- `{first, last)` shall be a valid range
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam InputIterator The type of the iterators.
- @par Constraints
- `InputIterator` satisfies __InputIterator__ and does not
- satisfy __ForwardIterator__.
- @return An iterator which refers to the first inserted character
- or `pos` if no characters were inserted
- @param pos The position to insert at.
- @param first An iterator representing the first character to insert.
- @param last An iterator representing one past the last character to insert.
- @throw std::length_error `size() + insert_count > max_size()`
- */
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- #ifdef BHO_STATIC_STRING_DOCS
- iterator
- #else
- typename std::enable_if<
- detail::is_input_iterator<
- InputIterator>::value &&
- !detail::is_forward_iterator<
- InputIterator>::value, iterator>::type
- #endif
- insert(
- const_iterator pos,
- InputIterator first,
- InputIterator last);
- #ifndef BHO_STATIC_STRING_DOCS
- template<typename ForwardIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- typename std::enable_if<
- detail::is_forward_iterator<
- ForwardIterator>::value,
- iterator>::type
- insert(
- const_iterator pos,
- ForwardIterator first,
- ForwardIterator last);
- #endif
- /** Insert into the string.
- Inserts characters from `ilist` before `pos`.
- @par Precondition
- `pos` shall be valid within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return An iterator which refers to the first inserted character
- or `pos` if no characters were inserted
- @param pos The position to insert at.
- @param ilist The initializer list from which to insert.
- @throw std::length_error `size() + ilist.size() > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- insert(
- const_iterator pos,
- std::initializer_list<value_type> ilist)
- {
- return insert_unchecked(pos, ilist.begin(), ilist.size());
- }
- /** Insert into the string.
- Constructs a temporary `string_view_type` object `sv` from `t` and
- inserts `{sv.begin(), sv.end())` at `index`.
- @par Precondition
- `index` shall be valid within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @param index The index to insert at.
- @param t The string to insert from.
- @throw std::length_error `size() + sv.size() > max_size()`
- @throw std::out_of_range `index > size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const T& t)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return insert(index, sv.data(), sv.size());
- }
- /** Insert into the string.
- Constructs a temporary `string_view_type` object `sv` from `t`
- and inserts `sv.substr(index_str, count)` at `index`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const_pointer>::value`.
- @return `*this`
- @param index The index to insert at.
- @param t The string to insert from.
- @param index_str The index in the temporary `string_view_type` object
- to start the substring from.
- @param count The number of characters to insert.
- @throw std::length_error `size() + sv.size() > max_size()`
- @throw std::out_of_range `index > size()`
- @throw std::out_of_range `index_str > sv.size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert(
- size_type index,
- const T& t,
- size_type index_str,
- size_type count = npos)
- {
- detail::common_string_view_type<T, CharT, Traits> sv(t);
- if ( index_str > sv.size() )
- detail::throw_exception<std::out_of_range>("index_str > t.size()");
- return insert(index, sv.data() + index_str, (std::min)(sv.size() - index_str, count));
- }
- /** Erase from the string.
- Erases `num` characters from the string, starting at `index`.
- `num` is determined as the smaller of `count` and `size() - index`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param index The index to erase at.
- The default argument for this parameter is `0`.
- @param count The number of characters to erase.
- The default argument for this parameter is @ref npos.
- @throw std::out_of_range `index > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- erase(
- size_type index = 0,
- size_type count = npos)
- {
- erase(data() + index, data() + index + capped_length(index, count));
- return *this;
- }
- /** Erase from the string.
- Erases the character at `pos`.
- @par Preconditions
- `pos` shall be valid within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return An iterator referring to character immediately following
- the erased character, or @ref end() if one does not exist.
- @param pos An iterator referring to the character to erase.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- erase(const_iterator pos)
- {
- BHO_STATIC_STRING_ASSERT(!empty());
- return erase(pos, pos + 1);
- }
- /** Erase from the string.
- Erases the characters in the range `{first, last)`.
- @par Precondition
- `{first, last}` shall be valid within `{data(), data() + size()}`
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return An iterator referring to the character `last`
- previously referred to, or @ref end() if one does not exist.
- @param first An iterator referring to the first character to erase.
- @param last An iterator past the last character to erase.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- erase(
- const_iterator first,
- const_iterator last);
- /** Append a character.
- Appends a character to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @param ch The character to append.
- @throw std::length_error `size() >= max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- push_back(value_type ch);
- /** Remove the last character.
- Removes a character from the end of the string.
- @par Precondition
- `not empty()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- pop_back() noexcept
- {
- BHO_STATIC_STRING_ASSERT(!empty());
- this->set_size(size() - 1);
- term();
- }
- /** Append to the string.
- Appends `count` copies of `ch` to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param count The number of characters to append.
- @param ch The character to append.
- @throw std::length_error `size() + count > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- size_type count,
- value_type ch);
- /** Append to the string.
- Appends `s` to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @tparam M The size of the string to append.
- @return `*this`
- @param s The string to append.
- @throw std::length_error `size() + s.size() > max_size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- const basic_static_string<M, CharT, Traits>& s)
- {
- return append(s.data(), s.size());
- }
- /** Append to the string.
- Appends the substring `sub` to the end of the string,
- where `sub` is `s.substr(pos, count)`.
- @par Exception Safety
- Strong guarantee.
- @tparam M The size of the string to append.
- @return `*this`
- @param s The string to append.
- @param pos The index at which to begin the substring.
- @param count The size of the substring. The default
- argument for this parameter is @ref npos.
- @throw std::length_error `size() + sub.size() > max_size()`
- @throw std::out_of_range `pos > s.size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- const basic_static_string<M, CharT, Traits>& s,
- size_type pos,
- size_type count = npos)
- {
- return append(s.data() + pos, s.capped_length(pos, count));
- }
- /** Append to the string.
- Appends `count` characters from the string pointed
- to by `s` to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @note The string can contain null characters.
- @return `*this`
- @param s The string to append.
- @param count The number of characters to append.
- @throw std::length_error `size() + count > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- const_pointer s,
- size_type count);
- /** Append to the string.
- Appends `count` characters from the string pointed
- to by `s` to the end of the string, where `count`
- is `traits_type::length(s)`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param s The string to append.
- @throw std::length_error `size() + count > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(const_pointer s)
- {
- return append(s, traits_type::length(s));
- }
- // KRYSTIAN TODO: change exception safety
- /** Append to the string.
- Appends characters from the range `{first, last)`
- to the end of the string.
- @par Precondition
- `{first, last)` shall be a valid range
- @par Exception Safety
- Strong guarantee.
- @tparam InputIterator The type of the iterators.
- @par Constraints
- `InputIterator` satisfies __InputIterator__.
- @return `*this`
- @param first An iterator referring to the
- first character to append.
- @param last An iterator past the end of
- last character to append.
- @throw std::length_error `size() + std::distance(first, last) > max_size()`
- */
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- #ifdef BHO_STATIC_STRING_DOCS
- basic_static_string&
- #else
- typename std::enable_if<
- detail::is_input_iterator<InputIterator>::value,
- basic_static_string&>::type
- #endif
- append(
- InputIterator first,
- InputIterator last)
- {
- this->set_size(size() + read_back(true, first, last));
- return term();
- }
- /** Append to the string.
- Appends the characters from `ilist` to the
- end of the string.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param ilist The initializer list to append.
- @throw std::length_error `size() + ilist.size() > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- std::initializer_list<value_type> ilist)
- {
- return append(ilist.begin(), ilist.size());
- }
- /** Append to the string.
- Appends `sv` to the end of the string,
- where `sv` is `string_view_type(t)`.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<T const&, string_view>::value &&
- !std::is_convertible<T const&, char const*>::value
- @endcode
- @return `*this`
- @param t The string to append.
- @throw std::length_error `size() + sv.size() > max_size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(const T& t)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return append(sv.data(), sv.size());
- }
- /** Append to the string.
- Appends the substring `sv` to the end of the string,
- where `sv` is `string_view_type(t).substr(pos, count)`.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<T const&, string_view>::value &&
- !std::is_convertible<T const&, char const*>::value
- @endcode
- @return `*this`
- @param t The object to append.
- @param pos The index at which to begin the substring.
- @param count The size of the substring. The default
- argument for this parameter is @ref npos.
- @throw std::length_error `size() + sv.size() > max_size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- append(
- const T& t,
- size_type pos,
- size_type count = npos)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- if ( pos > sv.size() )
- detail::throw_exception<std::out_of_range>("pos > t.size()");
- return append(sv.data() + pos, (std::min)(sv.size() - pos, count));
- }
- /** Append to the string.
- Appends `s` to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @tparam M The size of the string to append.
- @return `*this`
- @param s The string to append.
- @throw std::length_error `size() + s.size() > max_size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator+=(
- const basic_static_string<M, CharT, Traits>& s)
- {
- return append(s);
- }
- /** Append to the string.
- Appends a character to the end of the string.
- @par Exception Safety
- Strong guarantee.
- @param ch The character to append.
- @throw std::length_error `size() >= max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator+=(value_type ch)
- {
- push_back(ch);
- return *this;
- }
- /** Append to the string.
- Appends `count` characters from the string pointed
- to by `s` to the end of the string, where `count`
- is `traits_type::length(s)`.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param s The string to append.
- @throw std::length_error `size() + count > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator+=(const_pointer s)
- {
- return append(s);
- }
- /** Append to the string.
- Appends the characters from `ilist` to the
- end of the string.
- @par Exception Safety
- Strong guarantee.
- @return `*this`
- @param ilist The initializer list to append.
- @throw std::length_error `size() + ilist.size() > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator+=(
- std::initializer_list<value_type> ilist)
- {
- return append(ilist);
- }
- /** Append to the string.
- Appends `sv` to the end of the string,
- where `sv` is `string_view_type(t)`.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<T const&, string_view>::value &&
- !std::is_convertible<T const&, char const*>::value
- @endcode
- @return `*this`
- @param t The string to append.
- @throw std::length_error `size() + sv.size() > max_size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- operator+=(const T& t)
- {
- return append(t);
- }
- /** Compare a string with the string.
- Let `comp` be `traits_type::compare(data(), s.data(), std::min(size(), s.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `size() == s.size()`, `-1` if `size() < s.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @return The result of lexicographically comparing `s` and the string.
- @tparam M The size of the string to compare with.
- @param s The string to compare.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- const basic_static_string<M, CharT, Traits>& s) const noexcept
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data(), size(), s.data(), s.size());
- }
- /** Compare a string with the string.
- Let `sub` be `substr(pos1, count1)` and `comp` be
- `traits_type::compare(sub.data(), s.data(), std::min(sub.size(), s.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub.size() == s.size()`, `-1` if `sub.size() < s.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @return The result of lexicographically comparing `sub` and `s`.
- @tparam M The size of the string to compare with.
- @param pos1 The index at which to begin the substring.
- @param count1 The size of the substring.
- @param s The string to compare.
- @throw std::out_of_range `pos1 > size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const basic_static_string<M, CharT, Traits>& s) const
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data() + pos1, capped_length(pos1, count1), s.data(), s.size());
- }
- /** Compare a string with the string.
- Let `sub1` be `substr(pos1, count1)`, `sub2` be
- `s.substr(pos2, count2)`, and `comp` be
- `traits_type::compare(sub1.data(), sub2.data(), std::min(sub1.size(), sub2.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub1.size() == sub2.size()`, `-1` if `sub1.size() < sub2.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @return The result of lexicographically comparing `sub1` and `sub2`.
- @param pos1 The index at which to begin the substring.
- @param count1 The size of the substring.
- @param s The string to compare.
- @param pos2 The index at which to begin the substring to compare.
- @param count2 The size of the substring to compare.
- @throw std::out_of_range `pos1 > size()`
- @throw std::out_of_range `pos2 > s.size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const basic_static_string<M, CharT, Traits>& s,
- size_type pos2,
- size_type count2 = npos) const
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data() + pos1, capped_length(pos1, count1),
- s.data() + pos2, s.capped_length(pos2, count2));
- }
- /** Compare a string with the string.
- Let `len` be `traits_type::length(s)` and `comp` be
- `traits_type::compare(data(), s, std::min(size(), len)`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `size() == len`, `-1` if `size() < len`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @return The result of lexicographically comparing `s` and the string.
- @param s The string to compare.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(const_pointer s) const noexcept
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data(), size(), s, traits_type::length(s));
- }
- /** Compare a string with the string.
- Let `sub` be `substr(pos1, count1)`, `len` be
- `traits_type::length(s)`, and `comp` be
- `traits_type::compare(sub.data(), s, std::min(size(), len)`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub.size() == len`, `-1` if `sub.size() < len`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @return The result of lexicographically comparing `s` and `sub`.
- @param pos1 The index at which to begin the substring.
- @param count1 The size of the substring.
- @param s The string to compare.
- @throw std::out_of_range `pos1 > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const_pointer s) const
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data() + pos1, capped_length(pos1, count1), s, traits_type::length(s));
- }
- /** Compare a string with the string.
- Let `sub` be `substr(pos1, count1)`, and `comp` be
- `traits_type::compare(sub.data(), s, std::min(size(), count2)`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub.size() == count2`, `-1` if `sub.size() < count2`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @return The result of lexicographically comparing `s` and `sub`.
- @param pos1 The index at which to begin the substring.
- @param count1 The size of the substring.
- @param s The string to compare.
- @param count2 The length of the string to compare.
- @throw std::out_of_range `pos1 > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const_pointer s,
- size_type count2) const
- {
- return detail::lexicographical_compare<CharT, Traits>(
- data() + pos1, capped_length(pos1, count1), s, count2);
- }
- /** Compare a string with the string.
- Let `s` be `string_view_type(t)` and `comp` be
- `traits_type::compare(data(), s.data(), std::min(size(), s.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `size() == s.size()`, `-1` if `size() < s.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const_pointer>::value.
- @endcode
- @return The result of lexicographically comparing `s` and the string.
- @param t The string to compare.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(const T& t) const noexcept
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return detail::lexicographical_compare<CharT, Traits>(
- data(), size(), sv.data(), sv.size());
- }
- /** Compare a string with the string.
- Let `s` be `string_view_type(t)`, `sub` be
- `substr(pos1, count1)`, and `comp` be
- `traits_type::compare(sub.data(), s.data(), std::min(sub.size(), s.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub.size() == s.size()`, `-1` if `sub.size() < s.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const_pointer>::value.
- @endcode
- @return The result of lexicographically comparing `s` and `sub`.
- @param pos1 The index at which to begin the substring.
- @param count1 The length of the substring.
- @param t The string to compare.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const T& t) const
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return detail::lexicographical_compare<CharT, Traits>(
- data() + pos1, capped_length(pos1, count1), sv.data(), sv.size());
- }
- /** Compare a string with the string.
- Let `sub1` be `substr(pos1, count1)`, `sub2` be
- `string_view_type(t).substr(pos2, count2)`, and `comp` be
- `traits_type::compare(sub1.data(), sub2.data(), std::min(sub1.size(), sub2.size())`.
- If `comp != 0`, then the result is `comp`. Otherwise, the result is
- `0` if `sub1.size() == sub2.size()`, `-1` if `sub1.size() < sub2.size()`, and `1`
- otherwise.
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- @tparam T The type of the object to convert.
- @par Constraints
- @code
- std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const_pointer>::value.
- @endcode
- @return The result of lexicographically comparing `sub1` and `sub2`.
- @param pos1 The index at which to begin the substring in the string.
- @param count1 The length of the substring in the string.
- @param t The string to compare.
- @param pos2 The index at which to begin the substring in the string view.
- @param count2 The length of the substring in the string view.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- int
- compare(
- size_type pos1,
- size_type count1,
- const T& t,
- size_type pos2,
- size_type count2 = npos) const
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- if ( pos2 > sv.size())
- detail::throw_exception<std::out_of_range>("pos2 > sv.size()");
- return compare(
- pos1, count1, sv.data() + pos2,
- (std::min)(sv.size() - pos2, count2));
- }
- /** Return a substring.
- Returns a substring of the string.
- @par Exception Safety
- Strong guarantee.
- @return A string object containing the characters
- `{data() + pos, std::min(count, size() - pos))`.
- @param pos The index to being the substring at. The
- default arugment for this parameter is `0`.
- @param count The length of the substring. The default arugment
- for this parameter is @ref npos.
- @throw std::out_of_range `pos > size()`
- */
- #ifndef BHO_STATIC_STRING_GCC5_BAD_CONSTEXPR
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- #endif
- basic_static_string
- substr(
- size_type pos = 0,
- size_type count = npos) const
- {
- return basic_static_string(
- data() + pos, capped_length(pos, count));
- }
- #ifdef BHO_STATIC_STRING_HAS_ANY_STRING_VIEW
- /** Return a string view of a substring.
- Returns a view of a substring.
- @par Exception Safety
- Strong guarantee.
- @return A `string_view_type` object referring
- to `{data() + pos, std::min(count, size() - pos))`.
- @param pos The index to being the substring at. The
- default arugment for this parameter is `0`.
- @param count The length of the substring. The default arugment
- for this parameter is @ref npos.
- @throw std::out_of_range `pos > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- string_view_type
- subview(
- size_type pos = 0,
- size_type count = npos) const
- {
- return string_view_type(
- data() + pos, capped_length(pos, count));
- }
- #endif
- /** Copy a substring to another string.
- Copies `std::min(count, size() - pos)` characters starting at
- index `pos` to the string pointed to by `dest`.
- @note The resulting string is not null terminated.
- @return The number of characters copied.
- @param count The number of characters to copy.
- @param dest The string to copy to.
- @param pos The index to begin copying from. The
- default argument for this parameter is `0`.
- @throw std::out_of_range `pos > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- copy(
- pointer dest,
- size_type count,
- size_type pos = 0) const
- {
- const auto num_copied = capped_length(pos, count);
- traits_type::copy(dest, data() + pos, num_copied);
- return num_copied;
- }
- /** Change the size of the string.
- Resizes the string to contain `n` characters. If
- `n > size()`, characters with the value `CharT()` are
- appended. Otherwise, `size()` is reduced to `n`.
- @param n The size to resize the string to.
- @throw std::out_of_range `n > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- resize(size_type n)
- {
- resize(n, value_type());
- }
- /** Change the size of the string.
- Resizes the string to contain `n` characters. If
- `n > size()`, copies of `c` are
- appended. Otherwise, `size()` is reduced to `n`.
- @param n The size to resize the string to.
- @param c The characters to append if the size
- increases.
- @throw std::out_of_range `n > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- resize(
- size_type n,
- value_type c);
- /** Swap two strings.
- Swaps the contents of the string and `s`.
- @par Exception Safety
- Strong guarantee.
- @note
- All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @param s The string to swap with.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- swap(basic_static_string& s) noexcept;
- /** Swap two strings.
- Swaps the contents of the string and `s`.
- @par Exception Safety
- Strong guarantee.
- @note
- All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam M The size of the string to swap with.
- @param s The string to swap with.
- @throw std::length_error `s.size() > max_size() || size() > s.max_size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- swap(basic_static_string<M, CharT, Traits>& s);
- /** Replace a part of the string.
- Replaces `rcount` characters starting at index `pos1` with those
- of `str`, where `rcount` is `std::min(n1, size() - pos1)`.
- @par Exception Safety
- Strong guarantee.
- @note The replacement is done unchecked when
- the capacity of `str` differs from that of the
- string the function is called on.
- All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam M The size of the input string.
- @return `*this`
- @param pos1 The index to replace at.
- @param n1 The number of characters to replace.
- @param str The string to replace with.
- @throw std::length_error `size() + (str.size() - rcount) > max_size()`
- @throw std::out_of_range `pos1 > size()`
- */
- template<size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const basic_static_string<M, CharT, Traits>& str)
- {
- return replace_unchecked(pos1, n1, str.data(), str.size());
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const basic_static_string& str)
- {
- return replace(pos1, n1, str.data(), str.size());
- }
- #endif
- /** Replace a part of the string.
- Replaces `rcount` characters starting at index `pos1` with those of
- `str.subview(pos2, n2)`, where `rcount` is `std::min(n1, size() - pos1)`.
- @par Exception Safety
- Strong guarantee.
- @note The replacement is done unchecked when
- the capacity of `str` differs from that of the
- string the function is called on.
- All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param pos1 The index to replace at.
- @param n1 The number of characters to replace.
- @param str The string to replace with.
- @param pos2 The index to begin the substring.
- @param n2 The length of the substring.
- The default argument for this parameter is @ref npos.
- @throw std::length_error `size() + (std::min(str.size(), n2) - rcount) > max_size()`
- @throw std::out_of_range `pos1 > size()`
- @throw std::out_of_range `pos2 > str.size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos2,
- size_type n2 = npos)
- {
- return replace_unchecked(pos1, n1, str.data() + pos2, str.capped_length(pos2, n2));
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const basic_static_string& str,
- size_type pos2,
- size_type n2 = npos)
- {
- return replace(pos1, n1, str.data() + pos2, str.capped_length(pos2, n2));
- }
- #endif
- /** Replace a part of the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and
- replaces `rcount` characters starting at index `pos1` with those
- of `sv`, where `rcount` is `std::min(n1, size() - pos1)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return `*this`
- @param pos1 The index to replace at.
- @param n1 The number of characters to replace.
- @param t The object to replace with.
- @throw std::length_error `size() + (sv.size() - rcount) > max_size()`
- @throw std::out_of_range `pos1 > size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const T& t)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return replace(pos1, n1, sv.data(), sv.size());
- }
- /** Replace a part of the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and
- replaces `rcount` characters starting at index `pos1` with those
- of `sv.substr(pos2, n2)`, where `rcount` is `std::min(n1, size() - pos)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return `*this`
- @param pos1 The index to replace at.
- @param n1 The number of characters to replace.
- @param t The object to replace with.
- @param pos2 The index to begin the substring.
- @param n2 The length of the substring.
- The default argument for this parameter is @ref npos.
- @throw std::length_error `size() + (std::min(n2, sv.size()) - rcount) > max_size()`
- @throw std::out_of_range `pos1 > size()`
- @throw std::out_of_range `pos2 > sv.size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos1,
- size_type n1,
- const T& t,
- size_type pos2,
- size_type n2 = npos)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- if ( pos2 > sv.size())
- detail::throw_exception<std::out_of_range>("pos2 > t.size()");
- return replace(
- pos1, n1, sv.data() + pos2,
- (std::min)(sv.size() - pos2, n2));
- }
- /** Replace a part of the string.
- Replaces `rcount` characters starting at index `pos` with those of
- `{s, s + n2)`, where `rcount` is `std::min(n1, size() - pos)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param pos The index to replace at.
- @param n1 The number of characters to replace.
- @param s The string to replace with.
- @param n2 The length of the string to replace with.
- @throw std::length_error `size() + (n2 - rcount) > max_size()`
- @throw std::out_of_range `pos > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos,
- size_type n1,
- const_pointer s,
- size_type n2)
- {
- return replace(data() + pos, data() + pos + capped_length(pos, n1), s, n2);
- }
- /** Replace a part of the string.
- Replaces `rcount` characters starting at index `pos` with those of
- `{s, s + len)`, where the length of the string `len` is `traits_type::length(s)` and `rcount`
- is `std::min(n1, size() - pos)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param pos The index to replace at.
- @param n1 The number of characters to replace.
- @param s The string to replace with.
- @throw std::length_error `size() + (len - rcount) > max_size()`
- @throw std::out_of_range `pos > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos,
- size_type n1,
- const_pointer s)
- {
- return replace(pos, n1, s, traits_type::length(s));
- }
- /** Replace a part of the string.
- Replaces `rcount` characters starting at index `pos` with `n2` copies
- of `c`, where `rcount` is `std::min(n1, size() - pos)`.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param pos The index to replace at.
- @param n1 The number of characters to replace.
- @param n2 The number of characters to replace with.
- @param c The character to replace with.
- @throw std::length_error `size() + (n2 - rcount) > max_size()`
- @throw std::out_of_range `pos > size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- size_type pos,
- size_type n1,
- size_type n2,
- value_type c)
- {
- return replace(data() + pos, data() + pos + capped_length(pos, n1), n2, c);
- }
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)`
- with those of `str`.
- @par Precondition
- `{i1, i2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note The replacement is done unchecked when
- the capacity of `str` differs from that of the
- string the function is called on.
- All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam M The size of the input string.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator referring past the end of
- the last character to replace.
- @param str The string to replace with.
- @throw std::length_error `size() + (str.size() - std::distance(i1, i2)) > max_size()`
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- const basic_static_string<M, CharT, Traits>& str)
- {
- return replace_unchecked(i1, i2, str.data(), str.size());
- }
- #ifndef BHO_STATIC_STRING_DOCS
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- const basic_static_string& str)
- {
- return replace(i1, i2, str.data(), str.size());
- }
- #endif
- /** Replace a part of the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and
- replaces the characters in the range `{i1, i2)` with those
- of `sv`.
- @par Precondition
- `{i1, i2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator referring past the end of
- the last character to replace.
- @param t The object to replace with.
- @throw std::length_error `size() + (sv.size() - std::distance(i1, i2)) > max_size()`
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- const T& t)
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return replace(i1, i2, sv.data(), sv.data() + sv.size());
- }
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)` with those of
- `{s, s + n)`.
- @par Precondition
- `{i1, i2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator referring past the end of
- the last character to replace.
- @param s The string to replace with.
- @param n The length of the string to replace with.
- @throw std::length_error `size() + (n - std::distance(i1, i2)) > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- const_pointer s,
- size_type n)
- {
- return replace(i1, i2, s, s + n);
- }
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)` with those of
- `{s, s + len)`, where the length of the string `len` is `traits_type::length(s)`.
- @par Precondition
- `{i1, i2)` shall be a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator referring past the end of
- the last character to replace.
- @param s The string to replace with.
- @throw std::length_error `size() + (len - std::distance(i1, i2)) > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- const_pointer s)
- {
- return replace(i1, i2, s, traits_type::length(s));
- }
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)` with
- `n` copies of `c`.
- @par Precondition
- `{i1, i2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator past the end of
- the last character to replace.
- @param n The number of characters to replace with.
- @param c The character to replace with.
- @throw std::length_error `size() + (n - std::distance(i1, i2)) > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- size_type n,
- value_type c);
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)`
- with those of `{j1, j2)`.
- @par Precondition
- `{i1, i2)` is a valid range.
- `{j1, j2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @tparam InputIterator The type of the iterators.
- @par Constraints
- `InputIterator` satisfies __InputIterator__ and does not
- satisfy __ForwardIterator__.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator referring past the end of
- the last character to replace.
- @param j1 An iterator referring to the first character to replace with.
- @param j2 An iterator referring past the end of
- the last character to replace with.
- @throw std::length_error `size() + (inserted - std::distance(i1, i2)) > max_size()`
- */
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- #ifdef BHO_STATIC_STRING_DOCS
- basic_static_string&
- #else
- typename std::enable_if<
- detail::is_input_iterator<
- InputIterator>::value &&
- !detail::is_forward_iterator<
- InputIterator>::value,
- basic_static_string<N, CharT, Traits>&>::type
- #endif
- replace(
- const_iterator i1,
- const_iterator i2,
- InputIterator j1,
- InputIterator j2);
- #ifndef BHO_STATIC_STRING_DOCS
- template<typename ForwardIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- typename std::enable_if<
- detail::is_forward_iterator<
- ForwardIterator>::value,
- basic_static_string<N, CharT, Traits>&>::type
- replace(
- const_iterator i1,
- const_iterator i2,
- ForwardIterator j1,
- ForwardIterator j2);
- #endif
- /** Replace a part of the string.
- Replaces the characters in the range `{i1, i2)`
- with those of contained in the initializer list `il`.
- @par Precondition
- `{i1, i2)` is a valid range.
- @par Exception Safety
- Strong guarantee.
- @note All references, pointers, or iterators
- referring to contained elements are invalidated. Any
- past-the-end iterators are also invalidated.
- @return `*this`
- @param i1 An iterator referring to the first character to replace.
- @param i2 An iterator past the end of
- the last character to replace.
- @param il The initializer list to replace with.
- @throw std::length_error `size() + (il.size() - std::distance(i1, i2)) > max_size()`
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace(
- const_iterator i1,
- const_iterator i2,
- std::initializer_list<value_type> il)
- {
- return replace_unchecked(i1, i2, il.begin(), il.size());
- }
- //--------------------------------------------------------------------------
- //
- // Search
- //
- //--------------------------------------------------------------------------
- /** Find the first occurrence of a string within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the first occurrence of `sv` within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @note An empty string is always found.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The lowest index `idx` greater than or equal to `pos`
- where each element of `{sv.begin(), sv.end())` is equal to
- that of `{begin() + idx, begin() + idx + count)` if one exists,
- and @ref npos otherwise.
- @param t The string to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find(
- const T& t,
- size_type pos = 0) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return find(sv.data(), pos, sv.size());
- }
- /** Find the first occurrence of a string within the string.
- Finds the first occurrence of `str` within the
- string starting at the index `pos`.
- @par Complexity
- Linear.
- @return The lowest index `idx` greater than or equal to `pos`
- where each element of `str` is equal to that of
- `{begin() + idx, begin() + idx + str.size())`
- if one exists, and @ref npos otherwise.
- @param str The string to search for.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = 0) const noexcept
- {
- return find(str.data(), pos, str.size());
- }
- /** Find the first occurrence of a string within the string.
- Finds the first occurrence of the string pointed to
- by `s` within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @note An empty string is always found.
- @return The lowest index `idx` greater than or equal to `pos`
- where each element of `{s, s + n)` is equal to that of
- `{begin() + idx, begin() + idx + n)` if one exists,
- and @ref npos otherwise.
- @param s The string to search for.
- @param pos The index to start searching at.
- @param n The length of the string to search for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the first occurrence of a string within the string.
- Finds the first occurrence of the string pointed to by `s`
- of length `count` within the string starting at the index `pos`,
- where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @note An empty string is always found.
- @return The lowest index `idx` greater than or equal to `pos`
- where each element of `{s, s + count)` is equal to that of
- `{begin() + idx, begin() + idx + count)` if one exists,
- and @ref npos otherwise.
- @param s The string to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find(
- const_pointer s,
- size_type pos = 0) const noexcept
- {
- return find(s, pos, traits_type::length(s));
- }
- /** Find the first occurrence of a character within the string.
- Finds the first occurrence of `c` within the string
- starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first occurrence of `c` within
- `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param c The character to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find(
- value_type c,
- size_type pos = 0) const noexcept
- {
- return find(&c, pos, 1);
- }
- /** Find the last occurrence of a string within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the last occurrence of `sv` within the string starting before or at
- the index `pos`.
- @par Complexity
- Linear.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The highest index `idx` less than or equal to `pos`
- where each element of `{sv.begin(), sv.end())` is equal to
- that of `{begin() + idx, begin() + idx + count)` if one exists,
- and @ref npos otherwise.
- @param t The string to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is @ref npos.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- rfind(
- const T& t,
- size_type pos = npos) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return rfind(sv.data(), pos, sv.size());
- }
- /** Find the last occurrence of a string within the string.
- Finds the last occurrence of `str` within the string
- starting before or at the index `pos`.
- @par Complexity
- Linear.
- @return The highest index `idx` less than or equal to `pos`
- where each element of `str` is equal to that
- of `{begin() + idx, begin() + idx + str.size())`
- if one exists, and @ref npos otherwise.
- @param str The string to search for.
- @param pos The index to start searching at. The default argument for
- this parameter is @ref npos.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- rfind(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = npos) const noexcept
- {
- return rfind(str.data(), pos, str.size());
- }
- /** Find the last occurrence of a string within the string.
- Finds the last occurrence of the string pointed to
- by `s` within the string starting before or at
- the index `pos`.
- @par Complexity
- Linear.
- @return The highest index `idx` less than or equal to `pos`
- where each element of `{s, s + n)` is equal to that of
- `{begin() + idx, begin() + idx + n)` if one exists,
- and @ref npos otherwise.
- @param s The string to search for.
- @param pos The index to start searching at.
- @param n The length of the string to search for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- rfind(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the last occurrence of a string within the string.
- Finds the last occurrence of the string pointed to by `s`
- of length `count` within the string starting before or at the
- index `pos`, where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @return The highest index `idx` less than or equal to `pos`
- where each element of `{s, s + count)` is equal to that of
- `{begin() + idx, begin() + idx + count)` if one exists,
- and @ref npos otherwise.
- @param s The string to search for.
- @param pos The index to stop searching at. The default argument
- for this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- rfind(
- const_pointer s,
- size_type pos = npos) const noexcept
- {
- return rfind(s, pos, traits_type::length(s));
- }
- /** Find the last occurrence of a character within the string.
- Finds the last occurrence of `c` within the string
- starting before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last occurrence of `c` within
- `{begin(), begin() + pos}` if it exists, and @ref npos otherwise.
- @param c The character to search for.
- @param pos The index to stop searching at. The default argument
- for this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- rfind(
- value_type c,
- size_type pos = npos) const noexcept
- {
- return rfind(&c, pos, 1);
- }
- /** Find the first occurrence of any of the characters within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the first occurrence of any of the characters in `sv`
- within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The index corrosponding to the first occurrence of
- any of the characters in `{sv.begin(), sv.end())` within
- `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param t The characters to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_of(
- const T& t,
- size_type pos = 0) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return find_first_of(sv.data(), pos, sv.size());
- }
- /** Find the first occurrence of any of the characters within the string.
- Finds the first occurrence of any of the characters within `str` within the
- string starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first occurrence of any of the characters
- of `str` within `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param str The characters to search for.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_of(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = 0) const noexcept
- {
- return find_first_of(str.data(), pos, str.size());
- }
- /** Find the first occurrence of any of the characters within the string.
- Finds the first occurrence of any of the characters within the string pointed to
- by `s` within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first occurrence
- of any of the characters in `{s, s + n)` within `{begin() + pos, end())`
- if it exists, and @ref npos otherwise.
- @param s The characters to search for.
- @param pos The index to start searching at.
- @param n The length of the string to search for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the first occurrence of any of the characters within the string.
- Finds the first occurrence of the any of the characters within string
- pointed to by `s` of length `count` within the string starting at the
- index `pos`, where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first occurrence of any of
- the characters in `{s, s + count)` within
- `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param s The characters to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_of(
- const_pointer s,
- size_type pos = 0) const noexcept
- {
- return find_first_of(s, pos, traits_type::length(s));
- }
- /** Find the first occurrence of a character within the string.
- Finds the first occurrence of `c` within the string
- starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first occurrence of `c` within
- `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param c The character to search for.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_of(
- value_type c,
- size_type pos = 0) const noexcept
- {
- return find_first_of(&c, pos, 1);
- }
- /** Find the last occurrence of any of the characters within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the last occurrence of any of the characters in `sv`
- within the string before or at the index `pos`.
- @par Complexity
- Linear.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The index corrosponding to the last occurrence of
- any of the characters in `{sv.begin(), sv.end())` within
- `{begin(), begin() + pos}` if it exists, and @ref npos otherwise.
- @param t The characters to search for.
- @param pos The index to stop searching at. The default argument
- for this parameter is @ref npos.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_of(
- const T& t,
- size_type pos = npos) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return find_last_of(sv.data(), pos, sv.size());
- }
- /** Find the last occurrence of any of the characters within the string.
- Finds the last occurrence of any of the characters within `str` within the
- string starting before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last occurrence of any of the characters
- of `str` within `{begin(), begin() + pos}` if it exists, and @ref npos otherwise.
- @param str The characters to search for.
- @param pos The index to stop searching at. The default argument for
- this parameter is @ref npos.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_of(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = npos) const noexcept
- {
- return find_last_of(str.data(), pos, str.size());
- }
- /** Find the last occurrence of any of the characters within the string.
- Finds the last occurrence of any of the characters within the string pointed to
- by `s` within the string before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last occurrence
- of any of the characters in `{s, s + n)` within `{begin(), begin() + pos}`
- if it exists, and @ref npos otherwise.
- @param s The characters to search for.
- @param pos The index to stop searching at.
- @param n The length of the string to search for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the last occurrence of any of the characters within the string.
- Finds the last occurrence of any of the characters within the string pointed to
- by `s` of length `count` within the string before or at the index `pos`,
- where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last occurrence
- of any of the characters in `{s, s + count)` within `{begin(), begin() + pos}`
- if it exists, and @ref npos otherwise.
- @param s The characters to search for.
- @param pos The index to stop searching at. The default argument for
- this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_of(
- const_pointer s,
- size_type pos = npos) const noexcept
- {
- return find_last_of(s, pos, traits_type::length(s));
- }
- /** Find the last occurrence of a character within the string.
- Finds the last occurrence of `c` within the string
- before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last occurrence of `c` within
- `{begin(), begin() + pos}` if it exists, and @ref npos otherwise.
- @param c The character to search for.
- @param pos The index to stop searching at. The default argument
- for this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_of(
- value_type c,
- size_type pos = npos) const noexcept
- {
- return find_last_of(&c, pos, 1);
- }
- /** Find the first occurrence of a character not within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the first character that is not within `sv`, starting at the index `pos`.
- @par Complexity
- Linear.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The index corrosponding to the first occurrence of
- a character that is not in `{sv.begin(), sv.end())` within
- `{begin() + pos, end())` if it exists, and @ref npos otherwise.
- @param t The characters to ignore.
- @param pos The index to start searching at. The default argument
- for this parameter is `0`.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_not_of(
- const T& t,
- size_type pos = 0) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return find_first_not_of(sv.data(), pos, sv.size());
- }
- /** Find the first occurrence of any of the characters not within the string.
- Finds the first occurrence of a character that is not within `str`
- within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first character of `{begin() + pos, end())`
- that is not within `str` if it exists, and @ref npos otherwise.
- @param str The characters to ignore.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- */
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_not_of(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = 0) const noexcept
- {
- return find_first_not_of(str.data(), pos, str.size());
- }
- /** Find the first occurrence of any of the characters not within the string.
- Finds the first occurrence of a character that is not within the string
- pointed to by `s` within the string starting at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first character of `{begin() + pos, end())`
- that is not within `{s, s + n)` if it exists, and @ref npos otherwise.
- @param s The characters to ignore.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- @param n The length of the characters to ignore.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_not_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the first occurrence of any of the characters not within the string.
- Finds the first occurrence of a character that is not within the string
- pointed to by `s` of length `count` within the string starting
- at the index `pos`, where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first character of `{begin() + pos, end())`
- that is not within `{s, s + count)` if it exists, and @ref npos otherwise.
- @param s The characters to ignore.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_not_of(
- const_pointer s,
- size_type pos = 0) const noexcept
- {
- return find_first_not_of(s, pos, traits_type::length(s));
- }
- /** Find the first occurrence of a character not equal to `c`.
- Finds the first occurrence of a character that is not equal
- to `c`.
- @par Complexity
- Linear.
- @return The index corrosponding to the first character of `{begin() + pos, end())`
- that is not equal to `c` if it exists, and @ref npos otherwise.
- @param c The character to ignore.
- @param pos The index to start searching at. The default argument for
- this parameter is `0`.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_first_not_of(
- value_type c,
- size_type pos = 0) const noexcept
- {
- return find_first_not_of(&c, pos, 1);
- }
- /** Find the last occurrence of a character not within the string.
- Constructs a temporary `string_view_type` object `sv` from `t`, and finds
- the last character that is not within `sv`, starting at the index `pos`.
- @par Complexity
- Linear.
- @tparam T The type of the object to convert.
- @par Constraints
- `std::is_convertible<const T&, string_view>::value &&
- !std::is_convertible<const T&, const CharT*>::value`.
- @return The index corrosponding to the last occurrence of
- a character that is not in `{sv.begin(), sv.end())` within
- `{begin(), begin() + pos}` if it exists, and @ref npos otherwise.
- @param t The characters to ignore.
- @param pos The index to start searching at. The default argument
- for this parameter is @ref npos.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_not_of(
- const T& t,
- size_type pos = npos) const
- #ifdef BHO_STATIC_STRING_DOCS
- noexcept(detail::is_nothrow_convertible<const T&, string_view_type>::value)
- #else
- noexcept(detail::is_nothrow_convertible<const T&, detail::common_string_view_type<T, CharT, Traits>>::value)
- #endif
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- return find_last_not_of(sv.data(), pos, sv.size());
- }
- /** Find the last occurrence of a character not within the string.
- Finds the last occurrence of a character that is not within `str`
- within the string before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last character of `{begin(), begin() + pos}`
- that is not within `str` if it exists, and @ref npos otherwise.
- @param str The characters to ignore.
- @param pos The index to stop searching at. The default argument for
- this parameter is @ref npos.
- */
- template<size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_not_of(
- const basic_static_string<M, CharT, Traits>& str,
- size_type pos = npos) const noexcept
- {
- return find_last_not_of(str.data(), pos, str.size());
- }
- /** Find the last occurrence of a character not within the string.
- Finds the last occurrence of a character that is not within the
- string pointed to by `s` within the string before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last character of `{begin(), begin() + pos}`
- that is not within `{s, s + n)` if it exists, and @ref npos otherwise.
- @param s The characters to ignore.
- @param pos The index to stop searching at. The default argument for
- this parameter is @ref npos.
- @param n The length of the characters to ignore.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_not_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept;
- /** Find the last occurrence of a character not within the string.
- Finds the last occurrence of a character that is not within the
- string pointed to by `s` of length `count` within the string
- before or at the index `pos`, where `count` is `traits_type::length(s)`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last character of `{begin(), begin() + pos}`
- that is not within `{s, s + count)` if it exists, and @ref npos otherwise.
- @param s The characters to ignore.
- @param pos The index to stop searching at. The default argument for
- this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_not_of(
- const_pointer s,
- size_type pos = npos) const noexcept
- {
- return find_last_not_of(s, pos, traits_type::length(s));
- }
- /** Find the last occurrence of a character not equal to `c`.
- Finds the last occurrence of a character that is not equal
- to `c` before or at the index `pos`.
- @par Complexity
- Linear.
- @return The index corrosponding to the last character of `{begin(), begin() + pos}`
- that is not equal to `c` if it exists, and @ref npos otherwise.
- @param c The character to ignore.
- @param pos The index to start searching at. The default argument for
- this parameter is @ref npos.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- find_last_not_of(
- value_type c,
- size_type pos = npos) const noexcept
- {
- return find_last_not_of(&c, pos, 1);
- }
- /** Return whether the string begins with a string.
- Returns `true` if the string begins with `s`, and `false` otherwise.
- @par Complexity
- Linear.
- @param t The string view to check for.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- starts_with(
- T const& t) const noexcept
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- const size_type len = sv.size();
- return size() >= len && !traits_type::compare(data(), sv.data(), len);
- }
- /** Return whether the string begins with a character.
- Returns `true` if the string begins with `c`, and `false` otherwise.
- @par Complexity
- Constant.
- @param c The character to check for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- starts_with(
- value_type c) const noexcept
- {
- return !empty() && traits_type::eq(front(), c);
- }
- /** Return whether the string begins with a string.
- Returns `true` if the string begins with the string
- pointed to be `s` of length `traits_type::length(s)`,
- and `false` otherwise.
- @par Complexity
- Linear.
- @param s The string to check for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- starts_with(
- const_pointer s) const noexcept
- {
- const size_type len = traits_type::length(s);
- return size() >= len && !traits_type::compare(data(), s, len);
- }
- /** Return whether the string ends with a string.
- Returns `true` if the string ends with `s`, and `false` otherwise.
- @par Complexity
- Linear.
- @param t The string view to check for.
- */
- template<typename T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- ends_with(
- T const& t) const noexcept
- {
- detail::common_string_view_type<T, CharT, Traits> sv = t;
- const size_type len = sv.size();
- return size() >= len && !traits_type::compare(data() + (size() - len), sv.data(), len);
- }
- /** Return whether the string ends with a character.
- Returns `true` if the string ends with `c`, and `false` otherwise.
- @par Complexity
- Constant.
- @param c The character to check for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- ends_with(
- value_type c) const noexcept
- {
- return !empty() && traits_type::eq(back(), c);
- }
- /** Return whether the string ends with a string.
- Returns `true` if the string ends with the string
- pointed to be `s` of length `traits_type::length(s)`,
- and `false` otherwise.
- @par Complexity
- Linear.
- @param s The string to check for.
- */
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- bool
- ends_with(
- const_pointer s) const noexcept
- {
- const size_type len = traits_type::length(s);
- return size() >= len && !traits_type::compare(data() + (size() - len), s, len);
- }
- private:
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- term() noexcept
- {
- this->term_impl();
- return *this;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign_char(value_type ch, std::true_type) noexcept
- {
- this->set_size(1);
- traits_type::assign(data()[0], ch);
- return term();
- }
- BHO_STATIC_STRING_NORETURN
- basic_static_string&
- assign_char(value_type, std::false_type)
- {
- detail::throw_exception<std::length_error>("max_size() == 0");
- // This eliminates any potential warnings
- #ifdef BHO_STATIC_STRING_NO_NORETURN
- return *this;
- #endif
- }
- // Returns the size of data read from input iterator. Read data begins at data() + size() + 1.
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- read_back(
- bool overwrite_null,
- InputIterator first,
- InputIterator last);
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace_unchecked(
- size_type pos,
- size_type n1,
- const_pointer s,
- size_type n2)
- {
- if (pos > size())
- detail::throw_exception<std::out_of_range>(
- "pos > size()");
- return replace_unchecked(data() + pos, data() + pos + capped_length(pos, n1), s, n2);
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- replace_unchecked(
- const_iterator i1,
- const_iterator i2,
- const_pointer s,
- size_type n2);
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- insert_unchecked(
- size_type index,
- const_pointer s,
- size_type count)
- {
- if (index > size())
- detail::throw_exception<std::out_of_range>(
- "index > size()");
- insert_unchecked(data() + index, s, count);
- return *this;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- iterator
- insert_unchecked(
- const_iterator pos,
- const_pointer s,
- size_type count);
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- basic_static_string&
- assign_unchecked(
- const_pointer s,
- size_type count) noexcept
- {
- this->set_size(count);
- traits_type::copy(data(), s, size() + 1);
- return *this;
- }
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- size_type
- capped_length(
- size_type index,
- size_type length) const
- {
- if (index > size())
- detail::throw_exception<std::out_of_range>(
- "index > size()");
- return (std::min)(size() - index, length);
- }
- };
- //------------------------------------------------------------------------------
- //
- // Non-member functions
- //
- //------------------------------------------------------------------------------
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator==(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) == 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator!=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) != 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) < 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) <= 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) > 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return lhs.compare(rhs) >= 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator==(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) == 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator==(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) == 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator==(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) == 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator==(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) == 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator!=(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) != 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator!=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) != 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator!=(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) != 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator!=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) != 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) < 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) < 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) < 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) < 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<=(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) <= 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) <= 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<=(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) <= 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator<=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) <= 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) > 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) > 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) > 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) > 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>=(
- const CharT* lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs, Traits::length(lhs),
- rhs.data(), rhs.size()) >= 0;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT* rhs)
- {
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhs, Traits::length(rhs)) >= 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>=(
- const T& lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> lhsv = lhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhsv.data(), lhsv.size(),
- rhs.data(), rhs.size()) >= 0;
- }
- template<std::size_t N, typename CharT, typename Traits, class T
- #ifndef BHO_STATIC_STRING_DOCS
- , typename = detail::enable_if_viewable_t<T, CharT, Traits>
- #endif
- >
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- bool
- operator>=(
- const basic_static_string<N, CharT, Traits>& lhs,
- const T& rhs)
- {
- detail::common_string_view_type<T, CharT, Traits> rhsv = rhs;
- return detail::lexicographical_compare<CharT, Traits>(
- lhs.data(), lhs.size(),
- rhsv.data(), rhsv.size()) >= 0;
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- basic_static_string<N + M, CharT, Traits>
- operator+(
- const basic_static_string<N, CharT, Traits>& lhs,
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- return basic_static_string<N + M, CharT, Traits>(lhs) += rhs;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- basic_static_string<N + 1, CharT, Traits>
- operator+(
- const basic_static_string<N, CharT, Traits>& lhs,
- CharT rhs)
- {
- return basic_static_string<N + 1, CharT, Traits>(lhs) += rhs;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- basic_static_string<N + 1, CharT, Traits>
- operator+(
- CharT lhs,
- const basic_static_string<N, CharT, Traits>& rhs)
- {
- // The cast to std::size_t is needed here since 0 is a null pointer constant
- return basic_static_string<N + 1, CharT, Traits>(rhs).insert(
- std::size_t(0), 1, lhs);
- }
- // Add a null terminated character array to a string.
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- basic_static_string<N + M, CharT, Traits>
- operator+(
- const basic_static_string<N, CharT, Traits>& lhs,
- const CharT(&rhs)[M])
- {
- return basic_static_string<N + M, CharT, Traits>(lhs).append(+rhs);
- }
- // Add a string to a null terminated character array.
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- basic_static_string<N + M, CharT, Traits>
- operator+(
- const CharT(&lhs)[N],
- const basic_static_string<M, CharT, Traits>& rhs)
- {
- // The cast to std::size_t is needed here since 0 is a null pointer constant
- return basic_static_string<N + M, CharT, Traits>(rhs).insert(
- std::size_t(0), +lhs);
- }
- //------------------------------------------------------------------------------
- //
- // erase_if
- //
- //------------------------------------------------------------------------------
- template<
- std::size_t N, typename CharT,
- typename Traits, typename UnaryPredicate>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- typename
- basic_static_string<N, CharT, Traits>::size_type
- erase_if(
- basic_static_string<N, CharT, Traits>& str,
- UnaryPredicate pred)
- {
- auto first = str.begin();
- for (auto it = first; it != str.end(); ++it)
- if (!pred(*it))
- *first++ = std::move(*it);
- const auto count = str.end() - first;
- str.erase(first, str.end());
- return count;
- }
- //------------------------------------------------------------------------------
- //
- // swap
- //
- //------------------------------------------------------------------------------
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- void
- swap(
- basic_static_string<N, CharT, Traits>& lhs,
- basic_static_string<N, CharT, Traits>& rhs)
- {
- lhs.swap(rhs);
- }
- template<
- std::size_t N, std::size_t M,
- typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- inline
- void
- swap(
- basic_static_string<N, CharT, Traits>& lhs,
- basic_static_string<M, CharT, Traits>& rhs)
- {
- lhs.swap(rhs);
- }
- //------------------------------------------------------------------------------
- //
- // Input/Output
- //
- //------------------------------------------------------------------------------
- template<std::size_t N, typename CharT, typename Traits>
- inline
- std::basic_ostream<CharT, Traits>&
- operator<<(
- std::basic_ostream<CharT, Traits>& os,
- const basic_static_string<N, CharT, Traits>& s)
- {
- #ifdef BHO_STATIC_STRING_HAS_ANY_STRING_VIEW
- return os << basic_string_view<CharT, Traits>(s.data(), s.size());
- #else
- for (auto c: s)
- os << c;
- return os;
- #endif
- }
- //------------------------------------------------------------------------------
- //
- // Numeric conversions
- //
- //------------------------------------------------------------------------------
- // Signed overloads have a + 2, one for the missing digit,
- // and one for the sign.
- // Unsigned overloads have a + 1, for the missing digit.
- // Floating point overloads have a + 4, for the sign
- // of the integral part, sign of the exponent, the 'e',
- // and the decimal.
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<int>::digits10 + 2>
- inline
- to_static_string(int value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<int>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<long>::digits10 + 2>
- inline
- to_static_string(long value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<long>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<long long>::digits10 + 2>
- inline
- to_static_string(long long value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<long long>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<unsigned int>::digits10 + 1>
- inline
- to_static_string(unsigned int value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<unsigned int>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<unsigned long>::digits10 + 1>
- inline
- to_static_string(unsigned long value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<unsigned long>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<unsigned long long>::digits10 + 1>
- inline
- to_static_string(unsigned long long value) noexcept
- {
- return detail::to_static_string_int_impl<
- std::numeric_limits<unsigned long long>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<float>::max_digits10 + 4>
- inline
- to_static_string(float value) noexcept
- {
- return detail::to_static_string_float_impl<
- std::numeric_limits<float>::max_digits10 + 4>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<double>::max_digits10 + 4>
- inline
- to_static_string(double value) noexcept
- {
- return detail::to_static_string_float_impl<
- std::numeric_limits<double>::max_digits10 + 4>(value);
- }
- /// Converts `value` to a `static_string`
- static_string<std::numeric_limits<long double>::max_digits10 + 4>
- inline
- to_static_string(long double value) noexcept
- {
- return detail::to_static_string_float_impl<
- std::numeric_limits<long double>::max_digits10 + 4>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<int>::digits10 + 2>
- inline
- to_static_wstring(int value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<int>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<long>::digits10 + 2>
- inline
- to_static_wstring(long value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<long>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<long long>::digits10 + 2>
- inline
- to_static_wstring(long long value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<long long>::digits10 + 2>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<unsigned int>::digits10 + 1>
- inline
- to_static_wstring(unsigned int value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<unsigned int>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<unsigned long>::digits10 + 1>
- inline
- to_static_wstring(unsigned long value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<unsigned long>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<unsigned long long>::digits10 + 1>
- inline
- to_static_wstring(unsigned long long value) noexcept
- {
- return detail::to_static_wstring_int_impl<
- std::numeric_limits<unsigned long long>::digits10 + 1>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<float>::max_digits10 + 4>
- inline
- to_static_wstring(float value) noexcept
- {
- return detail::to_static_wstring_float_impl<
- std::numeric_limits<float>::max_digits10 + 4>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<double>::max_digits10 + 4>
- inline
- to_static_wstring(double value) noexcept
- {
- return detail::to_static_wstring_float_impl<
- std::numeric_limits<double>::max_digits10 + 4>(value);
- }
- /// Converts `value` to a `static_wstring`
- static_wstring<std::numeric_limits<long double>::max_digits10 + 4>
- inline
- to_static_wstring(long double value) noexcept
- {
- return detail::to_static_wstring_float_impl<
- std::numeric_limits<long double>::max_digits10 + 4>(value);
- }
- //------------------------------------------------------------------------------
- //
- // Deduction Guides
- //
- //------------------------------------------------------------------------------
- #ifdef BHO_STATIC_STRING_USE_DEDUCT
- template<std::size_t N, typename CharT>
- basic_static_string(const CharT(&)[N]) ->
- basic_static_string<N, CharT, std::char_traits<CharT>>;
- #endif
- //------------------------------------------------------------------------------
- //
- // Hashing
- //
- //------------------------------------------------------------------------------
- #ifndef BHO_STATIC_STRING_STANDALONE
- /// hash_value overload for BHO.Container_Hash
- template <std::size_t N,
- typename CharT,
- typename Traits>
- std::size_t
- hash_value(
- const basic_static_string<N, CharT, Traits>& str)
- {
- return bho::hash_range(str.begin(), str.end());
- }
- #endif
- } // static_strings
- //------------------------------------------------------------------------------
- //
- // using Declarations
- //
- //------------------------------------------------------------------------------
- using static_strings::static_string;
- using static_strings::static_wstring;
- using static_strings::static_u16string;
- using static_strings::static_u32string;
- } // bho
- /// std::hash partial specialization for basic_static_string
- namespace std {
- template<std::size_t N, typename CharT, typename Traits>
- struct hash<
- #ifdef BHO_STATIC_STRING_DOCS
- basic_static_string
- #else
- bho::static_strings::basic_static_string<N, CharT, Traits>
- #endif
- >
- {
- std::size_t
- operator()(
- const bho::static_strings::basic_static_string<N, CharT, Traits>& str) const noexcept
- {
- #if !defined(BHO_STATIC_STRING_STANDALONE)
- return bho::hash_range(str.begin(), str.end());
- #elif defined(BHO_STATIC_STRING_HAS_ANY_STRING_VIEW)
- using view_type = typename
- bho::static_strings::basic_string_view<CharT, Traits>;
- return std::hash<view_type>()(view_type(str.data(), str.size()));
- #else
- std::size_t seed = 0;
- for (CharT const& c : str) {
- mix_impl(std::integral_constant<bool, sizeof(std::size_t) >= 8>{}, seed, c);
- }
- return seed;
- #endif
- }
- static
- void
- mix_impl(std::true_type, std::size_t& seed, CharT c)
- {
- seed += 0x9e3779b9 + std::hash<CharT>()( c );
- std::size_t const m = (std::size_t(0xe9846af) << 32) + 0x9b1a615d;
- seed ^= seed >> 32;
- seed *= m;
- seed ^= seed >> 32;
- seed *= m;
- seed ^= seed >> 28;
- }
- static
- void
- mix_impl(std::false_type, std::size_t& seed, CharT c)
- {
- seed += 0x9e3779b9 + std::hash<CharT>()( c );
- std::size_t const m1 = 0x21f0aaad;
- std::size_t const m2 = 0x735a2d97;
- seed ^= seed >> 16;
- seed *= m1;
- seed ^= seed >> 15;
- seed *= m2;
- seed ^= seed >> 15;
- }
- };
- } // std
- //--------------------------------------------------------------------------
- //
- // Implementation
- //
- //--------------------------------------------------------------------------
- #ifndef BHO_STATIC_STRING_DOCS
- namespace bho {
- namespace static_strings {
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- assign(
- size_type count,
- value_type ch) ->
- basic_static_string&
- {
- if (count > max_size())
- detail::throw_exception<std::length_error>(
- "count > max_size()");
- this->set_size(count);
- traits_type::assign(data(), size(), ch);
- return term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- assign(
- const_pointer s,
- size_type count) ->
- basic_static_string&
- {
- if (count > max_size())
- detail::throw_exception<std::length_error>(
- "count > max_size()");
- this->set_size(count);
- traits_type::move(data(), s, size());
- return term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- assign(
- InputIterator first,
- InputIterator last) ->
- typename std::enable_if<
- detail::is_input_iterator<InputIterator>::value,
- basic_static_string&>::type
- {
- auto ptr = data();
- for (std::size_t i = 0; first != last; ++first, ++ptr, ++i)
- {
- if (i >= max_size())
- {
- this->set_size(i);
- term();
- detail::throw_exception<std::length_error>("n > max_size()");
- }
- traits_type::assign(*ptr, *first);
- }
- this->set_size(ptr - data());
- return term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- insert(
- const_iterator pos,
- size_type count,
- value_type ch) ->
- iterator
- {
- const auto curr_size = size();
- const auto curr_data = data();
- if (count > max_size() - curr_size)
- detail::throw_exception<std::length_error>(
- "count > max_size() - curr_size");
- const auto index = pos - curr_data;
- traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
- traits_type::assign(&curr_data[index], count, ch);
- this->set_size(curr_size + count);
- return &curr_data[index];
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename ForwardIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- insert(
- const_iterator pos,
- ForwardIterator first,
- ForwardIterator last) ->
- typename std::enable_if<
- detail::is_forward_iterator<
- ForwardIterator>::value, iterator>::type
- {
- // input
- const std::size_t count = detail::distance(first, last);
- const auto first_addr = &*first;
- const auto last_addr = first_addr + count;
- // output
- const auto curr_size = size();
- const auto curr_data = data();
- const std::size_t index = pos - curr_data;
- auto dest = &curr_data[index];
- if (count > max_size() - curr_size)
- detail::throw_exception<std::length_error>(
- "count > max_size() - curr_size");
- traits_type::move(dest + count, dest, curr_size - index + 1);
- const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr);
- if (!inside || last_addr <= pos)
- {
- detail::copy_with_traits<Traits>(first, last, dest);
- }
- else /* if (inside) */
- {
- const size_type offset = first_addr - curr_data;
- if (offset < index)
- {
- const size_type diff = index - offset;
- traits_type::copy(dest, &curr_data[offset], diff);
- traits_type::copy(&curr_data[index + diff], dest + count, count - diff);
- }
- else
- {
- auto src = &curr_data[offset + count];
- traits_type::copy(dest, src, count);
- }
- }
- this->set_size(curr_size + count);
- return curr_data + index;
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- insert(
- const_iterator pos,
- InputIterator first,
- InputIterator last) ->
- typename std::enable_if<
- detail::is_input_iterator<
- InputIterator>::value &&
- !detail::is_forward_iterator<
- InputIterator>::value, iterator>::type
- {
- const auto curr_size = size();
- const auto curr_data = data();
- const auto count = read_back(false, first, last);
- const std::size_t index = pos - curr_data;
- std::rotate(&curr_data[index], &curr_data[curr_size + 1], &curr_data[curr_size + count + 1]);
- this->set_size(curr_size + count);
- return curr_data + index;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- erase(
- const_iterator first,
- const_iterator last) ->
- iterator
- {
- const auto curr_data = data();
- const std::size_t index = first - curr_data;
- traits_type::move(&curr_data[index], last, (end() - last) + 1);
- this->set_size(size() - std::size_t(last - first));
- return curr_data + index;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- basic_static_string<N, CharT, Traits>::
- push_back(
- value_type ch)
- {
- const auto curr_size = size();
- if (curr_size >= max_size())
- detail::throw_exception<std::length_error>(
- "curr_size >= max_size()");
- traits_type::assign(data()[curr_size], ch);
- this->set_size(curr_size + 1);
- term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- append(
- size_type count,
- value_type ch) ->
- basic_static_string&
- {
- const auto curr_size = size();
- if (count > max_size() - curr_size)
- detail::throw_exception<std::length_error>(
- "count > max_size() - size()");
- traits_type::assign(end(), count, ch);
- this->set_size(curr_size + count);
- return term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- append(
- const_pointer s,
- size_type count) ->
- basic_static_string&
- {
- const auto curr_size = size();
- if (count > max_size() - curr_size)
- detail::throw_exception<std::length_error>(
- "count > max_size() - size()");
- traits_type::copy(end(), s, count);
- this->set_size(curr_size + count);
- return term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- basic_static_string<N, CharT, Traits>::
- resize(size_type n, value_type c)
- {
- if (n > max_size())
- detail::throw_exception<std::length_error>(
- "n > max_size()");
- const auto curr_size = size();
- if(n > curr_size)
- traits_type::assign(data() + curr_size, n - curr_size, c);
- this->set_size(n);
- term();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- basic_static_string<N, CharT, Traits>::
- swap(basic_static_string& s) noexcept
- {
- const auto curr_size = size();
- basic_static_string tmp(s);
- s.set_size(curr_size);
- traits_type::copy(&s.data()[0], data(), curr_size + 1);
- this->set_size(tmp.size());
- traits_type::copy(data(), tmp.data(), size() + 1);
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<std::size_t M>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- void
- basic_static_string<N, CharT, Traits>::
- swap(basic_static_string<M, CharT, Traits>& s)
- {
- const auto curr_size = size();
- if (curr_size > s.max_size())
- detail::throw_exception<std::length_error>(
- "curr_size > s.max_size()");
- if (s.size() > max_size())
- detail::throw_exception<std::length_error>(
- "s.size() > max_size()");
- basic_static_string tmp(s);
- s.set_size(curr_size);
- traits_type::copy(&s.data()[0], data(), curr_size + 1);
- this->set_size(tmp.size());
- traits_type::copy(data(), &tmp.data()[0], size() + 1);
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- replace(
- const_iterator i1,
- const_iterator i2,
- size_type n,
- value_type c) ->
- basic_static_string<N, CharT, Traits>&
- {
- const auto curr_size = size();
- const auto curr_data = data();
- const std::size_t n1 = i2 - i1;
- if (n > max_size() || curr_size - n1 >= max_size() - n)
- detail::throw_exception<std::length_error>(
- "replaced string exceeds max_size()");
- const auto pos = i1 - curr_data;
- traits_type::move(&curr_data[pos + n], i2, (end() - i2) + 1);
- traits_type::assign(&curr_data[pos], n, c);
- this->set_size((curr_size - n1) + n);
- return *this;
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename ForwardIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- replace(
- const_iterator i1,
- const_iterator i2,
- ForwardIterator j1,
- ForwardIterator j2) ->
- typename std::enable_if<
- detail::is_forward_iterator<ForwardIterator>::value,
- basic_static_string<N, CharT, Traits>&>::type
- {
- const auto curr_size = size();
- const auto curr_data = data();
- const auto first_addr = &*j1;
- const std::size_t n1 = i2 - i1;
- const std::size_t n2 = detail::distance(j1, j2);
- const std::size_t pos = i1 - curr_data;
- if (n2 > max_size() || curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2)
- detail::throw_exception<std::length_error>(
- "replaced string exceeds max_size()");
- const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr);
- if (inside && first_addr == i1 && n1 == n2)
- return *this;
- // Short circuit evaluation ensures that the pointer arithmetic is valid
- if (!inside || (inside && (first_addr + n2 <= i1)))
- {
- // source outside
- traits_type::move(&curr_data[pos + n2], &curr_data[pos + n1], curr_size - pos - n1 + 1);
- detail::copy_with_traits<Traits>(j1, j2, &curr_data[pos]);
- }
- else
- {
- // source inside
- const size_type offset = first_addr - curr_data;
- if (n2 >= n1)
- {
- // grow/unchanged
- const size_type diff = offset <= pos + n1 ? (std::min)((pos + n1) - offset, n2) : 0;
- // shift all right of splice point by n2 - n1 to the right
- traits_type::move(&curr_data[pos + n2], &curr_data[pos + n1], curr_size - pos - n1 + 1);
- // copy all before splice point
- traits_type::move(&curr_data[pos], &curr_data[offset], diff);
- // copy all after splice point
- traits_type::move(&curr_data[pos + diff], &curr_data[(offset - n1) + n2 + diff], n2 - diff);
- }
- else
- {
- // shrink
- // copy all elements into place
- traits_type::move(&curr_data[pos], &curr_data[offset], n2);
- // shift all elements after splice point left
- traits_type::move(&curr_data[pos + n2], &curr_data[pos + n1], curr_size - pos - n1 + 1);
- }
- }
- this->set_size((curr_size - n1) + n2);
- return *this;
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- replace(
- const_iterator i1,
- const_iterator i2,
- InputIterator j1,
- InputIterator j2) ->
- typename std::enable_if<
- detail::is_input_iterator<
- InputIterator>::value &&
- !detail::is_forward_iterator<
- InputIterator>::value,
- basic_static_string<N, CharT, Traits>&>::type
- {
- const auto curr_size = size();
- const auto curr_data = data();
- const std::size_t n1 = detail::distance(i1, i2);
- const std::size_t n2 = read_back(false, j1, j2);
- const std::size_t pos = i1 - curr_data;
- // Rotate to the correct order. [i2, end] will now start with the replaced string,
- // continue to the existing string not being replaced, and end with a null terminator
- std::rotate(&curr_data[pos], &curr_data[curr_size + 1], &curr_data[curr_size + n2 + 1]);
- // Move everything from the end of the splice point to the end of the rotated string to
- // the begining of the splice point
- traits_type::move(&curr_data[pos + n2], &curr_data[pos + n2 + n1], ((curr_size - n1) + n2) - pos);
- this->set_size((curr_size - n1) + n2);
- return *this;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- find(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- const auto curr_size = size();
- if (pos > curr_size || n > curr_size - pos)
- return npos;
- if (!n)
- return pos;
- const auto res = detail::search(data() + pos, data() + curr_size, s, s + n, traits_type::eq);
- return res == end() ? npos : detail::distance(data(), res);
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- rfind(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- const auto curr_size = size();
- const auto curr_data = data();
- if (curr_size < n)
- return npos;
- if (pos > curr_size - n)
- pos = curr_size - n;
- if (!n)
- return pos;
- for (auto sub = &curr_data[pos]; sub >= curr_data; --sub)
- if (!traits_type::compare(sub, s, n))
- return detail::distance(curr_data, sub);
- return npos;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- find_first_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- const auto curr_data = data();
- if (pos >= size() || !n)
- return npos;
- const auto res = detail::find_first_of(&curr_data[pos], &curr_data[size()], s, &s[n], traits_type::eq);
- return res == end() ? npos : detail::distance(curr_data, res);
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- find_last_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- const auto curr_size = size();
- if (!n)
- return npos;
- if (pos >= curr_size)
- pos = 0;
- else
- pos = curr_size - (pos + 1);
- const auto res = detail::find_first_of(rbegin() + pos, rend(), s, &s[n], traits_type::eq);
- return res == rend() ? npos : curr_size - 1 - detail::distance(rbegin(), res);
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- find_first_not_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- if (pos >= size())
- return npos;
- if (!n)
- return pos;
- const auto res = detail::find_not_of<Traits>(data() + pos, data() + size(), s, n);
- return res == end() ? npos : detail::distance(data(), res);
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- find_last_not_of(
- const_pointer s,
- size_type pos,
- size_type n) const noexcept ->
- size_type
- {
- const auto curr_size = size();
- if (pos >= curr_size)
- pos = curr_size - 1;
- if (!n)
- return pos;
- pos = curr_size - (pos + 1);
- const auto res = detail::find_not_of<Traits>(rbegin() + pos, rend(), s, n);
- return res == rend() ? npos : curr_size - 1 - detail::distance(rbegin(), res);
- }
- template<std::size_t N, typename CharT, typename Traits>
- template<typename InputIterator>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- read_back(
- bool overwrite_null,
- InputIterator first,
- InputIterator last) ->
- size_type
- {
- const auto curr_data = data();
- auto new_size = size();
- for (; first != last; ++first)
- {
- if (new_size >= max_size())
- {
- // if we overwrote the null terminator,
- // put it back
- if (overwrite_null)
- term();
- detail::throw_exception<std::length_error>(
- "count > max_size() - size()");
- }
- traits_type::assign(curr_data[new_size++ + (!overwrite_null)], *first);
- }
- return new_size - size();
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- replace_unchecked(
- const_iterator i1,
- const_iterator i2,
- const_pointer s,
- size_type n2) ->
- basic_static_string&
- {
- const auto curr_data = data();
- const auto curr_size = size();
- const std::size_t pos = i1 - curr_data;
- const std::size_t n1 = i2 - i1;
- if (n2 > max_size() || curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2)
- detail::throw_exception<std::length_error>(
- "replaced string exceeds max_size()");
- traits_type::move(&curr_data[pos + n2], i2, (end() - i2) + 1);
- traits_type::copy(&curr_data[pos], s, n2);
- this->set_size((curr_size - n1) + n2);
- return *this;
- }
- template<std::size_t N, typename CharT, typename Traits>
- BHO_STATIC_STRING_CPP14_CONSTEXPR
- auto
- basic_static_string<N, CharT, Traits>::
- insert_unchecked(
- const_iterator pos,
- const_pointer s,
- size_type count) ->
- iterator
- {
- const auto curr_data = data();
- const auto curr_size = size();
- if (count > max_size() - curr_size)
- detail::throw_exception<std::length_error>(
- "count > max_size() - curr_size");
- const std::size_t index = pos - curr_data;
- traits_type::move(&curr_data[index + count], pos, (end() - pos) + 1);
- traits_type::copy(&curr_data[index], s, count);
- this->set_size(curr_size + count);
- return curr_data + index;
- }
- } // static_strings
- } // bho
- #if defined(__GNUC__) && __GNUC__ >= 7
- #pragma GCC diagnostic pop
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 8
- #pragma GCC diagnostic pop
- #endif
- #endif
- #endif
|