34 #ifndef _BASIC_STRING_H
35 #define _BASIC_STRING_H 1
37 #pragma GCC system_header
41 #if __cplusplus >= 201103L
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[];
181 _S_empty_rep() _GLIBCXX_NOEXCEPT
186 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
187 return *
reinterpret_cast<_Rep*
>(__p);
191 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
192 {
return this->_M_refcount < 0; }
195 _M_is_shared()
const _GLIBCXX_NOEXCEPT
196 {
return this->_M_refcount > 0; }
199 _M_set_leaked() _GLIBCXX_NOEXCEPT
200 { this->_M_refcount = -1; }
203 _M_set_sharable() _GLIBCXX_NOEXCEPT
204 { this->_M_refcount = 0; }
207 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
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) _GLIBCXX_NOEXCEPT
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) _GLIBCXX_NOEXCEPT
275 : _Alloc(__a), _M_p(__dat) { }
285 static const size_type
npos =
static_cast<size_type
>(-1);
289 mutable _Alloc_hider _M_dataplus;
292 _M_data() const _GLIBCXX_NOEXCEPT
293 {
return _M_dataplus._M_p; }
296 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
297 {
return (_M_dataplus._M_p = __p); }
300 _M_rep() const _GLIBCXX_NOEXCEPT
301 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
306 _M_ibegin() const _GLIBCXX_NOEXCEPT
307 {
return iterator(_M_data()); }
310 _M_iend() const _GLIBCXX_NOEXCEPT
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_fmt(__N(
"%s: __pos (which is %zu) > "
325 "this->size() (which is %zu)"),
326 __s, __pos, this->
size());
331 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
334 __throw_length_error(__N(__s));
339 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
341 const bool __testoff = __off < this->
size() - __pos;
342 return __testoff ? __off : this->
size() - __pos;
347 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
349 return (less<const _CharT*>()(__s, _M_data())
350 || less<const _CharT*>()(_M_data() + this->
size(), __s));
356 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
359 traits_type::assign(*__d, *__s);
361 traits_type::copy(__d, __s, __n);
365 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
368 traits_type::assign(*__d, *__s);
370 traits_type::move(__d, __s, __n);
374 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
377 traits_type::assign(*__d, __c);
379 traits_type::assign(__d, __n, __c);
384 template<
class _Iterator>
386 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
389 for (; __k1 != __k2; ++__k1, ++__p)
390 traits_type::assign(*__p, *__k1);
394 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
395 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
398 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
400 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
403 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
404 { _M_copy(__p, __k1, __k2 - __k1); }
407 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
409 { _M_copy(__p, __k1, __k2 - __k1); }
412 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
414 const difference_type __d = difference_type(__n1 - __n2);
416 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
417 return __gnu_cxx::__numeric_traits<int>::__max;
418 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
419 return __gnu_cxx::__numeric_traits<int>::__min;
425 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
431 _S_empty_rep() _GLIBCXX_NOEXCEPT
432 {
return _Rep::_S_empty_rep(); }
443 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
444 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
446 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
468 size_type __n =
npos);
477 size_type __n,
const _Alloc& __a);
489 const _Alloc& __a = _Alloc());
495 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc());
502 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc());
504 #if __cplusplus >= 201103L
513 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
516 : _M_dataplus(__str._M_dataplus)
518 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
519 __str._M_data(_S_empty_rep()._M_refdata());
521 __str._M_data(_S_construct(size_type(), _CharT(),
get_allocator()));
539 template<
class _InputIterator>
540 basic_string(_InputIterator __beg, _InputIterator __end,
541 const _Alloc& __a = _Alloc());
555 {
return this->
assign(__str); }
563 {
return this->
assign(__s); }
579 #if __cplusplus >= 201103L
603 this->
assign(__l.begin(), __l.size());
617 return iterator(_M_data());
626 {
return const_iterator(_M_data()); }
636 return iterator(_M_data() + this->
size());
644 end() const _GLIBCXX_NOEXCEPT
645 {
return const_iterator(_M_data() + this->
size()); }
661 const_reverse_iterator
679 const_reverse_iterator
683 #if __cplusplus >= 201103L
690 {
return const_iterator(this->_M_data()); }
698 {
return const_iterator(this->_M_data() + this->
size()); }
705 const_reverse_iterator
714 const_reverse_iterator
725 {
return _M_rep()->_M_length; }
731 {
return _M_rep()->_M_length; }
736 {
return _Rep::_S_max_size; }
749 resize(size_type __n, _CharT __c);
763 { this->
resize(__n, _CharT()); }
765 #if __cplusplus >= 201103L
786 {
return _M_rep()->_M_capacity; }
806 reserve(size_type __res_arg = 0);
814 { _M_mutate(0, this->
size(), 0); }
822 {
return this->
size() == 0; }
838 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
839 return _M_data()[__pos];
857 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
859 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
861 return _M_data()[__pos];
875 at(size_type __n)
const
877 if (__n >= this->
size())
878 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
879 "(which is %zu) >= this->size() "
882 return _M_data()[__n];
900 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
901 "(which is %zu) >= this->size() "
905 return _M_data()[__n];
908 #if __cplusplus >= 201103L
950 {
return this->
append(__str); }
959 {
return this->
append(__s); }
973 #if __cplusplus >= 201103L
981 {
return this->
append(__l.begin(), __l.size()); }
1015 append(
const _CharT* __s, size_type __n);
1025 __glibcxx_requires_string(__s);
1026 return this->
append(__s, traits_type::length(__s));
1038 append(size_type __n, _CharT __c);
1040 #if __cplusplus >= 201103L
1048 {
return this->
append(__l.begin(), __l.size()); }
1059 template<
class _InputIterator>
1061 append(_InputIterator __first, _InputIterator __last)
1062 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1071 const size_type __len = 1 + this->
size();
1072 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1074 traits_type::assign(_M_data()[this->
size()], __c);
1075 _M_rep()->_M_set_length_and_sharable(__len);
1086 #if __cplusplus >= 201103L
1119 {
return this->
assign(__str._M_data()
1120 + __str._M_check(__pos,
"basic_string::assign"),
1121 __str._M_limit(__pos, __n)); }
1134 assign(
const _CharT* __s, size_type __n);
1148 __glibcxx_requires_string(__s);
1149 return this->
assign(__s, traits_type::length(__s));
1163 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1173 template<
class _InputIterator>
1175 assign(_InputIterator __first, _InputIterator __last)
1176 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1178 #if __cplusplus >= 201103L
1186 {
return this->
assign(__l.begin(), __l.size()); }
1203 insert(iterator __p, size_type __n, _CharT __c)
1204 { this->
replace(__p, __p, __n, __c); }
1218 template<
class _InputIterator>
1220 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1221 { this->
replace(__p, __p, __beg, __end); }
1223 #if __cplusplus >= 201103L
1233 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1234 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1252 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1274 size_type __pos2, size_type __n)
1275 {
return this->
insert(__pos1, __str._M_data()
1276 + __str._M_check(__pos2,
"basic_string::insert"),
1277 __str._M_limit(__pos2, __n)); }
1296 insert(size_type __pos,
const _CharT* __s, size_type __n);
1316 __glibcxx_requires_string(__s);
1317 return this->
insert(__pos, __s, traits_type::length(__s));
1337 insert(size_type __pos, size_type __n, _CharT __c)
1338 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1339 size_type(0), __n, __c); }
1357 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1358 const size_type __pos = __p - _M_ibegin();
1359 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1360 _M_rep()->_M_set_leaked();
1361 return iterator(_M_data() + __pos);
1382 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1383 _M_limit(__pos, __n), size_type(0));
1398 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1399 && __position < _M_iend());
1400 const size_type __pos = __position - _M_ibegin();
1401 _M_mutate(__pos, size_type(1), size_type(0));
1402 _M_rep()->_M_set_leaked();
1403 return iterator(_M_data() + __pos);
1418 #if __cplusplus >= 201103L
1448 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1470 size_type __pos2, size_type __n2)
1471 {
return this->
replace(__pos1, __n1, __str._M_data()
1472 + __str._M_check(__pos2,
"basic_string::replace"),
1473 __str._M_limit(__pos2, __n2)); }
1494 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1514 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1516 __glibcxx_requires_string(__s);
1517 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1538 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1539 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1540 _M_limit(__pos, __n1), __n2, __c); }
1557 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1575 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1577 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1578 && __i2 <= _M_iend());
1579 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1596 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1598 __glibcxx_requires_string(__s);
1599 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1617 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1619 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1620 && __i2 <= _M_iend());
1621 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1639 template<
class _InputIterator>
1642 _InputIterator __k1, _InputIterator __k2)
1644 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1645 && __i2 <= _M_iend());
1646 __glibcxx_requires_valid_range(__k1, __k2);
1647 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1648 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1656 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1657 && __i2 <= _M_iend());
1658 __glibcxx_requires_valid_range(__k1, __k2);
1659 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1664 replace(iterator __i1, iterator __i2,
1665 const _CharT* __k1,
const _CharT* __k2)
1667 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1668 && __i2 <= _M_iend());
1669 __glibcxx_requires_valid_range(__k1, __k2);
1670 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1675 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1677 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1678 && __i2 <= _M_iend());
1679 __glibcxx_requires_valid_range(__k1, __k2);
1680 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1681 __k1.base(), __k2 - __k1);
1685 replace(iterator __i1, iterator __i2,
1686 const_iterator __k1, const_iterator __k2)
1688 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1689 && __i2 <= _M_iend());
1690 __glibcxx_requires_valid_range(__k1, __k2);
1691 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1692 __k1.base(), __k2 - __k1);
1695 #if __cplusplus >= 201103L
1712 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
1716 template<
class _Integer>
1719 _Integer __val, __true_type)
1720 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1722 template<
class _InputIterator>
1724 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1725 _InputIterator __k2, __false_type);
1728 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1732 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
1737 template<
class _InIterator>
1739 _S_construct_aux(_InIterator __beg, _InIterator __end,
1740 const _Alloc& __a, __false_type)
1742 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1743 return _S_construct(__beg, __end, __a, _Tag());
1748 template<
class _Integer>
1750 _S_construct_aux(_Integer __beg, _Integer __end,
1751 const _Alloc& __a, __true_type)
1752 {
return _S_construct_aux_2(static_cast<size_type>(__beg),
1756 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
1757 {
return _S_construct(__req, __c, __a); }
1759 template<
class _InIterator>
1761 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
1763 typedef typename std::__is_integer<_InIterator>::__type _Integral;
1764 return _S_construct_aux(__beg, __end, __a, _Integral());
1768 template<
class _InIterator>
1770 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
1771 input_iterator_tag);
1775 template<
class _FwdIterator>
1777 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
1778 forward_iterator_tag);
1781 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
1798 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
1820 {
return _M_data(); }
1830 {
return _M_data(); }
1837 {
return _M_dataplus; }
1852 find(
const _CharT* __s, size_type __pos, size_type __n)
const;
1867 {
return this->
find(__str.
data(), __pos, __str.
size()); }
1880 find(
const _CharT* __s, size_type __pos = 0)
const
1882 __glibcxx_requires_string(__s);
1883 return this->
find(__s, __pos, traits_type::length(__s));
1897 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1912 {
return this->
rfind(__str.data(), __pos, __str.size()); }
1927 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const;
1942 __glibcxx_requires_string(__s);
1943 return this->
rfind(__s, __pos, traits_type::length(__s));
1957 rfind(_CharT __c, size_type __pos =
npos) const _GLIBCXX_NOEXCEPT;
1973 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
1988 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
2003 __glibcxx_requires_string(__s);
2004 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2021 {
return this->
find(__c, __pos); }
2052 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
2067 __glibcxx_requires_string(__s);
2068 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2085 {
return this->
rfind(__c, __pos); }
2116 size_type __n)
const;
2131 __glibcxx_requires_string(__s);
2179 size_type __n)
const;
2194 __glibcxx_requires_string(__s);
2227 _M_check(__pos,
"basic_string::substr"), __n); }
2246 const size_type __size = this->
size();
2247 const size_type __osize = __str.
size();
2248 const size_type __len =
std::min(__size, __osize);
2250 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2252 __r = _S_compare(__size, __osize);
2303 size_type __pos2, size_type __n2)
const;
2320 compare(
const _CharT* __s)
const;
2344 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2371 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2372 size_type __n2)
const;
2382 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2383 basic_string<_CharT, _Traits, _Alloc>
2398 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2399 basic_string<_CharT,_Traits,_Alloc>
2401 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2409 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2410 basic_string<_CharT,_Traits,_Alloc>
2411 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2419 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2420 inline basic_string<_CharT, _Traits, _Alloc>
2422 const _CharT* __rhs)
2435 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2436 inline basic_string<_CharT, _Traits, _Alloc>
2440 typedef typename __string_type::size_type __size_type;
2441 __string_type __str(__lhs);
2442 __str.append(__size_type(1), __rhs);
2446 #if __cplusplus >= 201103L
2447 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2448 inline basic_string<_CharT, _Traits, _Alloc>
2449 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2450 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2451 {
return std::move(__lhs.append(__rhs)); }
2453 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2454 inline basic_string<_CharT, _Traits, _Alloc>
2455 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2456 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2457 {
return std::move(__rhs.insert(0, __lhs)); }
2459 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2460 inline basic_string<_CharT, _Traits, _Alloc>
2461 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2462 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2464 const auto __size = __lhs.size() + __rhs.size();
2465 const bool __cond = (__size > __lhs.capacity()
2466 && __size <= __rhs.capacity());
2467 return __cond ? std::move(__rhs.insert(0, __lhs))
2468 : std::move(__lhs.append(__rhs));
2471 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2472 inline basic_string<_CharT, _Traits, _Alloc>
2474 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2475 {
return std::move(__rhs.insert(0, __lhs)); }
2477 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2478 inline basic_string<_CharT, _Traits, _Alloc>
2480 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2481 {
return std::move(__rhs.insert(0, 1, __lhs)); }
2483 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2484 inline basic_string<_CharT, _Traits, _Alloc>
2485 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2486 const _CharT* __rhs)
2487 {
return std::move(__lhs.append(__rhs)); }
2489 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2490 inline basic_string<_CharT, _Traits, _Alloc>
2491 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2493 {
return std::move(__lhs.append(1, __rhs)); }
2503 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2507 {
return __lhs.
compare(__rhs) == 0; }
2509 template<
typename _CharT>
2511 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
2512 operator==(
const basic_string<_CharT>& __lhs,
2513 const basic_string<_CharT>& __rhs)
2514 {
return (__lhs.size() == __rhs.size()
2524 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2526 operator==(
const _CharT* __lhs,
2528 {
return __rhs.
compare(__lhs) == 0; }
2536 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2539 const _CharT* __rhs)
2540 {
return __lhs.
compare(__rhs) == 0; }
2549 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2553 {
return !(__lhs == __rhs); }
2561 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2563 operator!=(
const _CharT* __lhs,
2565 {
return !(__lhs == __rhs); }
2573 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2576 const _CharT* __rhs)
2577 {
return !(__lhs == __rhs); }
2586 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2588 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2590 {
return __lhs.
compare(__rhs) < 0; }
2598 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2600 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2601 const _CharT* __rhs)
2602 {
return __lhs.compare(__rhs) < 0; }
2610 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2612 operator<(
const _CharT* __lhs,
2614 {
return __rhs.
compare(__lhs) > 0; }
2623 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2627 {
return __lhs.
compare(__rhs) > 0; }
2635 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2638 const _CharT* __rhs)
2639 {
return __lhs.
compare(__rhs) > 0; }
2647 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2649 operator>(
const _CharT* __lhs,
2651 {
return __rhs.
compare(__lhs) < 0; }
2660 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2662 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2664 {
return __lhs.
compare(__rhs) <= 0; }
2672 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2674 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2675 const _CharT* __rhs)
2676 {
return __lhs.compare(__rhs) <= 0; }
2684 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2686 operator<=(
const _CharT* __lhs,
2688 {
return __rhs.
compare(__lhs) >= 0; }
2697 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2701 {
return __lhs.
compare(__rhs) >= 0; }
2709 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2712 const _CharT* __rhs)
2713 {
return __lhs.
compare(__rhs) >= 0; }
2721 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2723 operator>=(
const _CharT* __lhs,
2725 {
return __rhs.
compare(__lhs) <= 0; }
2734 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2738 { __lhs.
swap(__rhs); }
2752 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2753 basic_istream<_CharT, _Traits>&
2754 operator>>(basic_istream<_CharT, _Traits>& __is,
2755 basic_string<_CharT, _Traits, _Alloc>& __str);
2758 basic_istream<char>&
2759 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2770 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2771 inline basic_ostream<_CharT, _Traits>&
2772 operator<<(basic_ostream<_CharT, _Traits>& __os,
2777 return __ostream_insert(__os, __str.data(), __str.size());
2793 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2794 basic_istream<_CharT, _Traits>&
2795 getline(basic_istream<_CharT, _Traits>& __is,
2796 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2810 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2811 inline basic_istream<_CharT, _Traits>&
2817 basic_istream<char>&
2818 getline(basic_istream<char>& __in, basic_string<char>& __str,
2821 #ifdef _GLIBCXX_USE_WCHAR_T
2823 basic_istream<wchar_t>&
2824 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2828 _GLIBCXX_END_NAMESPACE_VERSION
2831 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
2832 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2836 namespace std _GLIBCXX_VISIBILITY(default)
2838 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2842 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2843 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
2847 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2848 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
2851 inline unsigned long
2852 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2853 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
2857 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2858 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
2861 inline unsigned long long
2862 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2863 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
2868 stof(
const string& __str,
size_t* __idx = 0)
2869 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
2872 stod(
const string& __str,
size_t* __idx = 0)
2873 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
2876 stold(
const string& __str,
size_t* __idx = 0)
2877 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
2884 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(int),
2889 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2890 4 *
sizeof(unsigned),
2895 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(long),
2900 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2901 4 *
sizeof(
unsigned long),
2906 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2907 4 *
sizeof(
long long),
2912 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2913 4 *
sizeof(
unsigned long long),
2920 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
2921 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2929 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
2930 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2938 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
2939 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2943 #ifdef _GLIBCXX_USE_WCHAR_T
2945 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2946 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
2950 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2951 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
2954 inline unsigned long
2955 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2956 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
2960 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2961 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
2964 inline unsigned long long
2965 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2966 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
2971 stof(
const wstring& __str,
size_t* __idx = 0)
2972 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
2975 stod(
const wstring& __str,
size_t* __idx = 0)
2976 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
2979 stold(
const wstring& __str,
size_t* __idx = 0)
2980 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
2984 to_wstring(
int __val)
2985 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(int),
2989 to_wstring(
unsigned __val)
2990 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2991 4 *
sizeof(unsigned),
2995 to_wstring(
long __val)
2996 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(long),
3000 to_wstring(
unsigned long __val)
3001 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
3002 4 *
sizeof(
unsigned long),
3006 to_wstring(
long long __val)
3007 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
3008 4 *
sizeof(
long long),
3012 to_wstring(
unsigned long long __val)
3013 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
3014 4 *
sizeof(
unsigned long long),
3018 to_wstring(
float __val)
3021 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
3022 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3027 to_wstring(
double __val)
3030 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
3031 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3036 to_wstring(
long double __val)
3039 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
3040 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3045 _GLIBCXX_END_NAMESPACE_VERSION
3050 #if __cplusplus >= 201103L
3054 namespace std _GLIBCXX_VISIBILITY(default)
3056 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3060 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
3064 :
public __hash_base<size_t, string>
3067 operator()(
const string& __s)
const noexcept
3068 {
return std::_Hash_impl::hash(__s.
data(), __s.
length()); }
3075 #ifdef _GLIBCXX_USE_WCHAR_T
3079 :
public __hash_base<size_t, wstring>
3082 operator()(
const wstring& __s)
const noexcept
3083 {
return std::_Hash_impl::hash(__s.
data(),
3084 __s.
length() *
sizeof(wchar_t)); }
3093 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3097 :
public __hash_base<size_t, u16string>
3100 operator()(
const u16string& __s)
const noexcept
3101 {
return std::_Hash_impl::hash(__s.
data(),
3102 __s.
length() *
sizeof(char16_t)); }
3112 :
public __hash_base<size_t, u32string>
3115 operator()(
const u32string& __s)
const noexcept
3116 {
return std::_Hash_impl::hash(__s.
data(),
3117 __s.
length() *
sizeof(char32_t)); }
3125 #if __cplusplus > 201103L
3127 inline namespace literals
3129 inline namespace string_literals
3132 inline basic_string<char>
3133 operator""s(
const char* __str,
size_t __len)
3134 {
return basic_string<char>{__str, __len}; }
3136 #ifdef _GLIBCXX_USE_WCHAR_T
3137 inline basic_string<wchar_t>
3138 operator""s(
const wchar_t* __str,
size_t __len)
3139 {
return basic_string<wchar_t>{__str, __len}; }
3142 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3143 inline basic_string<char16_t>
3144 operator""s(
const char16_t* __str,
size_t __len)
3145 {
return basic_string<char16_t>{__str, __len}; }
3147 inline basic_string<char32_t>
3148 operator""s(
const char32_t* __str,
size_t __len)
3149 {
return basic_string<char32_t>{__str, __len}; }
3155 #endif // __cplusplus > 201103L
3157 _GLIBCXX_END_NAMESPACE_VERSION
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
const_reverse_iterator crend() const noexcept
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const
Find position of a character of C string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
size_type find(const _CharT *__s, size_type __pos=0) const
Find position of a C string.
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.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
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.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
size_type capacity() const noexcept
const_iterator end() const noexcept
size_type max_size() const noexcept
Returns the size() of the largest possible 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 & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
Template class basic_istream.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
void push_back(_CharT __c)
Append a single character.
const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
iterator erase(iterator __position)
Remove one character.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into 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.
const_reverse_iterator rend() const noexcept
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
basic_string< wchar_t > wstring
A string of wchar_t.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n)
Set value to a substring of a string.
bool empty() const noexcept
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
reverse_iterator rbegin()
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
basic_string & operator=(const _CharT *__s)
Copy contents of s into this string.
const_iterator cbegin() const noexcept
const_iterator begin() const noexcept
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
void swap(basic_string &__s)
Swap contents with another string.
static const size_type npos
Value returned by various member functions when they fail.
reference at(size_type __n)
Provides access to the data contained in the string.
basic_string & operator+=(const _CharT *__s)
Append a C string.
basic_string & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
const_reference front() const noexcept
size_type find_last_not_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character not in C string.
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.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
size_type find(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a string.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
basic_string(const _Alloc &__a)
Construct an empty string using allocator a.
const_iterator cend() const noexcept
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.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
basic_string & assign(basic_string &&__str)
Set value to contents of another string.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
const_reference back() const noexcept
~basic_string() noexcept
Destroy the string instance.
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with C string.
char_type widen(char __c) const
Widens characters.
basic_string & append(const _CharT *__s)
Append a C string.
const_reverse_iterator crbegin() const noexcept
Basis for explicit traits specializations.
basic_string & append(const basic_string &__str)
Append a string to this string.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character of C string.
int compare(const basic_string &__str) const
Compare to a string.
void pop_back()
Remove the last character.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
Managing sequences of characters and character-like objects.
iterator insert(iterator __p, _CharT __c)
Insert one character.
void resize(size_type __n)
Resizes the string to the specified number of characters.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
Primary class template hash.
basic_string & operator=(basic_string &&__str)
Move assign the value of str to this string.
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)
Insert a substring.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
size_type rfind(const _CharT *__s, size_type __pos=npos) const
Find last position of a C string.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const
Find position of a character not in C string.
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.