36 #ifndef _BASIC_STRING_H
37 #define _BASIC_STRING_H 1
39 #pragma GCC system_header
43 #ifdef __GXX_EXPERIMENTAL_CXX0X__
47 namespace std _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
108 template<
typename _CharT,
typename _Traits,
typename _Alloc>
111 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
115 typedef _Traits traits_type;
116 typedef typename _Traits::char_type value_type;
117 typedef _Alloc allocator_type;
118 typedef typename _CharT_alloc_type::size_type size_type;
119 typedef typename _CharT_alloc_type::difference_type difference_type;
120 typedef typename _CharT_alloc_type::reference reference;
121 typedef typename _CharT_alloc_type::const_reference const_reference;
122 typedef typename _CharT_alloc_type::pointer pointer;
123 typedef typename _CharT_alloc_type::const_pointer const_pointer;
124 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
125 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
148 size_type _M_capacity;
149 _Atomic_word _M_refcount;
152 struct _Rep : _Rep_base
155 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
170 static const size_type _S_max_size;
171 static const _CharT _S_terminal;
175 static size_type _S_empty_rep_storage[];
183 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
184 return *
reinterpret_cast<_Rep*
>(__p);
189 {
return this->_M_refcount < 0; }
193 {
return this->_M_refcount > 0; }
197 { this->_M_refcount = -1; }
201 { this->_M_refcount = 0; }
204 _M_set_length_and_sharable(size_type __n)
206 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
207 if (__builtin_expect(
this != &_S_empty_rep(),
false))
210 this->_M_set_sharable();
211 this->_M_length = __n;
212 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
220 {
return reinterpret_cast<_CharT*
>(
this + 1); }
223 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
225 return (!_M_is_leaked() && __alloc1 == __alloc2)
226 ? _M_refcopy() : _M_clone(__alloc1);
231 _S_create(size_type, size_type,
const _Alloc&);
234 _M_dispose(
const _Alloc& __a)
236 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
237 if (__builtin_expect(
this != &_S_empty_rep(),
false))
241 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
242 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
245 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
252 _M_destroy(
const _Alloc&)
throw();
257 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
258 if (__builtin_expect(
this != &_S_empty_rep(),
false))
260 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
265 _M_clone(
const _Alloc&, size_type __res = 0);
269 struct _Alloc_hider : _Alloc
271 _Alloc_hider(_CharT* __dat,
const _Alloc& __a)
272 : _Alloc(__a), _M_p(__dat) { }
282 static const size_type
npos =
static_cast<size_type
>(-1);
286 mutable _Alloc_hider _M_dataplus;
290 {
return _M_dataplus._M_p; }
294 {
return (_M_dataplus._M_p = __p); }
298 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
304 {
return iterator(_M_data()); }
308 {
return iterator(_M_data() + this->
size()); }
313 if (!_M_rep()->_M_is_leaked())
318 _M_check(size_type __pos,
const char* __s)
const
320 if (__pos > this->
size())
321 __throw_out_of_range(__N(__s));
326 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
329 __throw_length_error(__N(__s));
334 _M_limit(size_type __pos, size_type __off)
const
336 const bool __testoff = __off < this->
size() - __pos;
337 return __testoff ? __off : this->
size() - __pos;
342 _M_disjunct(
const _CharT* __s)
const
344 return (less<const _CharT*>()(__s, _M_data())
345 || less<const _CharT*>()(_M_data() + this->
size(), __s));
351 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n)
354 traits_type::assign(*__d, *__s);
356 traits_type::copy(__d, __s, __n);
360 _M_move(_CharT* __d,
const _CharT* __s, size_type __n)
363 traits_type::assign(*__d, *__s);
365 traits_type::move(__d, __s, __n);
369 _M_assign(_CharT* __d, size_type __n, _CharT __c)
372 traits_type::assign(*__d, __c);
374 traits_type::assign(__d, __n, __c);
379 template<
class _Iterator>
381 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
383 for (; __k1 != __k2; ++__k1, ++__p)
384 traits_type::assign(*__p, *__k1);
388 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
389 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
392 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
393 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
396 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
397 { _M_copy(__p, __k1, __k2 - __k1); }
400 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
401 { _M_copy(__p, __k1, __k2 - __k1); }
404 _S_compare(size_type __n1, size_type __n2)
406 const difference_type __d = difference_type(__n1 - __n2);
408 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
409 return __gnu_cxx::__numeric_traits<int>::__max;
410 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
411 return __gnu_cxx::__numeric_traits<int>::__min;
417 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
424 {
return _Rep::_S_empty_rep(); }
435 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
436 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
438 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
460 size_type __n =
npos);
469 size_type __n,
const _Alloc& __a);
481 const _Alloc& __a = _Alloc());
487 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc());
494 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc());
496 #ifdef __GXX_EXPERIMENTAL_CXX0X__
505 : _M_dataplus(__str._M_dataplus)
507 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
508 __str._M_data(_S_empty_rep()._M_refdata());
510 __str._M_data(_S_construct(size_type(), _CharT(),
get_allocator()));
520 #endif // __GXX_EXPERIMENTAL_CXX0X__
528 template<
class _InputIterator>
529 basic_string(_InputIterator __beg, _InputIterator __end,
530 const _Alloc& __a = _Alloc());
544 {
return this->
assign(__str); }
552 {
return this->
assign(__s); }
568 #ifdef __GXX_EXPERIMENTAL_CXX0X__
591 this->
assign(__l.begin(), __l.size());
594 #endif // __GXX_EXPERIMENTAL_CXX0X__
605 return iterator(_M_data());
614 {
return const_iterator(_M_data()); }
624 return iterator(_M_data() + this->
size());
632 end() const _GLIBCXX_NOEXCEPT
633 {
return const_iterator(_M_data() + this->
size()); }
649 const_reverse_iterator
667 const_reverse_iterator
671 #ifdef __GXX_EXPERIMENTAL_CXX0X__
678 {
return const_iterator(this->_M_data()); }
686 {
return const_iterator(this->_M_data() + this->
size()); }
693 const_reverse_iterator
702 const_reverse_iterator
713 {
return _M_rep()->_M_length; }
719 {
return _M_rep()->_M_length; }
724 {
return _Rep::_S_max_size; }
737 resize(size_type __n, _CharT __c);
751 { this->
resize(__n, _CharT()); }
753 #ifdef __GXX_EXPERIMENTAL_CXX0X__
774 {
return _M_rep()->_M_capacity; }
794 reserve(size_type __res_arg = 0);
801 { _M_mutate(0, this->
size(), 0); }
809 {
return this->
size() == 0; }
825 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
826 return _M_data()[__pos];
843 _GLIBCXX_DEBUG_ASSERT(__pos <=
size());
845 _GLIBCXX_DEBUG_PEDASSERT(__pos <
size());
847 return _M_data()[__pos];
861 at(size_type __n)
const
863 if (__n >= this->
size())
864 __throw_out_of_range(__N(
"basic_string::at"));
865 return _M_data()[__n];
883 __throw_out_of_range(__N(
"basic_string::at"));
885 return _M_data()[__n];
888 #ifdef __GXX_EXPERIMENTAL_CXX0X__
930 {
return this->
append(__str); }
939 {
return this->
append(__s); }
953 #ifdef __GXX_EXPERIMENTAL_CXX0X__
961 {
return this->
append(__l.begin(), __l.size()); }
962 #endif // __GXX_EXPERIMENTAL_CXX0X__
995 append(
const _CharT* __s, size_type __n);
1005 __glibcxx_requires_string(__s);
1006 return this->
append(__s, traits_type::length(__s));
1018 append(size_type __n, _CharT __c);
1020 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1028 {
return this->
append(__l.begin(), __l.size()); }
1029 #endif // __GXX_EXPERIMENTAL_CXX0X__
1039 template<
class _InputIterator>
1041 append(_InputIterator __first, _InputIterator __last)
1042 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1051 const size_type __len = 1 + this->
size();
1052 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1054 traits_type::assign(_M_data()[this->
size()], __c);
1055 _M_rep()->_M_set_length_and_sharable(__len);
1066 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1081 #endif // __GXX_EXPERIMENTAL_CXX0X__
1098 {
return this->
assign(__str._M_data()
1099 + __str._M_check(__pos,
"basic_string::assign"),
1100 __str._M_limit(__pos, __n)); }
1113 assign(
const _CharT* __s, size_type __n);
1127 __glibcxx_requires_string(__s);
1128 return this->
assign(__s, traits_type::length(__s));
1142 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1152 template<
class _InputIterator>
1154 assign(_InputIterator __first, _InputIterator __last)
1155 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1157 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1165 {
return this->
assign(__l.begin(), __l.size()); }
1166 #endif // __GXX_EXPERIMENTAL_CXX0X__
1182 insert(iterator __p, size_type __n, _CharT __c)
1183 { this->
replace(__p, __p, __n, __c); }
1197 template<
class _InputIterator>
1199 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1200 { this->
replace(__p, __p, __beg, __end); }
1202 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1212 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1213 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1215 #endif // __GXX_EXPERIMENTAL_CXX0X__
1231 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1253 size_type __pos2, size_type __n)
1254 {
return this->
insert(__pos1, __str._M_data()
1255 + __str._M_check(__pos2,
"basic_string::insert"),
1256 __str._M_limit(__pos2, __n)); }
1275 insert(size_type __pos,
const _CharT* __s, size_type __n);
1295 __glibcxx_requires_string(__s);
1296 return this->
insert(__pos, __s, traits_type::length(__s));
1316 insert(size_type __pos, size_type __n, _CharT __c)
1317 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1318 size_type(0), __n, __c); }
1336 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1337 const size_type __pos = __p - _M_ibegin();
1338 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1339 _M_rep()->_M_set_leaked();
1340 return iterator(_M_data() + __pos);
1361 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1362 _M_limit(__pos, __n), size_type(0));
1377 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1378 && __position < _M_iend());
1379 const size_type __pos = __position - _M_ibegin();
1380 _M_mutate(__pos, size_type(1), size_type(0));
1381 _M_rep()->_M_set_leaked();
1382 return iterator(_M_data() + __pos);
1397 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1406 #endif // __GXX_EXPERIMENTAL_CXX0X__
1427 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1449 size_type __pos2, size_type __n2)
1450 {
return this->
replace(__pos1, __n1, __str._M_data()
1451 + __str._M_check(__pos2,
"basic_string::replace"),
1452 __str._M_limit(__pos2, __n2)); }
1473 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1493 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1495 __glibcxx_requires_string(__s);
1496 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1517 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1518 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1519 _M_limit(__pos, __n1), __n2, __c); }
1536 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1554 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1556 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1557 && __i2 <= _M_iend());
1558 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1575 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1577 __glibcxx_requires_string(__s);
1578 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1596 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1598 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1599 && __i2 <= _M_iend());
1600 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1618 template<
class _InputIterator>
1621 _InputIterator __k1, _InputIterator __k2)
1623 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1624 && __i2 <= _M_iend());
1625 __glibcxx_requires_valid_range(__k1, __k2);
1626 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1627 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1635 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1636 && __i2 <= _M_iend());
1637 __glibcxx_requires_valid_range(__k1, __k2);
1638 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1643 replace(iterator __i1, iterator __i2,
1644 const _CharT* __k1,
const _CharT* __k2)
1646 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1647 && __i2 <= _M_iend());
1648 __glibcxx_requires_valid_range(__k1, __k2);
1649 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1654 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
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,
1660 __k1.base(), __k2 - __k1);
1664 replace(iterator __i1, iterator __i2,
1665 const_iterator __k1, const_iterator __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,
1671 __k1.base(), __k2 - __k1);
1674 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1691 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
1692 #endif // __GXX_EXPERIMENTAL_CXX0X__
1695 template<
class _Integer>
1698 _Integer __val, __true_type)
1699 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1701 template<
class _InputIterator>
1703 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1704 _InputIterator __k2, __false_type);
1707 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1711 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
1716 template<
class _InIterator>
1718 _S_construct_aux(_InIterator __beg, _InIterator __end,
1719 const _Alloc& __a, __false_type)
1721 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1722 return _S_construct(__beg, __end, __a, _Tag());
1727 template<
class _Integer>
1729 _S_construct_aux(_Integer __beg, _Integer __end,
1730 const _Alloc& __a, __true_type)
1731 {
return _S_construct_aux_2(static_cast<size_type>(__beg),
1735 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
1736 {
return _S_construct(__req, __c, __a); }
1738 template<
class _InIterator>
1740 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
1742 typedef typename std::__is_integer<_InIterator>::__type _Integral;
1743 return _S_construct_aux(__beg, __end, __a, _Integral());
1747 template<
class _InIterator>
1749 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
1750 input_iterator_tag);
1754 template<
class _FwdIterator>
1756 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
1757 forward_iterator_tag);
1760 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
1777 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
1798 {
return _M_data(); }
1808 {
return _M_data(); }
1815 {
return _M_dataplus; }
1830 find(
const _CharT* __s, size_type __pos, size_type __n)
const;
1845 {
return this->
find(__str.
data(), __pos, __str.
size()); }
1858 find(
const _CharT* __s, size_type __pos = 0)
const
1860 __glibcxx_requires_string(__s);
1861 return this->
find(__s, __pos, traits_type::length(__s));
1875 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1890 {
return this->
rfind(__str.data(), __pos, __str.size()); }
1905 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const;
1920 __glibcxx_requires_string(__s);
1921 return this->
rfind(__s, __pos, traits_type::length(__s));
1935 rfind(_CharT __c, size_type __pos =
npos) const _GLIBCXX_NOEXCEPT;
1951 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
1966 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
1981 __glibcxx_requires_string(__s);
1982 return this->
find_first_of(__s, __pos, traits_type::length(__s));
1999 {
return this->
find(__c, __pos); }
2030 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
2045 __glibcxx_requires_string(__s);
2046 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2063 {
return this->
rfind(__c, __pos); }
2094 size_type __n)
const;
2109 __glibcxx_requires_string(__s);
2157 size_type __n)
const;
2172 __glibcxx_requires_string(__s);
2205 _M_check(__pos,
"basic_string::substr"), __n); }
2224 const size_type __size = this->
size();
2225 const size_type __osize = __str.
size();
2226 const size_type __len =
std::min(__size, __osize);
2228 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2230 __r = _S_compare(__size, __osize);
2281 size_type __pos2, size_type __n2)
const;
2298 compare(
const _CharT* __s)
const;
2322 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2349 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2350 size_type __n2)
const;
2360 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2361 basic_string<_CharT, _Traits, _Alloc>
2376 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2377 basic_string<_CharT,_Traits,_Alloc>
2379 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2387 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2388 basic_string<_CharT,_Traits,_Alloc>
2389 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2397 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2398 inline basic_string<_CharT, _Traits, _Alloc>
2400 const _CharT* __rhs)
2413 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2414 inline basic_string<_CharT, _Traits, _Alloc>
2418 typedef typename __string_type::size_type __size_type;
2419 __string_type __str(__lhs);
2420 __str.append(__size_type(1), __rhs);
2424 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2425 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2426 inline basic_string<_CharT, _Traits, _Alloc>
2427 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2428 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2429 {
return std::move(__lhs.append(__rhs)); }
2431 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2432 inline basic_string<_CharT, _Traits, _Alloc>
2433 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2434 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2435 {
return std::move(__rhs.insert(0, __lhs)); }
2437 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2438 inline basic_string<_CharT, _Traits, _Alloc>
2439 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2440 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2442 const auto __size = __lhs.size() + __rhs.size();
2443 const bool __cond = (__size > __lhs.capacity()
2444 && __size <= __rhs.capacity());
2445 return __cond ? std::move(__rhs.insert(0, __lhs))
2446 : std::move(__lhs.append(__rhs));
2449 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2450 inline basic_string<_CharT, _Traits, _Alloc>
2452 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2453 {
return std::move(__rhs.insert(0, __lhs)); }
2455 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2456 inline basic_string<_CharT, _Traits, _Alloc>
2458 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
2459 {
return std::move(__rhs.insert(0, 1, __lhs)); }
2461 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2462 inline basic_string<_CharT, _Traits, _Alloc>
2463 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2464 const _CharT* __rhs)
2465 {
return std::move(__lhs.append(__rhs)); }
2467 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2468 inline basic_string<_CharT, _Traits, _Alloc>
2469 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
2471 {
return std::move(__lhs.append(1, __rhs)); }
2481 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2485 {
return __lhs.
compare(__rhs) == 0; }
2487 template<
typename _CharT>
2489 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
2490 operator==(
const basic_string<_CharT>& __lhs,
2491 const basic_string<_CharT>& __rhs)
2492 {
return (__lhs.size() == __rhs.size()
2502 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2504 operator==(
const _CharT* __lhs,
2506 {
return __rhs.
compare(__lhs) == 0; }
2514 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2517 const _CharT* __rhs)
2518 {
return __lhs.
compare(__rhs) == 0; }
2527 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2531 {
return !(__lhs == __rhs); }
2539 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2541 operator!=(
const _CharT* __lhs,
2543 {
return !(__lhs == __rhs); }
2551 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2554 const _CharT* __rhs)
2555 {
return !(__lhs == __rhs); }
2564 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2566 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2568 {
return __lhs.
compare(__rhs) < 0; }
2576 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2578 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2579 const _CharT* __rhs)
2580 {
return __lhs.compare(__rhs) < 0; }
2588 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2590 operator<(
const _CharT* __lhs,
2592 {
return __rhs.
compare(__lhs) > 0; }
2601 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2605 {
return __lhs.
compare(__rhs) > 0; }
2613 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2616 const _CharT* __rhs)
2617 {
return __lhs.
compare(__rhs) > 0; }
2625 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2627 operator>(
const _CharT* __lhs,
2629 {
return __rhs.
compare(__lhs) < 0; }
2638 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2640 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2642 {
return __lhs.
compare(__rhs) <= 0; }
2650 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2652 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2653 const _CharT* __rhs)
2654 {
return __lhs.compare(__rhs) <= 0; }
2662 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2664 operator<=(
const _CharT* __lhs,
2666 {
return __rhs.
compare(__lhs) >= 0; }
2675 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2679 {
return __lhs.
compare(__rhs) >= 0; }
2687 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2690 const _CharT* __rhs)
2691 {
return __lhs.
compare(__rhs) >= 0; }
2699 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2701 operator>=(
const _CharT* __lhs,
2703 {
return __rhs.
compare(__lhs) <= 0; }
2712 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2716 { __lhs.
swap(__rhs); }
2730 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2731 basic_istream<_CharT, _Traits>&
2732 operator>>(basic_istream<_CharT, _Traits>& __is,
2733 basic_string<_CharT, _Traits, _Alloc>& __str);
2736 basic_istream<char>&
2737 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2748 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2749 inline basic_ostream<_CharT, _Traits>&
2750 operator<<(basic_ostream<_CharT, _Traits>& __os,
2755 return __ostream_insert(__os, __str.data(), __str.size());
2771 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2772 basic_istream<_CharT, _Traits>&
2773 getline(basic_istream<_CharT, _Traits>& __is,
2774 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2788 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2789 inline basic_istream<_CharT, _Traits>&
2795 basic_istream<char>&
2796 getline(basic_istream<char>& __in, basic_string<char>& __str,
2799 #ifdef _GLIBCXX_USE_WCHAR_T
2801 basic_istream<wchar_t>&
2802 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2806 _GLIBCXX_END_NAMESPACE_VERSION
2809 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
2810 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2814 namespace std _GLIBCXX_VISIBILITY(default)
2816 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2820 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2821 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
2825 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2826 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
2829 inline unsigned long
2830 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2831 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
2835 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2836 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
2839 inline unsigned long long
2840 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2841 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
2846 stof(
const string& __str,
size_t* __idx = 0)
2847 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
2850 stod(
const string& __str,
size_t* __idx = 0)
2851 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
2854 stold(
const string& __str,
size_t* __idx = 0)
2855 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
2862 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(int),
2867 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2868 4 *
sizeof(unsigned),
2873 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 *
sizeof(long),
2878 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2879 4 *
sizeof(
unsigned long),
2884 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2885 4 *
sizeof(
long long),
2890 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2891 4 *
sizeof(
unsigned long long),
2898 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
2899 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2907 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
2908 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2916 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
2917 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2921 #ifdef _GLIBCXX_USE_WCHAR_T
2923 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2924 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
2928 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2929 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
2932 inline unsigned long
2933 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2934 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
2938 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2939 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
2942 inline unsigned long long
2943 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2944 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
2949 stof(
const wstring& __str,
size_t* __idx = 0)
2950 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
2953 stod(
const wstring& __str,
size_t* __idx = 0)
2954 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
2957 stold(
const wstring& __str,
size_t* __idx = 0)
2958 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
2962 to_wstring(
int __val)
2963 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(int),
2967 to_wstring(
unsigned __val)
2968 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2969 4 *
sizeof(unsigned),
2973 to_wstring(
long __val)
2974 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(long),
2978 to_wstring(
unsigned long __val)
2979 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2980 4 *
sizeof(
unsigned long),
2984 to_wstring(
long long __val)
2985 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2986 4 *
sizeof(
long long),
2990 to_wstring(
unsigned long long __val)
2991 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2992 4 *
sizeof(
unsigned long long),
2996 to_wstring(
float __val)
2999 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
3000 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3005 to_wstring(
double __val)
3008 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
3009 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3014 to_wstring(
long double __val)
3017 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
3018 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
3023 _GLIBCXX_END_NAMESPACE_VERSION
3028 #ifdef __GXX_EXPERIMENTAL_CXX0X__
3032 namespace std _GLIBCXX_VISIBILITY(default)
3034 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3038 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
3042 :
public __hash_base<size_t, string>
3045 operator()(
const string& __s)
const noexcept
3046 {
return std::_Hash_impl::hash(__s.
data(), __s.
length()); }
3049 #ifdef _GLIBCXX_USE_WCHAR_T
3053 :
public __hash_base<size_t, wstring>
3056 operator()(
const wstring& __s)
const noexcept
3057 {
return std::_Hash_impl::hash(__s.
data(),
3058 __s.
length() *
sizeof(wchar_t)); }
3063 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3067 :
public __hash_base<size_t, u16string>
3070 operator()(
const u16string& __s)
const noexcept
3071 {
return std::_Hash_impl::hash(__s.
data(),
3072 __s.
length() *
sizeof(char16_t)); }
3078 :
public __hash_base<size_t, u32string>
3081 operator()(
const u32string& __s)
const noexcept
3082 {
return std::_Hash_impl::hash(__s.
data(),
3083 __s.
length() *
sizeof(char32_t)); }
3087 _GLIBCXX_END_NAMESPACE_VERSION
const_iterator cbegin() const noexcept
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
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(basic_string &&__str) noexcept
Move construct string.
size_type rfind(const _CharT *__s, size_type __pos=npos) const
Find last position of a C string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
const_reference back() const
const_iterator begin() const _GLIBCXX_NOEXCEPT
const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
reference at(size_type __n)
Provides access to the data contained in the string.
void push_back(_CharT __c)
Append a single character.
bool empty() const _GLIBCXX_NOEXCEPT
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
int compare(const basic_string &__str) const
Compare to a string.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
iterator insert(iterator __p, _CharT __c)
Insert one character.
void shrink_to_fit()
A non-binding request to reduce capacity() to size().
void swap(basic_string &__s)
Swap contents with another 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.
size_type capacity() const _GLIBCXX_NOEXCEPT
size_type find(const basic_string &__str, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a string.
const _CharT * c_str() const _GLIBCXX_NOEXCEPT
Return const pointer to null-terminated contents.
basic_string & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const
Find position of a character of C string.
~basic_string() _GLIBCXX_NOEXCEPT
Destroy the string instance.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
char_type widen(char __c) const
Widens characters.
size_type find_last_of(_CharT __c, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a character.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
basic_string & assign(basic_string &&__str)
Set value to contents of another string.
basic_string & operator=(const _CharT *__s)
Copy contents of s into this string.
const_reverse_iterator crbegin() const noexcept
basic_string & append(const basic_string &__str)
Append a string to this string.
basic_string & replace(iterator __i1, iterator __i2, const basic_string &__str)
Replace range of characters with string.
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
size_type size() const _GLIBCXX_NOEXCEPT
Returns the number of characters in the string, not including any null-termination.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a character not in string.
const _CharT * data() const _GLIBCXX_NOEXCEPT
Return const pointer to contents.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
reverse_iterator rbegin() _GLIBCXX_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.
basic_string & append(const _CharT *__s)
Append a C string.
size_type length() const _GLIBCXX_NOEXCEPT
Returns the number of characters in the string, not including any null-termination.
iterator begin() _GLIBCXX_NOEXCEPT
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
const_reverse_iterator crend() const noexcept
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a character of string.
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
const_iterator cend() const noexcept
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & operator+=(_CharT __c)
Append a character.
void pop_back()
Remove the last character.
basic_string()
Default constructor creates an empty string.
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
void resize(size_type __n)
Resizes the string to the specified number of characters.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a character not in string.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a character of string.
Template class basic_istream.This is the base class for all input streams. It provides text formattin...
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.
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
basic_string & operator+=(const _CharT *__s)
Append a C string.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character of C string.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n)
Set value to a substring of a string.
Managing sequences of characters and character-like objects.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
Basis for explicit traits specializations.
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
iterator erase(iterator __position)
Remove one character.
basic_string & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
size_type max_size() const _GLIBCXX_NOEXCEPT
Returns the size() of the largest possible string.
iterator end() _GLIBCXX_NOEXCEPT
bitset< _Nb > operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)
Insert a substring.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT
reverse_iterator rend() _GLIBCXX_NOEXCEPT
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
allocator_type get_allocator() const _GLIBCXX_NOEXCEPT
Return copy of allocator used to construct this string.
const_iterator end() const _GLIBCXX_NOEXCEPT
size_type find_first_of(_CharT __c, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a character.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with C string.
basic_string & operator=(basic_string &&__str)
Move assign the value of str to this string.
size_type rfind(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a string.
Primary class template hash.
const_reference operator[](size_type __pos) const
Subscript access to the data contained in the string.
size_type find(const _CharT *__s, size_type __pos=0) const
Find position of a C string.
void clear() _GLIBCXX_NOEXCEPT
static const size_type npos
Value returned by various member functions when they fail.
const_reference front() const