12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593 |
- #ifndef BOOST_CONTAINER_STRING_HPP
- #define BOOST_CONTAINER_STRING_HPP
- #ifndef BOOST_CONFIG_HPP
- # include <boost/config.hpp>
- #endif
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- #include <boost/container/detail/config_begin.hpp>
- #include <boost/container/detail/workaround.hpp>
- #include <boost/container/container_fwd.hpp>
- #include <boost/container/allocator_traits.hpp>
- #include <boost/container/new_allocator.hpp>
- #include <boost/container/throw_exception.hpp>
- #include <boost/container/detail/alloc_helpers.hpp>
- #include <boost/container/detail/allocator_version_traits.hpp>
- #include <boost/container/detail/allocation_type.hpp>
- #include <boost/container/detail/iterator.hpp>
- #include <boost/container/detail/iterators.hpp>
- #include <boost/container/detail/min_max.hpp>
- #include <boost/container/detail/mpl.hpp>
- #include <boost/container/detail/next_capacity.hpp>
- #include <boost/move/detail/to_raw_pointer.hpp>
- #include <boost/container/detail/version_type.hpp>
- #include <boost/container/detail/type_traits.hpp>
- #include <boost/container/detail/algorithm.hpp>
- #include <boost/container/detail/minimal_char_traits_header.hpp>
- #include <boost/intrusive/pointer_traits.hpp>
- #include <boost/intrusive/detail/hash_combine.hpp>
- #include <boost/move/detail/launder.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/move/adl_move_swap.hpp>
- #include <boost/move/traits.hpp>
- #include <iosfwd>
- #include <istream>
- #include <ostream>
- #include <ios>
- #include <locale>
- #include <cstddef>
- #include <climits>
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- #include <initializer_list>
- #endif
- #if defined(BOOST_GCC) && (BOOST_GCC >= 120000) && (BOOST_GCC < 130000)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Warray-bounds"
- #endif
- namespace boost {
- namespace container {
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- namespace dtl {
- template <class Allocator>
- class basic_string_base
- {
- basic_string_base & operator=(const basic_string_base &);
- basic_string_base(const basic_string_base &);
- typedef Allocator allocator_type;
- public:
- typedef allocator_traits<allocator_type> allocator_traits_type;
- typedef allocator_type stored_allocator_type;
- typedef typename allocator_traits_type::pointer pointer;
- typedef typename allocator_traits_type::value_type value_type;
- typedef typename allocator_traits_type::size_type size_type;
- typedef typename allocator_traits_type::difference_type difference_type;
- typedef ::boost::intrusive::pointer_traits<pointer> pointer_traits;
- inline basic_string_base()
- : members_()
- {}
- inline explicit basic_string_base(const allocator_type& a)
- : members_(a)
- {}
- inline explicit basic_string_base(BOOST_RV_REF(allocator_type) a)
- : members_(boost::move(a))
- {}
- inline basic_string_base(const allocator_type& a, size_type n)
- : members_(a)
- {
- this->allocate_initial_block(n);
- }
- inline explicit basic_string_base(size_type n)
- : members_()
- {
- this->allocate_initial_block(n);
- }
- inline ~basic_string_base()
- {
- if(!this->is_short()){
- this->deallocate(this->priv_long_addr(), this->priv_long_storage());
- }
- }
- private:
- #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
- #endif
-
- struct long_t
- {
- size_type is_short : 1;
- size_type length : (sizeof(size_type)*CHAR_BIT - 1);
- size_type storage;
- pointer start;
- inline long_t()
- : is_short(0)
- {}
- inline long_t(size_type len, size_type stor, pointer ptr)
- : is_short(0), length(len), storage(stor), start(ptr)
- {}
- inline long_t(const long_t &other)
- {
- this->is_short = false;
- length = other.length;
- storage = other.storage;
- start = other.start;
- }
- inline long_t &operator= (const long_t &other)
- {
- length = other.length;
- storage = other.storage;
- start = other.start;
- return *this;
- }
- };
- #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
- #pragma GCC diagnostic pop
- #endif
-
-
- struct short_header
- {
- unsigned char is_short : 1;
- unsigned char length : (CHAR_BIT - 1);
- };
-
-
- typedef typename dtl::aligned_storage
- <sizeof(long_t), dtl::alignment_of<long_t>::value>::type long_raw_t;
- protected:
- BOOST_STATIC_CONSTEXPR size_type MinInternalBufferChars = 8;
- BOOST_STATIC_CONSTEXPR size_type AlignmentOfValueType =
- alignment_of<value_type>::value;
- BOOST_STATIC_CONSTEXPR size_type ShortDataOffset = ((sizeof(short_header)-1)/AlignmentOfValueType+1)*AlignmentOfValueType;
- BOOST_STATIC_CONSTEXPR size_type ZeroCostInternalBufferChars =
- (sizeof(long_t) - ShortDataOffset)/sizeof(value_type);
- BOOST_STATIC_CONSTEXPR size_type UnalignedFinalInternalBufferChars =
- (ZeroCostInternalBufferChars > MinInternalBufferChars) ?
- ZeroCostInternalBufferChars : MinInternalBufferChars;
- struct short_t
- {
- short_header h;
- value_type data[UnalignedFinalInternalBufferChars];
- };
- union repr_t_size_t
- {
- long_raw_t r;
- short_t s;
- };
- union repr_t
- {
- long_raw_t r_aligner;
- short_t s_aligner;
- unsigned char data[sizeof(repr_t_size_t)];
- };
- struct members_holder
- : public allocator_type
- {
- inline void init()
- {
- short_t &s = *::new(&this->m_repr) short_t;
- s.h.is_short = 1;
- s.h.length = 0;
- }
- inline members_holder()
- : allocator_type()
- { this->init(); }
- template<class AllocatorConvertible>
- inline explicit members_holder(BOOST_FWD_REF(AllocatorConvertible) a)
- : allocator_type(boost::forward<AllocatorConvertible>(a))
- { this->init(); }
- inline const short_t *pshort_repr() const
- { return move_detail::launder_cast<const short_t*>(&m_repr); }
- inline const long_t *plong_repr() const
- { return move_detail::launder_cast<const long_t*>(&m_repr); }
- inline short_t *pshort_repr()
- { return move_detail::launder_cast<short_t*>(&m_repr); }
- inline long_t *plong_repr()
- { return move_detail::launder_cast<long_t*>(&m_repr); }
- repr_t m_repr;
- } members_;
- inline const allocator_type &alloc() const
- { return members_; }
- inline allocator_type &alloc()
- { return members_; }
- BOOST_STATIC_CONSTEXPR size_type InternalBufferChars = (sizeof(repr_t) - ShortDataOffset)/sizeof(value_type);
- private:
- BOOST_STATIC_CONSTEXPR size_type MinAllocation = InternalBufferChars*2;
- protected:
- inline bool is_short() const
- {
-
-
- short_header hdr;
- BOOST_CONTAINER_STATIC_ASSERT((sizeof(short_header) == 1));
- *(unsigned char*)&hdr = *(unsigned char*)&this->members_.m_repr;
- return hdr.is_short != 0;
- }
- inline short_t *construct_short()
- {
- short_t *ps = ::new(&this->members_.m_repr) short_t;
- ps->h.is_short = 1;
- return ps;
- }
- inline void destroy_short()
- {
- BOOST_ASSERT(this->is_short());
- this->members_.pshort_repr()->~short_t();
- }
- short_t *assure_short()
- {
- if (!this->is_short()){
- this->destroy_long();
- return construct_short();
- }
- return this->members_.pshort_repr();
- }
- inline long_t *construct_long()
- {
- long_t *pl = ::new(&this->members_.m_repr) long_t;
-
- return pl;
- }
- inline void destroy_long()
- {
- BOOST_ASSERT(!this->is_short());
- this->members_.plong_repr()->~long_t();
- }
- long_t *assure_long()
- {
- if (this->is_short()){
- this->destroy_short();
- return this->construct_long();
- }
- return this->members_.plong_repr();
- }
-
- protected:
- typedef dtl::integral_constant<unsigned,
- boost::container::dtl::version<allocator_type>::value> alloc_version;
- pointer allocation_command(allocation_type command,
- size_type limit_size,
- size_type &prefer_in_recvd_out_size,
- pointer &reuse)
- {
- if(this->is_short() && (command & (expand_fwd | expand_bwd)) ){
- reuse = 0;
- command &= ~(expand_fwd | expand_bwd);
- }
- return dtl::allocator_version_traits<allocator_type>::allocation_command
- (this->alloc(), command, limit_size, prefer_in_recvd_out_size, reuse);
- }
- size_type next_capacity(size_type additional_objects) const
- {
- return growth_factor_100()
- ( this->priv_storage(), additional_objects, allocator_traits_type::max_size(this->alloc()));
- }
- void deallocate(pointer p, size_type n)
- {
- if (p && (n > InternalBufferChars))
- this->alloc().deallocate(p, n);
- }
- void destroy(pointer p, size_type n)
- {
- value_type *raw_p = boost::movelib::to_raw_pointer(p);
- for(; n--; ++raw_p){
- allocator_traits_type::destroy( this->alloc(), raw_p);
- }
- }
- inline void destroy(pointer p)
- {
- allocator_traits_type::destroy
- ( this->alloc()
- , boost::movelib::to_raw_pointer(p)
- );
- }
- void allocate_initial_block(size_type n)
- {
- if (n <= this->max_size()) {
- if(n > InternalBufferChars){
- size_type new_cap = this->next_capacity(n);
- pointer reuse = 0;
- pointer p = this->allocation_command(allocate_new, n, new_cap, reuse);
- BOOST_ASSERT(this->is_short());
- this->construct_long();
- this->priv_long_addr(p);
- this->priv_long_size(0);
- this->priv_storage(new_cap);
- }
- }
- else{
- throw_length_error("basic_string::allocate_initial_block max_size() exceeded");
- }
- }
- inline void deallocate_block()
- { this->deallocate(this->priv_addr(), this->priv_storage()); }
- inline size_type max_size() const
- { return allocator_traits_type::max_size(this->alloc()) - 1; }
- protected:
- inline size_type priv_capacity() const
- { return this->priv_storage() - 1; }
- inline pointer priv_short_addr() const
- { return pointer_traits::pointer_to(const_cast<value_type&>(this->members_.pshort_repr()->data[0])); }
-
- #if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
- #endif
- inline pointer priv_long_addr() const
- { return this->members_.plong_repr()->start; }
- inline pointer priv_addr() const
- {
- return this->is_short()
- ? priv_short_addr()
- : priv_long_addr()
- ;
- }
- inline pointer priv_end_addr() const
- {
- return this->is_short()
- ? this->priv_short_addr() + difference_type(this->priv_short_size())
- : this->priv_long_addr() + difference_type(this->priv_long_size())
- ;
- }
- inline void priv_long_addr(pointer addr)
- { this->members_.plong_repr()->start = addr; }
- inline size_type priv_storage() const
- { return this->is_short() ? priv_short_storage() : priv_long_storage(); }
- inline size_type priv_short_storage() const
- { return InternalBufferChars; }
- inline size_type priv_long_storage() const
- { return this->members_.plong_repr()->storage; }
- inline void priv_storage(size_type storage)
- {
- if(!this->is_short())
- this->priv_long_storage(storage);
- }
- inline void priv_long_storage(size_type storage)
- {
- this->members_.plong_repr()->storage = storage;
- }
- inline size_type priv_size() const
- { return this->is_short() ? this->priv_short_size() : this->priv_long_size(); }
- inline size_type priv_short_size() const
- { return this->members_.pshort_repr()->h.length; }
- inline size_type priv_long_size() const
- { return this->members_.plong_repr()->length; }
- inline void priv_size(size_type sz)
- {
- if(this->is_short())
- this->priv_short_size(sz);
- else
- this->priv_long_size(sz);
- }
- inline void priv_short_size(size_type sz)
- {
- typedef unsigned char uchar_type;
- BOOST_STATIC_CONSTEXPR uchar_type mask = uchar_type(uchar_type(-1) >> 1U);
- BOOST_ASSERT( sz <= mask );
-
- this->members_.pshort_repr()->h.length = uchar_type(uchar_type(sz) & mask);
- }
- inline void priv_long_size(size_type sz)
- {
- BOOST_STATIC_CONSTEXPR size_type mask = size_type(-1) >> 1U;
- BOOST_ASSERT( sz <= mask );
-
- this->members_.plong_repr()->length = sz & mask;
- }
- #if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
- #pragma GCC diagnostic pop
- #endif
- void swap_data(basic_string_base& other)
- {
- if(this->is_short()){
- if(other.is_short()){
- repr_t tmp(this->members_.m_repr);
- this->members_.m_repr = other.members_.m_repr;
- other.members_.m_repr = tmp;
- }
- else{
- short_t short_backup(*this->members_.pshort_repr());
- this->members_.pshort_repr()->~short_t();
- ::new(this->members_.plong_repr()) long_t(*other.members_.plong_repr());
- other.members_.plong_repr()->~long_t();
- ::new(other.members_.pshort_repr()) short_t(short_backup);
- }
- }
- else{
- if(other.is_short()){
- short_t short_backup(*other.members_.pshort_repr());
- other.members_.pshort_repr()->~short_t();
- ::new(other.members_.plong_repr()) long_t(*this->members_.plong_repr());
- this->members_.plong_repr()->~long_t();
- ::new(this->members_.pshort_repr()) short_t(short_backup);
- }
- else{
- boost::adl_move_swap(*this->members_.plong_repr(), *other.members_.plong_repr());
- }
- }
- }
- };
- }
- #endif
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- template <class CharT, class Traits = std::char_traits<CharT>, class Allocator = void >
- #else
- template <class CharT, class Traits, class Allocator>
- #endif
- class basic_string
- : private dtl::basic_string_base<typename real_allocator<CharT, Allocator>::type>
- {
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- private:
- BOOST_COPYABLE_AND_MOVABLE(basic_string)
- typedef dtl::basic_string_base<typename real_allocator<CharT, Allocator>::type> base_t;
- typedef typename base_t::allocator_traits_type allocator_traits_type;
- BOOST_STATIC_CONSTEXPR typename base_t::size_type InternalBufferChars = base_t::InternalBufferChars;
- protected:
-
- template <class Tr>
- struct Eq_traits
- {
-
- typedef typename Tr::char_type first_argument_type;
- typedef typename Tr::char_type second_argument_type;
- typedef bool result_type;
- bool operator()(const first_argument_type& x, const second_argument_type& y) const
- { return Tr::eq(x, y); }
- };
- template <class Tr>
- struct Not_within_traits
- {
- typedef typename Tr::char_type argument_type;
- typedef bool result_type;
- typedef const typename Tr::char_type* Pointer;
- const Pointer m_first;
- const Pointer m_last;
- Not_within_traits(Pointer f, Pointer l)
- : m_first(f), m_last(l) {}
- bool operator()(const typename Tr::char_type& x) const
- {
- return boost::container::find_if(m_first, m_last,
- boost::container::bind1st(Eq_traits<Tr>(), x)) == m_last;
- }
- };
- #endif
- public:
-
-
-
-
-
- typedef Traits traits_type;
- typedef CharT value_type;
- typedef typename real_allocator<CharT, Allocator>::type allocator_type;
- typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
- typedef typename ::boost::container::allocator_traits<allocator_type>::const_pointer const_pointer;
- typedef typename ::boost::container::allocator_traits<allocator_type>::reference reference;
- typedef typename ::boost::container::allocator_traits<allocator_type>::const_reference const_reference;
- typedef typename ::boost::container::allocator_traits<allocator_type>::size_type size_type;
- typedef typename ::boost::container::allocator_traits<allocator_type>::difference_type difference_type;
- typedef BOOST_CONTAINER_IMPDEF(allocator_type) stored_allocator_type;
- typedef BOOST_CONTAINER_IMPDEF(pointer) iterator;
- typedef BOOST_CONTAINER_IMPDEF(const_pointer) const_iterator;
- typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator;
- typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
- BOOST_STATIC_CONSTEXPR size_type npos = size_type(-1);
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- private:
- typedef constant_iterator<CharT> cvalue_iterator;
- typedef typename base_t::alloc_version alloc_version;
- typedef ::boost::intrusive::pointer_traits<pointer> pointer_traits;
- #endif
- public:
-
-
-
-
-
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- struct reserve_t {};
- basic_string(reserve_t, size_type n,
- const allocator_type& a = allocator_type())
-
-
- : base_t( allocator_traits_type::select_on_container_copy_construction(a)
- , n + 1)
- { this->priv_terminate_string(); }
- #endif
-
-
-
- basic_string() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<allocator_type>::value)
- : base_t()
- { this->priv_terminate_string(); }
-
-
-
- explicit basic_string(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW
- : base_t(a)
- { this->priv_terminate_string(); }
-
-
-
-
-
- basic_string(const basic_string& s)
- : base_t(allocator_traits_type::select_on_container_copy_construction(s.alloc()))
- {
- this->priv_terminate_string();
- this->assign(s.begin(), s.end());
- }
-
-
-
- template<template <class, class> class BasicStringView>
- explicit basic_string(BasicStringView<CharT, Traits> sv, const allocator_type& a = allocator_type())
- : base_t(allocator_traits_type::select_on_container_copy_construction(a))
- {
- this->priv_terminate_string();
- this->assign(sv);
- }
-
-
-
-
-
- basic_string(BOOST_RV_REF(basic_string) s) BOOST_NOEXCEPT_OR_NOTHROW
- : base_t(boost::move(s.alloc()))
- {
- if(s.alloc() == this->alloc()){
- this->swap_data(s);
- }
- else{
- this->assign(s.begin(), s.end());
- }
- }
-
-
-
-
-
- basic_string(const basic_string& s, const allocator_type &a)
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(s.begin(), s.end());
- }
-
-
-
-
-
-
- basic_string(BOOST_RV_REF(basic_string) s, const allocator_type &a)
- : base_t(a)
- {
- this->priv_terminate_string();
- if(s.alloc() == this->alloc()){
- this->swap_data(s);
- }
- else{
- this->assign(s.begin(), s.end());
- }
- }
-
-
- basic_string(const basic_string& s, size_type pos, size_type n = npos)
- : base_t()
- {
- this->priv_terminate_string();
- if (pos > s.size())
- throw_out_of_range("basic_string::basic_string out of range position");
- else
- this->assign
- (s.begin() + pos, s.begin() + pos + dtl::min_value(n, s.size() - pos));
- }
-
-
- basic_string(const basic_string& s, size_type pos, size_type n, const allocator_type& a)
- : base_t(a)
- {
- this->priv_terminate_string();
- if (pos > s.size())
- throw_out_of_range("basic_string::basic_string out of range position");
- else
- this->assign
- (s.begin() + pos, s.begin() + pos + dtl::min_value(n, s.size() - pos));
- }
-
-
- basic_string(const CharT* s, size_type n)
- : base_t()
- {
- this->priv_terminate_string();
- this->assign(s, s + difference_type(n));
- }
-
-
- basic_string(const CharT* s, size_type n, const allocator_type& a)
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(s, s + difference_type(n));
- }
-
-
- basic_string(const CharT* s)
- : base_t()
- {
- this->priv_terminate_string();
- this->assign(s, s + Traits::length(s));
- }
-
-
- basic_string(const CharT* s, const allocator_type& a)
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(s, s + Traits::length(s));
- }
-
-
- basic_string(size_type n, CharT c)
- : base_t()
- {
- this->priv_terminate_string();
- this->assign(n, c);
- }
-
-
- basic_string(size_type n, CharT c, const allocator_type& a)
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(n, c);
- }
-
-
- basic_string(size_type n, default_init_t)
- : base_t(n + 1)
- {
- this->priv_size(n);
- this->priv_terminate_string();
- }
-
-
- basic_string(size_type n, default_init_t, const allocator_type& a)
- : base_t(a, n + 1)
- {
- this->priv_size(n);
- this->priv_terminate_string();
- }
-
-
- template <class InputIterator>
- basic_string(InputIterator f, InputIterator l)
- : base_t()
- {
- this->priv_terminate_string();
- this->assign(f, l);
- }
-
-
- template <class InputIterator>
- basic_string(InputIterator f, InputIterator l, const allocator_type& a)
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(f, l);
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
- basic_string(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
- : base_t(a)
- {
- this->priv_terminate_string();
- this->assign(il.begin(), il.end());
- }
- #endif
-
-
-
-
-
- ~basic_string() BOOST_NOEXCEPT_OR_NOTHROW
- {}
-
-
-
-
-
- basic_string& operator=(BOOST_COPY_ASSIGN_REF(basic_string) x)
- {
- if (BOOST_LIKELY(this != &x)) {
- allocator_type &this_alloc = this->alloc();
- const allocator_type &x_alloc = x.alloc();
- dtl::bool_<allocator_traits_type::
- propagate_on_container_copy_assignment::value> flag;
- if(flag && this_alloc != x_alloc){
- if(!this->is_short()){
- this->deallocate_block();
- this->assure_short();
- Traits::assign(*this->priv_addr(), CharT(0));
- this->priv_short_size(0);
- }
- }
- dtl::assign_alloc(this->alloc(), x.alloc(), flag);
- this->assign(x.begin(), x.end());
- }
- return *this;
- }
-
-
-
-
-
-
-
-
- basic_string& operator=(BOOST_RV_REF(basic_string) x)
- BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
- || allocator_traits_type::is_always_equal::value)
- {
- if (BOOST_LIKELY(this != &x)) {
-
-
- const bool can_steal_resources_alloc
- = allocator_traits_type::propagate_on_container_move_assignment::value
- || allocator_traits_type::is_always_equal::value;
- dtl::bool_<can_steal_resources_alloc> flag;
- this->priv_move_assign(boost::move(x), flag);
- }
- return *this;
- }
-
-
- basic_string& operator=(const CharT* s)
- { return this->assign(s, s + Traits::length(s)); }
-
-
- basic_string& operator=(CharT c)
- { return this->assign(static_cast<size_type>(1), c); }
-
-
- template<template <class, class> class BasicStringView>
- basic_string& operator=(BasicStringView<CharT, Traits> sv)
- { return this->assign(sv.data(), sv.size()); }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
- basic_string& operator=(std::initializer_list<CharT> il)
- {
- return this->assign(il.begin(), il.end());
- }
- #endif
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->alloc(); }
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
- { return this->alloc(); }
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->alloc(); }
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_addr(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_addr(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- iterator end() BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_end_addr(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_end_addr(); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
- { return reverse_iterator(this->priv_end_addr()); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->crbegin(); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
- { return reverse_iterator(this->priv_addr()); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->crend(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_addr(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_end_addr(); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
- { return const_reverse_iterator(this->priv_end_addr()); }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
- { return const_reverse_iterator(this->priv_addr()); }
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
- { return !this->priv_size(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_size(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type length() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->size(); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
- { return base_t::max_size(); }
-
-
-
-
-
-
- void resize(size_type n, CharT c)
- {
- if (n <= this->size())
- this->erase(this->begin() + difference_type(n), this->end());
- else
- this->append(n - this->size(), c);
- }
-
-
-
-
-
-
- void resize(size_type n)
- { resize(n, CharT()); }
-
-
-
-
-
-
-
-
- void resize(size_type n, default_init_t)
- {
- if (n <= this->size())
- this->erase(this->begin() + difference_type(n), this->end());
- else{
- this->priv_reserve_no_null_end(n);
- this->priv_size(n);
- this->priv_terminate_string();
- }
- }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->priv_capacity(); }
-
-
-
-
-
-
- void reserve(size_type res_arg)
- { this->priv_reserve(res_arg); }
-
-
-
-
-
-
- void shrink_to_fit()
- {
-
- if(this->priv_storage() > InternalBufferChars){
-
-
- if(this->priv_size() < InternalBufferChars){
-
- pointer long_addr = this->priv_long_addr();
- size_type long_storage = this->priv_long_storage();
- size_type long_size = this->priv_long_size();
-
- Traits::copy( boost::movelib::to_raw_pointer(this->priv_short_addr())
- , boost::movelib::to_raw_pointer(long_addr)
- , long_size+1);
- BOOST_ASSERT(!this->is_short());
- this->destroy_long();
- this->construct_short();
- this->alloc().deallocate(long_addr, long_storage);
- }
- else{
-
- this->priv_shrink_to_fit_dynamic_buffer(alloc_version());
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference front() BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(!this->empty());
- return *this->priv_addr();
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(!this->empty());
- return *this->priv_addr();
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference back() BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(!this->empty());
- return *(this->priv_addr() + (this->size() - 1u) );
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(!this->empty());
- return *(this->priv_addr() + (this->size() - 1u) );
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference operator[](size_type n) BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(this->size() > n);
- return *(this->priv_addr() + difference_type(n));
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference operator[](size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(this->size() > n);
- return *(this->priv_addr() + difference_type(n));
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- reference at(size_type n)
- {
- if (n >= this->size())
- throw_out_of_range("basic_string::at invalid subscript");
- return *(this->priv_addr() + difference_type(n));
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const_reference at(size_type n) const {
- if (n >= this->size())
- throw_out_of_range("basic_string::at invalid subscript");
- return *(this->priv_addr() + difference_type(n));
- }
-
-
-
-
-
-
-
-
- basic_string& operator+=(const basic_string& s)
- { return this->append(s); }
-
-
- template<template<class, class> class BasicStringView>
- basic_string& operator+=(BasicStringView<CharT, Traits> sv)
- {
- return this->append(sv);
- }
-
-
-
- basic_string& operator+=(const CharT* s)
- { return this->append(s); }
-
-
-
- basic_string& operator+=(CharT c)
- { this->push_back(c); return *this; }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
- basic_string& operator+=(std::initializer_list<CharT> il)
- {
- return this->append(il);
- }
- #endif
-
-
-
- basic_string& append(const basic_string& s)
- { return this->append(s.begin(), s.end()); }
-
-
- template<template<class, class> class BasicStringView>
- basic_string& append(BasicStringView<CharT, Traits> sv)
- { return this->append(sv.data(), sv.size()); }
-
-
-
-
-
-
-
-
- basic_string& append(const basic_string& s, size_type pos, size_type n = npos)
- {
- if (pos > s.size())
- throw_out_of_range("basic_string::append out of range position");
- return this->append(s.begin() + pos,
- s.begin() + pos + dtl::min_value(n, s.size() - pos));
- }
-
-
-
-
-
-
-
-
-
-
- basic_string& append(const CharT* s, size_type n)
- { return this->append(s, s + difference_type(n)); }
-
-
-
-
-
- basic_string& append(const CharT* s)
- { return this->append(s, s + Traits::length(s)); }
-
-
-
- basic_string& append(size_type n, CharT c)
- { return this->append(cvalue_iterator(c, n), cvalue_iterator()); }
-
-
-
-
-
- template <class InputIter>
- basic_string& append(InputIter first, InputIter last)
- { this->insert(this->end(), first, last); return *this; }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
- basic_string& append(std::initializer_list<CharT> il)
- {
- return this->append(il.begin(), il.size());
- }
- #endif
-
-
- void push_back(CharT c)
- {
- const size_type old_size = this->priv_size();
- if (old_size < this->capacity()){
- const pointer addr = this->priv_addr();
- this->priv_construct_null(addr + difference_type(old_size + 1u));
- Traits::assign(addr[difference_type(old_size)], c);
- this->priv_size(old_size+1u);
- }
- else{
-
- this->append(size_type(1), c);
- }
- }
-
-
-
- basic_string& assign(const basic_string& s)
- { return this->operator=(s); }
-
-
-
- template<template <class, class> class BasicStringView>
- basic_string& assign(BasicStringView<CharT, Traits> sv)
- { return this->operator=(sv); }
-
-
-
-
-
-
-
- basic_string& assign(BOOST_RV_REF(basic_string) ms) BOOST_NOEXCEPT_OR_NOTHROW
- { return this->swap_data(ms), *this; }
-
-
-
-
-
-
-
-
- basic_string& assign(const basic_string& s, size_type pos, size_type n)
- {
- if (pos > s.size())
- throw_out_of_range("basic_string::assign out of range position");
- return this->assign(s.begin() + pos,
- s.begin() + pos + dtl::min_value(n, s.size() - pos));
- }
-
-
-
-
-
-
-
-
- basic_string& assign(const CharT* s, size_type n)
- { return this->assign(s, s + difference_type(n)); }
-
-
-
-
-
- basic_string& assign(const CharT* s)
- { return this->assign(s, s + Traits::length(s)); }
-
-
-
- basic_string& assign(size_type n, CharT c)
- { return this->assign(cvalue_iterator(c, n), cvalue_iterator()); }
-
-
-
- basic_string& assign(const CharT* first, const CharT* last)
- {
- size_type n = static_cast<size_type>(last - first);
- this->reserve(n);
- CharT* ptr = boost::movelib::to_raw_pointer(this->priv_addr());
- Traits::copy(ptr, first, n);
- this->priv_construct_null(ptr + difference_type(n));
- this->priv_size(n);
- return *this;
- }
-
-
-
- template <class InputIter>
- basic_string& assign(InputIter first, InputIter last
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- , typename dtl::disable_if_convertible<InputIter, size_type>::type * = 0
- #endif
- )
- {
- size_type cur = 0;
- const pointer addr = this->priv_addr();
- CharT *ptr = boost::movelib::to_raw_pointer(addr);
- const size_type old_size = this->priv_size();
- while (first != last && cur != old_size) {
- Traits::assign(*ptr, *first);
- ++first;
- ++cur;
- ++ptr;
- }
- if (first == last)
- this->erase(addr + difference_type(cur), addr + difference_type(old_size));
- else
- this->append(first, last);
- return *this;
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
- basic_string& assign(std::initializer_list<CharT> il)
- {
- return this->assign(il.begin(), il.size());
- }
- #endif
-
-
-
-
-
-
-
- basic_string& insert(size_type pos, const basic_string& s)
- {
- const size_type sz = this->size();
- if (pos > sz)
- throw_out_of_range("basic_string::insert out of range position");
- if (sz > this->max_size() - s.size())
- throw_length_error("basic_string::insert max_size() exceeded");
- this->insert(this->priv_addr() + pos, s.begin(), s.end());
- return *this;
- }
-
-
-
-
-
-
-
-
- basic_string& insert(size_type pos1, const basic_string& s, size_type pos2, size_type n = npos)
- {
- const size_type sz = this->size();
- const size_type str_size = s.size();
- if (pos1 > sz || pos2 > str_size)
- throw_out_of_range("basic_string::insert out of range position");
- size_type len = dtl::min_value(n, str_size - pos2);
- if (sz > this->max_size() - len)
- throw_length_error("basic_string::insert max_size() exceeded");
- const CharT *beg_ptr = boost::movelib::to_raw_pointer(s.begin()) + pos2;
- const CharT *end_ptr = beg_ptr + len;
- this->insert(this->priv_addr() + pos1, beg_ptr, end_ptr);
- return *this;
- }
-
-
-
-
-
-
-
-
-
-
-
- basic_string& insert(size_type pos, const CharT* s, size_type n)
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::insert out of range position");
- if (this->size() > this->max_size() - n)
- throw_length_error("basic_string::insert max_size() exceeded");
- this->insert(this->priv_addr() + pos, s, s + difference_type(n));
- return *this;
- }
-
-
-
-
-
-
-
-
- basic_string& insert(size_type pos, const CharT* s)
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::insert out of range position");
- size_type len = Traits::length(s);
- if (this->size() > this->max_size() - len)
- throw_length_error("basic_string::insert max_size() exceeded");
- this->insert(this->priv_addr() + pos, s, s + len);
- return *this;
- }
-
-
-
-
-
-
- basic_string& insert(size_type pos, size_type n, CharT c)
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::insert out of range position");
- if (this->size() > this->max_size() - n)
- throw_length_error("basic_string::insert max_size() exceeded");
- this->insert(const_iterator(this->priv_addr() + pos), n, c);
- return *this;
- }
-
-
- template<template<class, class> class BasicStringView>
- basic_string& insert(size_type pos, BasicStringView<CharT, Traits> sv)
- { return this->insert(pos, sv.data(), sv.size()); }
-
-
-
-
-
- iterator insert(const_iterator p, CharT c)
- {
- size_type new_offset = size_type(p - this->priv_addr());
- this->insert(p, cvalue_iterator(c, 1), cvalue_iterator());
- return this->priv_addr() + new_offset;
- }
-
-
-
-
-
- iterator insert(const_iterator p, size_type n, CharT c)
- { return this->insert(p, cvalue_iterator(c, n), cvalue_iterator()); }
-
-
-
-
-
- template <class InputIter>
- iterator insert(const_iterator p, InputIter first, InputIter last
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- , typename dtl::disable_if_or
- < void
- , dtl::is_convertible<InputIter, size_type>
- , dtl::is_not_input_iterator<InputIter>
- >::type * = 0
- #endif
- )
- {
- const size_type n_pos = p - this->cbegin();
- for ( ; first != last; ++first, ++p) {
- p = this->insert(p, *first);
- }
- return this->begin() + difference_type(n_pos);
- }
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <class ForwardIter>
- iterator insert(const_iterator p, ForwardIter first, ForwardIter last
- , typename dtl::disable_if_or
- < void
- , dtl::is_convertible<ForwardIter, size_type>
- , dtl::is_input_iterator<ForwardIter>
- >::type * = 0
- )
- {
- const size_type n_pos = size_type(p - this->cbegin());
- if (first != last) {
- const size_type n = boost::container::iterator_udistance(first, last);
- const size_type old_size = this->priv_size();
- const size_type remaining = this->capacity() - old_size;
- const pointer old_start = this->priv_addr();
- bool enough_capacity = false;
- size_type new_cap = 0;
-
- pointer hint = pointer();
- pointer allocation_ret = pointer();
- if (remaining >= n){
- enough_capacity = true;
- }
- else {
-
- new_cap = this->next_capacity(n);
- hint = old_start;
- allocation_ret = this->allocation_command
- (allocate_new | expand_fwd | expand_bwd, old_size + n + 1u, new_cap, hint);
-
- if(old_start == allocation_ret){
- enough_capacity = true;
- this->priv_storage(new_cap);
- }
- }
-
- if(enough_capacity){
- const size_type elems_after = old_size - size_type(p - old_start);
- const size_type old_length = old_size;
- size_type new_size = 0;
- if (elems_after >= n) {
- const pointer pointer_past_last = old_start + difference_type(old_size + 1u);
- priv_uninitialized_copy(old_start + difference_type(old_size - n + 1u),
- pointer_past_last, pointer_past_last);
- Traits::move(const_cast<CharT*>(boost::movelib::to_raw_pointer(p + difference_type(n))),
- boost::movelib::to_raw_pointer(p),
- (elems_after - n) + 1u);
- (priv_copy)(first, last, const_cast<CharT*>(boost::movelib::to_raw_pointer(p)));
- new_size = old_size + n;
- }
- else {
- ForwardIter mid = first;
- boost::container::iterator_uadvance(mid, elems_after + 1u);
- priv_uninitialized_copy(mid, last, old_start + difference_type(old_size + 1u));
- const size_type newer_size = old_size + (n - elems_after);
- this->priv_size(newer_size);
- priv_uninitialized_copy
- (p, const_iterator(old_start + difference_type(old_length + 1u)),
- old_start + difference_type(newer_size));
- (priv_copy)(first, mid, const_cast<CharT*>(boost::movelib::to_raw_pointer(p)));
- new_size = newer_size + elems_after;
- }
- this->priv_size(new_size);
- this->priv_construct_null(old_start + difference_type(new_size));
- }
- else{
- pointer new_start = allocation_ret;
- if(!hint){
-
- size_type new_length = 0;
-
- new_length += priv_uninitialized_copy
- (const_iterator(old_start), p, new_start);
- new_length += priv_uninitialized_copy
- (first, last, new_start + difference_type(new_length));
- new_length += priv_uninitialized_copy
- (p, const_iterator(old_start + difference_type(old_size)),
- new_start + difference_type(new_length));
- this->priv_construct_null(new_start + difference_type(new_length));
- this->deallocate_block();
- this->assure_long();
- this->priv_long_addr(new_start);
- this->priv_long_size(new_length);
- this->priv_long_storage(new_cap);
- }
- else{
-
-
- value_type * const oldbuf = boost::movelib::to_raw_pointer(old_start);
- value_type * const newbuf = boost::movelib::to_raw_pointer(new_start);
- const value_type *const pos = boost::movelib::to_raw_pointer(p);
- const size_type before = size_type(pos - oldbuf);
-
- Traits::move(newbuf, oldbuf, before);
- Traits::move(newbuf + difference_type(before + n), pos, old_size - before);
-
- priv_uninitialized_copy(first, last, new_start + difference_type(before));
- this->priv_construct_null(new_start + difference_type(old_size + n));
- this->assure_long();
- this->priv_long_addr(new_start);
- this->priv_long_size(old_size + n);
- this->priv_long_storage(new_cap);
- }
- }
- }
- return this->begin() + difference_type(n_pos);
- }
- #endif
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
-
-
- inline iterator insert(const_iterator p, std::initializer_list<CharT> il)
- {
- return this->insert(p, il.begin(), il.end());
- }
- #endif
-
-
-
-
-
- void pop_back() BOOST_NOEXCEPT_OR_NOTHROW
- {
- BOOST_ASSERT(!this->empty());
- iterator p = this->end();
- this->erase(--p);
- }
-
-
-
-
-
-
-
-
-
-
-
- basic_string& erase(size_type pos = 0, size_type n = npos)
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::erase out of range position");
- const pointer addr = this->priv_addr();
- erase(addr + difference_type(pos), addr + difference_type(pos) + dtl::min_value(n, this->size() - pos));
- return *this;
- }
-
-
-
-
-
-
- iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
- {
-
- CharT * const ptr = const_cast<CharT*>(boost::movelib::to_raw_pointer(p));
- const size_type old_size = this->priv_size();
- Traits::move(ptr,
- boost::movelib::to_raw_pointer(p + 1),
- old_size - size_type(p - this->priv_addr()));
- this->priv_size(old_size-1u);
- return iterator(ptr);
- }
-
-
-
-
-
-
-
-
- iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
- {
- CharT * f = const_cast<CharT*>(boost::movelib::to_raw_pointer(first));
- if (first != last) {
- const size_type num_erased = size_type(last - first);
- const size_type old_size = this->priv_size();
- Traits::move(f,
- boost::movelib::to_raw_pointer(last),
- old_size + 1u - size_type(last - this->priv_addr()));
- const size_type new_length = old_size - num_erased;
- this->priv_size(new_length);
- }
- return iterator(f);
- }
-
-
-
-
-
- void clear() BOOST_NOEXCEPT_OR_NOTHROW
- {
- if(this->is_short()) {
- Traits::assign(*this->priv_short_addr(), CharT(0));
- this->priv_short_size(0);
- }
- else {
- Traits::assign(*this->priv_long_addr(), CharT(0));
- this->priv_long_size(0);
- }
- }
-
-
-
-
-
-
-
- basic_string& replace(size_type pos1, size_type n1, const basic_string& str)
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::replace out of range position");
- const size_type len = dtl::min_value(n1, this->size() - pos1);
- if (this->size() - len >= this->max_size() - str.size())
- throw_length_error("basic_string::replace max_size() exceeded");
- const pointer addr = this->priv_addr();
- return this->replace( const_iterator(addr + difference_type(pos1))
- , const_iterator(addr + difference_type(pos1 + len))
- , str.begin(), str.end());
- }
-
-
- template<template<class, class> class BasicStringView>
- inline basic_string& replace(size_type pos1, size_type n1, BasicStringView<CharT, Traits> sv)
- {
- return this->replace(pos1, n1, sv.data(), sv.size());
- }
-
-
-
-
-
-
-
-
-
- basic_string& replace(size_type pos1, size_type n1,
- const basic_string& str, size_type pos2, size_type n2 = npos)
- {
- if (pos2 > str.size())
- throw_out_of_range("basic_string::replace out of range position");
- return this->replace(pos1, n1, str.data()+pos2, dtl::min_value(n2, str.size() - pos2));
- }
-
-
-
-
-
-
- template<template<class, class> class BasicStringView>
- basic_string& replace(size_type pos1, size_type n1, BasicStringView<CharT, Traits> sv,
- size_type pos2, size_type n2 = npos)
- {
- if (pos2 > sv.size())
- throw_out_of_range("basic_string::replace out of range position");
- return this->replace(pos1, n1, sv.data()+pos2, dtl::min_value(n2, sv.size() - pos2));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- basic_string& replace(size_type pos1, size_type n1, const CharT* s, size_type n2)
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::replace out of range position");
- const size_type len = dtl::min_value(n1, this->size() - pos1);
- const size_type max_sz = this->max_size();
- if (n2 > max_sz || (this->size() - len) >= (max_sz - n2))
- throw_length_error("basic_string::replace max_size() exceeded");
- const pointer addr = this->priv_addr() + pos1;
- return this->replace(addr, addr + difference_type(len), s, s + difference_type(n2));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- inline basic_string& replace(size_type pos, size_type n1, const CharT* s)
- {
- return this->replace(pos, n1, s, Traits::length(s));
- }
-
-
-
-
-
-
-
-
- basic_string& replace(size_type pos1, size_type n1, size_type n2, CharT c)
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::replace out of range position");
- const size_type len = dtl::min_value(n1, this->size() - pos1);
- if (n2 > this->max_size() || this->size() - len >= this->max_size() - n2)
- throw_length_error("basic_string::replace max_size() exceeded");
- const pointer addr = this->priv_addr();
- return this->replace(addr + difference_type(pos1), addr + difference_type(pos1 + len), n2, c);
- }
-
-
-
-
-
-
-
- inline basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str)
- { return this->replace(i1, i2, str.data(), str.data()+str.size()); }
-
-
-
-
-
-
-
-
- inline basic_string& replace(const_iterator i1, const_iterator i2, const CharT* s, size_type n)
- { return this->replace(i1, i2, s, s + difference_type(n)); }
-
-
-
-
-
-
-
-
- inline basic_string& replace(const_iterator i1, const_iterator i2, const CharT* s)
- { return this->replace(i1, i2, s, s + Traits::length(s)); }
-
-
-
-
-
-
-
- basic_string& replace(const_iterator i1, const_iterator i2, size_type n, CharT c)
- {
- const size_type len = static_cast<size_type>(i2 - i1);
- if (len >= n) {
- Traits::assign(const_cast<CharT*>(boost::movelib::to_raw_pointer(i1)), n, c);
- erase(i1 + difference_type(n), i2);
- }
- else {
- Traits::assign(const_cast<CharT*>(boost::movelib::to_raw_pointer(i1)), len, c);
- insert(i2, n - len, c);
- }
- return *this;
- }
-
-
-
-
-
-
-
- template <class InputIter>
- basic_string& replace(const_iterator i1, const_iterator i2, InputIter j1, InputIter j2
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- , typename dtl::disable_if_or
- < void
- , dtl::is_convertible<InputIter, size_type>
- , dtl::is_input_iterator<InputIter>
- >::type * = 0
- #endif
- )
- {
- for ( ; i1 != i2 && j1 != j2; ++i1, ++j1){
- Traits::assign(*const_cast<CharT*>(boost::movelib::to_raw_pointer(i1)), *j1);
- }
- if (j1 == j2)
- this->erase(i1, i2);
- else
- this->insert(i2, j1, j2);
- return *this;
- }
- #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- template <class ForwardIter>
- basic_string& replace(const_iterator i1, const_iterator i2, ForwardIter j1, ForwardIter j2
- , typename dtl::disable_if_or
- < void
- , dtl::is_convertible<ForwardIter, size_type>
- , dtl::is_not_input_iterator<ForwardIter>
- >::type * = 0
- )
- {
- difference_type n = boost::container::iterator_distance(j1, j2);
- const difference_type len = i2 - i1;
- if (len >= n) {
- this->priv_copy(j1, j2, const_cast<CharT*>(boost::movelib::to_raw_pointer(i1)));
- this->erase(i1 + difference_type(n), i2);
- }
- else {
- ForwardIter m = j1;
- boost::container::iterator_advance(m, len);
- this->priv_copy(j1, m, const_cast<CharT*>(boost::movelib::to_raw_pointer(i1)));
- this->insert(i2, m, j2);
- }
- return *this;
- }
- #endif
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- inline basic_string& replace(const_iterator i1, const_iterator i2, BasicStringView<CharT, Traits> sv)
- {
- return this->replace( static_cast<size_type>(i1 - this->cbegin())
- , static_cast<size_type>(i2 - i1), sv);
- }
- #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
-
-
-
-
-
- inline basic_string& replace(const_iterator i1, const_iterator i2, std::initializer_list<CharT> il)
- {
- return this->replace( static_cast<size_type>(i1 - this->cbegin())
- , static_cast<size_type>(i2 - i1)
- , il.begin(), il.size());
- }
- #endif
-
-
-
-
-
-
-
-
-
-
-
- size_type copy(CharT* s, size_type n, size_type pos = 0) const
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::copy out of range position");
- const size_type len = dtl::min_value(n, this->size() - pos);
- Traits::copy(s, boost::movelib::to_raw_pointer(this->priv_addr() + pos), len);
- return len;
- }
-
-
-
-
- void swap(basic_string& x)
- BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
- || allocator_traits_type::is_always_equal::value)
- {
- this->base_t::swap_data(x);
- dtl::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;
- dtl::swap_alloc(this->alloc(), x.alloc(), flag);
- }
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const CharT* c_str() const BOOST_NOEXCEPT_OR_NOTHROW
- { return boost::movelib::to_raw_pointer(this->priv_addr()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- const CharT* data() const BOOST_NOEXCEPT_OR_NOTHROW
- { return boost::movelib::to_raw_pointer(this->priv_addr()); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- CharT* data() BOOST_NOEXCEPT_OR_NOTHROW
- { return boost::movelib::to_raw_pointer(this->priv_addr()); }
- #ifndef BOOST_CONTAINER_TEMPLATED_CONVERSION_OPERATOR_BROKEN
-
-
-
- template<template <class, class> class BasicStringView>
- inline operator BasicStringView<CharT, Traits>() const BOOST_NOEXCEPT_OR_NOTHROW
- { return this->to_view< BasicStringView<CharT, Traits> >(); }
- #endif
-
-
-
-
-
-
- template<class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- BasicStringView to_view() const BOOST_NOEXCEPT_OR_NOTHROW
- { return BasicStringView(this->data(), this->size()); }
-
-
-
-
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find(const basic_string& s, size_type pos = 0) const
- { return find(s.c_str(), pos, s.size()); }
-
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find(BasicStringView<CharT, Traits> sv, size_type pos = 0) const
- { return this->find(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find(const CharT* s, size_type pos, size_type n) const
- {
- if (pos + n > this->size())
- return npos;
- else {
- const pointer addr = this->priv_addr();
- pointer finish = addr + difference_type(this->priv_size());
- const const_iterator result =
- boost::container::search(boost::movelib::to_raw_pointer(addr + difference_type(pos)),
- boost::movelib::to_raw_pointer(finish),
- s, s + difference_type(n), Eq_traits<Traits>());
- return result != finish ? size_type(result - begin()) : npos;
- }
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find(const CharT* s, size_type pos = 0) const
- { return this->find(s, pos, Traits::length(s)); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find(CharT c, size_type pos = 0) const
- {
- const size_type sz = this->size();
- if (pos >= sz)
- return npos;
- else {
- const pointer addr = this->priv_addr();
- pointer finish = addr + difference_type(sz);
- const const_iterator result =
- boost::container::find_if(addr + difference_type(pos), finish,
- boost::container::bind2nd(Eq_traits<Traits>(), c));
- return result != finish ? size_type(result - begin()) : npos;
- }
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type rfind(const basic_string& str, size_type pos = npos) const
- { return this->rfind(str.c_str(), pos, str.size()); }
-
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type rfind(BasicStringView<CharT, Traits> sv, size_type pos = npos) const
- { return this->rfind(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type rfind(const CharT* s, size_type pos, size_type n) const
- {
- const size_type len = this->size();
- if (n > len)
- return npos;
- else if (n == 0)
- return dtl::min_value(len, pos);
- else {
- const const_iterator last = begin() + difference_type(dtl::min_value(len - n, pos) + n);
- const const_iterator result = boost::container::find_end
- (begin(), last, s, s + difference_type(n), Eq_traits<Traits>());
- return result != last ? size_type(result - begin()) : npos;
- }
- }
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type rfind(const CharT* s, size_type pos = npos) const
- { return this->rfind(s, pos, Traits::length(s)); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type rfind(CharT c, size_type pos = npos) const
- {
- const size_type len = this->size();
- if (len < 1)
- return npos;
- else {
- const const_iterator last = begin() + dtl::min_value(len - 1, pos) + 1;
- const_reverse_iterator rresult =
- boost::container::find_if(const_reverse_iterator(last), rend(),
- boost::container::bind2nd(Eq_traits<Traits>(), c));
- return rresult != rend() ? size_type((rresult.base() - 1) - begin()) : npos;
- }
- }
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_of(const basic_string& str, size_type pos = 0) const
- { return this->find_first_of(str.c_str(), pos, str.size()); }
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_of(BasicStringView<CharT, Traits> sv, size_type pos = 0) const
- { return this->find_first_of(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_of(const CharT* s, size_type pos, size_type n) const
- {
- const size_type sz = this->size();
- if (pos >= sz)
- return npos;
- else {
- const pointer addr = this->priv_addr();
- pointer finish = addr + difference_type(sz);
- const_iterator result = boost::container::find_first_of
- (addr + difference_type(pos), finish, s, s + difference_type(n), Eq_traits<Traits>());
- return result != finish ? size_type(result - this->begin()) : npos;
- }
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_of(const CharT* s, size_type pos = 0) const
- { return this->find_first_of(s, pos, Traits::length(s)); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_of(CharT c, size_type pos = 0) const
- { return this->find(c, pos); }
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_of(const basic_string& str, size_type pos = npos) const
- { return this->find_last_of(str.c_str(), pos, str.size()); }
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_of(BasicStringView<CharT, Traits> sv, size_type pos = npos) const
- { return this->find_last_of(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_of(const CharT* s, size_type pos, size_type n) const
- {
- const size_type len = this->size();
- if (len < 1)
- return npos;
- else {
- const pointer addr = this->priv_addr();
- const const_iterator last = addr + difference_type(dtl::min_value(len - 1, pos) + 1);
- const const_reverse_iterator rresult =
- boost::container::find_first_of(const_reverse_iterator(last), rend(),
- s, s + difference_type(n), Eq_traits<Traits>());
- return rresult != rend() ? size_type((rresult.base() - 1) - addr) : npos;
- }
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_of(const CharT* s, size_type pos = npos) const
- { return this->find_last_of(s, pos, Traits::length(s)); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_of(CharT c, size_type pos = npos) const
- { return this->rfind(c, pos); }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_not_of(const basic_string& str, size_type pos = 0) const
- { return this->find_first_not_of(str.c_str(), pos, str.size()); }
-
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_not_of(BasicStringView<CharT, Traits> sv, size_type pos = 0) const
- { return this->find_first_not_of(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_not_of(const CharT* s, size_type pos, size_type n) const
- {
- if (pos > this->size())
- return npos;
- else {
- const pointer addr = this->priv_addr();
- const pointer finish = addr + difference_type(this->priv_size());
- const const_iterator result = boost::container::find_if
- (addr + difference_type(pos), finish, Not_within_traits<Traits>(s, s + difference_type(n)));
- return result != finish ? size_type(result - addr) : npos;
- }
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_not_of(const CharT* s, size_type pos = 0) const
- { return this->find_first_not_of(s, pos, Traits::length(s)); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_first_not_of(CharT c, size_type pos = 0) const
- {
- if (pos > this->size())
- return npos;
- else {
- const pointer addr = this->priv_addr();
- const pointer finish = addr + difference_type(this->priv_size());
- const const_iterator result
- = boost::container::find_if(addr + difference_type(pos), finish,
- boost::container::not1(boost::container::bind2nd(Eq_traits<Traits>(), c)));
- return result != finish ? size_type(result - begin()) : npos;
- }
- }
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_not_of(const basic_string& str, size_type pos = npos) const
- { return this->find_last_not_of(str.c_str(), pos, str.size()); }
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_not_of(BasicStringView<CharT, Traits> sv, size_type pos = npos) const
- { return this->find_last_not_of(sv.data(), pos, sv.size()); }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_not_of(const CharT* s, size_type pos, size_type n) const
- {
- const size_type len = this->size();
- if (len < 1)
- return npos;
- else {
- const const_iterator last = begin() + dtl::min_value(len - 1, pos) + 1;
- const const_reverse_iterator rresult =
- boost::container::find_if(const_reverse_iterator(last), rend(),
- Not_within_traits<Traits>(s, s + difference_type(n)));
- return rresult != rend() ? size_type((rresult.base() - 1) - begin()) : npos;
- }
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_not_of(const CharT* s, size_type pos = npos) const
- { return this->find_last_not_of(s, pos, Traits::length(s)); }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- size_type find_last_not_of(CharT c, size_type pos = npos) const
- {
- const size_type len = this->size();
- if (len < 1)
- return npos;
- else {
- const const_iterator last = begin() + dtl::min_value(len - 1, pos) + 1;
- const const_reverse_iterator rresult =
- boost::container::find_if(const_reverse_iterator(last), rend(),
- boost::container::not1(boost::container::bind2nd(Eq_traits<Traits>(), c)));
- return rresult != rend() ? size_type((rresult.base() - 1) - begin()) : npos;
- }
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- basic_string substr(size_type pos = 0, size_type n = npos) const
- {
- if (pos > this->size())
- throw_out_of_range("basic_string::substr out of range position");
- const pointer addr = this->priv_addr();
- return basic_string(addr + difference_type(pos),
- addr + difference_type(pos + dtl::min_value(n, size() - pos)), this->alloc());
- }
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(const basic_string& str) const
- {
- const pointer addr = this->priv_addr();
- const pointer str_addr = str.priv_addr();
- return this->s_compare(addr, addr + difference_type(this->priv_size()), str_addr, str_addr + difference_type(str.priv_size()));
- }
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(BasicStringView<CharT,Traits> sv) const
- {
- const pointer addr = this->priv_addr();
- return this->s_compare(addr, addr + difference_type(this->priv_size()), sv.data(), sv.data() + difference_type(sv.size()));
- }
-
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, const basic_string& str) const
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::compare out of range position");
- const pointer addr = this->priv_addr();
- const pointer str_addr = str.priv_addr();
- return this->s_compare(addr + difference_type(pos1),
- addr + difference_type(pos1 + dtl::min_value(n1, this->size() - pos1)),
- str_addr, str_addr + difference_type(str.priv_size()));
- }
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, BasicStringView<CharT,Traits> sv) const
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::compare out of range position");
- const pointer addr = this->priv_addr() + pos1;
- const CharT* str_addr = sv.data();
- return this->s_compare(addr, addr + difference_type(dtl::min_value(n1, this->size() - pos1)),
- str_addr, str_addr + sv.size());
- }
-
-
-
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const
- {
- if (pos1 > this->size() || pos2 > str.size())
- throw_out_of_range("basic_string::compare out of range position");
- const pointer addr = this->priv_addr() + pos1;
- const pointer str_addr = str.priv_addr() + pos2;
- return this->s_compare(addr, addr + difference_type(dtl::min_value(n1, this->size() - pos1)),
- str_addr, str_addr + difference_type(dtl::min_value(n2, str.size() - pos2)));
- }
-
-
-
-
-
-
-
-
- template<template <class, class> class BasicStringView>
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, BasicStringView<CharT,Traits> sv, size_type pos2, size_type n2) const
- {
- if (pos1 > this->size() || pos2 > sv.size())
- throw_out_of_range("basic_string::compare out of range position");
- const pointer addr = this->priv_addr() + pos1;
- const CharT * str_addr = sv.data() + pos2;
- return this->s_compare(addr, addr + difference_type(dtl::min_value(n1, this->size() - pos1)),
- str_addr, str_addr + difference_type(dtl::min_value(n2, sv.size() - pos2)));
- }
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(const CharT* s) const
- {
- const pointer addr = this->priv_addr();
- return this->s_compare(addr, addr + difference_type(this->priv_size()), s, s + Traits::length(s));
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, const CharT* s, size_type n2) const
- {
- if (pos1 > this->size())
- throw_out_of_range("basic_string::compare out of range position");
- const pointer addr = this->priv_addr();
- return this->s_compare( addr + difference_type(pos1),
- addr + difference_type(pos1 + dtl::min_value(n1, this->size() - pos1)),
- s, s + difference_type(n2));
- }
-
-
-
-
-
- BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
- int compare(size_type pos1, size_type n1, const CharT* s) const
- { return this->compare(pos1, n1, s, Traits::length(s)); }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- private:
- void priv_move_assign(BOOST_RV_REF(basic_string) x, dtl::bool_<true> )
- {
-
- this->clear();
-
- dtl::bool_<allocator_traits_type::
- propagate_on_container_move_assignment::value> flag;
- dtl::move_alloc(this->alloc(), x.alloc(), flag);
-
- this->swap_data(x);
- }
- void priv_move_assign(BOOST_RV_REF(basic_string) x, dtl::bool_<false> )
- {
-
-
- if (this->alloc() == x.alloc()) {
- this->priv_move_assign(boost::move(x), dtl::true_());
- }
- else {
- this->assign(x.begin(), x.end());
- }
- }
- bool priv_reserve_no_null_end(size_type res_arg)
- {
- if (res_arg > this->max_size()){
- throw_length_error("basic_string::reserve max_size() exceeded");
- }
- const bool do_alloc = this->capacity() < res_arg;
- if (do_alloc){
-
- size_type n = res_arg + 1;
- size_type new_cap = this->next_capacity(n);
- pointer reuse = 0;
- pointer new_start = this->allocation_command(allocate_new, n, new_cap, reuse);
- const pointer addr = this->priv_addr();
- size_type new_length = priv_uninitialized_copy
- (addr, addr + difference_type(this->priv_size()), new_start);
- this->deallocate_block();
- this->assure_long();
- this->priv_long_addr(new_start);
- this->priv_long_size(new_length);
- this->priv_storage(new_cap);
- }
- return do_alloc;
- }
- void priv_reserve(size_type res_arg)
- {
- if(this->priv_reserve_no_null_end(res_arg))
- this->priv_terminate_string();
- }
- template<class It1, class It2>
- static int s_compare(It1 f1, It1 l1, It2 f2, It2 l2)
- {
- const std::size_t n1 = std::size_t(l1 - f1);
- const std::size_t n2 = std::size_t(l2 - f2);
- const int cmp = Traits::compare(boost::movelib::to_raw_pointer(f1),
- boost::movelib::to_raw_pointer(f2),
- dtl::min_value(n1, n2));
- return cmp != 0 ? cmp : (n1 < n2 ? -1 : (n1 > n2 ? 1 : 0));
- }
- template<class AllocVersion>
- void priv_shrink_to_fit_dynamic_buffer
- ( AllocVersion
- , typename dtl::enable_if<dtl::is_same<AllocVersion, version_1> >::type* = 0)
- {
-
- size_type real_cap = 0;
- const pointer long_addr = this->priv_long_addr();
- const size_type long_size = this->priv_long_size();
- const size_type long_storage = this->priv_long_storage();
-
- BOOST_CONTAINER_TRY{
- pointer reuse = 0;
- real_cap = long_size+1;
- const pointer ret = this->allocation_command(allocate_new, long_size+1, real_cap, reuse);
-
- Traits::copy( boost::movelib::to_raw_pointer(ret)
- , boost::movelib::to_raw_pointer(this->priv_long_addr())
- , long_size+1);
- this->priv_long_addr(ret);
- this->priv_storage(real_cap);
-
- this->alloc().deallocate(long_addr, long_storage);
- }
- BOOST_CONTAINER_CATCH(...){
- return;
- }
- BOOST_CONTAINER_CATCH_END
- }
- template<class AllocVersion>
- void priv_shrink_to_fit_dynamic_buffer
- ( AllocVersion
- , typename dtl::enable_if<dtl::is_same<AllocVersion, version_2> >::type* = 0)
- {
- size_type received_size = this->priv_long_size()+1;
- pointer hint = this->priv_long_addr();
- if(this->alloc().allocation_command
- ( shrink_in_place | nothrow_allocation, this->priv_long_storage(), received_size, hint)){
- this->priv_storage(received_size);
- }
- }
- inline void priv_construct_null(pointer p)
- { traits_type::assign(*p, CharT()); }
-
-
- inline void priv_terminate_string()
- { this->priv_construct_null(this->priv_end_addr()); }
- template<class InpIt, class FwdIt> inline
- size_type priv_uninitialized_copy(InpIt first, InpIt last, FwdIt dest)
- {
-
- size_type constructed = 0;
- for (; first != last; ++dest, ++first, ++constructed){
- traits_type::assign(*dest, *first);
- }
- return constructed;
- }
- template <class InputIterator, class OutIterator>
- static void priv_copy(InputIterator first, InputIterator last, OutIterator result)
- {
- for ( ; first != last; ++first, ++result)
- Traits::assign(*result, *first);
- }
- static inline void priv_copy(const CharT* first, const CharT* last, CharT* result)
- { Traits::copy(result, first, std::size_t(last - first)); }
- template <class Integer>
- inline basic_string& priv_replace_dispatch(const_iterator first, const_iterator last,
- Integer n, Integer x,
- dtl::true_)
- { return this->replace(first, last, (size_type) n, (CharT) x); }
- template <class InputIter>
- inline basic_string& priv_replace_dispatch(const_iterator first, const_iterator last,
- InputIter f, InputIter l,
- dtl::false_)
- {
- typedef typename boost::container::iterator_traits<InputIter>::iterator_category Category;
- return this->priv_replace(first, last, f, l, Category());
- }
- #endif
- };
- #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
- template <typename InputIterator>
- basic_string(InputIterator, InputIterator) ->
- basic_string<typename iterator_traits<InputIterator>::value_type>;
- template <typename InputIterator, typename Allocator>
- basic_string(InputIterator, InputIterator, Allocator const&) ->
- basic_string<typename iterator_traits<InputIterator>::value_type, Allocator>;
- #endif
- #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
- typedef basic_string
- <char
- ,std::char_traits<char>
- ,new_allocator<char> >
- string;
- typedef basic_string
- <wchar_t
- ,std::char_traits<wchar_t>
- ,new_allocator<wchar_t> >
- wstring;
- #else
- template<class S>
- struct is_string
- {
- BOOST_STATIC_CONSTEXPR bool value = false;
- };
- template<class C, class T, class A>
- struct is_string< basic_string<C, T, A> >
- {
- BOOST_STATIC_CONSTEXPR bool value = true;
- };
- #endif
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT,Traits,Allocator>
- operator+(const basic_string<CharT,Traits,Allocator>& x
- ,const basic_string<CharT,Traits,Allocator>& y)
- {
- typedef basic_string<CharT,Traits,Allocator> str_t;
- typedef typename str_t::reserve_t reserve_t;
- reserve_t reserve;
- str_t result(reserve, x.size() + y.size(), x.get_stored_allocator());
- result.append(x);
- result.append(y);
- return result;
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT, Traits, Allocator> operator+
- ( BOOST_RV_REF_BEG basic_string<CharT, Traits, Allocator> BOOST_RV_REF_END x
- , BOOST_RV_REF_BEG basic_string<CharT, Traits, Allocator> BOOST_RV_REF_END y)
- {
- x += y;
- return boost::move(x);
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT, Traits, Allocator> operator+
- ( BOOST_RV_REF_BEG basic_string<CharT, Traits, Allocator> BOOST_RV_REF_END x
- , const basic_string<CharT,Traits,Allocator>& y)
- {
- x += y;
- return boost::move(x);
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT, Traits, Allocator> operator+
- (const basic_string<CharT,Traits,Allocator>& x
- ,BOOST_RV_REF_BEG basic_string<CharT, Traits, Allocator> BOOST_RV_REF_END y)
- {
- y.insert(y.begin(), x.begin(), x.end());
- return boost::move(y);
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT, Traits, Allocator> operator+
- (const CharT* s, basic_string<CharT, Traits, Allocator> y)
- {
- y.insert(y.begin(), s, s + Traits::length(s));
- return y;
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT,Traits,Allocator> operator+
- (basic_string<CharT,Traits,Allocator> x, const CharT* s)
- {
- x += s;
- return x;
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT,Traits,Allocator> operator+
- (CharT c, basic_string<CharT,Traits,Allocator> y)
- {
- y.insert(y.begin(), c);
- return y;
- }
- template <class CharT, class Traits, class Allocator> inline
- basic_string<CharT,Traits,Allocator> operator+
- (basic_string<CharT,Traits,Allocator> x, const CharT c)
- {
- x += c;
- return x;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator==(const basic_string<CharT,Traits,Allocator>& x, const basic_string<CharT,Traits,Allocator>& y)
- {
- return x.size() == y.size() &&
- Traits::compare(x.data(), y.data(), x.size()) == 0;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator==(const CharT* s, const basic_string<CharT,Traits,Allocator>& y)
- {
- typename basic_string<CharT,Traits,Allocator>::size_type n = Traits::length(s);
- return n == y.size() && Traits::compare(s, y.data(), n) == 0;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator==(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- {
- typename basic_string<CharT,Traits,Allocator>::size_type n = Traits::length(s);
- return x.size() == n && Traits::compare(x.data(), s, n) == 0;
- }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator==( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- {
- return x.size() == y.size() &&
- Traits::compare(x.data(), y.data(), x.size()) == 0;
- }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator==( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- {
- return x.size() == y.size() &&
- Traits::compare(x.data(), y.data(), x.size()) == 0;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator!=(const basic_string<CharT,Traits,Allocator>& x, const basic_string<CharT,Traits,Allocator>& y)
- { return !(x == y); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator!=(const CharT* s, const basic_string<CharT,Traits,Allocator>& y)
- { return !(s == y); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator!=(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- { return !(x == s); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator!=( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- { return !(x == y); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator!=( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- { return !(x == y); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<(const basic_string<CharT,Traits,Allocator>& x, const basic_string<CharT,Traits,Allocator>& y)
- {
- return x.compare(y) < 0;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<(const CharT* s, const basic_string<CharT,Traits,Allocator>& y)
- {
- return y.compare(s) > 0;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- {
- return x.compare(s) < 0;
- }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator<( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- { return y.compare(x) > 0; }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator<( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- { return x.compare(y) < 0; }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>(const basic_string<CharT,Traits,Allocator>& x, const basic_string<CharT,Traits,Allocator>& y) {
- return y < x;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>(const CharT* s, const basic_string<CharT,Traits,Allocator>& y) {
- return y < s;
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- {
- return s < x;
- }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator>( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- { return y < x; }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator>( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- { return y < x; }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<=(const basic_string<CharT,Traits,Allocator>& x, const basic_string<CharT,Traits,Allocator>& y)
- {
- return !(y < x);
- }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<=(const CharT* s, const basic_string<CharT,Traits,Allocator>& y)
- { return !(y < s); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator<=(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- { return !(s < x); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator<=( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- { return !(y < x); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator<=( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- { return !(y < x); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>=(const basic_string<CharT,Traits,Allocator>& x,
- const basic_string<CharT,Traits,Allocator>& y)
- { return !(x < y); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>=(const CharT* s, const basic_string<CharT,Traits,Allocator>& y)
- { return !(s < y); }
- template <class CharT, class Traits, class Allocator>
- inline bool
- operator>=(const basic_string<CharT,Traits,Allocator>& x, const CharT* s)
- { return !(x < s); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator>=( BasicStringView<CharT,Traits> x, const basic_string<CharT,Traits,Allocator>& y)
- { return !(x < y); }
- template <class CharT, class Traits, class Allocator, template <class, class> class BasicStringView>
- inline
- BOOST_CONTAINER_DOC1ST( bool,
- typename dtl::disable_if
- <is_string< BasicStringView<CharT BOOST_MOVE_I Traits> > BOOST_MOVE_I bool >::type)
- operator>=( const basic_string<CharT,Traits,Allocator>& x, BasicStringView<CharT,Traits> y)
- { return !(x < y); }
- template <class CharT, class Traits, class Allocator>
- inline void swap(basic_string<CharT,Traits,Allocator>& x, basic_string<CharT,Traits,Allocator>& y)
- BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
- { x.swap(y); }
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- namespace dtl {
- template <class CharT, class Traits>
- inline bool
- string_fill(std::basic_ostream<CharT, Traits>& os,
- std::basic_streambuf<CharT, Traits>* buf,
- std::size_t n)
- {
- CharT f = os.fill();
- std::size_t i;
- bool ok = true;
- for (i = 0; i < n; i++)
- ok = ok && !Traits::eq_int_type(buf->sputc(f), Traits::eof());
- return ok;
- }
- }
- #endif
- template <class CharT, class Traits, class Allocator>
- std::basic_ostream<CharT, Traits>&
- operator<<(std::basic_ostream<CharT, Traits>& os, const basic_string<CharT,Traits,Allocator>& s)
- {
- typename std::basic_ostream<CharT, Traits>::sentry sentry(os);
- bool ok = false;
- if (sentry) {
- ok = true;
- typename basic_string<CharT,Traits,Allocator>::size_type n = s.size();
- typename basic_string<CharT,Traits,Allocator>::size_type pad_len = 0;
- const bool left = (os.flags() & std::ios::left) != 0;
- const std::size_t w = os.width(0);
- std::basic_streambuf<CharT, Traits>* buf = os.rdbuf();
- if (w != 0 && n < w)
- pad_len = w - n;
- if (!left)
- ok = dtl::string_fill(os, buf, pad_len);
- ok = ok &&
- buf->sputn(s.data(), std::streamsize(n)) == std::streamsize(n);
- if (left)
- ok = ok && dtl::string_fill(os, buf, pad_len);
- }
- if (!ok)
- os.setstate(std::ios_base::failbit);
- return os;
- }
- template <class CharT, class Traits, class Allocator>
- std::basic_istream<CharT, Traits>&
- operator>>(std::basic_istream<CharT, Traits>& is, basic_string<CharT,Traits,Allocator>& s)
- {
- typename std::basic_istream<CharT, Traits>::sentry sentry(is);
- if (sentry) {
- std::basic_streambuf<CharT, Traits>* buf = is.rdbuf();
- const std::ctype<CharT>& ctype = std::use_facet<std::ctype<CharT> >(is.getloc());
- s.clear();
- std::size_t n = is.width(0);
- if (n == 0)
- n = static_cast<std::size_t>(-1);
- else
- s.reserve(n);
- while (n-- > 0) {
- typename Traits::int_type c1 = buf->sbumpc();
- if (Traits::eq_int_type(c1, Traits::eof())) {
- is.setstate(std::ios_base::eofbit);
- break;
- }
- else {
- CharT c = Traits::to_char_type(c1);
- if (ctype.is(std::ctype<CharT>::space, c)) {
- if (Traits::eq_int_type(buf->sputbackc(c), Traits::eof()))
- is.setstate(std::ios_base::failbit);
- break;
- }
- else
- s.push_back(c);
- }
- }
-
- if (s.size() == 0)
- is.setstate(std::ios_base::failbit);
- }
- else
- is.setstate(std::ios_base::failbit);
- return is;
- }
- template <class CharT, class Traits, class Allocator>
- std::basic_istream<CharT, Traits>&
- getline(std::istream& is, basic_string<CharT,Traits,Allocator>& s,CharT delim)
- {
- typename basic_string<CharT,Traits,Allocator>::size_type nread = 0;
- typename std::basic_istream<CharT, Traits>::sentry sentry(is, true);
- if (sentry) {
- std::basic_streambuf<CharT, Traits>* buf = is.rdbuf();
- s.clear();
- while (nread < s.max_size()) {
- int c1 = buf->sbumpc();
- if (Traits::eq_int_type(c1, Traits::eof())) {
- is.setstate(std::ios_base::eofbit);
- break;
- }
- else {
- ++nread;
- CharT c = Traits::to_char_type(c1);
- if (!Traits::eq(c, delim))
- s.push_back(c);
- else
- break;
- }
- }
- }
- if (nread == 0 || nread >= s.max_size())
- is.setstate(std::ios_base::failbit);
- return is;
- }
- template <class CharT, class Traits, class Allocator>
- inline std::basic_istream<CharT, Traits>&
- getline(std::basic_istream<CharT, Traits>& is, basic_string<CharT,Traits,Allocator>& s)
- {
- return getline(is, s, '\n');
- }
- template <class Ch, class Allocator>
- inline std::size_t hash_value(basic_string<Ch, std::char_traits<Ch>, Allocator> const& v)
- {
- std::size_t seed = 0;
- const Ch *first = v.data();
- for(std::size_t i = 0, i_max = v.size(); i != i_max; ++i)
- {
- boost::intrusive::detail::hash_combine_size_t(seed, static_cast<std::size_t>(*first));
- ++first;
- }
- return seed;
- }
- }}
- #if defined(BOOST_GCC) && (BOOST_GCC >= 120000) && (BOOST_GCC < 130000)
- #pragma GCC diagnostic pop
- #endif
- #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
- namespace boost {
- template <class C, class T, class Allocator>
- struct has_trivial_destructor_after_move<boost::container::basic_string<C, T, Allocator> >
- {
- typedef typename boost::container::basic_string<C, T, Allocator>::allocator_type allocator_type;
- typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
- BOOST_STATIC_CONSTEXPR bool value =
- ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
- ::boost::has_trivial_destructor_after_move<pointer>::value;
- };
- }
- #endif
- #include <boost/container/detail/config_end.hpp>
- #endif
|