34 #ifndef _BASIC_STRING_H
35 #define _BASIC_STRING_H 1
37 #pragma GCC system_header
41 #if __cplusplus >= 201103L
42 #include <initializer_list>
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
111 template<
typename _CharT,
typename _Traits,
typename _Alloc>
114 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
118 typedef _Traits traits_type;
119 typedef typename _Traits::char_type value_type;
120 typedef _Alloc allocator_type;
121 typedef typename _CharT_alloc_type::size_type size_type;
122 typedef typename _CharT_alloc_type::difference_type difference_type;
123 typedef typename _CharT_alloc_type::reference reference;
124 typedef typename _CharT_alloc_type::const_reference const_reference;
125 typedef typename _CharT_alloc_type::pointer pointer;
126 typedef typename _CharT_alloc_type::const_pointer const_pointer;
127 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
128 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
151 size_type _M_capacity;
152 _Atomic_word _M_refcount;
155 struct _Rep : _Rep_base
158 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
173 static const size_type _S_max_size;
174 static const _CharT _S_terminal;
178 static size_type _S_empty_rep_storage[];
186 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
187 return *
reinterpret_cast<_Rep*
>(__p);
192 {
return this->_M_refcount < 0; }
196 {
return this->_M_refcount > 0; }
200 { this->_M_refcount = -1; }
204 { this->_M_refcount = 0; }
207 _M_set_length_and_sharable(size_type __n)
209 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
210 if (__builtin_expect(
this != &_S_empty_rep(),
false))
213 this->_M_set_sharable();
214 this->_M_length = __n;
215 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
223 {
return reinterpret_cast<_CharT*
>(
this + 1); }
226 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
228 return (!_M_is_leaked() && __alloc1 == __alloc2)
229 ? _M_refcopy() : _M_clone(__alloc1);
234 _S_create(size_type, size_type,
const _Alloc&);
237 _M_dispose(
const _Alloc& __a)
239 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
240 if (__builtin_expect(
this != &_S_empty_rep(),
false))
244 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
245 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
248 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
255 _M_destroy(
const _Alloc&)
throw();
260 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
261 if (__builtin_expect(
this != &_S_empty_rep(),
false))
263 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
268 _M_clone(
const _Alloc&, size_type __res = 0);
272 struct _Alloc_hider : _Alloc
274 _Alloc_hider(_CharT* __dat,
const _Alloc& __a)
275 : _Alloc(__a), _M_p(__dat) { }
285 static const size_type
npos =
static_cast<size_type
>(-1);
289 mutable _Alloc_hider _M_dataplus;
293 {
return _M_dataplus._M_p; }
297 {
return (_M_dataplus._M_p = __p); }
301 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
307 {
return iterator(_M_data()); }
311 {
return iterator(_M_data() + this->
size()); }
316 if (!_M_rep()->_M_is_leaked())
321 _M_check(size_type __pos,
const char* __s)
const
323 if (__pos > this->
size())
324 __throw_out_of_range(__N(__s));
329 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
332 __throw_length_error(__N(__s));
337 _M_limit(size_type __pos, size_type __off)
const
339 const bool __testoff = __off < this->
size() - __pos;
340 return __testoff ? __off : this->
size() - __pos;
345 _M_disjunct(
const _CharT* __s)
const
347 return (less<const _CharT*>()(__s, _M_data())
348 || less<const _CharT*>()(_M_data() + this->
size(), __s));
354 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n)
357 traits_type::assign(*__d, *__s);
359 traits_type::copy(__d, __s, __n);
363 _M_move(_CharT* __d,
const _CharT* __s, size_type __n)
366 traits_type::assign(*__d, *__s);
372 _M_assign(_CharT* __d, size_type __n, _CharT __c)
375 traits_type::assign(*__d, __c);
377 traits_type::assign(__d, __n, __c);
382 template<
class _Iterator>
384 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
386 for (; __k1 != __k2; ++__k1, ++__p)
387 traits_type::assign(*__p, *__k1);
391 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
392 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
395 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
396 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
399 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
400 { _M_copy(__p, __k1, __k2 - __k1); }
403 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
404 { _M_copy(__p, __k1, __k2 - __k1); }
407 _S_compare(size_type __n1, size_type __n2)
409 const difference_type __d = difference_type(__n1 - __n2);
411 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
412 return __gnu_cxx::__numeric_traits<int>::__max;
413 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
414 return __gnu_cxx::__numeric_traits<int>::__min;
420 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
427 {
return _Rep::_S_empty_rep(); }
438 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
439 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
441 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
463 size_type __n = npos);
472 size_type __n,
const _Alloc& __a);
484 const _Alloc& __a = _Alloc());
490 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc());
497 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc());
499 #if __cplusplus >= 201103L
508 : _M_dataplus(__str._M_dataplus)
510 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
511 __str._M_data(_S_empty_rep()._M_refdata());
513 __str._M_data(_S_construct(size_type(), _CharT(),
get_allocator()));
522 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc());
531 template<
class _InputIterator>
532 basic_string(_InputIterator __beg, _InputIterator __end,
533 const _Alloc& __a = _Alloc());
547 {
return this->
assign(__str); }
555 {
return this->
assign(__s); }
571 #if __cplusplus >= 201103L
594 this->
assign(__l.begin(), __l.size());
608 return iterator(_M_data());
617 {
return const_iterator(_M_data()); }
627 return iterator(_M_data() + this->
size());
635 end() const _GLIBCXX_NOEXCEPT
636 {
return const_iterator(_M_data() + this->
size()); }
645 {
return reverse_iterator(this->
end()); }
652 const_reverse_iterator
654 {
return const_reverse_iterator(this->
end()); }
663 {
return reverse_iterator(this->
begin()); }
670 const_reverse_iterator
672 {
return const_reverse_iterator(this->
begin()); }
674 #if __cplusplus >= 201103L
681 {
return const_iterator(this->_M_data()); }
689 {
return const_iterator(this->_M_data() + this->
size()); }
696 const_reverse_iterator
698 {
return const_reverse_iterator(this->
end()); }
705 const_reverse_iterator
707 {
return const_reverse_iterator(this->
begin()); }
716 {
return _M_rep()->_M_length; }
722 {
return _M_rep()->_M_length; }
727 {
return _Rep::_S_max_size; }
740 resize(size_type __n, _CharT __c);
754 { this->
resize(__n, _CharT()); }
756 #if __cplusplus >= 201103L
777 {
return _M_rep()->_M_capacity; }
797 reserve(size_type __res_arg = 0);
804 { _M_mutate(0, this->
size(), 0); }
812 {
return this->
size() == 0; }
828 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
829 return _M_data()[__pos];
846 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
848 _GLIBCXX_DEBUG_PEDASSERT(__pos <
size());
850 return _M_data()[__pos];
864 at(size_type __n)
const
866 if (__n >= this->
size())
867 __throw_out_of_range(__N(
"basic_string::at"));
868 return _M_data()[__n];
886 __throw_out_of_range(__N(
"basic_string::at"));
888 return _M_data()[__n];
891 #if __cplusplus >= 201103L
933 {
return this->
append(__str); }
942 {
return this->
append(__s); }
956 #if __cplusplus >= 201103L
964 {
return this->
append(__l.begin(), __l.size()); }
998 append(
const _CharT* __s, size_type __n);
1008 __glibcxx_requires_string(__s);
1009 return this->
append(__s, traits_type::length(__s));
1021 append(size_type __n, _CharT __c);
1023 #if __cplusplus >= 201103L
1031 {
return this->
append(__l.begin(), __l.size()); }
1042 template<
class _InputIterator>
1044 append(_InputIterator __first, _InputIterator __last)
1045 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1054 const size_type __len = 1 + this->
size();
1055 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1057 traits_type::assign(_M_data()[this->
size()], __c);
1058 _M_rep()->_M_set_length_and_sharable(__len);
1069 #if __cplusplus >= 201103L
1101 {
return this->
assign(__str._M_data()
1102 + __str._M_check(__pos,
"basic_string::assign"),
1103 __str._M_limit(__pos, __n)); }
1116 assign(
const _CharT* __s, size_type __n);
1130 __glibcxx_requires_string(__s);
1131 return this->
assign(__s, traits_type::length(__s));
1145 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1155 template<
class _InputIterator>
1157 assign(_InputIterator __first, _InputIterator __last)
1158 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1160 #if __cplusplus >= 201103L
1168 {
return this->
assign(__l.begin(), __l.size()); }
1185 insert(iterator __p, size_type __n, _CharT __c)
1186 { this->
replace(__p, __p, __n, __c); }
1200 template<
class _InputIterator>
1202 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1203 { this->
replace(__p, __p, __beg, __end); }
1205 #if __cplusplus >= 201103L
1213 insert(iterator __p, initializer_list<_CharT> __l)
1215 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1216 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1234 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1256 size_type __pos2, size_type __n)
1257 {
return this->
insert(__pos1, __str._M_data()
1258 + __str._M_check(__pos2,
"basic_string::insert"),
1259 __str._M_limit(__pos2, __n)); }
1278 insert(size_type __pos,
const _CharT* __s, size_type __n);
1298 __glibcxx_requires_string(__s);
1299 return this->
insert(__pos, __s, traits_type::length(__s));
1319 insert(size_type __pos, size_type __n, _CharT __c)
1320 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1321 size_type(0), __n, __c); }
1339 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1340 const size_type __pos = __p - _M_ibegin();
1341 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1342 _M_rep()->_M_set_leaked();
1343 return iterator(_M_data() + __pos);
1362 erase(size_type __pos = 0, size_type __n = npos)
1364 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1365 _M_limit(__pos, __n), size_type(0));
1380 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1381 && __position < _M_iend());
1382 const size_type __pos = __position - _M_ibegin();
1383 _M_mutate(__pos, size_type(1), size_type(0));
1384 _M_rep()->_M_set_leaked();
1385 return iterator(_M_data() + __pos);
1398 erase(iterator __first, iterator __last);
1400 #if __cplusplus >= 201103L
1430 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1452 size_type __pos2, size_type __n2)
1453 {
return this->
replace(__pos1, __n1, __str._M_data()
1454 + __str._M_check(__pos2,
"basic_string::replace"),
1455 __str._M_limit(__pos2, __n2)); }
1476 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1496 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1498 __glibcxx_requires_string(__s);
1499 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1520 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1521 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1522 _M_limit(__pos, __n1), __n2, __c); }
1539 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1557 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1559 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1560 && __i2 <= _M_iend());
1561 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1578 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1580 __glibcxx_requires_string(__s);
1581 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1599 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1601 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1602 && __i2 <= _M_iend());
1603 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1621 template<
class _InputIterator>
1624 _InputIterator __k1, _InputIterator __k2)
1626 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1627 && __i2 <= _M_iend());
1628 __glibcxx_requires_valid_range(__k1, __k2);
1629 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1630 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1636 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1638 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1639 && __i2 <= _M_iend());
1640 __glibcxx_requires_valid_range(__k1, __k2);
1641 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1646 replace(iterator __i1, iterator __i2,
1647 const _CharT* __k1,
const _CharT* __k2)
1649 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1650 && __i2 <= _M_iend());
1651 __glibcxx_requires_valid_range(__k1, __k2);
1652 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1657 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1659 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1660 && __i2 <= _M_iend());
1661 __glibcxx_requires_valid_range(__k1, __k2);
1662 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1663 __k1.base(), __k2 - __k1);
1667 replace(iterator __i1, iterator __i2,
1668 const_iterator __k1, const_iterator __k2)
1670 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1671 && __i2 <= _M_iend());
1672 __glibcxx_requires_valid_range(__k1, __k2);
1673 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1674 __k1.base(), __k2 - __k1);
1677 #if __cplusplus >= 201103L
1693 initializer_list<_CharT> __l)
1694 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
1698 template<
class _Integer>
1700 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1701 _Integer __val, __true_type)
1702 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1704 template<
class _InputIterator>
1706 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1707 _InputIterator __k2, __false_type);
1710 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1714 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
1719 template<
class _InIterator>
1721 _S_construct_aux(_InIterator __beg, _InIterator __end,
1722 const _Alloc& __a, __false_type)
1724 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1725 return _S_construct(__beg, __end, __a, _Tag());
1730 template<
class _Integer>
1732 _S_construct_aux(_Integer __beg, _Integer __end,
1733 const _Alloc& __a, __true_type)
1734 {
return _S_construct_aux_2(static_cast<size_type>(__beg),
1738 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
1739 {
return _S_construct(__req, __c, __a); }
1741 template<
class _InIterator>
1743 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
1745 typedef typename std::__is_integer<_InIterator>::__type _Integral;
1746 return _S_construct_aux(__beg, __end, __a, _Integral());
1750 template<
class _InIterator>
1752 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
1753 input_iterator_tag);
1757 template<
class _FwdIterator>
1759 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
1760 forward_iterator_tag);
1763 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
1780 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
1801 {
return _M_data(); }
1811 {
return _M_data(); }
1818 {
return _M_dataplus; }
1833 find(
const _CharT* __s, size_type __pos, size_type __n)
const;
1848 {
return this->
find(__str.
data(), __pos, __str.
size()); }
1861 find(
const _CharT* __s, size_type __pos = 0)
const
1863 __glibcxx_requires_string(__s);
1864 return this->
find(__s, __pos, traits_type::length(__s));
1878 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1893 {
return this->
rfind(__str.data(), __pos, __str.size()); }
1908 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const;
1921 rfind(
const _CharT* __s, size_type __pos = npos)
const
1923 __glibcxx_requires_string(__s);
1924 return this->
rfind(__s, __pos, traits_type::length(__s));
1938 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1954 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
1969 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
1984 __glibcxx_requires_string(__s);
1985 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2002 {
return this->
find(__c, __pos); }
2033 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
2048 __glibcxx_requires_string(__s);
2049 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2066 {
return this->
rfind(__c, __pos); }
2097 size_type __n)
const;
2112 __glibcxx_requires_string(__s);
2160 size_type __n)
const;
2175 __glibcxx_requires_string(__s);
2206 substr(size_type __pos = 0, size_type __n = npos)
const
2208 _M_check(__pos,
"basic_string::substr"), __n); }
2227 const size_type __size = this->
size();
2228 const size_type __osize = __str.
size();
2229 const size_type __len =
std::min(__size, __osize);
2231 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2233 __r = _S_compare(__size, __osize);
2284 size_type __pos2, size_type __n2)
const;
2301 compare(
const _CharT* __s)
const;
2325 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2352 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2353 size_type __n2)
const;
2363 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2364 basic_string<_CharT, _Traits, _Alloc>
2379 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2380 basic_string<_CharT,_Traits,_Alloc>
2382 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2390 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2391 basic_string<_CharT,_Traits,_Alloc>
2392 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2400 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2401 inline basic_string<_CharT, _Traits, _Alloc>
2403 const _CharT* __rhs)
2416 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2417 inline basic_string<_CharT, _Traits, _Alloc>
2421 typedef typename __string_type::size_type __size_type;
2422 __string_type __str(__lhs);
2423 __str.append(__size_type(1), __rhs);
2427 #if __cplusplus >= 201103L
2428 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2429 inline basic_string<_CharT, _Traits, _Alloc>
2430 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2431 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2432 {
return std::move(__lhs.append(__rhs)); }
2434 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2435 inline basic_string<_CharT, _Traits, _Alloc>
2436 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2437 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2438 {
return std::move(__rhs.insert(0, __lhs)); }
2440 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2441 inline basic_string<_CharT, _Traits, _Alloc>
2442 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2443 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2445 const auto __size = __lhs.size() + __rhs.size();
2446 const bool __cond = (__size > __lhs.capacity()
2447 && __size <= __rhs.capacity());
2448 return __cond ?
std::move(__rhs.insert(0, __lhs))
2452 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2453 inline basic_string<_CharT, _Traits, _Alloc>
2455 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2456 {
return std::move(__rhs.insert(0, __lhs)); }
2458 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2459 inline basic_string<_CharT, _Traits, _Alloc>
2461 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2462 {
return std::move(__rhs.insert(0, 1, __lhs)); }
2464 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2465 inline basic_string<_CharT, _Traits, _Alloc>
2466 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2467 const _CharT* __rhs)
2468 {
return std::move(__lhs.append(__rhs)); }
2470 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2471 inline basic_string<_CharT, _Traits, _Alloc>
2472 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2474 {
return std::move(__lhs.append(1, __rhs)); }
2484 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2488 {
return __lhs.
compare(__rhs) == 0; }
2490 template<
typename _CharT>
2492 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
2493 operator==(
const basic_string<_CharT>& __lhs,
2494 const basic_string<_CharT>& __rhs)
2495 {
return (__lhs.size() == __rhs.size()
2505 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2507 operator==(
const _CharT* __lhs,
2509 {
return __rhs.
compare(__lhs) == 0; }
2517 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2520 const _CharT* __rhs)
2521 {
return __lhs.
compare(__rhs) == 0; }
2530 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2534 {
return !(__lhs == __rhs); }
2542 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2544 operator!=(
const _CharT* __lhs,
2546 {
return !(__lhs == __rhs); }
2554 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2557 const _CharT* __rhs)
2558 {
return !(__lhs == __rhs); }
2567 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2569 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2571 {
return __lhs.
compare(__rhs) < 0; }
2579 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2581 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2582 const _CharT* __rhs)
2583 {
return __lhs.compare(__rhs) < 0; }
2591 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2595 {
return __rhs.
compare(__lhs) > 0; }
2604 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2608 {
return __lhs.
compare(__rhs) > 0; }
2616 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2619 const _CharT* __rhs)
2620 {
return __lhs.
compare(__rhs) > 0; }
2628 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2632 {
return __rhs.
compare(__lhs) < 0; }
2641 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2643 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2645 {
return __lhs.
compare(__rhs) <= 0; }
2653 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2655 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2656 const _CharT* __rhs)
2657 {
return __lhs.compare(__rhs) <= 0; }
2665 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2669 {
return __rhs.
compare(__lhs) >= 0; }
2678 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2682 {
return __lhs.
compare(__rhs) >= 0; }
2690 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2693 const _CharT* __rhs)
2694 {
return __lhs.
compare(__rhs) >= 0; }
2702 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2706 {
return __rhs.
compare(__lhs) <= 0; }
2715 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2719 { __lhs.
swap(__rhs); }
2733 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2734 basic_istream<_CharT, _Traits>&
2735 operator>>(basic_istream<_CharT, _Traits>& __is,
2736 basic_string<_CharT, _Traits, _Alloc>& __str);
2739 basic_istream<char>&
2740 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2751 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2752 inline basic_ostream<_CharT, _Traits>&
2753 operator<<(basic_ostream<_CharT, _Traits>& __os,
2758 return __ostream_insert(__os, __str.data(), __str.size());
2774 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2775 basic_istream<_CharT, _Traits>&
2776 getline(basic_istream<_CharT, _Traits>& __is,
2777 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2791 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2792 inline basic_istream<_CharT, _Traits>&
2795 {
return getline(__is, __str, __is.widen(
'\n')); }
2798 basic_istream<char>&
2799 getline(basic_istream<char>& __in, basic_string<char>& __str,
2802 #ifdef _GLIBCXX_USE_WCHAR_T
2804 basic_istream<wchar_t>&
2805 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2809 _GLIBCXX_END_NAMESPACE_VERSION
2812 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
2813 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2817 namespace std _GLIBCXX_VISIBILITY(default)
2819 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2823 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2824 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
2828 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2829 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
2832 inline unsigned long
2833 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2834 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
2838 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2839 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
2842 inline unsigned long long
2843 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2844 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
2849 stof(
const string& __str,
size_t* __idx = 0)
2850 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
2853 stod(
const string& __str,
size_t* __idx = 0)
2854 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
2857 stold(
const string& __str,
size_t* __idx = 0)
2858 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
2864 to_string(
int __val)
2865 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(int),
2869 to_string(
unsigned __val)
2870 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2871 4 *
sizeof(unsigned),
2875 to_string(
long __val)
2876 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(long),
2880 to_string(
unsigned long __val)
2881 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2882 4 *
sizeof(
unsigned long),
2886 to_string(
long long __val)
2887 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2888 4 *
sizeof(
long long),
2892 to_string(
unsigned long long __val)
2893 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2894 4 *
sizeof(
unsigned long long),
2898 to_string(
float __val)
2901 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
2902 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2907 to_string(
double __val)
2910 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
2911 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2916 to_string(
long double __val)
2919 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
2920 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2924 #ifdef _GLIBCXX_USE_WCHAR_T
2926 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2927 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
2931 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2932 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
2935 inline unsigned long
2936 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2937 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
2941 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2942 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
2945 inline unsigned long long
2946 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2947 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
2952 stof(
const wstring& __str,
size_t* __idx = 0)
2953 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
2956 stod(
const wstring& __str,
size_t* __idx = 0)
2957 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
2960 stold(
const wstring& __str,
size_t* __idx = 0)
2961 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
2965 to_wstring(
int __val)
2966 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(int),
2970 to_wstring(
unsigned __val)
2971 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2972 4 *
sizeof(unsigned),
2976 to_wstring(
long __val)
2977 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(long),
2981 to_wstring(
unsigned long __val)
2982 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2983 4 *
sizeof(
unsigned long),
2987 to_wstring(
long long __val)
2988 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2989 4 *
sizeof(
long long),
2993 to_wstring(
unsigned long long __val)
2994 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2995 4 *
sizeof(
unsigned long long),
2999 to_wstring(
float __val)
3002 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
3003 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3008 to_wstring(
double __val)
3011 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
3012 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3017 to_wstring(
long double __val)
3020 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
3021 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3026 _GLIBCXX_END_NAMESPACE_VERSION
3031 #if __cplusplus >= 201103L
3035 namespace std _GLIBCXX_VISIBILITY(default)
3037 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3041 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
3045 :
public __hash_base<size_t, string>
3048 operator()(
const string& __s)
const noexcept
3049 {
return std::_Hash_impl::hash(__s.
data(), __s.
length()); }
3053 struct __is_fast_hash<
hash<
string>> : std::false_type
3056 #ifdef _GLIBCXX_USE_WCHAR_T
3060 :
public __hash_base<size_t, wstring>
3063 operator()(
const wstring& __s)
const noexcept
3064 {
return std::_Hash_impl::hash(__s.
data(),
3065 __s.
length() *
sizeof(wchar_t)); }
3069 struct __is_fast_hash<
hash<
wstring>> : std::false_type
3074 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3078 :
public __hash_base<size_t, u16string>
3081 operator()(
const u16string& __s)
const noexcept
3082 {
return std::_Hash_impl::hash(__s.
data(),
3083 __s.
length() *
sizeof(char16_t)); }
3093 :
public __hash_base<size_t, u32string>
3096 operator()(
const u32string& __s)
const noexcept
3097 {
return std::_Hash_impl::hash(__s.
data(),
3098 __s.
length() *
sizeof(char32_t)); }
3106 _GLIBCXX_END_NAMESPACE_VERSION
void swap(basic_string &__s)
Swap contents with another string.
void push_back(_CharT __c)
Append a single character.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
void shrink_to_fit()
A non-binding request to reduce capacity() to size().
Basis for explicit traits specializations.
size_type capacity() const noexcept
basic_string & replace(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2)
Replace characters with value from another string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
size_type find_last_not_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character not in C string.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with C string.
const_reference back() const
const_reverse_iterator rbegin() const noexcept
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
void pop_back()
Remove the last character.
size_type find(const _CharT *__s, size_type __pos=0) const
Find position of a C string.
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
const_iterator begin() const noexcept
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
static const size_type npos
Value returned by various member functions when they fail.
basic_string & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
size_type rfind(const _CharT *__s, size_type __pos=npos) const
Find last position of a C string.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Managing sequences of characters and character-like objects.
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
const_iterator end() const noexcept
const_reference operator[](size_type __pos) const
Subscript access to the data contained in the string.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
iterator begin() noexcept
int compare(const basic_string &__str) const
Compare to a string.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
basic_string(basic_string &&__str) noexcept
Move construct string.
ISO C++ entities toplevel namespace is std.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & replace(iterator __i1, iterator __i2, const basic_string &__str)
Replace range of characters with string.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
reference at(size_type __n)
Provides access to the data contained in the string.
basic_string & operator+=(const _CharT *__s)
Append a C string.
const_reference front() const
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
iterator erase(iterator __position)
Remove one character.
basic_string()
Default constructor creates an empty string.
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
bool operator<=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't follow string.
~basic_string() noexcept
Destroy the string instance.
const_reverse_iterator crbegin() const noexcept
basic_string & operator=(const _CharT *__s)
Copy contents of s into this string.
bool operator<(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string precedes string.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const
Find position of a character of C string.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
const_iterator cbegin() const noexcept
basic_string & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(basic_string &&__str)
Set value to contents of another string.
basic_string & append(const basic_string &__str)
Append a string to this string.
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
basic_string & operator+=(_CharT __c)
Append a character.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
basic_string & append(const _CharT *__s)
Append a C string.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
bool empty() const noexcept
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character of C string.
size_type find(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a string.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
Primary class template hash.
const_iterator cend() const noexcept
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)
Insert a substring.
void resize(size_type __n)
Resizes the string to the specified number of characters.
reverse_iterator rend() noexcept
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
iterator insert(iterator __p, _CharT __c)
Insert one character.
const_reverse_iterator rend() const noexcept
reverse_iterator rbegin() noexcept
basic_string & operator=(basic_string &&__str)
Move assign the value of str to this string.
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const
Find position of a character not in C string.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n)
Set value to a substring of a string.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
basic_istream< _CharT, _Traits > & operator>>(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str)
Read stream into a string.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
const_reverse_iterator crend() const noexcept
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
basic_string< wchar_t > wstring
A string of wchar_t.