string 37 KB

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