string 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. // Debugging string implementation -*- C++ -*-
  2. // Copyright (C) 2003-2022 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 debug/string
  21. * This file is a GNU debug extension to the Standard C++ Library.
  22. */
  23. #ifndef _GLIBCXX_DEBUG_STRING
  24. #define _GLIBCXX_DEBUG_STRING 1
  25. #pragma GCC system_header
  26. #include <string>
  27. #include <debug/safe_sequence.h>
  28. #include <debug/safe_container.h>
  29. #include <debug/safe_iterator.h>
  30. #define _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_Cond,_File,_Line,_Func) \
  31. if (! (_Cond)) \
  32. __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
  33. ._M_message(#_Cond)._M_error()
  34. #if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
  35. # define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
  36. # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr
  37. #else
  38. # define _GLIBCXX_INSERT_RETURNS_ITERATOR 0
  39. # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr)
  40. #endif
  41. namespace __gnu_debug
  42. {
  43. /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
  44. template<typename _CharT, typename _Integer>
  45. inline const _CharT*
  46. __check_string(const _CharT* __s,
  47. _Integer __n __attribute__((__unused__)),
  48. const char* __file __attribute__((__unused__)),
  49. unsigned int __line __attribute__((__unused__)),
  50. const char* __function __attribute__((__unused__)))
  51. {
  52. #ifdef _GLIBCXX_DEBUG_PEDANTIC
  53. _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0,
  54. __file, __line, __function);
  55. #endif
  56. return __s;
  57. }
  58. /** Checks that __s is non-NULL and then returns __s. */
  59. template<typename _CharT>
  60. inline const _CharT*
  61. __check_string(const _CharT* __s,
  62. const char* __file __attribute__((__unused__)),
  63. unsigned int __line __attribute__((__unused__)),
  64. const char* __function __attribute__((__unused__)))
  65. {
  66. #ifdef _GLIBCXX_DEBUG_PEDANTIC
  67. _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0,
  68. __file, __line, __function);
  69. #endif
  70. return __s;
  71. }
  72. #define __glibcxx_check_string_n_constructor(_Str, _Size) \
  73. __check_string(_Str, _Size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  74. #define __glibcxx_check_string_constructor(_Str) \
  75. __check_string(_Str, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  76. /// Class std::basic_string with safety/checking/debug instrumentation.
  77. template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
  78. typename _Allocator = std::allocator<_CharT> >
  79. class basic_string
  80. : public __gnu_debug::_Safe_container<
  81. basic_string<_CharT, _Traits, _Allocator>,
  82. _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
  83. public std::basic_string<_CharT, _Traits, _Allocator>
  84. {
  85. typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
  86. typedef __gnu_debug::_Safe_container<
  87. basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
  88. _Safe;
  89. template<typename _ItT, typename _SeqT, typename _CatT>
  90. friend class ::__gnu_debug::_Safe_iterator;
  91. // type used for positions in insert, erase etc.
  92. typedef __gnu_debug::_Safe_iterator<
  93. typename _Base::__const_iterator, basic_string> __const_iterator;
  94. public:
  95. // types:
  96. typedef _Traits traits_type;
  97. typedef typename _Traits::char_type value_type;
  98. typedef _Allocator allocator_type;
  99. typedef typename _Base::size_type size_type;
  100. typedef typename _Base::difference_type difference_type;
  101. typedef typename _Base::reference reference;
  102. typedef typename _Base::const_reference const_reference;
  103. typedef typename _Base::pointer pointer;
  104. typedef typename _Base::const_pointer const_pointer;
  105. typedef __gnu_debug::_Safe_iterator<
  106. typename _Base::iterator, basic_string> iterator;
  107. typedef __gnu_debug::_Safe_iterator<
  108. typename _Base::const_iterator, basic_string> const_iterator;
  109. typedef std::reverse_iterator<iterator> reverse_iterator;
  110. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  111. using _Base::npos;
  112. // 21.3.1 construct/copy/destroy:
  113. explicit
  114. basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
  115. : _Base(__a) { }
  116. #if __cplusplus < 201103L
  117. basic_string() : _Base() { }
  118. basic_string(const basic_string& __str)
  119. : _Base(__str) { }
  120. ~basic_string() { }
  121. #else
  122. basic_string() = default;
  123. basic_string(const basic_string&) = default;
  124. basic_string(basic_string&&) = default;
  125. basic_string(std::initializer_list<_CharT> __l,
  126. const _Allocator& __a = _Allocator())
  127. : _Base(__l, __a)
  128. { }
  129. basic_string(const basic_string& __s, const _Allocator& __a)
  130. : _Base(__s, __a) { }
  131. basic_string(basic_string&& __s, const _Allocator& __a)
  132. noexcept(
  133. std::is_nothrow_constructible<_Base, _Base, const _Allocator&>::value )
  134. : _Safe(std::move(__s), __a),
  135. _Base(std::move(__s), __a)
  136. { }
  137. ~basic_string() = default;
  138. // Provides conversion from a normal-mode string to a debug-mode string
  139. basic_string(_Base&& __base) noexcept
  140. : _Base(std::move(__base)) { }
  141. #endif // C++11
  142. // Provides conversion from a normal-mode string to a debug-mode string
  143. basic_string(const _Base& __base)
  144. : _Base(__base) { }
  145. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  146. // 42. string ctors specify wrong default allocator
  147. basic_string(const basic_string& __str, size_type __pos,
  148. size_type __n = _Base::npos,
  149. const _Allocator& __a = _Allocator())
  150. : _Base(__str, __pos, __n, __a) { }
  151. basic_string(const _CharT* __s, size_type __n,
  152. const _Allocator& __a = _Allocator())
  153. : _Base(__glibcxx_check_string_n_constructor(__s, __n), __n, __a) { }
  154. basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
  155. : _Base(__glibcxx_check_string_constructor(__s), __a)
  156. { }
  157. basic_string(size_type __n, _CharT __c,
  158. const _Allocator& __a = _Allocator())
  159. : _Base(__n, __c, __a) { }
  160. template<typename _InputIterator>
  161. basic_string(_InputIterator __begin, _InputIterator __end,
  162. const _Allocator& __a = _Allocator())
  163. : _Base(__gnu_debug::__base(
  164. __glibcxx_check_valid_constructor_range(__begin, __end)),
  165. __gnu_debug::__base(__end), __a) { }
  166. #if __cplusplus >= 201103L
  167. basic_string&
  168. operator=(const basic_string&) = default;
  169. basic_string&
  170. operator=(basic_string&&) = default;
  171. #endif
  172. basic_string&
  173. operator=(const _CharT* __s)
  174. {
  175. __glibcxx_check_string(__s);
  176. _Base::operator=(__s);
  177. this->_M_invalidate_all();
  178. return *this;
  179. }
  180. basic_string&
  181. operator=(_CharT __c)
  182. {
  183. _Base::operator=(__c);
  184. this->_M_invalidate_all();
  185. return *this;
  186. }
  187. #if __cplusplus >= 201103L
  188. basic_string&
  189. operator=(std::initializer_list<_CharT> __l)
  190. {
  191. _Base::operator=(__l);
  192. this->_M_invalidate_all();
  193. return *this;
  194. }
  195. #endif // C++11
  196. // 21.3.2 iterators:
  197. iterator
  198. begin() // _GLIBCXX_NOEXCEPT
  199. { return iterator(_Base::begin(), this); }
  200. const_iterator
  201. begin() const _GLIBCXX_NOEXCEPT
  202. { return const_iterator(_Base::begin(), this); }
  203. iterator
  204. end() // _GLIBCXX_NOEXCEPT
  205. { return iterator(_Base::end(), this); }
  206. const_iterator
  207. end() const _GLIBCXX_NOEXCEPT
  208. { return const_iterator(_Base::end(), this); }
  209. reverse_iterator
  210. rbegin() // _GLIBCXX_NOEXCEPT
  211. { return reverse_iterator(end()); }
  212. const_reverse_iterator
  213. rbegin() const _GLIBCXX_NOEXCEPT
  214. { return const_reverse_iterator(end()); }
  215. reverse_iterator
  216. rend() // _GLIBCXX_NOEXCEPT
  217. { return reverse_iterator(begin()); }
  218. const_reverse_iterator
  219. rend() const _GLIBCXX_NOEXCEPT
  220. { return const_reverse_iterator(begin()); }
  221. #if __cplusplus >= 201103L
  222. const_iterator
  223. cbegin() const noexcept
  224. { return const_iterator(_Base::begin(), this); }
  225. const_iterator
  226. cend() const noexcept
  227. { return const_iterator(_Base::end(), this); }
  228. const_reverse_iterator
  229. crbegin() const noexcept
  230. { return const_reverse_iterator(end()); }
  231. const_reverse_iterator
  232. crend() const noexcept
  233. { return const_reverse_iterator(begin()); }
  234. #endif
  235. // 21.3.3 capacity:
  236. using _Base::size;
  237. using _Base::length;
  238. using _Base::max_size;
  239. void
  240. resize(size_type __n, _CharT __c)
  241. {
  242. _Base::resize(__n, __c);
  243. this->_M_invalidate_all();
  244. }
  245. void
  246. resize(size_type __n)
  247. { this->resize(__n, _CharT()); }
  248. #if __cplusplus >= 201103L
  249. void
  250. shrink_to_fit() noexcept
  251. {
  252. if (capacity() > size())
  253. {
  254. __try
  255. {
  256. reserve(0);
  257. this->_M_invalidate_all();
  258. }
  259. __catch(...)
  260. { }
  261. }
  262. }
  263. #endif
  264. using _Base::capacity;
  265. using _Base::reserve;
  266. void
  267. clear() // _GLIBCXX_NOEXCEPT
  268. {
  269. _Base::clear();
  270. this->_M_invalidate_all();
  271. }
  272. using _Base::empty;
  273. // 21.3.4 element access:
  274. const_reference
  275. operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
  276. {
  277. _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
  278. _M_message(__gnu_debug::__msg_subscript_oob)
  279. ._M_sequence(*this, "this")
  280. ._M_integer(__pos, "__pos")
  281. ._M_integer(this->size(), "size"));
  282. return _Base::operator[](__pos);
  283. }
  284. reference
  285. operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
  286. {
  287. #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
  288. __glibcxx_check_subscript(__pos);
  289. #else
  290. // as an extension v3 allows s[s.size()] when s is non-const.
  291. _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
  292. _M_message(__gnu_debug::__msg_subscript_oob)
  293. ._M_sequence(*this, "this")
  294. ._M_integer(__pos, "__pos")
  295. ._M_integer(this->size(), "size"));
  296. #endif
  297. return _Base::operator[](__pos);
  298. }
  299. using _Base::at;
  300. #if __cplusplus >= 201103L
  301. using _Base::front;
  302. using _Base::back;
  303. #endif
  304. // 21.3.5 modifiers:
  305. basic_string&
  306. operator+=(const basic_string& __str)
  307. {
  308. _Base::operator+=(__str);
  309. this->_M_invalidate_all();
  310. return *this;
  311. }
  312. basic_string&
  313. operator+=(const _CharT* __s)
  314. {
  315. __glibcxx_check_string(__s);
  316. _Base::operator+=(__s);
  317. this->_M_invalidate_all();
  318. return *this;
  319. }
  320. basic_string&
  321. operator+=(_CharT __c)
  322. {
  323. _Base::operator+=(__c);
  324. this->_M_invalidate_all();
  325. return *this;
  326. }
  327. #if __cplusplus >= 201103L
  328. basic_string&
  329. operator+=(std::initializer_list<_CharT> __l)
  330. {
  331. _Base::operator+=(__l);
  332. this->_M_invalidate_all();
  333. return *this;
  334. }
  335. #endif // C++11
  336. basic_string&
  337. append(const basic_string& __str)
  338. {
  339. _Base::append(__str);
  340. this->_M_invalidate_all();
  341. return *this;
  342. }
  343. basic_string&
  344. append(const basic_string& __str, size_type __pos, size_type __n)
  345. {
  346. _Base::append(__str, __pos, __n);
  347. this->_M_invalidate_all();
  348. return *this;
  349. }
  350. basic_string&
  351. append(const _CharT* __s, size_type __n)
  352. {
  353. __glibcxx_check_string_len(__s, __n);
  354. _Base::append(__s, __n);
  355. this->_M_invalidate_all();
  356. return *this;
  357. }
  358. basic_string&
  359. append(const _CharT* __s)
  360. {
  361. __glibcxx_check_string(__s);
  362. _Base::append(__s);
  363. this->_M_invalidate_all();
  364. return *this;
  365. }
  366. basic_string&
  367. append(size_type __n, _CharT __c)
  368. {
  369. _Base::append(__n, __c);
  370. this->_M_invalidate_all();
  371. return *this;
  372. }
  373. template<typename _InputIterator>
  374. basic_string&
  375. append(_InputIterator __first, _InputIterator __last)
  376. {
  377. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  378. __glibcxx_check_valid_range2(__first, __last, __dist);
  379. if (__dist.second >= __dp_sign)
  380. _Base::append(__gnu_debug::__unsafe(__first),
  381. __gnu_debug::__unsafe(__last));
  382. else
  383. _Base::append(__first, __last);
  384. this->_M_invalidate_all();
  385. return *this;
  386. }
  387. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  388. // 7. string clause minor problems
  389. void
  390. push_back(_CharT __c)
  391. {
  392. _Base::push_back(__c);
  393. this->_M_invalidate_all();
  394. }
  395. basic_string&
  396. assign(const basic_string& __x)
  397. {
  398. _Base::assign(__x);
  399. this->_M_invalidate_all();
  400. return *this;
  401. }
  402. #if __cplusplus >= 201103L
  403. basic_string&
  404. assign(basic_string&& __x)
  405. noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
  406. {
  407. _Base::assign(std::move(__x));
  408. this->_M_invalidate_all();
  409. return *this;
  410. }
  411. #endif // C++11
  412. basic_string&
  413. assign(const basic_string& __str, size_type __pos, size_type __n)
  414. {
  415. _Base::assign(__str, __pos, __n);
  416. this->_M_invalidate_all();
  417. return *this;
  418. }
  419. basic_string&
  420. assign(const _CharT* __s, size_type __n)
  421. {
  422. __glibcxx_check_string_len(__s, __n);
  423. _Base::assign(__s, __n);
  424. this->_M_invalidate_all();
  425. return *this;
  426. }
  427. basic_string&
  428. assign(const _CharT* __s)
  429. {
  430. __glibcxx_check_string(__s);
  431. _Base::assign(__s);
  432. this->_M_invalidate_all();
  433. return *this;
  434. }
  435. basic_string&
  436. assign(size_type __n, _CharT __c)
  437. {
  438. _Base::assign(__n, __c);
  439. this->_M_invalidate_all();
  440. return *this;
  441. }
  442. template<typename _InputIterator>
  443. basic_string&
  444. assign(_InputIterator __first, _InputIterator __last)
  445. {
  446. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  447. __glibcxx_check_valid_range2(__first, __last, __dist);
  448. if (__dist.second >= __dp_sign)
  449. _Base::assign(__gnu_debug::__unsafe(__first),
  450. __gnu_debug::__unsafe(__last));
  451. else
  452. _Base::assign(__first, __last);
  453. this->_M_invalidate_all();
  454. return *this;
  455. }
  456. #if __cplusplus >= 201103L
  457. basic_string&
  458. assign(std::initializer_list<_CharT> __l)
  459. {
  460. _Base::assign(__l);
  461. this->_M_invalidate_all();
  462. return *this;
  463. }
  464. #endif // C++11
  465. basic_string&
  466. insert(size_type __pos1, const basic_string& __str)
  467. {
  468. _Base::insert(__pos1, __str);
  469. this->_M_invalidate_all();
  470. return *this;
  471. }
  472. basic_string&
  473. insert(size_type __pos1, const basic_string& __str,
  474. size_type __pos2, size_type __n)
  475. {
  476. _Base::insert(__pos1, __str, __pos2, __n);
  477. this->_M_invalidate_all();
  478. return *this;
  479. }
  480. basic_string&
  481. insert(size_type __pos, const _CharT* __s, size_type __n)
  482. {
  483. __glibcxx_check_string(__s);
  484. _Base::insert(__pos, __s, __n);
  485. this->_M_invalidate_all();
  486. return *this;
  487. }
  488. basic_string&
  489. insert(size_type __pos, const _CharT* __s)
  490. {
  491. __glibcxx_check_string(__s);
  492. _Base::insert(__pos, __s);
  493. this->_M_invalidate_all();
  494. return *this;
  495. }
  496. basic_string&
  497. insert(size_type __pos, size_type __n, _CharT __c)
  498. {
  499. _Base::insert(__pos, __n, __c);
  500. this->_M_invalidate_all();
  501. return *this;
  502. }
  503. iterator
  504. insert(__const_iterator __p, _CharT __c)
  505. {
  506. __glibcxx_check_insert(__p);
  507. typename _Base::iterator __res = _Base::insert(__p.base(), __c);
  508. this->_M_invalidate_all();
  509. return iterator(__res, this);
  510. }
  511. #if __cplusplus >= 201103L
  512. iterator
  513. insert(const_iterator __p, size_type __n, _CharT __c)
  514. {
  515. __glibcxx_check_insert(__p);
  516. #if _GLIBCXX_USE_CXX11_ABI
  517. typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
  518. #else
  519. const size_type __offset = __p.base() - _Base::cbegin();
  520. _Base::insert(_Base::begin() + __offset, __n, __c);
  521. typename _Base::iterator __res = _Base::begin() + __offset;
  522. #endif
  523. this->_M_invalidate_all();
  524. return iterator(__res, this);
  525. }
  526. #else
  527. void
  528. insert(iterator __p, size_type __n, _CharT __c)
  529. {
  530. __glibcxx_check_insert(__p);
  531. _Base::insert(__p.base(), __n, __c);
  532. this->_M_invalidate_all();
  533. }
  534. #endif
  535. template<typename _InputIterator>
  536. iterator
  537. insert(__const_iterator __p,
  538. _InputIterator __first, _InputIterator __last)
  539. {
  540. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  541. __glibcxx_check_insert_range(__p, __first, __last, __dist);
  542. typename _Base::iterator __res;
  543. #if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
  544. const size_type __offset = __p.base() - _Base::begin();
  545. #endif
  546. if (__dist.second >= __dp_sign)
  547. {
  548. _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
  549. _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
  550. __gnu_debug::__unsafe(__last));
  551. }
  552. else
  553. {
  554. _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
  555. _Base::insert(__p.base(), __first, __last);
  556. }
  557. #if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
  558. __res = _Base::begin() + __offset;
  559. #endif
  560. this->_M_invalidate_all();
  561. return iterator(__res, this);
  562. }
  563. #if __cplusplus >= 201103L
  564. iterator
  565. insert(const_iterator __p, std::initializer_list<_CharT> __l)
  566. {
  567. __glibcxx_check_insert(__p);
  568. #if _GLIBCXX_USE_CXX11_ABI
  569. const auto __res = _Base::insert(__p.base(), __l);
  570. #else
  571. const size_type __offset = __p.base() - _Base::cbegin();
  572. _Base::insert(_Base::begin() + __offset, __l);
  573. auto __res = _Base::begin() + __offset;
  574. #endif
  575. this->_M_invalidate_all();
  576. return iterator(__res, this);
  577. }
  578. #endif // C++11
  579. basic_string&
  580. erase(size_type __pos = 0, size_type __n = _Base::npos)
  581. {
  582. _Base::erase(__pos, __n);
  583. this->_M_invalidate_all();
  584. return *this;
  585. }
  586. iterator
  587. erase(__const_iterator __position)
  588. {
  589. __glibcxx_check_erase(__position);
  590. typename _Base::iterator __res = _Base::erase(__position.base());
  591. this->_M_invalidate_all();
  592. return iterator(__res, this);
  593. }
  594. iterator
  595. erase(__const_iterator __first, __const_iterator __last)
  596. {
  597. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  598. // 151. can't currently clear() empty container
  599. __glibcxx_check_erase_range(__first, __last);
  600. typename _Base::iterator __res = _Base::erase(__first.base(),
  601. __last.base());
  602. this->_M_invalidate_all();
  603. return iterator(__res, this);
  604. }
  605. #if __cplusplus >= 201103L
  606. void
  607. pop_back() // noexcept
  608. {
  609. __glibcxx_check_nonempty();
  610. _Base::pop_back();
  611. this->_M_invalidate_all();
  612. }
  613. #endif // C++11
  614. basic_string&
  615. replace(size_type __pos1, size_type __n1, const basic_string& __str)
  616. {
  617. _Base::replace(__pos1, __n1, __str);
  618. this->_M_invalidate_all();
  619. return *this;
  620. }
  621. basic_string&
  622. replace(size_type __pos1, size_type __n1, const basic_string& __str,
  623. size_type __pos2, size_type __n2)
  624. {
  625. _Base::replace(__pos1, __n1, __str, __pos2, __n2);
  626. this->_M_invalidate_all();
  627. return *this;
  628. }
  629. basic_string&
  630. replace(size_type __pos, size_type __n1, const _CharT* __s,
  631. size_type __n2)
  632. {
  633. __glibcxx_check_string_len(__s, __n2);
  634. _Base::replace(__pos, __n1, __s, __n2);
  635. this->_M_invalidate_all();
  636. return *this;
  637. }
  638. basic_string&
  639. replace(size_type __pos, size_type __n1, const _CharT* __s)
  640. {
  641. __glibcxx_check_string(__s);
  642. _Base::replace(__pos, __n1, __s);
  643. this->_M_invalidate_all();
  644. return *this;
  645. }
  646. basic_string&
  647. replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
  648. {
  649. _Base::replace(__pos, __n1, __n2, __c);
  650. this->_M_invalidate_all();
  651. return *this;
  652. }
  653. basic_string&
  654. replace(__const_iterator __i1, __const_iterator __i2,
  655. const basic_string& __str)
  656. {
  657. __glibcxx_check_erase_range(__i1, __i2);
  658. _Base::replace(__i1.base(), __i2.base(), __str);
  659. this->_M_invalidate_all();
  660. return *this;
  661. }
  662. basic_string&
  663. replace(__const_iterator __i1, __const_iterator __i2,
  664. const _CharT* __s, size_type __n)
  665. {
  666. __glibcxx_check_erase_range(__i1, __i2);
  667. __glibcxx_check_string_len(__s, __n);
  668. _Base::replace(__i1.base(), __i2.base(), __s, __n);
  669. this->_M_invalidate_all();
  670. return *this;
  671. }
  672. basic_string&
  673. replace(__const_iterator __i1, __const_iterator __i2,
  674. const _CharT* __s)
  675. {
  676. __glibcxx_check_erase_range(__i1, __i2);
  677. __glibcxx_check_string(__s);
  678. _Base::replace(__i1.base(), __i2.base(), __s);
  679. this->_M_invalidate_all();
  680. return *this;
  681. }
  682. basic_string&
  683. replace(__const_iterator __i1, __const_iterator __i2,
  684. size_type __n, _CharT __c)
  685. {
  686. __glibcxx_check_erase_range(__i1, __i2);
  687. _Base::replace(__i1.base(), __i2.base(), __n, __c);
  688. this->_M_invalidate_all();
  689. return *this;
  690. }
  691. template<typename _InputIterator>
  692. basic_string&
  693. replace(__const_iterator __i1, __const_iterator __i2,
  694. _InputIterator __j1, _InputIterator __j2)
  695. {
  696. __glibcxx_check_erase_range(__i1, __i2);
  697. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  698. __glibcxx_check_valid_range2(__j1, __j2, __dist);
  699. if (__dist.second >= __dp_sign)
  700. _Base::replace(__i1.base(), __i2.base(),
  701. __gnu_debug::__unsafe(__j1),
  702. __gnu_debug::__unsafe(__j2));
  703. else
  704. _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
  705. this->_M_invalidate_all();
  706. return *this;
  707. }
  708. #if __cplusplus >= 201103L
  709. basic_string&
  710. replace(__const_iterator __i1, __const_iterator __i2,
  711. std::initializer_list<_CharT> __l)
  712. {
  713. __glibcxx_check_erase_range(__i1, __i2);
  714. _Base::replace(__i1.base(), __i2.base(), __l);
  715. this->_M_invalidate_all();
  716. return *this;
  717. }
  718. #endif // C++11
  719. size_type
  720. copy(_CharT* __s, size_type __n, size_type __pos = 0) const
  721. {
  722. __glibcxx_check_string_len(__s, __n);
  723. return _Base::copy(__s, __n, __pos);
  724. }
  725. void
  726. swap(basic_string& __x)
  727. _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
  728. {
  729. _Safe::_M_swap(__x);
  730. _Base::swap(__x);
  731. }
  732. // 21.3.6 string operations:
  733. const _CharT*
  734. c_str() const _GLIBCXX_NOEXCEPT
  735. {
  736. const _CharT* __res = _Base::c_str();
  737. this->_M_invalidate_all();
  738. return __res;
  739. }
  740. const _CharT*
  741. data() const _GLIBCXX_NOEXCEPT
  742. {
  743. const _CharT* __res = _Base::data();
  744. this->_M_invalidate_all();
  745. return __res;
  746. }
  747. using _Base::get_allocator;
  748. size_type
  749. find(const basic_string& __str, size_type __pos = 0) const
  750. _GLIBCXX_NOEXCEPT
  751. { return _Base::find(__str, __pos); }
  752. size_type
  753. find(const _CharT* __s, size_type __pos, size_type __n) const
  754. {
  755. __glibcxx_check_string(__s);
  756. return _Base::find(__s, __pos, __n);
  757. }
  758. size_type
  759. find(const _CharT* __s, size_type __pos = 0) const
  760. {
  761. __glibcxx_check_string(__s);
  762. return _Base::find(__s, __pos);
  763. }
  764. size_type
  765. find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
  766. { return _Base::find(__c, __pos); }
  767. size_type
  768. rfind(const basic_string& __str, size_type __pos = _Base::npos) const
  769. _GLIBCXX_NOEXCEPT
  770. { return _Base::rfind(__str, __pos); }
  771. size_type
  772. rfind(const _CharT* __s, size_type __pos, size_type __n) const
  773. {
  774. __glibcxx_check_string_len(__s, __n);
  775. return _Base::rfind(__s, __pos, __n);
  776. }
  777. size_type
  778. rfind(const _CharT* __s, size_type __pos = _Base::npos) const
  779. {
  780. __glibcxx_check_string(__s);
  781. return _Base::rfind(__s, __pos);
  782. }
  783. size_type
  784. rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
  785. { return _Base::rfind(__c, __pos); }
  786. size_type
  787. find_first_of(const basic_string& __str, size_type __pos = 0) const
  788. _GLIBCXX_NOEXCEPT
  789. { return _Base::find_first_of(__str, __pos); }
  790. size_type
  791. find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
  792. {
  793. __glibcxx_check_string(__s);
  794. return _Base::find_first_of(__s, __pos, __n);
  795. }
  796. size_type
  797. find_first_of(const _CharT* __s, size_type __pos = 0) const
  798. {
  799. __glibcxx_check_string(__s);
  800. return _Base::find_first_of(__s, __pos);
  801. }
  802. size_type
  803. find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
  804. { return _Base::find_first_of(__c, __pos); }
  805. size_type
  806. find_last_of(const basic_string& __str,
  807. size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
  808. { return _Base::find_last_of(__str, __pos); }
  809. size_type
  810. find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
  811. {
  812. __glibcxx_check_string(__s);
  813. return _Base::find_last_of(__s, __pos, __n);
  814. }
  815. size_type
  816. find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
  817. {
  818. __glibcxx_check_string(__s);
  819. return _Base::find_last_of(__s, __pos);
  820. }
  821. size_type
  822. find_last_of(_CharT __c, size_type __pos = _Base::npos) const
  823. _GLIBCXX_NOEXCEPT
  824. { return _Base::find_last_of(__c, __pos); }
  825. size_type
  826. find_first_not_of(const basic_string& __str, size_type __pos = 0) const
  827. _GLIBCXX_NOEXCEPT
  828. { return _Base::find_first_not_of(__str, __pos); }
  829. size_type
  830. find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
  831. {
  832. __glibcxx_check_string_len(__s, __n);
  833. return _Base::find_first_not_of(__s, __pos, __n);
  834. }
  835. size_type
  836. find_first_not_of(const _CharT* __s, size_type __pos = 0) const
  837. {
  838. __glibcxx_check_string(__s);
  839. return _Base::find_first_not_of(__s, __pos);
  840. }
  841. size_type
  842. find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
  843. { return _Base::find_first_not_of(__c, __pos); }
  844. size_type
  845. find_last_not_of(const basic_string& __str,
  846. size_type __pos = _Base::npos) const
  847. _GLIBCXX_NOEXCEPT
  848. { return _Base::find_last_not_of(__str, __pos); }
  849. size_type
  850. find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
  851. {
  852. __glibcxx_check_string(__s);
  853. return _Base::find_last_not_of(__s, __pos, __n);
  854. }
  855. size_type
  856. find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
  857. {
  858. __glibcxx_check_string(__s);
  859. return _Base::find_last_not_of(__s, __pos);
  860. }
  861. size_type
  862. find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
  863. _GLIBCXX_NOEXCEPT
  864. { return _Base::find_last_not_of(__c, __pos); }
  865. basic_string
  866. substr(size_type __pos = 0, size_type __n = _Base::npos) const
  867. { return basic_string(_Base::substr(__pos, __n)); }
  868. int
  869. compare(const basic_string& __str) const
  870. { return _Base::compare(__str); }
  871. int
  872. compare(size_type __pos1, size_type __n1,
  873. const basic_string& __str) const
  874. { return _Base::compare(__pos1, __n1, __str); }
  875. int
  876. compare(size_type __pos1, size_type __n1, const basic_string& __str,
  877. size_type __pos2, size_type __n2) const
  878. { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
  879. int
  880. compare(const _CharT* __s) const
  881. {
  882. __glibcxx_check_string(__s);
  883. return _Base::compare(__s);
  884. }
  885. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  886. // 5. string::compare specification questionable
  887. int
  888. compare(size_type __pos1, size_type __n1, const _CharT* __s) const
  889. {
  890. __glibcxx_check_string(__s);
  891. return _Base::compare(__pos1, __n1, __s);
  892. }
  893. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  894. // 5. string::compare specification questionable
  895. int
  896. compare(size_type __pos1, size_type __n1,const _CharT* __s,
  897. size_type __n2) const
  898. {
  899. __glibcxx_check_string_len(__s, __n2);
  900. return _Base::compare(__pos1, __n1, __s, __n2);
  901. }
  902. _Base&
  903. _M_base() _GLIBCXX_NOEXCEPT { return *this; }
  904. const _Base&
  905. _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
  906. using _Safe::_M_invalidate_all;
  907. };
  908. template<typename _CharT, typename _Traits, typename _Allocator>
  909. inline basic_string<_CharT,_Traits,_Allocator>
  910. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  911. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  912. { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
  913. template<typename _CharT, typename _Traits, typename _Allocator>
  914. inline basic_string<_CharT,_Traits,_Allocator>
  915. operator+(const _CharT* __lhs,
  916. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  917. {
  918. __glibcxx_check_string(__lhs);
  919. return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
  920. }
  921. template<typename _CharT, typename _Traits, typename _Allocator>
  922. inline basic_string<_CharT,_Traits,_Allocator>
  923. operator+(_CharT __lhs,
  924. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  925. { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
  926. template<typename _CharT, typename _Traits, typename _Allocator>
  927. inline basic_string<_CharT,_Traits,_Allocator>
  928. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  929. const _CharT* __rhs)
  930. {
  931. __glibcxx_check_string(__rhs);
  932. return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
  933. }
  934. template<typename _CharT, typename _Traits, typename _Allocator>
  935. inline basic_string<_CharT,_Traits,_Allocator>
  936. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  937. _CharT __rhs)
  938. { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
  939. template<typename _CharT, typename _Traits, typename _Allocator>
  940. inline bool
  941. operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  942. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  943. { return __lhs._M_base() == __rhs._M_base(); }
  944. template<typename _CharT, typename _Traits, typename _Allocator>
  945. inline bool
  946. operator==(const _CharT* __lhs,
  947. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  948. {
  949. __glibcxx_check_string(__lhs);
  950. return __lhs == __rhs._M_base();
  951. }
  952. template<typename _CharT, typename _Traits, typename _Allocator>
  953. inline bool
  954. operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  955. const _CharT* __rhs)
  956. {
  957. __glibcxx_check_string(__rhs);
  958. return __lhs._M_base() == __rhs;
  959. }
  960. template<typename _CharT, typename _Traits, typename _Allocator>
  961. inline bool
  962. operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  963. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  964. { return __lhs._M_base() != __rhs._M_base(); }
  965. template<typename _CharT, typename _Traits, typename _Allocator>
  966. inline bool
  967. operator!=(const _CharT* __lhs,
  968. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  969. {
  970. __glibcxx_check_string(__lhs);
  971. return __lhs != __rhs._M_base();
  972. }
  973. template<typename _CharT, typename _Traits, typename _Allocator>
  974. inline bool
  975. operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  976. const _CharT* __rhs)
  977. {
  978. __glibcxx_check_string(__rhs);
  979. return __lhs._M_base() != __rhs;
  980. }
  981. template<typename _CharT, typename _Traits, typename _Allocator>
  982. inline bool
  983. operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  984. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  985. { return __lhs._M_base() < __rhs._M_base(); }
  986. template<typename _CharT, typename _Traits, typename _Allocator>
  987. inline bool
  988. operator<(const _CharT* __lhs,
  989. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  990. {
  991. __glibcxx_check_string(__lhs);
  992. return __lhs < __rhs._M_base();
  993. }
  994. template<typename _CharT, typename _Traits, typename _Allocator>
  995. inline bool
  996. operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  997. const _CharT* __rhs)
  998. {
  999. __glibcxx_check_string(__rhs);
  1000. return __lhs._M_base() < __rhs;
  1001. }
  1002. template<typename _CharT, typename _Traits, typename _Allocator>
  1003. inline bool
  1004. operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1005. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1006. { return __lhs._M_base() <= __rhs._M_base(); }
  1007. template<typename _CharT, typename _Traits, typename _Allocator>
  1008. inline bool
  1009. operator<=(const _CharT* __lhs,
  1010. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1011. {
  1012. __glibcxx_check_string(__lhs);
  1013. return __lhs <= __rhs._M_base();
  1014. }
  1015. template<typename _CharT, typename _Traits, typename _Allocator>
  1016. inline bool
  1017. operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1018. const _CharT* __rhs)
  1019. {
  1020. __glibcxx_check_string(__rhs);
  1021. return __lhs._M_base() <= __rhs;
  1022. }
  1023. template<typename _CharT, typename _Traits, typename _Allocator>
  1024. inline bool
  1025. operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1026. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1027. { return __lhs._M_base() >= __rhs._M_base(); }
  1028. template<typename _CharT, typename _Traits, typename _Allocator>
  1029. inline bool
  1030. operator>=(const _CharT* __lhs,
  1031. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1032. {
  1033. __glibcxx_check_string(__lhs);
  1034. return __lhs >= __rhs._M_base();
  1035. }
  1036. template<typename _CharT, typename _Traits, typename _Allocator>
  1037. inline bool
  1038. operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1039. const _CharT* __rhs)
  1040. {
  1041. __glibcxx_check_string(__rhs);
  1042. return __lhs._M_base() >= __rhs;
  1043. }
  1044. template<typename _CharT, typename _Traits, typename _Allocator>
  1045. inline bool
  1046. operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1047. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1048. { return __lhs._M_base() > __rhs._M_base(); }
  1049. template<typename _CharT, typename _Traits, typename _Allocator>
  1050. inline bool
  1051. operator>(const _CharT* __lhs,
  1052. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1053. {
  1054. __glibcxx_check_string(__lhs);
  1055. return __lhs > __rhs._M_base();
  1056. }
  1057. template<typename _CharT, typename _Traits, typename _Allocator>
  1058. inline bool
  1059. operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1060. const _CharT* __rhs)
  1061. {
  1062. __glibcxx_check_string(__rhs);
  1063. return __lhs._M_base() > __rhs;
  1064. }
  1065. // 21.3.7.8:
  1066. template<typename _CharT, typename _Traits, typename _Allocator>
  1067. inline void
  1068. swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
  1069. basic_string<_CharT,_Traits,_Allocator>& __rhs)
  1070. { __lhs.swap(__rhs); }
  1071. template<typename _CharT, typename _Traits, typename _Allocator>
  1072. std::basic_ostream<_CharT, _Traits>&
  1073. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1074. const basic_string<_CharT, _Traits, _Allocator>& __str)
  1075. { return __os << __str._M_base(); }
  1076. template<typename _CharT, typename _Traits, typename _Allocator>
  1077. std::basic_istream<_CharT,_Traits>&
  1078. operator>>(std::basic_istream<_CharT,_Traits>& __is,
  1079. basic_string<_CharT,_Traits,_Allocator>& __str)
  1080. {
  1081. std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
  1082. __str._M_invalidate_all();
  1083. return __res;
  1084. }
  1085. template<typename _CharT, typename _Traits, typename _Allocator>
  1086. std::basic_istream<_CharT,_Traits>&
  1087. getline(std::basic_istream<_CharT,_Traits>& __is,
  1088. basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
  1089. {
  1090. std::basic_istream<_CharT,_Traits>& __res = getline(__is,
  1091. __str._M_base(),
  1092. __delim);
  1093. __str._M_invalidate_all();
  1094. return __res;
  1095. }
  1096. template<typename _CharT, typename _Traits, typename _Allocator>
  1097. std::basic_istream<_CharT,_Traits>&
  1098. getline(std::basic_istream<_CharT,_Traits>& __is,
  1099. basic_string<_CharT,_Traits,_Allocator>& __str)
  1100. {
  1101. std::basic_istream<_CharT,_Traits>& __res = getline(__is,
  1102. __str._M_base());
  1103. __str._M_invalidate_all();
  1104. return __res;
  1105. }
  1106. typedef basic_string<char> string;
  1107. typedef basic_string<wchar_t> wstring;
  1108. #ifdef _GLIBCXX_USE_CHAR8_T
  1109. /// A string of @c char8_t
  1110. typedef basic_string<char8_t> u8string;
  1111. #endif
  1112. #if __cplusplus >= 201103L
  1113. /// A string of @c char16_t
  1114. typedef basic_string<char16_t> u16string;
  1115. /// A string of @c char32_t
  1116. typedef basic_string<char32_t> u32string;
  1117. #endif
  1118. template<typename _CharT, typename _Traits, typename _Allocator>
  1119. struct _Insert_range_from_self_is_safe<
  1120. __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
  1121. { enum { __value = 1 }; };
  1122. } // namespace __gnu_debug
  1123. #if __cplusplus >= 201103L
  1124. namespace std _GLIBCXX_VISIBILITY(default)
  1125. {
  1126. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  1127. /// std::hash specialization for __gnu_debug::basic_string.
  1128. template<typename _CharT>
  1129. struct hash<__gnu_debug::basic_string<_CharT>>
  1130. : public hash<std::basic_string<_CharT>>
  1131. { };
  1132. template<typename _CharT>
  1133. struct __is_fast_hash<hash<__gnu_debug::basic_string<_CharT>>>
  1134. : __is_fast_hash<hash<std::basic_string<_CharT>>>
  1135. { };
  1136. _GLIBCXX_END_NAMESPACE_VERSION
  1137. }
  1138. #endif /* C++11 */
  1139. #undef _GLIBCXX_INSERT_RETURNS_ITERATOR
  1140. #undef _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY
  1141. #endif