string 36 KB

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