vstring.h 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967
  1. // Versatile string -*- C++ -*-
  2. // Copyright (C) 2005-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file ext/vstring.h
  21. * This file is a GNU extension to the Standard C++ Library.
  22. */
  23. #ifndef _VSTRING_H
  24. #define _VSTRING_H 1
  25. #pragma GCC system_header
  26. #if __cplusplus >= 201103L
  27. #include <initializer_list>
  28. #endif
  29. #include <ext/vstring_util.h>
  30. #include <ext/rc_string_base.h>
  31. #include <ext/sso_string_base.h>
  32. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  33. {
  34. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  35. /**
  36. * @class __versa_string vstring.h
  37. * @brief Template class __versa_string.
  38. * @ingroup extensions
  39. *
  40. * Data structure managing sequences of characters and
  41. * character-like objects.
  42. */
  43. template<typename _CharT, typename _Traits, typename _Alloc,
  44. template <typename, typename, typename> class _Base>
  45. class __versa_string
  46. : private _Base<_CharT, _Traits, _Alloc>
  47. {
  48. typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
  49. typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
  50. // Types:
  51. public:
  52. typedef _Traits traits_type;
  53. typedef typename _Traits::char_type value_type;
  54. typedef _Alloc allocator_type;
  55. typedef typename _CharT_alloc_type::size_type size_type;
  56. typedef typename _CharT_alloc_type::difference_type difference_type;
  57. typedef value_type& reference;
  58. typedef const value_type& const_reference;
  59. typedef typename _CharT_alloc_type::pointer pointer;
  60. typedef typename _CharT_alloc_type::const_pointer const_pointer;
  61. typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
  62. typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
  63. const_iterator;
  64. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  65. typedef std::reverse_iterator<iterator> reverse_iterator;
  66. // Data Member (public):
  67. /// Value returned by various member functions when they fail.
  68. static const size_type npos = static_cast<size_type>(-1);
  69. private:
  70. size_type
  71. _M_check(size_type __pos, const char* __s) const
  72. {
  73. if (__pos > this->size())
  74. std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
  75. "this->size() (which is %zu)"),
  76. __s, __pos, this->size());
  77. return __pos;
  78. }
  79. void
  80. _M_check_length(size_type __n1, size_type __n2, const char* __s) const
  81. {
  82. if (this->max_size() - (this->size() - __n1) < __n2)
  83. std::__throw_length_error(__N(__s));
  84. }
  85. // NB: _M_limit doesn't check for a bad __pos value.
  86. size_type
  87. _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
  88. {
  89. const bool __testoff = __off < this->size() - __pos;
  90. return __testoff ? __off : this->size() - __pos;
  91. }
  92. // True if _Rep and source do not overlap.
  93. bool
  94. _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
  95. {
  96. return (std::less<const _CharT*>()(__s, this->_M_data())
  97. || std::less<const _CharT*>()(this->_M_data()
  98. + this->size(), __s));
  99. }
  100. // For the internal use we have functions similar to `begin'/`end'
  101. // but they do not call _M_leak.
  102. iterator
  103. _M_ibegin() const _GLIBCXX_NOEXCEPT
  104. { return iterator(this->_M_data()); }
  105. iterator
  106. _M_iend() const _GLIBCXX_NOEXCEPT
  107. { return iterator(this->_M_data() + this->_M_length()); }
  108. public:
  109. // Construct/copy/destroy:
  110. // NB: We overload ctors in some cases instead of using default
  111. // arguments, per 17.4.4.4 para. 2 item 2.
  112. /**
  113. * @brief Construct an empty string using allocator @a a.
  114. */
  115. explicit
  116. __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
  117. : __vstring_base(__a) { }
  118. // NB: per LWG issue 42, semantics different from IS:
  119. /**
  120. * @brief Construct string with copy of value of @a __str.
  121. * @param __str Source string.
  122. */
  123. __versa_string(const __versa_string& __str)
  124. : __vstring_base(__str) { }
  125. #if __cplusplus >= 201103L
  126. /**
  127. * @brief String move constructor.
  128. * @param __str Source string.
  129. *
  130. * The newly-constructed %string contains the exact contents of
  131. * @a __str. The contents of @a __str are a valid, but unspecified
  132. * string.
  133. */
  134. __versa_string(__versa_string&& __str) noexcept
  135. : __vstring_base(std::move(__str)) { }
  136. /**
  137. * @brief Construct string from an initializer list.
  138. * @param __l std::initializer_list of characters.
  139. * @param __a Allocator to use (default is default allocator).
  140. */
  141. __versa_string(std::initializer_list<_CharT> __l,
  142. const _Alloc& __a = _Alloc())
  143. : __vstring_base(__l.begin(), __l.end(), __a) { }
  144. #endif
  145. /**
  146. * @brief Construct string as copy of a substring.
  147. * @param __str Source string.
  148. * @param __pos Index of first character to copy from.
  149. * @param __n Number of characters to copy (default remainder).
  150. */
  151. __versa_string(const __versa_string& __str, size_type __pos,
  152. size_type __n = npos)
  153. : __vstring_base(__str._M_data()
  154. + __str._M_check(__pos,
  155. "__versa_string::__versa_string"),
  156. __str._M_data() + __str._M_limit(__pos, __n)
  157. + __pos, _Alloc()) { }
  158. /**
  159. * @brief Construct string as copy of a substring.
  160. * @param __str Source string.
  161. * @param __pos Index of first character to copy from.
  162. * @param __n Number of characters to copy.
  163. * @param __a Allocator to use.
  164. */
  165. __versa_string(const __versa_string& __str, size_type __pos,
  166. size_type __n, const _Alloc& __a)
  167. : __vstring_base(__str._M_data()
  168. + __str._M_check(__pos,
  169. "__versa_string::__versa_string"),
  170. __str._M_data() + __str._M_limit(__pos, __n)
  171. + __pos, __a) { }
  172. /**
  173. * @brief Construct string initialized by a character array.
  174. * @param __s Source character array.
  175. * @param __n Number of characters to copy.
  176. * @param __a Allocator to use (default is default allocator).
  177. *
  178. * NB: @a __s must have at least @a __n characters, '\\0' has no special
  179. * meaning.
  180. */
  181. __versa_string(const _CharT* __s, size_type __n,
  182. const _Alloc& __a = _Alloc())
  183. : __vstring_base(__s, __s + __n, __a) { }
  184. /**
  185. * @brief Construct string as copy of a C string.
  186. * @param __s Source C string.
  187. * @param __a Allocator to use (default is default allocator).
  188. */
  189. __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
  190. : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
  191. __s + npos, __a) { }
  192. /**
  193. * @brief Construct string as multiple characters.
  194. * @param __n Number of characters.
  195. * @param __c Character to use.
  196. * @param __a Allocator to use (default is default allocator).
  197. */
  198. __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
  199. : __vstring_base(__n, __c, __a) { }
  200. /**
  201. * @brief Construct string as copy of a range.
  202. * @param __beg Start of range.
  203. * @param __end End of range.
  204. * @param __a Allocator to use (default is default allocator).
  205. */
  206. #if __cplusplus >= 201103L
  207. template<class _InputIterator,
  208. typename = std::_RequireInputIter<_InputIterator>>
  209. #else
  210. template<class _InputIterator>
  211. #endif
  212. __versa_string(_InputIterator __beg, _InputIterator __end,
  213. const _Alloc& __a = _Alloc())
  214. : __vstring_base(__beg, __end, __a) { }
  215. /**
  216. * @brief Destroy the string instance.
  217. */
  218. ~__versa_string() _GLIBCXX_NOEXCEPT { }
  219. /**
  220. * @brief Assign the value of @a str to this string.
  221. * @param __str Source string.
  222. */
  223. __versa_string&
  224. operator=(const __versa_string& __str)
  225. { return this->assign(__str); }
  226. #if __cplusplus >= 201103L
  227. /**
  228. * @brief String move assignment operator.
  229. * @param __str Source string.
  230. *
  231. * The contents of @a __str are moved into this string (without
  232. * copying). @a __str is a valid, but unspecified string.
  233. */
  234. __versa_string&
  235. operator=(__versa_string&& __str) noexcept
  236. {
  237. // NB: DR 1204.
  238. this->swap(__str);
  239. return *this;
  240. }
  241. /**
  242. * @brief Set value to string constructed from initializer list.
  243. * @param __l std::initializer_list.
  244. */
  245. __versa_string&
  246. operator=(std::initializer_list<_CharT> __l)
  247. {
  248. this->assign(__l.begin(), __l.end());
  249. return *this;
  250. }
  251. #endif
  252. /**
  253. * @brief Copy contents of @a __s into this string.
  254. * @param __s Source null-terminated string.
  255. */
  256. __versa_string&
  257. operator=(const _CharT* __s)
  258. { return this->assign(__s); }
  259. /**
  260. * @brief Set value to string of length 1.
  261. * @param __c Source character.
  262. *
  263. * Assigning to a character makes this string length 1 and
  264. * (*this)[0] == @a __c.
  265. */
  266. __versa_string&
  267. operator=(_CharT __c)
  268. {
  269. this->assign(1, __c);
  270. return *this;
  271. }
  272. // Iterators:
  273. /**
  274. * Returns a read/write iterator that points to the first character in
  275. * the %string. Unshares the string.
  276. */
  277. iterator
  278. begin() _GLIBCXX_NOEXCEPT
  279. {
  280. this->_M_leak();
  281. return iterator(this->_M_data());
  282. }
  283. /**
  284. * Returns a read-only (constant) iterator that points to the first
  285. * character in the %string.
  286. */
  287. const_iterator
  288. begin() const _GLIBCXX_NOEXCEPT
  289. { return const_iterator(this->_M_data()); }
  290. /**
  291. * Returns a read/write iterator that points one past the last
  292. * character in the %string. Unshares the string.
  293. */
  294. iterator
  295. end() _GLIBCXX_NOEXCEPT
  296. {
  297. this->_M_leak();
  298. return iterator(this->_M_data() + this->size());
  299. }
  300. /**
  301. * Returns a read-only (constant) iterator that points one past the
  302. * last character in the %string.
  303. */
  304. const_iterator
  305. end() const _GLIBCXX_NOEXCEPT
  306. { return const_iterator(this->_M_data() + this->size()); }
  307. /**
  308. * Returns a read/write reverse iterator that points to the last
  309. * character in the %string. Iteration is done in reverse element
  310. * order. Unshares the string.
  311. */
  312. reverse_iterator
  313. rbegin() _GLIBCXX_NOEXCEPT
  314. { return reverse_iterator(this->end()); }
  315. /**
  316. * Returns a read-only (constant) reverse iterator that points
  317. * to the last character in the %string. Iteration is done in
  318. * reverse element order.
  319. */
  320. const_reverse_iterator
  321. rbegin() const _GLIBCXX_NOEXCEPT
  322. { return const_reverse_iterator(this->end()); }
  323. /**
  324. * Returns a read/write reverse iterator that points to one before the
  325. * first character in the %string. Iteration is done in reverse
  326. * element order. Unshares the string.
  327. */
  328. reverse_iterator
  329. rend() _GLIBCXX_NOEXCEPT
  330. { return reverse_iterator(this->begin()); }
  331. /**
  332. * Returns a read-only (constant) reverse iterator that points
  333. * to one before the first character in the %string. Iteration
  334. * is done in reverse element order.
  335. */
  336. const_reverse_iterator
  337. rend() const _GLIBCXX_NOEXCEPT
  338. { return const_reverse_iterator(this->begin()); }
  339. #if __cplusplus >= 201103L
  340. /**
  341. * Returns a read-only (constant) iterator that points to the first
  342. * character in the %string.
  343. */
  344. const_iterator
  345. cbegin() const noexcept
  346. { return const_iterator(this->_M_data()); }
  347. /**
  348. * Returns a read-only (constant) iterator that points one past the
  349. * last character in the %string.
  350. */
  351. const_iterator
  352. cend() const noexcept
  353. { return const_iterator(this->_M_data() + this->size()); }
  354. /**
  355. * Returns a read-only (constant) reverse iterator that points
  356. * to the last character in the %string. Iteration is done in
  357. * reverse element order.
  358. */
  359. const_reverse_iterator
  360. crbegin() const noexcept
  361. { return const_reverse_iterator(this->end()); }
  362. /**
  363. * Returns a read-only (constant) reverse iterator that points
  364. * to one before the first character in the %string. Iteration
  365. * is done in reverse element order.
  366. */
  367. const_reverse_iterator
  368. crend() const noexcept
  369. { return const_reverse_iterator(this->begin()); }
  370. #endif
  371. public:
  372. // Capacity:
  373. /// Returns the number of characters in the string, not including any
  374. /// null-termination.
  375. size_type
  376. size() const _GLIBCXX_NOEXCEPT
  377. { return this->_M_length(); }
  378. /// Returns the number of characters in the string, not including any
  379. /// null-termination.
  380. size_type
  381. length() const _GLIBCXX_NOEXCEPT
  382. { return this->_M_length(); }
  383. /// Returns the size() of the largest possible %string.
  384. size_type
  385. max_size() const _GLIBCXX_NOEXCEPT
  386. { return this->_M_max_size(); }
  387. /**
  388. * @brief Resizes the %string to the specified number of characters.
  389. * @param __n Number of characters the %string should contain.
  390. * @param __c Character to fill any new elements.
  391. *
  392. * This function will %resize the %string to the specified
  393. * number of characters. If the number is smaller than the
  394. * %string's current size the %string is truncated, otherwise
  395. * the %string is extended and new elements are set to @a __c.
  396. */
  397. void
  398. resize(size_type __n, _CharT __c);
  399. /**
  400. * @brief Resizes the %string to the specified number of characters.
  401. * @param __n Number of characters the %string should contain.
  402. *
  403. * This function will resize the %string to the specified
  404. * length. If the new size is smaller than the %string's
  405. * current size the %string is truncated, otherwise the %string
  406. * is extended and new characters are default-constructed. For
  407. * basic types such as char, this means setting them to 0.
  408. */
  409. void
  410. resize(size_type __n)
  411. { this->resize(__n, _CharT()); }
  412. #if __cplusplus >= 201103L
  413. /// A non-binding request to reduce capacity() to size().
  414. void
  415. shrink_to_fit() noexcept
  416. {
  417. if (capacity() > size())
  418. {
  419. __try
  420. { this->reserve(0); }
  421. __catch(...)
  422. { }
  423. }
  424. }
  425. #endif
  426. /**
  427. * Returns the total number of characters that the %string can
  428. * hold before needing to allocate more memory.
  429. */
  430. size_type
  431. capacity() const _GLIBCXX_NOEXCEPT
  432. { return this->_M_capacity(); }
  433. /**
  434. * @brief Attempt to preallocate enough memory for specified number of
  435. * characters.
  436. * @param __res_arg Number of characters required.
  437. * @throw std::length_error If @a __res_arg exceeds @c max_size().
  438. *
  439. * This function attempts to reserve enough memory for the
  440. * %string to hold the specified number of characters. If the
  441. * number requested is more than max_size(), length_error is
  442. * thrown.
  443. *
  444. * The advantage of this function is that if optimal code is a
  445. * necessity and the user can determine the string length that
  446. * will be required, the user can reserve the memory in
  447. * %advance, and thus prevent a possible reallocation of memory
  448. * and copying of %string data.
  449. */
  450. void
  451. reserve(size_type __res_arg = 0)
  452. { this->_M_reserve(__res_arg); }
  453. /**
  454. * Erases the string, making it empty.
  455. */
  456. void
  457. clear() _GLIBCXX_NOEXCEPT
  458. { this->_M_clear(); }
  459. /**
  460. * Returns true if the %string is empty. Equivalent to
  461. * <code>*this == ""</code>.
  462. */
  463. bool
  464. empty() const _GLIBCXX_NOEXCEPT
  465. { return this->size() == 0; }
  466. // Element access:
  467. /**
  468. * @brief Subscript access to the data contained in the %string.
  469. * @param __pos The index of the character to access.
  470. * @return Read-only (constant) reference to the character.
  471. *
  472. * This operator allows for easy, array-style, data access.
  473. * Note that data access with this operator is unchecked and
  474. * out_of_range lookups are not defined. (For checked lookups
  475. * see at().)
  476. */
  477. const_reference
  478. operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
  479. {
  480. __glibcxx_assert(__pos <= this->size());
  481. return this->_M_data()[__pos];
  482. }
  483. /**
  484. * @brief Subscript access to the data contained in the %string.
  485. * @param __pos The index of the character to access.
  486. * @return Read/write reference to the character.
  487. *
  488. * This operator allows for easy, array-style, data access.
  489. * Note that data access with this operator is unchecked and
  490. * out_of_range lookups are not defined. (For checked lookups
  491. * see at().) Unshares the string.
  492. */
  493. reference
  494. operator[](size_type __pos) _GLIBCXX_NOEXCEPT
  495. {
  496. // Allow pos == size() both in C++98 mode, as v3 extension,
  497. // and in C++11 mode.
  498. __glibcxx_assert(__pos <= this->size());
  499. // In pedantic mode be strict in C++98 mode.
  500. _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L
  501. || __pos < this->size());
  502. this->_M_leak();
  503. return this->_M_data()[__pos];
  504. }
  505. /**
  506. * @brief Provides access to the data contained in the %string.
  507. * @param __n The index of the character to access.
  508. * @return Read-only (const) reference to the character.
  509. * @throw std::out_of_range If @a __n is an invalid index.
  510. *
  511. * This function provides for safer data access. The parameter
  512. * is first checked that it is in the range of the string. The
  513. * function throws out_of_range if the check fails.
  514. */
  515. const_reference
  516. at(size_type __n) const
  517. {
  518. if (__n >= this->size())
  519. std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
  520. "(which is %zu) >= this->size() "
  521. "(which is %zu)"),
  522. __n, this->size());
  523. return this->_M_data()[__n];
  524. }
  525. /**
  526. * @brief Provides access to the data contained in the %string.
  527. * @param __n The index of the character to access.
  528. * @return Read/write reference to the character.
  529. * @throw std::out_of_range If @a __n is an invalid index.
  530. *
  531. * This function provides for safer data access. The parameter
  532. * is first checked that it is in the range of the string. The
  533. * function throws out_of_range if the check fails. Success
  534. * results in unsharing the string.
  535. */
  536. reference
  537. at(size_type __n)
  538. {
  539. if (__n >= this->size())
  540. std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
  541. "(which is %zu) >= this->size() "
  542. "(which is %zu)"),
  543. __n, this->size());
  544. this->_M_leak();
  545. return this->_M_data()[__n];
  546. }
  547. #if __cplusplus >= 201103L
  548. /**
  549. * Returns a read/write reference to the data at the first
  550. * element of the %string.
  551. */
  552. reference
  553. front() noexcept
  554. { return operator[](0); }
  555. /**
  556. * Returns a read-only (constant) reference to the data at the first
  557. * element of the %string.
  558. */
  559. const_reference
  560. front() const noexcept
  561. { return operator[](0); }
  562. /**
  563. * Returns a read/write reference to the data at the last
  564. * element of the %string.
  565. */
  566. reference
  567. back() noexcept
  568. { return operator[](this->size() - 1); }
  569. /**
  570. * Returns a read-only (constant) reference to the data at the
  571. * last element of the %string.
  572. */
  573. const_reference
  574. back() const noexcept
  575. { return operator[](this->size() - 1); }
  576. #endif
  577. // Modifiers:
  578. /**
  579. * @brief Append a string to this string.
  580. * @param __str The string to append.
  581. * @return Reference to this string.
  582. */
  583. __versa_string&
  584. operator+=(const __versa_string& __str)
  585. { return this->append(__str); }
  586. /**
  587. * @brief Append a C string.
  588. * @param __s The C string to append.
  589. * @return Reference to this string.
  590. */
  591. __versa_string&
  592. operator+=(const _CharT* __s)
  593. { return this->append(__s); }
  594. /**
  595. * @brief Append a character.
  596. * @param __c The character to append.
  597. * @return Reference to this string.
  598. */
  599. __versa_string&
  600. operator+=(_CharT __c)
  601. {
  602. this->push_back(__c);
  603. return *this;
  604. }
  605. #if __cplusplus >= 201103L
  606. /**
  607. * @brief Append an initializer_list of characters.
  608. * @param __l The initializer_list of characters to be appended.
  609. * @return Reference to this string.
  610. */
  611. __versa_string&
  612. operator+=(std::initializer_list<_CharT> __l)
  613. { return this->append(__l.begin(), __l.end()); }
  614. #endif // C++11
  615. /**
  616. * @brief Append a string to this string.
  617. * @param __str The string to append.
  618. * @return Reference to this string.
  619. */
  620. __versa_string&
  621. append(const __versa_string& __str)
  622. { return _M_append(__str._M_data(), __str.size()); }
  623. /**
  624. * @brief Append a substring.
  625. * @param __str The string to append.
  626. * @param __pos Index of the first character of str to append.
  627. * @param __n The number of characters to append.
  628. * @return Reference to this string.
  629. * @throw std::out_of_range if @a pos is not a valid index.
  630. *
  631. * This function appends @a __n characters from @a __str
  632. * starting at @a __pos to this string. If @a __n is is larger
  633. * than the number of available characters in @a __str, the
  634. * remainder of @a __str is appended.
  635. */
  636. __versa_string&
  637. append(const __versa_string& __str, size_type __pos, size_type __n)
  638. { return _M_append(__str._M_data()
  639. + __str._M_check(__pos, "__versa_string::append"),
  640. __str._M_limit(__pos, __n)); }
  641. /**
  642. * @brief Append a C substring.
  643. * @param __s The C string to append.
  644. * @param __n The number of characters to append.
  645. * @return Reference to this string.
  646. */
  647. __versa_string&
  648. append(const _CharT* __s, size_type __n)
  649. {
  650. __glibcxx_requires_string_len(__s, __n);
  651. _M_check_length(size_type(0), __n, "__versa_string::append");
  652. return _M_append(__s, __n);
  653. }
  654. /**
  655. * @brief Append a C string.
  656. * @param __s The C string to append.
  657. * @return Reference to this string.
  658. */
  659. __versa_string&
  660. append(const _CharT* __s)
  661. {
  662. __glibcxx_requires_string(__s);
  663. const size_type __n = traits_type::length(__s);
  664. _M_check_length(size_type(0), __n, "__versa_string::append");
  665. return _M_append(__s, __n);
  666. }
  667. /**
  668. * @brief Append multiple characters.
  669. * @param __n The number of characters to append.
  670. * @param __c The character to use.
  671. * @return Reference to this string.
  672. *
  673. * Appends n copies of c to this string.
  674. */
  675. __versa_string&
  676. append(size_type __n, _CharT __c)
  677. { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
  678. #if __cplusplus >= 201103L
  679. /**
  680. * @brief Append an initializer_list of characters.
  681. * @param __l The initializer_list of characters to append.
  682. * @return Reference to this string.
  683. */
  684. __versa_string&
  685. append(std::initializer_list<_CharT> __l)
  686. { return this->append(__l.begin(), __l.end()); }
  687. #endif // C++11
  688. /**
  689. * @brief Append a range of characters.
  690. * @param __first Iterator referencing the first character to append.
  691. * @param __last Iterator marking the end of the range.
  692. * @return Reference to this string.
  693. *
  694. * Appends characters in the range [first,last) to this string.
  695. */
  696. #if __cplusplus >= 201103L
  697. template<class _InputIterator,
  698. typename = std::_RequireInputIter<_InputIterator>>
  699. #else
  700. template<class _InputIterator>
  701. #endif
  702. __versa_string&
  703. append(_InputIterator __first, _InputIterator __last)
  704. { return this->replace(_M_iend(), _M_iend(), __first, __last); }
  705. /**
  706. * @brief Append a single character.
  707. * @param __c Character to append.
  708. */
  709. void
  710. push_back(_CharT __c)
  711. {
  712. const size_type __size = this->size();
  713. if (__size + 1 > this->capacity() || this->_M_is_shared())
  714. this->_M_mutate(__size, size_type(0), 0, size_type(1));
  715. traits_type::assign(this->_M_data()[__size], __c);
  716. this->_M_set_length(__size + 1);
  717. }
  718. /**
  719. * @brief Set value to contents of another string.
  720. * @param __str Source string to use.
  721. * @return Reference to this string.
  722. */
  723. __versa_string&
  724. assign(const __versa_string& __str)
  725. {
  726. this->_M_assign(__str);
  727. return *this;
  728. }
  729. #if __cplusplus >= 201103L
  730. /**
  731. * @brief Set value to contents of another string.
  732. * @param __str Source string to use.
  733. * @return Reference to this string.
  734. *
  735. * This function sets this string to the exact contents of @a __str.
  736. * @a __str is a valid, but unspecified string.
  737. */
  738. __versa_string&
  739. assign(__versa_string&& __str) noexcept
  740. {
  741. this->swap(__str);
  742. return *this;
  743. }
  744. #endif // C++11
  745. /**
  746. * @brief Set value to a substring of a string.
  747. * @param __str The string to use.
  748. * @param __pos Index of the first character of str.
  749. * @param __n Number of characters to use.
  750. * @return Reference to this string.
  751. * @throw std::out_of_range if @a __pos is not a valid index.
  752. *
  753. * This function sets this string to the substring of @a __str
  754. * consisting of @a __n characters at @a __pos. If @a __n is
  755. * is larger than the number of available characters in @a
  756. * __str, the remainder of @a __str is used.
  757. */
  758. __versa_string&
  759. assign(const __versa_string& __str, size_type __pos, size_type __n)
  760. { return _M_replace(size_type(0), this->size(), __str._M_data()
  761. + __str._M_check(__pos, "__versa_string::assign"),
  762. __str._M_limit(__pos, __n)); }
  763. /**
  764. * @brief Set value to a C substring.
  765. * @param __s The C string to use.
  766. * @param __n Number of characters to use.
  767. * @return Reference to this string.
  768. *
  769. * This function sets the value of this string to the first @a
  770. * __n characters of @a __s. If @a __n is is larger than the
  771. * number of available characters in @a __s, the remainder of
  772. * @a __s is used.
  773. */
  774. __versa_string&
  775. assign(const _CharT* __s, size_type __n)
  776. {
  777. __glibcxx_requires_string_len(__s, __n);
  778. return _M_replace(size_type(0), this->size(), __s, __n);
  779. }
  780. /**
  781. * @brief Set value to contents of a C string.
  782. * @param __s The C string to use.
  783. * @return Reference to this string.
  784. *
  785. * This function sets the value of this string to the value of
  786. * @a __s. The data is copied, so there is no dependence on @a
  787. * __s once the function returns.
  788. */
  789. __versa_string&
  790. assign(const _CharT* __s)
  791. {
  792. __glibcxx_requires_string(__s);
  793. return _M_replace(size_type(0), this->size(), __s,
  794. traits_type::length(__s));
  795. }
  796. /**
  797. * @brief Set value to multiple characters.
  798. * @param __n Length of the resulting string.
  799. * @param __c The character to use.
  800. * @return Reference to this string.
  801. *
  802. * This function sets the value of this string to @a __n copies of
  803. * character @a __c.
  804. */
  805. __versa_string&
  806. assign(size_type __n, _CharT __c)
  807. { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
  808. /**
  809. * @brief Set value to a range of characters.
  810. * @param __first Iterator referencing the first character to append.
  811. * @param __last Iterator marking the end of the range.
  812. * @return Reference to this string.
  813. *
  814. * Sets value of string to characters in the range
  815. * [first,last).
  816. */
  817. #if __cplusplus >= 201103L
  818. template<class _InputIterator,
  819. typename = std::_RequireInputIter<_InputIterator>>
  820. #else
  821. template<class _InputIterator>
  822. #endif
  823. __versa_string&
  824. assign(_InputIterator __first, _InputIterator __last)
  825. { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
  826. #if __cplusplus >= 201103L
  827. /**
  828. * @brief Set value to an initializer_list of characters.
  829. * @param __l The initializer_list of characters to assign.
  830. * @return Reference to this string.
  831. */
  832. __versa_string&
  833. assign(std::initializer_list<_CharT> __l)
  834. { return this->assign(__l.begin(), __l.end()); }
  835. #endif // C++11
  836. #if __cplusplus >= 201103L
  837. /**
  838. * @brief Insert multiple characters.
  839. * @param __p Const_iterator referencing location in string to
  840. * insert at.
  841. * @param __n Number of characters to insert
  842. * @param __c The character to insert.
  843. * @return Iterator referencing the first inserted char.
  844. * @throw std::length_error If new length exceeds @c max_size().
  845. *
  846. * Inserts @a __n copies of character @a __c starting at the
  847. * position referenced by iterator @a __p. If adding
  848. * characters causes the length to exceed max_size(),
  849. * length_error is thrown. The value of the string doesn't
  850. * change if an error is thrown.
  851. */
  852. iterator
  853. insert(const_iterator __p, size_type __n, _CharT __c)
  854. {
  855. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  856. const size_type __pos = __p - _M_ibegin();
  857. this->replace(__p, __p, __n, __c);
  858. return iterator(this->_M_data() + __pos);
  859. }
  860. #else
  861. /**
  862. * @brief Insert multiple characters.
  863. * @param __p Iterator referencing location in string to insert at.
  864. * @param __n Number of characters to insert
  865. * @param __c The character to insert.
  866. * @throw std::length_error If new length exceeds @c max_size().
  867. *
  868. * Inserts @a __n copies of character @a __c starting at the
  869. * position referenced by iterator @a __p. If adding
  870. * characters causes the length to exceed max_size(),
  871. * length_error is thrown. The value of the string doesn't
  872. * change if an error is thrown.
  873. */
  874. void
  875. insert(iterator __p, size_type __n, _CharT __c)
  876. { this->replace(__p, __p, __n, __c); }
  877. #endif
  878. #if __cplusplus >= 201103L
  879. /**
  880. * @brief Insert a range of characters.
  881. * @param __p Const_iterator referencing location in string to
  882. * insert at.
  883. * @param __beg Start of range.
  884. * @param __end End of range.
  885. * @return Iterator referencing the first inserted char.
  886. * @throw std::length_error If new length exceeds @c max_size().
  887. *
  888. * Inserts characters in range [beg,end). If adding characters
  889. * causes the length to exceed max_size(), length_error is
  890. * thrown. The value of the string doesn't change if an error
  891. * is thrown.
  892. */
  893. template<class _InputIterator,
  894. typename = std::_RequireInputIter<_InputIterator>>
  895. iterator
  896. insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
  897. {
  898. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  899. const size_type __pos = __p - _M_ibegin();
  900. this->replace(__p, __p, __beg, __end);
  901. return iterator(this->_M_data() + __pos);
  902. }
  903. #else
  904. /**
  905. * @brief Insert a range of characters.
  906. * @param __p Iterator referencing location in string to insert at.
  907. * @param __beg Start of range.
  908. * @param __end End of range.
  909. * @throw std::length_error If new length exceeds @c max_size().
  910. *
  911. * Inserts characters in range [beg,end). If adding characters
  912. * causes the length to exceed max_size(), length_error is
  913. * thrown. The value of the string doesn't change if an error
  914. * is thrown.
  915. */
  916. template<class _InputIterator>
  917. void
  918. insert(iterator __p, _InputIterator __beg, _InputIterator __end)
  919. { this->replace(__p, __p, __beg, __end); }
  920. #endif
  921. #if __cplusplus >= 201103L
  922. /**
  923. * @brief Insert an initializer_list of characters.
  924. * @param __p Const_iterator referencing location in string to
  925. * insert at.
  926. * @param __l The initializer_list of characters to insert.
  927. * @return Iterator referencing the first inserted char.
  928. * @throw std::length_error If new length exceeds @c max_size().
  929. */
  930. iterator
  931. insert(const_iterator __p, std::initializer_list<_CharT> __l)
  932. { return this->insert(__p, __l.begin(), __l.end()); }
  933. #endif // C++11
  934. /**
  935. * @brief Insert value of a string.
  936. * @param __pos1 Iterator referencing location in string to insert at.
  937. * @param __str The string to insert.
  938. * @return Reference to this string.
  939. * @throw std::length_error If new length exceeds @c max_size().
  940. *
  941. * Inserts value of @a __str starting at @a __pos1. If adding
  942. * characters causes the length to exceed max_size(),
  943. * length_error is thrown. The value of the string doesn't
  944. * change if an error is thrown.
  945. */
  946. __versa_string&
  947. insert(size_type __pos1, const __versa_string& __str)
  948. { return this->replace(__pos1, size_type(0),
  949. __str._M_data(), __str.size()); }
  950. /**
  951. * @brief Insert a substring.
  952. * @param __pos1 Iterator referencing location in string to insert at.
  953. * @param __str The string to insert.
  954. * @param __pos2 Start of characters in str to insert.
  955. * @param __n Number of characters to insert.
  956. * @return Reference to this string.
  957. * @throw std::length_error If new length exceeds @c max_size().
  958. * @throw std::out_of_range If @a __pos1 > size() or
  959. * @a __pos2 > @a __str.size().
  960. *
  961. * Starting at @a __pos1, insert @a __n character of @a __str
  962. * beginning with @a __pos2. If adding characters causes the
  963. * length to exceed max_size(), length_error is thrown. If @a
  964. * __pos1 is beyond the end of this string or @a __pos2 is
  965. * beyond the end of @a __str, out_of_range is thrown. The
  966. * value of the string doesn't change if an error is thrown.
  967. */
  968. __versa_string&
  969. insert(size_type __pos1, const __versa_string& __str,
  970. size_type __pos2, size_type __n)
  971. { return this->replace(__pos1, size_type(0), __str._M_data()
  972. + __str._M_check(__pos2, "__versa_string::insert"),
  973. __str._M_limit(__pos2, __n)); }
  974. /**
  975. * @brief Insert a C substring.
  976. * @param __pos Iterator referencing location in string to insert at.
  977. * @param __s The C string to insert.
  978. * @param __n The number of characters to insert.
  979. * @return Reference to this string.
  980. * @throw std::length_error If new length exceeds @c max_size().
  981. * @throw std::out_of_range If @a __pos is beyond the end of this
  982. * string.
  983. *
  984. * Inserts the first @a __n characters of @a __s starting at @a
  985. * __pos. If adding characters causes the length to exceed
  986. * max_size(), length_error is thrown. If @a __pos is beyond
  987. * end(), out_of_range is thrown. The value of the string
  988. * doesn't change if an error is thrown.
  989. */
  990. __versa_string&
  991. insert(size_type __pos, const _CharT* __s, size_type __n)
  992. { return this->replace(__pos, size_type(0), __s, __n); }
  993. /**
  994. * @brief Insert a C string.
  995. * @param __pos Iterator referencing location in string to insert at.
  996. * @param __s The C string to insert.
  997. * @return Reference to this string.
  998. * @throw std::length_error If new length exceeds @c max_size().
  999. * @throw std::out_of_range If @a __pos is beyond the end of this
  1000. * string.
  1001. *
  1002. * Inserts the first @a __n characters of @a __s starting at @a
  1003. * __pos. If adding characters causes the length to exceed
  1004. * max_size(), length_error is thrown. If @a __pos is beyond
  1005. * end(), out_of_range is thrown. The value of the string
  1006. * doesn't change if an error is thrown.
  1007. */
  1008. __versa_string&
  1009. insert(size_type __pos, const _CharT* __s)
  1010. {
  1011. __glibcxx_requires_string(__s);
  1012. return this->replace(__pos, size_type(0), __s,
  1013. traits_type::length(__s));
  1014. }
  1015. /**
  1016. * @brief Insert multiple characters.
  1017. * @param __pos Index in string to insert at.
  1018. * @param __n Number of characters to insert
  1019. * @param __c The character to insert.
  1020. * @return Reference to this string.
  1021. * @throw std::length_error If new length exceeds @c max_size().
  1022. * @throw std::out_of_range If @a __pos is beyond the end of this
  1023. * string.
  1024. *
  1025. * Inserts @a __n copies of character @a __c starting at index
  1026. * @a __pos. If adding characters causes the length to exceed
  1027. * max_size(), length_error is thrown. If @a __pos > length(),
  1028. * out_of_range is thrown. The value of the string doesn't
  1029. * change if an error is thrown.
  1030. */
  1031. __versa_string&
  1032. insert(size_type __pos, size_type __n, _CharT __c)
  1033. { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
  1034. size_type(0), __n, __c); }
  1035. /**
  1036. * @brief Insert one character.
  1037. * @param __p Iterator referencing position in string to insert at.
  1038. * @param __c The character to insert.
  1039. * @return Iterator referencing newly inserted char.
  1040. * @throw std::length_error If new length exceeds @c max_size().
  1041. *
  1042. * Inserts character @a __c at position referenced by @a __p.
  1043. * If adding character causes the length to exceed max_size(),
  1044. * length_error is thrown. If @a __p is beyond end of string,
  1045. * out_of_range is thrown. The value of the string doesn't
  1046. * change if an error is thrown.
  1047. */
  1048. iterator
  1049. #if __cplusplus >= 201103L
  1050. insert(const_iterator __p, _CharT __c)
  1051. #else
  1052. insert(iterator __p, _CharT __c)
  1053. #endif
  1054. {
  1055. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  1056. const size_type __pos = __p - _M_ibegin();
  1057. _M_replace_aux(__pos, size_type(0), size_type(1), __c);
  1058. this->_M_set_leaked();
  1059. return iterator(this->_M_data() + __pos);
  1060. }
  1061. /**
  1062. * @brief Remove characters.
  1063. * @param __pos Index of first character to remove (default 0).
  1064. * @param __n Number of characters to remove (default remainder).
  1065. * @return Reference to this string.
  1066. * @throw std::out_of_range If @a __pos is beyond the end of this
  1067. * string.
  1068. *
  1069. * Removes @a __n characters from this string starting at @a
  1070. * __pos. The length of the string is reduced by @a __n. If
  1071. * there are < @a __n characters to remove, the remainder of
  1072. * the string is truncated. If @a __p is beyond end of string,
  1073. * out_of_range is thrown. The value of the string doesn't
  1074. * change if an error is thrown.
  1075. */
  1076. __versa_string&
  1077. erase(size_type __pos = 0, size_type __n = npos)
  1078. {
  1079. this->_M_erase(_M_check(__pos, "__versa_string::erase"),
  1080. _M_limit(__pos, __n));
  1081. return *this;
  1082. }
  1083. /**
  1084. * @brief Remove one character.
  1085. * @param __position Iterator referencing the character to remove.
  1086. * @return iterator referencing same location after removal.
  1087. *
  1088. * Removes the character at @a __position from this string. The
  1089. * value of the string doesn't change if an error is thrown.
  1090. */
  1091. iterator
  1092. #if __cplusplus >= 201103L
  1093. erase(const_iterator __position)
  1094. #else
  1095. erase(iterator __position)
  1096. #endif
  1097. {
  1098. _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
  1099. && __position < _M_iend());
  1100. const size_type __pos = __position - _M_ibegin();
  1101. this->_M_erase(__pos, size_type(1));
  1102. this->_M_set_leaked();
  1103. return iterator(this->_M_data() + __pos);
  1104. }
  1105. /**
  1106. * @brief Remove a range of characters.
  1107. * @param __first Iterator referencing the first character to remove.
  1108. * @param __last Iterator referencing the end of the range.
  1109. * @return Iterator referencing location of first after removal.
  1110. *
  1111. * Removes the characters in the range [first,last) from this
  1112. * string. The value of the string doesn't change if an error
  1113. * is thrown.
  1114. */
  1115. iterator
  1116. #if __cplusplus >= 201103L
  1117. erase(const_iterator __first, const_iterator __last)
  1118. #else
  1119. erase(iterator __first, iterator __last)
  1120. #endif
  1121. {
  1122. _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
  1123. && __last <= _M_iend());
  1124. const size_type __pos = __first - _M_ibegin();
  1125. this->_M_erase(__pos, __last - __first);
  1126. this->_M_set_leaked();
  1127. return iterator(this->_M_data() + __pos);
  1128. }
  1129. #if __cplusplus >= 201103L
  1130. /**
  1131. * @brief Remove the last character.
  1132. *
  1133. * The string must be non-empty.
  1134. */
  1135. void
  1136. pop_back()
  1137. { this->_M_erase(size()-1, 1); }
  1138. #endif // C++11
  1139. /**
  1140. * @brief Replace characters with value from another string.
  1141. * @param __pos Index of first character to replace.
  1142. * @param __n Number of characters to be replaced.
  1143. * @param __str String to insert.
  1144. * @return Reference to this string.
  1145. * @throw std::out_of_range If @a __pos is beyond the end of this
  1146. * string.
  1147. * @throw std::length_error If new length exceeds @c max_size().
  1148. *
  1149. * Removes the characters in the range [pos,pos+n) from this
  1150. * string. In place, the value of @a __str is inserted. If @a
  1151. * __pos is beyond end of string, out_of_range is thrown. If
  1152. * the length of the result exceeds max_size(), length_error is
  1153. * thrown. The value of the string doesn't change if an error
  1154. * is thrown.
  1155. */
  1156. __versa_string&
  1157. replace(size_type __pos, size_type __n, const __versa_string& __str)
  1158. { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
  1159. /**
  1160. * @brief Replace characters with value from another string.
  1161. * @param __pos1 Index of first character to replace.
  1162. * @param __n1 Number of characters to be replaced.
  1163. * @param __str String to insert.
  1164. * @param __pos2 Index of first character of str to use.
  1165. * @param __n2 Number of characters from str to use.
  1166. * @return Reference to this string.
  1167. * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
  1168. * str.size().
  1169. * @throw std::length_error If new length exceeds @c max_size().
  1170. *
  1171. * Removes the characters in the range [pos1,pos1 + n) from
  1172. * this string. In place, the value of @a __str is inserted.
  1173. * If @a __pos is beyond end of string, out_of_range is thrown.
  1174. * If the length of the result exceeds max_size(), length_error
  1175. * is thrown. The value of the string doesn't change if an
  1176. * error is thrown.
  1177. */
  1178. __versa_string&
  1179. replace(size_type __pos1, size_type __n1, const __versa_string& __str,
  1180. size_type __pos2, size_type __n2)
  1181. {
  1182. return this->replace(__pos1, __n1, __str._M_data()
  1183. + __str._M_check(__pos2,
  1184. "__versa_string::replace"),
  1185. __str._M_limit(__pos2, __n2));
  1186. }
  1187. /**
  1188. * @brief Replace characters with value of a C substring.
  1189. * @param __pos Index of first character to replace.
  1190. * @param __n1 Number of characters to be replaced.
  1191. * @param __s C string to insert.
  1192. * @param __n2 Number of characters from @a __s to use.
  1193. * @return Reference to this string.
  1194. * @throw std::out_of_range If @a __pos1 > size().
  1195. * @throw std::length_error If new length exceeds @c max_size().
  1196. *
  1197. * Removes the characters in the range [pos,pos + n1) from this
  1198. * string. In place, the first @a __n2 characters of @a __s
  1199. * are inserted, or all of @a __s if @a __n2 is too large. If
  1200. * @a __pos is beyond end of string, out_of_range is thrown.
  1201. * If the length of result exceeds max_size(), length_error is
  1202. * thrown. The value of the string doesn't change if an error
  1203. * is thrown.
  1204. */
  1205. __versa_string&
  1206. replace(size_type __pos, size_type __n1, const _CharT* __s,
  1207. size_type __n2)
  1208. {
  1209. __glibcxx_requires_string_len(__s, __n2);
  1210. return _M_replace(_M_check(__pos, "__versa_string::replace"),
  1211. _M_limit(__pos, __n1), __s, __n2);
  1212. }
  1213. /**
  1214. * @brief Replace characters with value of a C string.
  1215. * @param __pos Index of first character to replace.
  1216. * @param __n1 Number of characters to be replaced.
  1217. * @param __s C string to insert.
  1218. * @return Reference to this string.
  1219. * @throw std::out_of_range If @a __pos > size().
  1220. * @throw std::length_error If new length exceeds @c max_size().
  1221. *
  1222. * Removes the characters in the range [pos,pos + n1) from this
  1223. * string. In place, the characters of @a __s are inserted. If
  1224. * @a pos is beyond end of string, out_of_range is thrown. If
  1225. * the length of result exceeds max_size(), length_error is thrown.
  1226. * The value of the string doesn't change if an error is thrown.
  1227. */
  1228. __versa_string&
  1229. replace(size_type __pos, size_type __n1, const _CharT* __s)
  1230. {
  1231. __glibcxx_requires_string(__s);
  1232. return this->replace(__pos, __n1, __s, traits_type::length(__s));
  1233. }
  1234. /**
  1235. * @brief Replace characters with multiple characters.
  1236. * @param __pos Index of first character to replace.
  1237. * @param __n1 Number of characters to be replaced.
  1238. * @param __n2 Number of characters to insert.
  1239. * @param __c Character to insert.
  1240. * @return Reference to this string.
  1241. * @throw std::out_of_range If @a __pos > size().
  1242. * @throw std::length_error If new length exceeds @c max_size().
  1243. *
  1244. * Removes the characters in the range [pos,pos + n1) from this
  1245. * string. In place, @a __n2 copies of @a __c are inserted.
  1246. * If @a __pos is beyond end of string, out_of_range is thrown.
  1247. * If the length of result exceeds max_size(), length_error is
  1248. * thrown. The value of the string doesn't change if an error
  1249. * is thrown.
  1250. */
  1251. __versa_string&
  1252. replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
  1253. { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
  1254. _M_limit(__pos, __n1), __n2, __c); }
  1255. /**
  1256. * @brief Replace range of characters with string.
  1257. * @param __i1 Iterator referencing start of range to replace.
  1258. * @param __i2 Iterator referencing end of range to replace.
  1259. * @param __str String value to insert.
  1260. * @return Reference to this string.
  1261. * @throw std::length_error If new length exceeds @c max_size().
  1262. *
  1263. * Removes the characters in the range [i1,i2). In place, the
  1264. * value of @a __str is inserted. If the length of result
  1265. * exceeds max_size(), length_error is thrown. The value of
  1266. * the string doesn't change if an error is thrown.
  1267. */
  1268. __versa_string&
  1269. #if __cplusplus >= 201103L
  1270. replace(const_iterator __i1, const_iterator __i2,
  1271. const __versa_string& __str)
  1272. #else
  1273. replace(iterator __i1, iterator __i2, const __versa_string& __str)
  1274. #endif
  1275. { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
  1276. /**
  1277. * @brief Replace range of characters with C substring.
  1278. * @param __i1 Iterator referencing start of range to replace.
  1279. * @param __i2 Iterator referencing end of range to replace.
  1280. * @param __s C string value to insert.
  1281. * @param __n Number of characters from s to insert.
  1282. * @return Reference to this string.
  1283. * @throw std::length_error If new length exceeds @c max_size().
  1284. *
  1285. * Removes the characters in the range [i1,i2). In place, the
  1286. * first @a n characters of @a __s are inserted. If the length
  1287. * of result exceeds max_size(), length_error is thrown. The
  1288. * value of the string doesn't change if an error is thrown.
  1289. */
  1290. __versa_string&
  1291. #if __cplusplus >= 201103L
  1292. replace(const_iterator __i1, const_iterator __i2,
  1293. const _CharT* __s, size_type __n)
  1294. #else
  1295. replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
  1296. #endif
  1297. {
  1298. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1299. && __i2 <= _M_iend());
  1300. return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
  1301. }
  1302. /**
  1303. * @brief Replace range of characters with C string.
  1304. * @param __i1 Iterator referencing start of range to replace.
  1305. * @param __i2 Iterator referencing end of range to replace.
  1306. * @param __s C string value to insert.
  1307. * @return Reference to this string.
  1308. * @throw std::length_error If new length exceeds @c max_size().
  1309. *
  1310. * Removes the characters in the range [i1,i2). In place, the
  1311. * characters of @a __s are inserted. If the length of result
  1312. * exceeds max_size(), length_error is thrown. The value of
  1313. * the string doesn't change if an error is thrown.
  1314. */
  1315. __versa_string&
  1316. #if __cplusplus >= 201103L
  1317. replace(const_iterator __i1, const_iterator __i2, const _CharT* __s)
  1318. #else
  1319. replace(iterator __i1, iterator __i2, const _CharT* __s)
  1320. #endif
  1321. {
  1322. __glibcxx_requires_string(__s);
  1323. return this->replace(__i1, __i2, __s, traits_type::length(__s));
  1324. }
  1325. /**
  1326. * @brief Replace range of characters with multiple characters
  1327. * @param __i1 Iterator referencing start of range to replace.
  1328. * @param __i2 Iterator referencing end of range to replace.
  1329. * @param __n Number of characters to insert.
  1330. * @param __c Character to insert.
  1331. * @return Reference to this string.
  1332. * @throw std::length_error If new length exceeds @c max_size().
  1333. *
  1334. * Removes the characters in the range [i1,i2). In place, @a
  1335. * __n copies of @a __c are inserted. If the length of result
  1336. * exceeds max_size(), length_error is thrown. The value of
  1337. * the string doesn't change if an error is thrown.
  1338. */
  1339. __versa_string&
  1340. #if __cplusplus >= 201103L
  1341. replace(const_iterator __i1, const_iterator __i2, size_type __n,
  1342. _CharT __c)
  1343. #else
  1344. replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
  1345. #endif
  1346. {
  1347. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1348. && __i2 <= _M_iend());
  1349. return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
  1350. }
  1351. /**
  1352. * @brief Replace range of characters with range.
  1353. * @param __i1 Iterator referencing start of range to replace.
  1354. * @param __i2 Iterator referencing end of range to replace.
  1355. * @param __k1 Iterator referencing start of range to insert.
  1356. * @param __k2 Iterator referencing end of range to insert.
  1357. * @return Reference to this string.
  1358. * @throw std::length_error If new length exceeds @c max_size().
  1359. *
  1360. * Removes the characters in the range [i1,i2). In place,
  1361. * characters in the range [k1,k2) are inserted. If the length
  1362. * of result exceeds max_size(), length_error is thrown. The
  1363. * value of the string doesn't change if an error is thrown.
  1364. */
  1365. #if __cplusplus >= 201103L
  1366. template<class _InputIterator,
  1367. typename = std::_RequireInputIter<_InputIterator>>
  1368. __versa_string&
  1369. replace(const_iterator __i1, const_iterator __i2,
  1370. _InputIterator __k1, _InputIterator __k2)
  1371. {
  1372. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1373. && __i2 <= _M_iend());
  1374. __glibcxx_requires_valid_range(__k1, __k2);
  1375. return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
  1376. std::__false_type());
  1377. }
  1378. #else
  1379. template<class _InputIterator>
  1380. __versa_string&
  1381. replace(iterator __i1, iterator __i2,
  1382. _InputIterator __k1, _InputIterator __k2)
  1383. {
  1384. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1385. && __i2 <= _M_iend());
  1386. __glibcxx_requires_valid_range(__k1, __k2);
  1387. typedef typename std::__is_integer<_InputIterator>::__type _Integral;
  1388. return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
  1389. }
  1390. #endif
  1391. // Specializations for the common case of pointer and iterator:
  1392. // useful to avoid the overhead of temporary buffering in _M_replace.
  1393. __versa_string&
  1394. #if __cplusplus >= 201103L
  1395. replace(const_iterator __i1, const_iterator __i2,
  1396. _CharT* __k1, _CharT* __k2)
  1397. #else
  1398. replace(iterator __i1, iterator __i2,
  1399. _CharT* __k1, _CharT* __k2)
  1400. #endif
  1401. {
  1402. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1403. && __i2 <= _M_iend());
  1404. __glibcxx_requires_valid_range(__k1, __k2);
  1405. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1406. __k1, __k2 - __k1);
  1407. }
  1408. __versa_string&
  1409. #if __cplusplus >= 201103L
  1410. replace(const_iterator __i1, const_iterator __i2,
  1411. const _CharT* __k1, const _CharT* __k2)
  1412. #else
  1413. replace(iterator __i1, iterator __i2,
  1414. const _CharT* __k1, const _CharT* __k2)
  1415. #endif
  1416. {
  1417. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1418. && __i2 <= _M_iend());
  1419. __glibcxx_requires_valid_range(__k1, __k2);
  1420. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1421. __k1, __k2 - __k1);
  1422. }
  1423. __versa_string&
  1424. #if __cplusplus >= 201103L
  1425. replace(const_iterator __i1, const_iterator __i2,
  1426. iterator __k1, iterator __k2)
  1427. #else
  1428. replace(iterator __i1, iterator __i2,
  1429. iterator __k1, iterator __k2)
  1430. #endif
  1431. {
  1432. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1433. && __i2 <= _M_iend());
  1434. __glibcxx_requires_valid_range(__k1, __k2);
  1435. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1436. __k1.base(), __k2 - __k1);
  1437. }
  1438. __versa_string&
  1439. #if __cplusplus >= 201103L
  1440. replace(const_iterator __i1, const_iterator __i2,
  1441. const_iterator __k1, const_iterator __k2)
  1442. #else
  1443. replace(iterator __i1, iterator __i2,
  1444. const_iterator __k1, const_iterator __k2)
  1445. #endif
  1446. {
  1447. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1448. && __i2 <= _M_iend());
  1449. __glibcxx_requires_valid_range(__k1, __k2);
  1450. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1451. __k1.base(), __k2 - __k1);
  1452. }
  1453. #if __cplusplus >= 201103L
  1454. /**
  1455. * @brief Replace range of characters with initializer_list.
  1456. * @param __i1 Iterator referencing start of range to replace.
  1457. * @param __i2 Iterator referencing end of range to replace.
  1458. * @param __l The initializer_list of characters to insert.
  1459. * @return Reference to this string.
  1460. * @throw std::length_error If new length exceeds @c max_size().
  1461. *
  1462. * Removes the characters in the range [i1,i2). In place,
  1463. * characters in the range [k1,k2) are inserted. If the length
  1464. * of result exceeds max_size(), length_error is thrown. The
  1465. * value of the string doesn't change if an error is thrown.
  1466. */
  1467. __versa_string&
  1468. replace(const_iterator __i1, const_iterator __i2,
  1469. std::initializer_list<_CharT> __l)
  1470. { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
  1471. #endif // C++11
  1472. private:
  1473. template<class _Integer>
  1474. __versa_string&
  1475. _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
  1476. _Integer __n, _Integer __val, std::__true_type)
  1477. { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
  1478. template<class _InputIterator>
  1479. __versa_string&
  1480. _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
  1481. _InputIterator __k1, _InputIterator __k2,
  1482. std::__false_type);
  1483. __versa_string&
  1484. _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
  1485. _CharT __c);
  1486. __versa_string&
  1487. _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
  1488. const size_type __len2);
  1489. __versa_string&
  1490. _M_append(const _CharT* __s, size_type __n);
  1491. public:
  1492. /**
  1493. * @brief Copy substring into C string.
  1494. * @param __s C string to copy value into.
  1495. * @param __n Number of characters to copy.
  1496. * @param __pos Index of first character to copy.
  1497. * @return Number of characters actually copied
  1498. * @throw std::out_of_range If pos > size().
  1499. *
  1500. * Copies up to @a __n characters starting at @a __pos into the
  1501. * C string @a s. If @a __pos is greater than size(),
  1502. * out_of_range is thrown.
  1503. */
  1504. size_type
  1505. copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
  1506. /**
  1507. * @brief Swap contents with another string.
  1508. * @param __s String to swap with.
  1509. *
  1510. * Exchanges the contents of this string with that of @a __s in
  1511. * constant time.
  1512. */
  1513. void
  1514. swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
  1515. { this->_M_swap(__s); }
  1516. // String operations:
  1517. /**
  1518. * @brief Return const pointer to null-terminated contents.
  1519. *
  1520. * This is a handle to internal data. Do not modify or dire things may
  1521. * happen.
  1522. */
  1523. const _CharT*
  1524. c_str() const _GLIBCXX_NOEXCEPT
  1525. { return this->_M_data(); }
  1526. /**
  1527. * @brief Return const pointer to contents.
  1528. *
  1529. * This is a handle to internal data. Do not modify or dire things may
  1530. * happen.
  1531. */
  1532. const _CharT*
  1533. data() const _GLIBCXX_NOEXCEPT
  1534. { return this->_M_data(); }
  1535. /**
  1536. * @brief Return copy of allocator used to construct this string.
  1537. */
  1538. allocator_type
  1539. get_allocator() const _GLIBCXX_NOEXCEPT
  1540. { return allocator_type(this->_M_get_allocator()); }
  1541. /**
  1542. * @brief Find position of a C substring.
  1543. * @param __s C string to locate.
  1544. * @param __pos Index of character to search from.
  1545. * @param __n Number of characters from @a __s to search for.
  1546. * @return Index of start of first occurrence.
  1547. *
  1548. * Starting from @a __pos, searches forward for the first @a
  1549. * __n characters in @a __s within this string. If found,
  1550. * returns the index where it begins. If not found, returns
  1551. * npos.
  1552. */
  1553. size_type
  1554. find(const _CharT* __s, size_type __pos, size_type __n) const;
  1555. /**
  1556. * @brief Find position of a string.
  1557. * @param __str String to locate.
  1558. * @param __pos Index of character to search from (default 0).
  1559. * @return Index of start of first occurrence.
  1560. *
  1561. * Starting from @a __pos, searches forward for value of @a
  1562. * __str within this string. If found, returns the index where
  1563. * it begins. If not found, returns npos.
  1564. */
  1565. size_type
  1566. find(const __versa_string& __str, size_type __pos = 0) const
  1567. _GLIBCXX_NOEXCEPT
  1568. { return this->find(__str.data(), __pos, __str.size()); }
  1569. /**
  1570. * @brief Find position of a C string.
  1571. * @param __s C string to locate.
  1572. * @param __pos Index of character to search from (default 0).
  1573. * @return Index of start of first occurrence.
  1574. *
  1575. * Starting from @a __pos, searches forward for the value of @a
  1576. * __s within this string. If found, returns the index where
  1577. * it begins. If not found, returns npos.
  1578. */
  1579. size_type
  1580. find(const _CharT* __s, size_type __pos = 0) const
  1581. {
  1582. __glibcxx_requires_string(__s);
  1583. return this->find(__s, __pos, traits_type::length(__s));
  1584. }
  1585. /**
  1586. * @brief Find position of a character.
  1587. * @param __c Character to locate.
  1588. * @param __pos Index of character to search from (default 0).
  1589. * @return Index of first occurrence.
  1590. *
  1591. * Starting from @a __pos, searches forward for @a __c within
  1592. * this string. If found, returns the index where it was
  1593. * found. If not found, returns npos.
  1594. */
  1595. size_type
  1596. find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
  1597. /**
  1598. * @brief Find last position of a string.
  1599. * @param __str String to locate.
  1600. * @param __pos Index of character to search back from (default end).
  1601. * @return Index of start of last occurrence.
  1602. *
  1603. * Starting from @a __pos, searches backward for value of @a
  1604. * __str within this string. If found, returns the index where
  1605. * it begins. If not found, returns npos.
  1606. */
  1607. size_type
  1608. rfind(const __versa_string& __str, size_type __pos = npos) const
  1609. _GLIBCXX_NOEXCEPT
  1610. { return this->rfind(__str.data(), __pos, __str.size()); }
  1611. /**
  1612. * @brief Find last position of a C substring.
  1613. * @param __s C string to locate.
  1614. * @param __pos Index of character to search back from.
  1615. * @param __n Number of characters from s to search for.
  1616. * @return Index of start of last occurrence.
  1617. *
  1618. * Starting from @a __pos, searches backward for the first @a
  1619. * __n characters in @a __s within this string. If found,
  1620. * returns the index where it begins. If not found, returns
  1621. * npos.
  1622. */
  1623. size_type
  1624. rfind(const _CharT* __s, size_type __pos, size_type __n) const;
  1625. /**
  1626. * @brief Find last position of a C string.
  1627. * @param __s C string to locate.
  1628. * @param __pos Index of character to start search at (default end).
  1629. * @return Index of start of last occurrence.
  1630. *
  1631. * Starting from @a __pos, searches backward for the value of
  1632. * @a __s within this string. If found, returns the index
  1633. * where it begins. If not found, returns npos.
  1634. */
  1635. size_type
  1636. rfind(const _CharT* __s, size_type __pos = npos) const
  1637. {
  1638. __glibcxx_requires_string(__s);
  1639. return this->rfind(__s, __pos, traits_type::length(__s));
  1640. }
  1641. /**
  1642. * @brief Find last position of a character.
  1643. * @param __c Character to locate.
  1644. * @param __pos Index of character to search back from (default end).
  1645. * @return Index of last occurrence.
  1646. *
  1647. * Starting from @a __pos, searches backward for @a __c within
  1648. * this string. If found, returns the index where it was
  1649. * found. If not found, returns npos.
  1650. */
  1651. size_type
  1652. rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
  1653. /**
  1654. * @brief Find position of a character of string.
  1655. * @param __str String containing characters to locate.
  1656. * @param __pos Index of character to search from (default 0).
  1657. * @return Index of first occurrence.
  1658. *
  1659. * Starting from @a __pos, searches forward for one of the characters of
  1660. * @a __str within this string. If found, returns the index where it was
  1661. * found. If not found, returns npos.
  1662. */
  1663. size_type
  1664. find_first_of(const __versa_string& __str, size_type __pos = 0) const
  1665. _GLIBCXX_NOEXCEPT
  1666. { return this->find_first_of(__str.data(), __pos, __str.size()); }
  1667. /**
  1668. * @brief Find position of a character of C substring.
  1669. * @param __s String containing characters to locate.
  1670. * @param __pos Index of character to search from.
  1671. * @param __n Number of characters from s to search for.
  1672. * @return Index of first occurrence.
  1673. *
  1674. * Starting from @a __pos, searches forward for one of the
  1675. * first @a __n characters of @a __s within this string. If
  1676. * found, returns the index where it was found. If not found,
  1677. * returns npos.
  1678. */
  1679. size_type
  1680. find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
  1681. /**
  1682. * @brief Find position of a character of C string.
  1683. * @param __s String containing characters to locate.
  1684. * @param __pos Index of character to search from (default 0).
  1685. * @return Index of first occurrence.
  1686. *
  1687. * Starting from @a __pos, searches forward for one of the
  1688. * characters of @a __s within this string. If found, returns
  1689. * the index where it was found. If not found, returns npos.
  1690. */
  1691. size_type
  1692. find_first_of(const _CharT* __s, size_type __pos = 0) const
  1693. {
  1694. __glibcxx_requires_string(__s);
  1695. return this->find_first_of(__s, __pos, traits_type::length(__s));
  1696. }
  1697. /**
  1698. * @brief Find position of a character.
  1699. * @param __c Character to locate.
  1700. * @param __pos Index of character to search from (default 0).
  1701. * @return Index of first occurrence.
  1702. *
  1703. * Starting from @a __pos, searches forward for the character
  1704. * @a __c within this string. If found, returns the index
  1705. * where it was found. If not found, returns npos.
  1706. *
  1707. * Note: equivalent to find(c, pos).
  1708. */
  1709. size_type
  1710. find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
  1711. { return this->find(__c, __pos); }
  1712. /**
  1713. * @brief Find last position of a character of string.
  1714. * @param __str String containing characters to locate.
  1715. * @param __pos Index of character to search back from (default end).
  1716. * @return Index of last occurrence.
  1717. *
  1718. * Starting from @a __pos, searches backward for one of the
  1719. * characters of @a __str within this string. If found,
  1720. * returns the index where it was found. If not found, returns
  1721. * npos.
  1722. */
  1723. size_type
  1724. find_last_of(const __versa_string& __str, size_type __pos = npos) const
  1725. _GLIBCXX_NOEXCEPT
  1726. { return this->find_last_of(__str.data(), __pos, __str.size()); }
  1727. /**
  1728. * @brief Find last position of a character of C substring.
  1729. * @param __s C string containing characters to locate.
  1730. * @param __pos Index of character to search back from.
  1731. * @param __n Number of characters from s to search for.
  1732. * @return Index of last occurrence.
  1733. *
  1734. * Starting from @a __pos, searches backward for one of the
  1735. * first @a __n characters of @a __s within this string. If
  1736. * found, returns the index where it was found. If not found,
  1737. * returns npos.
  1738. */
  1739. size_type
  1740. find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
  1741. /**
  1742. * @brief Find last position of a character of C string.
  1743. * @param __s C string containing characters to locate.
  1744. * @param __pos Index of character to search back from (default end).
  1745. * @return Index of last occurrence.
  1746. *
  1747. * Starting from @a __pos, searches backward for one of the
  1748. * characters of @a __s within this string. If found, returns
  1749. * the index where it was found. If not found, returns npos.
  1750. */
  1751. size_type
  1752. find_last_of(const _CharT* __s, size_type __pos = npos) const
  1753. {
  1754. __glibcxx_requires_string(__s);
  1755. return this->find_last_of(__s, __pos, traits_type::length(__s));
  1756. }
  1757. /**
  1758. * @brief Find last position of a character.
  1759. * @param __c Character to locate.
  1760. * @param __pos Index of character to search back from (default end).
  1761. * @return Index of last occurrence.
  1762. *
  1763. * Starting from @a __pos, searches backward for @a __c within
  1764. * this string. If found, returns the index where it was
  1765. * found. If not found, returns npos.
  1766. *
  1767. * Note: equivalent to rfind(c, pos).
  1768. */
  1769. size_type
  1770. find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
  1771. { return this->rfind(__c, __pos); }
  1772. /**
  1773. * @brief Find position of a character not in string.
  1774. * @param __str String containing characters to avoid.
  1775. * @param __pos Index of character to search from (default 0).
  1776. * @return Index of first occurrence.
  1777. *
  1778. * Starting from @a __pos, searches forward for a character not
  1779. * contained in @a __str within this string. If found, returns
  1780. * the index where it was found. If not found, returns npos.
  1781. */
  1782. size_type
  1783. find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
  1784. _GLIBCXX_NOEXCEPT
  1785. { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
  1786. /**
  1787. * @brief Find position of a character not in C substring.
  1788. * @param __s C string containing characters to avoid.
  1789. * @param __pos Index of character to search from.
  1790. * @param __n Number of characters from s to consider.
  1791. * @return Index of first occurrence.
  1792. *
  1793. * Starting from @a __pos, searches forward for a character not
  1794. * contained in the first @a __n characters of @a __s within
  1795. * this string. If found, returns the index where it was
  1796. * found. If not found, returns npos.
  1797. */
  1798. size_type
  1799. find_first_not_of(const _CharT* __s, size_type __pos,
  1800. size_type __n) const;
  1801. /**
  1802. * @brief Find position of a character not in C string.
  1803. * @param __s C string containing characters to avoid.
  1804. * @param __pos Index of character to search from (default 0).
  1805. * @return Index of first occurrence.
  1806. *
  1807. * Starting from @a __pos, searches forward for a character not
  1808. * contained in @a __s within this string. If found, returns
  1809. * the index where it was found. If not found, returns npos.
  1810. */
  1811. size_type
  1812. find_first_not_of(const _CharT* __s, size_type __pos = 0) const
  1813. {
  1814. __glibcxx_requires_string(__s);
  1815. return this->find_first_not_of(__s, __pos, traits_type::length(__s));
  1816. }
  1817. /**
  1818. * @brief Find position of a different character.
  1819. * @param __c Character to avoid.
  1820. * @param __pos Index of character to search from (default 0).
  1821. * @return Index of first occurrence.
  1822. *
  1823. * Starting from @a __pos, searches forward for a character
  1824. * other than @a __c within this string. If found, returns the
  1825. * index where it was found. If not found, returns npos.
  1826. */
  1827. size_type
  1828. find_first_not_of(_CharT __c, size_type __pos = 0) const
  1829. _GLIBCXX_NOEXCEPT;
  1830. /**
  1831. * @brief Find last position of a character not in string.
  1832. * @param __str String containing characters to avoid.
  1833. * @param __pos Index of character to search back from (default end).
  1834. * @return Index of last occurrence.
  1835. *
  1836. * Starting from @a __pos, searches backward for a character
  1837. * not contained in @a __str within this string. If found,
  1838. * returns the index where it was found. If not found, returns
  1839. * npos.
  1840. */
  1841. size_type
  1842. find_last_not_of(const __versa_string& __str,
  1843. size_type __pos = npos) const _GLIBCXX_NOEXCEPT
  1844. { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
  1845. /**
  1846. * @brief Find last position of a character not in C substring.
  1847. * @param __s C string containing characters to avoid.
  1848. * @param __pos Index of character to search back from.
  1849. * @param __n Number of characters from s to consider.
  1850. * @return Index of last occurrence.
  1851. *
  1852. * Starting from @a __pos, searches backward for a character
  1853. * not contained in the first @a __n characters of @a __s
  1854. * within this string. If found, returns the index where it
  1855. * was found. If not found, returns npos.
  1856. */
  1857. size_type
  1858. find_last_not_of(const _CharT* __s, size_type __pos,
  1859. size_type __n) const;
  1860. /**
  1861. * @brief Find last position of a character not in C string.
  1862. * @param __s C string containing characters to avoid.
  1863. * @param __pos Index of character to search back from (default end).
  1864. * @return Index of last occurrence.
  1865. *
  1866. * Starting from @a __pos, searches backward for a character
  1867. * not contained in @a __s within this string. If found,
  1868. * returns the index where it was found. If not found, returns
  1869. * npos.
  1870. */
  1871. size_type
  1872. find_last_not_of(const _CharT* __s, size_type __pos = npos) const
  1873. {
  1874. __glibcxx_requires_string(__s);
  1875. return this->find_last_not_of(__s, __pos, traits_type::length(__s));
  1876. }
  1877. /**
  1878. * @brief Find last position of a different character.
  1879. * @param __c Character to avoid.
  1880. * @param __pos Index of character to search back from (default end).
  1881. * @return Index of last occurrence.
  1882. *
  1883. * Starting from @a __pos, searches backward for a character
  1884. * other than @a __c within this string. If found, returns the
  1885. * index where it was found. If not found, returns npos.
  1886. */
  1887. size_type
  1888. find_last_not_of(_CharT __c, size_type __pos = npos) const
  1889. _GLIBCXX_NOEXCEPT;
  1890. /**
  1891. * @brief Get a substring.
  1892. * @param __pos Index of first character (default 0).
  1893. * @param __n Number of characters in substring (default remainder).
  1894. * @return The new string.
  1895. * @throw std::out_of_range If pos > size().
  1896. *
  1897. * Construct and return a new string using the @a __n
  1898. * characters starting at @a __pos. If the string is too
  1899. * short, use the remainder of the characters. If @a __pos is
  1900. * beyond the end of the string, out_of_range is thrown.
  1901. */
  1902. __versa_string
  1903. substr(size_type __pos = 0, size_type __n = npos) const
  1904. {
  1905. return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
  1906. __n);
  1907. }
  1908. /**
  1909. * @brief Compare to a string.
  1910. * @param __str String to compare against.
  1911. * @return Integer < 0, 0, or > 0.
  1912. *
  1913. * Returns an integer < 0 if this string is ordered before @a
  1914. * __str, 0 if their values are equivalent, or > 0 if this
  1915. * string is ordered after @a __str. Determines the effective
  1916. * length rlen of the strings to compare as the smallest of
  1917. * size() and str.size(). The function then compares the two
  1918. * strings by calling traits::compare(data(), str.data(),rlen).
  1919. * If the result of the comparison is nonzero returns it,
  1920. * otherwise the shorter one is ordered first.
  1921. */
  1922. int
  1923. compare(const __versa_string& __str) const
  1924. {
  1925. if (this->_M_compare(__str))
  1926. return 0;
  1927. const size_type __size = this->size();
  1928. const size_type __osize = __str.size();
  1929. const size_type __len = std::min(__size, __osize);
  1930. int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
  1931. if (!__r)
  1932. __r = this->_S_compare(__size, __osize);
  1933. return __r;
  1934. }
  1935. /**
  1936. * @brief Compare substring to a string.
  1937. * @param __pos Index of first character of substring.
  1938. * @param __n Number of characters in substring.
  1939. * @param __str String to compare against.
  1940. * @return Integer < 0, 0, or > 0.
  1941. *
  1942. * Form the substring of this string from the @a __n characters
  1943. * starting at @a __pos. Returns an integer < 0 if the
  1944. * substring is ordered before @a __str, 0 if their values are
  1945. * equivalent, or > 0 if the substring is ordered after @a
  1946. * __str. Determines the effective length rlen of the strings
  1947. * to compare as the smallest of the length of the substring
  1948. * and @a __str.size(). The function then compares the two
  1949. * strings by calling
  1950. * traits::compare(substring.data(),str.data(),rlen). If the
  1951. * result of the comparison is nonzero returns it, otherwise
  1952. * the shorter one is ordered first.
  1953. */
  1954. int
  1955. compare(size_type __pos, size_type __n,
  1956. const __versa_string& __str) const;
  1957. /**
  1958. * @brief Compare substring to a substring.
  1959. * @param __pos1 Index of first character of substring.
  1960. * @param __n1 Number of characters in substring.
  1961. * @param __str String to compare against.
  1962. * @param __pos2 Index of first character of substring of str.
  1963. * @param __n2 Number of characters in substring of str.
  1964. * @return Integer < 0, 0, or > 0.
  1965. *
  1966. * Form the substring of this string from the @a __n1
  1967. * characters starting at @a __pos1. Form the substring of @a
  1968. * __str from the @a __n2 characters starting at @a __pos2.
  1969. * Returns an integer < 0 if this substring is ordered before
  1970. * the substring of @a __str, 0 if their values are equivalent,
  1971. * or > 0 if this substring is ordered after the substring of
  1972. * @a __str. Determines the effective length rlen of the
  1973. * strings to compare as the smallest of the lengths of the
  1974. * substrings. The function then compares the two strings by
  1975. * calling
  1976. * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
  1977. * If the result of the comparison is nonzero returns it,
  1978. * otherwise the shorter one is ordered first.
  1979. */
  1980. int
  1981. compare(size_type __pos1, size_type __n1, const __versa_string& __str,
  1982. size_type __pos2, size_type __n2) const;
  1983. /**
  1984. * @brief Compare to a C string.
  1985. * @param __s C string to compare against.
  1986. * @return Integer < 0, 0, or > 0.
  1987. *
  1988. * Returns an integer < 0 if this string is ordered before @a
  1989. * __s, 0 if their values are equivalent, or > 0 if this string
  1990. * is ordered after @a __s. Determines the effective length
  1991. * rlen of the strings to compare as the smallest of size() and
  1992. * the length of a string constructed from @a __s. The
  1993. * function then compares the two strings by calling
  1994. * traits::compare(data(),s,rlen). If the result of the
  1995. * comparison is nonzero returns it, otherwise the shorter one
  1996. * is ordered first.
  1997. */
  1998. int
  1999. compare(const _CharT* __s) const;
  2000. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2001. // 5 String::compare specification questionable
  2002. /**
  2003. * @brief Compare substring to a C string.
  2004. * @param __pos Index of first character of substring.
  2005. * @param __n1 Number of characters in substring.
  2006. * @param __s C string to compare against.
  2007. * @return Integer < 0, 0, or > 0.
  2008. *
  2009. * Form the substring of this string from the @a __n1
  2010. * characters starting at @a __pos. Returns an integer < 0 if
  2011. * the substring is ordered before @a __s, 0 if their values
  2012. * are equivalent, or > 0 if the substring is ordered after @a
  2013. * __s. Determines the effective length rlen of the strings to
  2014. * compare as the smallest of the length of the substring and
  2015. * the length of a string constructed from @a __s. The
  2016. * function then compares the two string by calling
  2017. * traits::compare(substring.data(),s,rlen). If the result of
  2018. * the comparison is nonzero returns it, otherwise the shorter
  2019. * one is ordered first.
  2020. */
  2021. int
  2022. compare(size_type __pos, size_type __n1, const _CharT* __s) const;
  2023. /**
  2024. * @brief Compare substring against a character array.
  2025. * @param __pos Index of first character of substring.
  2026. * @param __n1 Number of characters in substring.
  2027. * @param __s character array to compare against.
  2028. * @param __n2 Number of characters of s.
  2029. * @return Integer < 0, 0, or > 0.
  2030. *
  2031. * Form the substring of this string from the @a __n1
  2032. * characters starting at @a __pos. Form a string from the
  2033. * first @a __n2 characters of @a __s. Returns an integer < 0
  2034. * if this substring is ordered before the string from @a __s,
  2035. * 0 if their values are equivalent, or > 0 if this substring
  2036. * is ordered after the string from @a __s. Determines the
  2037. * effective length rlen of the strings to compare as the
  2038. * smallest of the length of the substring and @a __n2. The
  2039. * function then compares the two strings by calling
  2040. * traits::compare(substring.data(),__s,rlen). If the result of
  2041. * the comparison is nonzero returns it, otherwise the shorter
  2042. * one is ordered first.
  2043. *
  2044. * NB: __s must have at least n2 characters, <em>\\0</em> has no special
  2045. * meaning.
  2046. */
  2047. int
  2048. compare(size_type __pos, size_type __n1, const _CharT* __s,
  2049. size_type __n2) const;
  2050. };
  2051. // operator+
  2052. /**
  2053. * @brief Concatenate two strings.
  2054. * @param __lhs First string.
  2055. * @param __rhs Last string.
  2056. * @return New string with value of @a __lhs followed by @a __rhs.
  2057. */
  2058. template<typename _CharT, typename _Traits, typename _Alloc,
  2059. template <typename, typename, typename> class _Base>
  2060. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2061. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2062. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2063. /**
  2064. * @brief Concatenate C string and string.
  2065. * @param __lhs First string.
  2066. * @param __rhs Last string.
  2067. * @return New string with value of @a __lhs followed by @a __rhs.
  2068. */
  2069. template<typename _CharT, typename _Traits, typename _Alloc,
  2070. template <typename, typename, typename> class _Base>
  2071. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2072. operator+(const _CharT* __lhs,
  2073. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2074. /**
  2075. * @brief Concatenate character and string.
  2076. * @param __lhs First string.
  2077. * @param __rhs Last string.
  2078. * @return New string with @a __lhs followed by @a __rhs.
  2079. */
  2080. template<typename _CharT, typename _Traits, typename _Alloc,
  2081. template <typename, typename, typename> class _Base>
  2082. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2083. operator+(_CharT __lhs,
  2084. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2085. /**
  2086. * @brief Concatenate string and C string.
  2087. * @param __lhs First string.
  2088. * @param __rhs Last string.
  2089. * @return New string with @a __lhs followed by @a __rhs.
  2090. */
  2091. template<typename _CharT, typename _Traits, typename _Alloc,
  2092. template <typename, typename, typename> class _Base>
  2093. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2094. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2095. const _CharT* __rhs);
  2096. /**
  2097. * @brief Concatenate string and character.
  2098. * @param __lhs First string.
  2099. * @param __rhs Last string.
  2100. * @return New string with @a __lhs followed by @a __rhs.
  2101. */
  2102. template<typename _CharT, typename _Traits, typename _Alloc,
  2103. template <typename, typename, typename> class _Base>
  2104. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2105. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2106. _CharT __rhs);
  2107. #if __cplusplus >= 201103L
  2108. template<typename _CharT, typename _Traits, typename _Alloc,
  2109. template <typename, typename, typename> class _Base>
  2110. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2111. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2112. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2113. { return std::move(__lhs.append(__rhs)); }
  2114. template<typename _CharT, typename _Traits, typename _Alloc,
  2115. template <typename, typename, typename> class _Base>
  2116. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2117. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2118. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2119. { return std::move(__rhs.insert(0, __lhs)); }
  2120. template<typename _CharT, typename _Traits, typename _Alloc,
  2121. template <typename, typename, typename> class _Base>
  2122. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2123. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2124. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2125. {
  2126. const auto __size = __lhs.size() + __rhs.size();
  2127. const bool __cond = (__size > __lhs.capacity()
  2128. && __size <= __rhs.capacity());
  2129. return __cond ? std::move(__rhs.insert(0, __lhs))
  2130. : std::move(__lhs.append(__rhs));
  2131. }
  2132. template<typename _CharT, typename _Traits, typename _Alloc,
  2133. template <typename, typename, typename> class _Base>
  2134. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2135. operator+(const _CharT* __lhs,
  2136. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2137. { return std::move(__rhs.insert(0, __lhs)); }
  2138. template<typename _CharT, typename _Traits, typename _Alloc,
  2139. template <typename, typename, typename> class _Base>
  2140. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2141. operator+(_CharT __lhs,
  2142. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2143. { return std::move(__rhs.insert(0, 1, __lhs)); }
  2144. template<typename _CharT, typename _Traits, typename _Alloc,
  2145. template <typename, typename, typename> class _Base>
  2146. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2147. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2148. const _CharT* __rhs)
  2149. { return std::move(__lhs.append(__rhs)); }
  2150. template<typename _CharT, typename _Traits, typename _Alloc,
  2151. template <typename, typename, typename> class _Base>
  2152. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2153. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2154. _CharT __rhs)
  2155. { return std::move(__lhs.append(1, __rhs)); }
  2156. #endif
  2157. // operator ==
  2158. /**
  2159. * @brief Test equivalence of two strings.
  2160. * @param __lhs First string.
  2161. * @param __rhs Second string.
  2162. * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
  2163. */
  2164. template<typename _CharT, typename _Traits, typename _Alloc,
  2165. template <typename, typename, typename> class _Base>
  2166. inline bool
  2167. operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2168. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2169. { return __lhs.compare(__rhs) == 0; }
  2170. template<typename _CharT,
  2171. template <typename, typename, typename> class _Base>
  2172. inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
  2173. operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
  2174. std::allocator<_CharT>, _Base>& __lhs,
  2175. const __versa_string<_CharT, std::char_traits<_CharT>,
  2176. std::allocator<_CharT>, _Base>& __rhs)
  2177. { return (__lhs.size() == __rhs.size()
  2178. && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
  2179. __lhs.size())); }
  2180. /**
  2181. * @brief Test equivalence of C string and string.
  2182. * @param __lhs C string.
  2183. * @param __rhs String.
  2184. * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
  2185. */
  2186. template<typename _CharT, typename _Traits, typename _Alloc,
  2187. template <typename, typename, typename> class _Base>
  2188. inline bool
  2189. operator==(const _CharT* __lhs,
  2190. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2191. { return __rhs.compare(__lhs) == 0; }
  2192. /**
  2193. * @brief Test equivalence of string and C string.
  2194. * @param __lhs String.
  2195. * @param __rhs C string.
  2196. * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
  2197. */
  2198. template<typename _CharT, typename _Traits, typename _Alloc,
  2199. template <typename, typename, typename> class _Base>
  2200. inline bool
  2201. operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2202. const _CharT* __rhs)
  2203. { return __lhs.compare(__rhs) == 0; }
  2204. // operator !=
  2205. /**
  2206. * @brief Test difference of two strings.
  2207. * @param __lhs First string.
  2208. * @param __rhs Second string.
  2209. * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
  2210. */
  2211. template<typename _CharT, typename _Traits, typename _Alloc,
  2212. template <typename, typename, typename> class _Base>
  2213. inline bool
  2214. operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2215. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2216. { return !(__lhs == __rhs); }
  2217. /**
  2218. * @brief Test difference of C string and string.
  2219. * @param __lhs C string.
  2220. * @param __rhs String.
  2221. * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
  2222. */
  2223. template<typename _CharT, typename _Traits, typename _Alloc,
  2224. template <typename, typename, typename> class _Base>
  2225. inline bool
  2226. operator!=(const _CharT* __lhs,
  2227. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2228. { return !(__lhs == __rhs); }
  2229. /**
  2230. * @brief Test difference of string and C string.
  2231. * @param __lhs String.
  2232. * @param __rhs C string.
  2233. * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
  2234. */
  2235. template<typename _CharT, typename _Traits, typename _Alloc,
  2236. template <typename, typename, typename> class _Base>
  2237. inline bool
  2238. operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2239. const _CharT* __rhs)
  2240. { return !(__lhs == __rhs); }
  2241. // operator <
  2242. /**
  2243. * @brief Test if string precedes string.
  2244. * @param __lhs First string.
  2245. * @param __rhs Second string.
  2246. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2247. */
  2248. template<typename _CharT, typename _Traits, typename _Alloc,
  2249. template <typename, typename, typename> class _Base>
  2250. inline bool
  2251. operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2252. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2253. { return __lhs.compare(__rhs) < 0; }
  2254. /**
  2255. * @brief Test if string precedes C string.
  2256. * @param __lhs String.
  2257. * @param __rhs C string.
  2258. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2259. */
  2260. template<typename _CharT, typename _Traits, typename _Alloc,
  2261. template <typename, typename, typename> class _Base>
  2262. inline bool
  2263. operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2264. const _CharT* __rhs)
  2265. { return __lhs.compare(__rhs) < 0; }
  2266. /**
  2267. * @brief Test if C string precedes string.
  2268. * @param __lhs C string.
  2269. * @param __rhs String.
  2270. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2271. */
  2272. template<typename _CharT, typename _Traits, typename _Alloc,
  2273. template <typename, typename, typename> class _Base>
  2274. inline bool
  2275. operator<(const _CharT* __lhs,
  2276. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2277. { return __rhs.compare(__lhs) > 0; }
  2278. // operator >
  2279. /**
  2280. * @brief Test if string follows string.
  2281. * @param __lhs First string.
  2282. * @param __rhs Second string.
  2283. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2284. */
  2285. template<typename _CharT, typename _Traits, typename _Alloc,
  2286. template <typename, typename, typename> class _Base>
  2287. inline bool
  2288. operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2289. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2290. { return __lhs.compare(__rhs) > 0; }
  2291. /**
  2292. * @brief Test if string follows C string.
  2293. * @param __lhs String.
  2294. * @param __rhs C string.
  2295. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2296. */
  2297. template<typename _CharT, typename _Traits, typename _Alloc,
  2298. template <typename, typename, typename> class _Base>
  2299. inline bool
  2300. operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2301. const _CharT* __rhs)
  2302. { return __lhs.compare(__rhs) > 0; }
  2303. /**
  2304. * @brief Test if C string follows string.
  2305. * @param __lhs C string.
  2306. * @param __rhs String.
  2307. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2308. */
  2309. template<typename _CharT, typename _Traits, typename _Alloc,
  2310. template <typename, typename, typename> class _Base>
  2311. inline bool
  2312. operator>(const _CharT* __lhs,
  2313. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2314. { return __rhs.compare(__lhs) < 0; }
  2315. // operator <=
  2316. /**
  2317. * @brief Test if string doesn't follow string.
  2318. * @param __lhs First string.
  2319. * @param __rhs Second string.
  2320. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2321. */
  2322. template<typename _CharT, typename _Traits, typename _Alloc,
  2323. template <typename, typename, typename> class _Base>
  2324. inline bool
  2325. operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2326. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2327. { return __lhs.compare(__rhs) <= 0; }
  2328. /**
  2329. * @brief Test if string doesn't follow C string.
  2330. * @param __lhs String.
  2331. * @param __rhs C string.
  2332. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2333. */
  2334. template<typename _CharT, typename _Traits, typename _Alloc,
  2335. template <typename, typename, typename> class _Base>
  2336. inline bool
  2337. operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2338. const _CharT* __rhs)
  2339. { return __lhs.compare(__rhs) <= 0; }
  2340. /**
  2341. * @brief Test if C string doesn't follow string.
  2342. * @param __lhs C string.
  2343. * @param __rhs String.
  2344. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2345. */
  2346. template<typename _CharT, typename _Traits, typename _Alloc,
  2347. template <typename, typename, typename> class _Base>
  2348. inline bool
  2349. operator<=(const _CharT* __lhs,
  2350. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2351. { return __rhs.compare(__lhs) >= 0; }
  2352. // operator >=
  2353. /**
  2354. * @brief Test if string doesn't precede string.
  2355. * @param __lhs First string.
  2356. * @param __rhs Second string.
  2357. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2358. */
  2359. template<typename _CharT, typename _Traits, typename _Alloc,
  2360. template <typename, typename, typename> class _Base>
  2361. inline bool
  2362. operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2363. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2364. { return __lhs.compare(__rhs) >= 0; }
  2365. /**
  2366. * @brief Test if string doesn't precede C string.
  2367. * @param __lhs String.
  2368. * @param __rhs C string.
  2369. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2370. */
  2371. template<typename _CharT, typename _Traits, typename _Alloc,
  2372. template <typename, typename, typename> class _Base>
  2373. inline bool
  2374. operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2375. const _CharT* __rhs)
  2376. { return __lhs.compare(__rhs) >= 0; }
  2377. /**
  2378. * @brief Test if C string doesn't precede string.
  2379. * @param __lhs C string.
  2380. * @param __rhs String.
  2381. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2382. */
  2383. template<typename _CharT, typename _Traits, typename _Alloc,
  2384. template <typename, typename, typename> class _Base>
  2385. inline bool
  2386. operator>=(const _CharT* __lhs,
  2387. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2388. { return __rhs.compare(__lhs) <= 0; }
  2389. /**
  2390. * @brief Swap contents of two strings.
  2391. * @param __lhs First string.
  2392. * @param __rhs Second string.
  2393. *
  2394. * Exchanges the contents of @a __lhs and @a __rhs in constant time.
  2395. */
  2396. template<typename _CharT, typename _Traits, typename _Alloc,
  2397. template <typename, typename, typename> class _Base>
  2398. inline void
  2399. swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2400. __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2401. { __lhs.swap(__rhs); }
  2402. _GLIBCXX_END_NAMESPACE_VERSION
  2403. } // namespace
  2404. namespace std _GLIBCXX_VISIBILITY(default)
  2405. {
  2406. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2407. /**
  2408. * @brief Read stream into a string.
  2409. * @param __is Input stream.
  2410. * @param __str Buffer to store into.
  2411. * @return Reference to the input stream.
  2412. *
  2413. * Stores characters from @a __is into @a __str until whitespace is
  2414. * found, the end of the stream is encountered, or str.max_size()
  2415. * is reached. If is.width() is non-zero, that is the limit on the
  2416. * number of characters stored into @a __str. Any previous
  2417. * contents of @a __str are erased.
  2418. */
  2419. template<typename _CharT, typename _Traits, typename _Alloc,
  2420. template <typename, typename, typename> class _Base>
  2421. basic_istream<_CharT, _Traits>&
  2422. operator>>(basic_istream<_CharT, _Traits>& __is,
  2423. __gnu_cxx::__versa_string<_CharT, _Traits,
  2424. _Alloc, _Base>& __str);
  2425. /**
  2426. * @brief Write string to a stream.
  2427. * @param __os Output stream.
  2428. * @param __str String to write out.
  2429. * @return Reference to the output stream.
  2430. *
  2431. * Output characters of @a __str into os following the same rules as for
  2432. * writing a C string.
  2433. */
  2434. template<typename _CharT, typename _Traits, typename _Alloc,
  2435. template <typename, typename, typename> class _Base>
  2436. inline basic_ostream<_CharT, _Traits>&
  2437. operator<<(basic_ostream<_CharT, _Traits>& __os,
  2438. const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
  2439. _Base>& __str)
  2440. {
  2441. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2442. // 586. string inserter not a formatted function
  2443. return __ostream_insert(__os, __str.data(), __str.size());
  2444. }
  2445. /**
  2446. * @brief Read a line from stream into a string.
  2447. * @param __is Input stream.
  2448. * @param __str Buffer to store into.
  2449. * @param __delim Character marking end of line.
  2450. * @return Reference to the input stream.
  2451. *
  2452. * Stores characters from @a __is into @a __str until @a __delim is
  2453. * found, the end of the stream is encountered, or str.max_size()
  2454. * is reached. If is.width() is non-zero, that is the limit on the
  2455. * number of characters stored into @a __str. Any previous
  2456. * contents of @a __str are erased. If @a delim was encountered,
  2457. * it is extracted but not stored into @a __str.
  2458. */
  2459. template<typename _CharT, typename _Traits, typename _Alloc,
  2460. template <typename, typename, typename> class _Base>
  2461. basic_istream<_CharT, _Traits>&
  2462. getline(basic_istream<_CharT, _Traits>& __is,
  2463. __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
  2464. _CharT __delim);
  2465. /**
  2466. * @brief Read a line from stream into a string.
  2467. * @param __is Input stream.
  2468. * @param __str Buffer to store into.
  2469. * @return Reference to the input stream.
  2470. *
  2471. * Stores characters from is into @a __str until &apos;\n&apos; is
  2472. * found, the end of the stream is encountered, or str.max_size()
  2473. * is reached. If is.width() is non-zero, that is the limit on the
  2474. * number of characters stored into @a __str. Any previous
  2475. * contents of @a __str are erased. If end of line was
  2476. * encountered, it is extracted but not stored into @a __str.
  2477. */
  2478. template<typename _CharT, typename _Traits, typename _Alloc,
  2479. template <typename, typename, typename> class _Base>
  2480. inline basic_istream<_CharT, _Traits>&
  2481. getline(basic_istream<_CharT, _Traits>& __is,
  2482. __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
  2483. { return getline(__is, __str, __is.widen('\n')); }
  2484. _GLIBCXX_END_NAMESPACE_VERSION
  2485. } // namespace
  2486. #if __cplusplus >= 201103L
  2487. #include <ext/string_conversions.h>
  2488. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  2489. {
  2490. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2491. #if _GLIBCXX_USE_C99_STDLIB
  2492. // 21.4 Numeric Conversions [string.conversions].
  2493. inline int
  2494. stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2495. { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
  2496. __idx, __base); }
  2497. inline long
  2498. stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2499. { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
  2500. __idx, __base); }
  2501. inline unsigned long
  2502. stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2503. { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
  2504. __idx, __base); }
  2505. inline long long
  2506. stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2507. { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
  2508. __idx, __base); }
  2509. inline unsigned long long
  2510. stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
  2511. { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
  2512. __idx, __base); }
  2513. // NB: strtof vs strtod.
  2514. inline float
  2515. stof(const __vstring& __str, std::size_t* __idx = 0)
  2516. { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
  2517. inline double
  2518. stod(const __vstring& __str, std::size_t* __idx = 0)
  2519. { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
  2520. inline long double
  2521. stold(const __vstring& __str, std::size_t* __idx = 0)
  2522. { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
  2523. #endif // _GLIBCXX_USE_C99_STDLIB
  2524. #if _GLIBCXX_USE_C99_STDIO
  2525. // NB: (v)snprintf vs sprintf.
  2526. // DR 1261.
  2527. inline __vstring
  2528. to_string(int __val)
  2529. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
  2530. "%d", __val); }
  2531. inline __vstring
  2532. to_string(unsigned __val)
  2533. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2534. 4 * sizeof(unsigned),
  2535. "%u", __val); }
  2536. inline __vstring
  2537. to_string(long __val)
  2538. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2539. 4 * sizeof(long),
  2540. "%ld", __val); }
  2541. inline __vstring
  2542. to_string(unsigned long __val)
  2543. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2544. 4 * sizeof(unsigned long),
  2545. "%lu", __val); }
  2546. inline __vstring
  2547. to_string(long long __val)
  2548. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2549. 4 * sizeof(long long),
  2550. "%lld", __val); }
  2551. inline __vstring
  2552. to_string(unsigned long long __val)
  2553. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2554. 4 * sizeof(unsigned long long),
  2555. "%llu", __val); }
  2556. inline __vstring
  2557. to_string(float __val)
  2558. {
  2559. const int __n = __numeric_traits<float>::__max_exponent10 + 20;
  2560. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2561. "%f", __val);
  2562. }
  2563. inline __vstring
  2564. to_string(double __val)
  2565. {
  2566. const int __n = __numeric_traits<double>::__max_exponent10 + 20;
  2567. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2568. "%f", __val);
  2569. }
  2570. inline __vstring
  2571. to_string(long double __val)
  2572. {
  2573. const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
  2574. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2575. "%Lf", __val);
  2576. }
  2577. #endif // _GLIBCXX_USE_C99_STDIO
  2578. #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
  2579. inline int
  2580. stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2581. { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
  2582. __idx, __base); }
  2583. inline long
  2584. stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2585. { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
  2586. __idx, __base); }
  2587. inline unsigned long
  2588. stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2589. { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
  2590. __idx, __base); }
  2591. inline long long
  2592. stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2593. { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
  2594. __idx, __base); }
  2595. inline unsigned long long
  2596. stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2597. { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
  2598. __idx, __base); }
  2599. // NB: wcstof vs wcstod.
  2600. inline float
  2601. stof(const __wvstring& __str, std::size_t* __idx = 0)
  2602. { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
  2603. inline double
  2604. stod(const __wvstring& __str, std::size_t* __idx = 0)
  2605. { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
  2606. inline long double
  2607. stold(const __wvstring& __str, std::size_t* __idx = 0)
  2608. { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
  2609. #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
  2610. // DR 1261.
  2611. inline __wvstring
  2612. to_wstring(int __val)
  2613. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2614. 4 * sizeof(int),
  2615. L"%d", __val); }
  2616. inline __wvstring
  2617. to_wstring(unsigned __val)
  2618. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2619. 4 * sizeof(unsigned),
  2620. L"%u", __val); }
  2621. inline __wvstring
  2622. to_wstring(long __val)
  2623. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2624. 4 * sizeof(long),
  2625. L"%ld", __val); }
  2626. inline __wvstring
  2627. to_wstring(unsigned long __val)
  2628. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2629. 4 * sizeof(unsigned long),
  2630. L"%lu", __val); }
  2631. inline __wvstring
  2632. to_wstring(long long __val)
  2633. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2634. 4 * sizeof(long long),
  2635. L"%lld", __val); }
  2636. inline __wvstring
  2637. to_wstring(unsigned long long __val)
  2638. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2639. 4 * sizeof(unsigned long long),
  2640. L"%llu", __val); }
  2641. inline __wvstring
  2642. to_wstring(float __val)
  2643. {
  2644. const int __n = __numeric_traits<float>::__max_exponent10 + 20;
  2645. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2646. L"%f", __val);
  2647. }
  2648. inline __wvstring
  2649. to_wstring(double __val)
  2650. {
  2651. const int __n = __numeric_traits<double>::__max_exponent10 + 20;
  2652. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2653. L"%f", __val);
  2654. }
  2655. inline __wvstring
  2656. to_wstring(long double __val)
  2657. {
  2658. const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
  2659. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2660. L"%Lf", __val);
  2661. }
  2662. #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
  2663. #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
  2664. _GLIBCXX_END_NAMESPACE_VERSION
  2665. } // namespace
  2666. #endif
  2667. #if __cplusplus >= 201103L
  2668. #include <bits/functional_hash.h>
  2669. namespace std _GLIBCXX_VISIBILITY(default)
  2670. {
  2671. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2672. /// std::hash specialization for __vstring.
  2673. template<>
  2674. struct hash<__gnu_cxx::__vstring>
  2675. : public __hash_base<size_t, __gnu_cxx::__vstring>
  2676. {
  2677. size_t
  2678. operator()(const __gnu_cxx::__vstring& __s) const noexcept
  2679. { return std::_Hash_impl::hash(__s.data(), __s.length()); }
  2680. };
  2681. #ifdef _GLIBCXX_USE_WCHAR_T
  2682. /// std::hash specialization for __wvstring.
  2683. template<>
  2684. struct hash<__gnu_cxx::__wvstring>
  2685. : public __hash_base<size_t, __gnu_cxx::__wvstring>
  2686. {
  2687. size_t
  2688. operator()(const __gnu_cxx::__wvstring& __s) const noexcept
  2689. { return std::_Hash_impl::hash(__s.data(),
  2690. __s.length() * sizeof(wchar_t)); }
  2691. };
  2692. #endif
  2693. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  2694. /// std::hash specialization for __u16vstring.
  2695. template<>
  2696. struct hash<__gnu_cxx::__u16vstring>
  2697. : public __hash_base<size_t, __gnu_cxx::__u16vstring>
  2698. {
  2699. size_t
  2700. operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
  2701. { return std::_Hash_impl::hash(__s.data(),
  2702. __s.length() * sizeof(char16_t)); }
  2703. };
  2704. /// std::hash specialization for __u32vstring.
  2705. template<>
  2706. struct hash<__gnu_cxx::__u32vstring>
  2707. : public __hash_base<size_t, __gnu_cxx::__u32vstring>
  2708. {
  2709. size_t
  2710. operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
  2711. { return std::_Hash_impl::hash(__s.data(),
  2712. __s.length() * sizeof(char32_t)); }
  2713. };
  2714. #endif
  2715. _GLIBCXX_END_NAMESPACE_VERSION
  2716. } // namespace
  2717. #endif // C++11
  2718. #include <ext/vstring.tcc>
  2719. #endif /* _VSTRING_H */