36 #ifndef _BASIC_STRING_H
37 #define _BASIC_STRING_H 1
39 #pragma GCC system_header
45 _GLIBCXX_BEGIN_NAMESPACE(std)
103 template<typename _CharT, typename _Traits, typename _Alloc>
106 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
110 typedef _Traits traits_type;
111 typedef typename _Traits::char_type value_type;
112 typedef _Alloc allocator_type;
113 typedef typename _CharT_alloc_type::size_type size_type;
114 typedef typename _CharT_alloc_type::difference_type difference_type;
115 typedef typename _CharT_alloc_type::reference reference;
116 typedef typename _CharT_alloc_type::const_reference const_reference;
117 typedef typename _CharT_alloc_type::pointer pointer;
118 typedef typename _CharT_alloc_type::const_pointer const_pointer;
119 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
120 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
143 size_type _M_capacity;
144 _Atomic_word _M_refcount;
147 struct _Rep : _Rep_base
150 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
165 static const size_type _S_max_size;
166 static const _CharT _S_terminal;
170 static size_type _S_empty_rep_storage[];
178 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
179 return *
reinterpret_cast<_Rep*
>(__p);
184 {
return this->_M_refcount < 0; }
188 {
return this->_M_refcount > 0; }
192 { this->_M_refcount = -1; }
196 { this->_M_refcount = 0; }
199 _M_set_length_and_sharable(size_type __n)
201 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
202 if (__builtin_expect(
this != &_S_empty_rep(),
false))
205 this->_M_set_sharable();
206 this->_M_length = __n;
207 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
215 {
return reinterpret_cast<_CharT*
>(
this + 1); }
218 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
220 return (!_M_is_leaked() && __alloc1 == __alloc2)
221 ? _M_refcopy() : _M_clone(__alloc1);
226 _S_create(size_type, size_type,
const _Alloc&);
229 _M_dispose(
const _Alloc& __a)
231 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
232 if (__builtin_expect(
this != &_S_empty_rep(),
false))
234 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
240 _M_destroy(
const _Alloc&)
throw();
245 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
246 if (__builtin_expect(
this != &_S_empty_rep(),
false))
248 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
253 _M_clone(
const _Alloc&, size_type __res = 0);
257 struct _Alloc_hider : _Alloc
259 _Alloc_hider(_CharT* __dat,
const _Alloc& __a)
260 : _Alloc(__a), _M_p(__dat) { }
270 static const size_type npos =
static_cast<size_type
>(-1);
274 mutable _Alloc_hider _M_dataplus;
278 {
return _M_dataplus._M_p; }
282 {
return (_M_dataplus._M_p = __p); }
286 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
292 {
return iterator(_M_data()); }
296 {
return iterator(_M_data() + this->size()); }
301 if (!_M_rep()->_M_is_leaked())
306 _M_check(size_type __pos,
const char* __s)
const
308 if (__pos > this->size())
309 __throw_out_of_range(__N(__s));
314 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
316 if (this->max_size() - (this->size() - __n1) < __n2)
317 __throw_length_error(__N(__s));
322 _M_limit(size_type __pos, size_type __off)
const
324 const bool __testoff = __off < this->size() - __pos;
325 return __testoff ? __off : this->size() - __pos;
330 _M_disjunct(
const _CharT* __s)
const
332 return (less<const _CharT*>()(__s, _M_data())
333 || less<const _CharT*>()(_M_data() + this->size(), __s));
339 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n)
342 traits_type::assign(*__d, *__s);
344 traits_type::copy(__d, __s, __n);
348 _M_move(_CharT* __d,
const _CharT* __s, size_type __n)
351 traits_type::assign(*__d, *__s);
353 traits_type::move(__d, __s, __n);
357 _M_assign(_CharT* __d, size_type __n, _CharT __c)
360 traits_type::assign(*__d, __c);
362 traits_type::assign(__d, __n, __c);
367 template<
class _Iterator>
369 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
371 for (; __k1 != __k2; ++__k1, ++__p)
372 traits_type::assign(*__p, *__k1);
376 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
377 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
380 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
381 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
384 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
385 { _M_copy(__p, __k1, __k2 - __k1); }
388 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
389 { _M_copy(__p, __k1, __k2 - __k1); }
392 _S_compare(size_type __n1, size_type __n2)
394 const difference_type __d = difference_type(__n1 - __n2);
396 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
397 return __gnu_cxx::__numeric_traits<int>::__max;
398 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
399 return __gnu_cxx::__numeric_traits<int>::__min;
405 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
412 {
return _Rep::_S_empty_rep(); }
429 basic_string(
const _Alloc& __a);
436 basic_string(
const basic_string& __str);
443 basic_string(
const basic_string& __str, size_type __pos,
444 size_type __n = npos);
452 basic_string(
const basic_string& __str, size_type __pos,
453 size_type __n,
const _Alloc& __a);
464 basic_string(
const _CharT* __s, size_type __n,
465 const _Alloc& __a = _Alloc());
471 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc());
478 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc());
480 #ifdef __GXX_EXPERIMENTAL_CXX0X__
486 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc());
487 #endif // __GXX_EXPERIMENTAL_CXX0X__
495 template<
class _InputIterator>
496 basic_string(_InputIterator __beg, _InputIterator __end,
497 const _Alloc& __a = _Alloc());
503 { _M_rep()->_M_dispose(this->get_allocator()); }
510 operator=(
const basic_string& __str)
511 {
return this->assign(__str); }
518 operator=(
const _CharT* __s)
519 {
return this->assign(__s); }
529 operator=(_CharT __c)
531 this->assign(1, __c);
535 #ifdef __GXX_EXPERIMENTAL_CXX0X__
543 this->assign (__l.begin(), __l.end());
546 #endif // __GXX_EXPERIMENTAL_CXX0X__
557 return iterator(_M_data());
566 {
return const_iterator(_M_data()); }
576 return iterator(_M_data() + this->size());
585 {
return const_iterator(_M_data() + this->size()); }
594 {
return reverse_iterator(this->end()); }
601 const_reverse_iterator
603 {
return const_reverse_iterator(this->end()); }
612 {
return reverse_iterator(this->begin()); }
619 const_reverse_iterator
621 {
return const_reverse_iterator(this->begin()); }
629 {
return _M_rep()->_M_length; }
635 {
return _M_rep()->_M_length; }
640 {
return _Rep::_S_max_size; }
653 resize(size_type __n, _CharT __c);
666 resize(size_type __n)
667 { this->
resize(__n, _CharT()); }
675 {
return _M_rep()->_M_capacity; }
695 reserve(size_type __res_arg = 0);
702 { _M_mutate(0, this->size(), 0); }
709 {
return this->size() == 0; }
723 operator[] (size_type __pos)
const
725 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
726 return _M_data()[__pos];
740 operator[](size_type __pos)
743 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
745 _GLIBCXX_DEBUG_PEDASSERT(__pos < size());
747 return _M_data()[__pos];
761 at(size_type __n)
const
763 if (__n >= this->size())
764 __throw_out_of_range(__N(
"basic_string::at"));
765 return _M_data()[__n];
783 __throw_out_of_range(__N(
"basic_string::at"));
785 return _M_data()[__n];
795 operator+=(
const basic_string& __str)
796 {
return this->append(__str); }
804 operator+=(
const _CharT* __s)
805 {
return this->append(__s); }
813 operator+=(_CharT __c)
815 this->push_back(__c);
819 #ifdef __GXX_EXPERIMENTAL_CXX0X__
827 {
return this->append(__l.begin(), __l.end()); }
828 #endif // __GXX_EXPERIMENTAL_CXX0X__
836 append(
const basic_string& __str);
851 append(
const basic_string& __str, size_type __pos, size_type __n);
860 append(
const _CharT* __s, size_type __n);
868 append(
const _CharT* __s)
870 __glibcxx_requires_string(__s);
871 return this->append(__s, traits_type::length(__s));
883 append(size_type __n, _CharT __c);
885 #ifdef __GXX_EXPERIMENTAL_CXX0X__
893 {
return this->
append(__l.begin(), __l.end()); }
894 #endif // __GXX_EXPERIMENTAL_CXX0X__
904 template<
class _InputIterator>
906 append(_InputIterator __first, _InputIterator __last)
907 {
return this->replace(_M_iend(), _M_iend(), __first, __last); }
914 push_back(_CharT __c)
916 const size_type __len = 1 + this->size();
917 if (__len > this->capacity() || _M_rep()->_M_is_shared())
918 this->reserve(__len);
919 traits_type::assign(_M_data()[this->size()], __c);
920 _M_rep()->_M_set_length_and_sharable(__len);
929 assign(
const basic_string& __str);
944 assign(
const basic_string& __str, size_type __pos, size_type __n)
945 {
return this->
assign(__str._M_data()
946 + __str._M_check(__pos,
"basic_string::assign"),
947 __str._M_limit(__pos, __n)); }
960 assign(
const _CharT* __s, size_type __n);
972 assign(
const _CharT* __s)
974 __glibcxx_requires_string(__s);
975 return this->assign(__s, traits_type::length(__s));
988 assign(size_type __n, _CharT __c)
989 {
return _M_replace_aux(size_type(0), this->size(), __n, __c); }
999 template<
class _InputIterator>
1001 assign(_InputIterator __first, _InputIterator __last)
1002 {
return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
1004 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1012 {
return this->
assign(__l.begin(), __l.end()); }
1013 #endif // __GXX_EXPERIMENTAL_CXX0X__
1028 insert(iterator __p, size_type __n, _CharT __c)
1029 { this->replace(__p, __p, __n, __c); }
1042 template<
class _InputIterator>
1044 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1045 { this->replace(__p, __p, __beg, __end); }
1047 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1056 { this->
insert(__p, __l.begin(), __l.end()); }
1057 #endif // __GXX_EXPERIMENTAL_CXX0X__
1071 insert(size_type __pos1,
const basic_string& __str)
1072 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1093 insert(size_type __pos1,
const basic_string& __str,
1094 size_type __pos2, size_type __n)
1095 {
return this->
insert(__pos1, __str._M_data()
1096 + __str._M_check(__pos2,
"basic_string::insert"),
1097 __str._M_limit(__pos2, __n)); }
1116 insert(size_type __pos,
const _CharT* __s, size_type __n);
1134 insert(size_type __pos,
const _CharT* __s)
1136 __glibcxx_requires_string(__s);
1137 return this->insert(__pos, __s, traits_type::length(__s));
1157 insert(size_type __pos, size_type __n, _CharT __c)
1158 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1159 size_type(0), __n, __c); }
1174 insert(iterator __p, _CharT __c)
1176 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1177 const size_type __pos = __p - _M_ibegin();
1178 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1179 _M_rep()->_M_set_leaked();
1180 return iterator(_M_data() + __pos);
1198 erase(size_type __pos = 0, size_type __n = npos)
1200 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1201 _M_limit(__pos, __n), size_type(0));
1214 erase(iterator __position)
1216 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1217 && __position < _M_iend());
1218 const size_type __pos = __position - _M_ibegin();
1219 _M_mutate(__pos, size_type(1), size_type(0));
1220 _M_rep()->_M_set_leaked();
1221 return iterator(_M_data() + __pos);
1234 erase(iterator __first, iterator __last);
1253 replace(size_type __pos, size_type __n,
const basic_string& __str)
1254 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1275 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
1276 size_type __pos2, size_type __n2)
1277 {
return this->
replace(__pos1, __n1, __str._M_data()
1278 + __str._M_check(__pos2,
"basic_string::replace"),
1279 __str._M_limit(__pos2, __n2)); }
1299 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1318 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1320 __glibcxx_requires_string(__s);
1321 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1341 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1342 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1343 _M_limit(__pos, __n1), __n2, __c); }
1359 replace(iterator __i1, iterator __i2,
const basic_string& __str)
1360 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1377 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1379 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1380 && __i2 <= _M_iend());
1381 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1398 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1400 __glibcxx_requires_string(__s);
1401 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1419 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1421 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1422 && __i2 <= _M_iend());
1423 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1440 template<
class _InputIterator>
1442 replace(iterator __i1, iterator __i2,
1443 _InputIterator __k1, _InputIterator __k2)
1445 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1446 && __i2 <= _M_iend());
1447 __glibcxx_requires_valid_range(__k1, __k2);
1448 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1449 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1455 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1457 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1458 && __i2 <= _M_iend());
1459 __glibcxx_requires_valid_range(__k1, __k2);
1460 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1465 replace(iterator __i1, iterator __i2,
1466 const _CharT* __k1,
const _CharT* __k2)
1468 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1469 && __i2 <= _M_iend());
1470 __glibcxx_requires_valid_range(__k1, __k2);
1471 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1476 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1478 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1479 && __i2 <= _M_iend());
1480 __glibcxx_requires_valid_range(__k1, __k2);
1481 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1482 __k1.base(), __k2 - __k1);
1486 replace(iterator __i1, iterator __i2,
1487 const_iterator __k1, const_iterator __k2)
1489 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1490 && __i2 <= _M_iend());
1491 __glibcxx_requires_valid_range(__k1, __k2);
1492 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1493 __k1.base(), __k2 - __k1);
1496 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1510 basic_string& replace(iterator __i1, iterator __i2,
1512 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
1513 #endif // __GXX_EXPERIMENTAL_CXX0X__
1516 template<
class _Integer>
1518 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1519 _Integer __val, __true_type)
1520 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1522 template<
class _InputIterator>
1524 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1525 _InputIterator __k2, __false_type);
1528 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1532 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
1537 template<
class _InIterator>
1539 _S_construct_aux(_InIterator __beg, _InIterator __end,
1540 const _Alloc& __a, __false_type)
1542 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1543 return _S_construct(__beg, __end, __a, _Tag());
1548 template<
class _Integer>
1550 _S_construct_aux(_Integer __beg, _Integer __end,
1551 const _Alloc& __a, __true_type)
1552 {
return _S_construct(static_cast<size_type>(__beg), __end, __a); }
1554 template<
class _InIterator>
1556 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
1558 typedef typename std::__is_integer<_InIterator>::__type _Integral;
1559 return _S_construct_aux(__beg, __end, __a, _Integral());
1563 template<
class _InIterator>
1565 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
1566 input_iterator_tag);
1570 template<
class _FwdIterator>
1572 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
1573 forward_iterator_tag);
1576 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
1592 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
1602 swap(basic_string& __s);
1613 {
return _M_data(); }
1623 {
return _M_data(); }
1629 get_allocator()
const
1630 {
return _M_dataplus; }
1644 find(
const _CharT* __s, size_type __pos, size_type __n)
const;
1657 find(
const basic_string& __str, size_type __pos = 0)
const
1658 {
return this->
find(__str.
data(), __pos, __str.
size()); }
1671 find(
const _CharT* __s, size_type __pos = 0)
const
1673 __glibcxx_requires_string(__s);
1674 return this->find(__s, __pos, traits_type::length(__s));
1688 find(_CharT __c, size_type __pos = 0)
const;
1701 rfind(
const basic_string& __str, size_type __pos = npos)
const
1716 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const;
1729 rfind(
const _CharT* __s, size_type __pos = npos)
const
1731 __glibcxx_requires_string(__s);
1732 return this->rfind(__s, __pos, traits_type::length(__s));
1746 rfind(_CharT __c, size_type __pos = npos)
const;
1759 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
1774 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
1787 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
1789 __glibcxx_requires_string(__s);
1790 return this->find_first_of(__s, __pos, traits_type::length(__s));
1806 find_first_of(_CharT __c, size_type __pos = 0)
const
1807 {
return this->find(__c, __pos); }
1820 find_last_of(
const basic_string& __str, size_type __pos = npos)
const
1835 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const;
1848 find_last_of(
const _CharT* __s, size_type __pos = npos)
const
1850 __glibcxx_requires_string(__s);
1851 return this->find_last_of(__s, __pos, traits_type::length(__s));
1867 find_last_of(_CharT __c, size_type __pos = npos)
const
1868 {
return this->rfind(__c, __pos); }
1881 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
1896 find_first_not_of(
const _CharT* __s, size_type __pos,
1897 size_type __n)
const;
1910 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
1912 __glibcxx_requires_string(__s);
1913 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1927 find_first_not_of(_CharT __c, size_type __pos = 0)
const;
1940 find_last_not_of(
const basic_string& __str, size_type __pos = npos)
const
1956 find_last_not_of(
const _CharT* __s, size_type __pos,
1957 size_type __n)
const;
1969 find_last_not_of(
const _CharT* __s, size_type __pos = npos)
const
1971 __glibcxx_requires_string(__s);
1972 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1986 find_last_not_of(_CharT __c, size_type __pos = npos)
const;
2001 substr(size_type __pos = 0, size_type __n = npos)
const
2002 {
return basic_string(*
this,
2003 _M_check(__pos,
"basic_string::substr"), __n); }
2019 compare(
const basic_string& __str)
const
2021 const size_type __size = this->size();
2022 const size_type __osize = __str.
size();
2023 const size_type __len =
std::min(__size, __osize);
2025 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2027 __r = _S_compare(__size, __osize);
2049 compare(size_type __pos, size_type __n,
const basic_string& __str)
const;
2073 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
2074 size_type __pos2, size_type __n2)
const;
2091 compare(
const _CharT* __s)
const;
2114 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2139 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2140 size_type __n2)
const;
2143 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2144 inline basic_string<_CharT, _Traits, _Alloc>::
2146 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2147 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2149 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2159 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2160 basic_string<_CharT, _Traits, _Alloc>
2175 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2176 basic_string<_CharT,_Traits,_Alloc>
2177 operator+(
const _CharT* __lhs,
2178 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2186 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2187 basic_string<_CharT,_Traits,_Alloc>
2188 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2196 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2197 inline basic_string<_CharT, _Traits, _Alloc>
2199 const _CharT* __rhs)
2212 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2213 inline basic_string<_CharT, _Traits, _Alloc>
2217 typedef typename __string_type::size_type __size_type;
2218 __string_type __str(__lhs);
2219 __str.append(__size_type(1), __rhs);
2230 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2234 {
return __lhs.
compare(__rhs) == 0; }
2236 template<
typename _CharT>
2238 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
2239 operator==(
const basic_string<_CharT>& __lhs,
2240 const basic_string<_CharT>& __rhs)
2241 {
return (__lhs.size() == __rhs.size()
2251 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2253 operator==(
const _CharT* __lhs,
2255 {
return __rhs.
compare(__lhs) == 0; }
2263 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2266 const _CharT* __rhs)
2267 {
return __lhs.
compare(__rhs) == 0; }
2276 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2280 {
return !(__lhs == __rhs); }
2288 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2290 operator!=(
const _CharT* __lhs,
2292 {
return !(__lhs == __rhs); }
2300 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2303 const _CharT* __rhs)
2304 {
return !(__lhs == __rhs); }
2313 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2315 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2317 {
return __lhs.
compare(__rhs) < 0; }
2325 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2327 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2328 const _CharT* __rhs)
2329 {
return __lhs.compare(__rhs) < 0; }
2337 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2339 operator<(
const _CharT* __lhs,
2341 {
return __rhs.
compare(__lhs) > 0; }
2350 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2354 {
return __lhs.
compare(__rhs) > 0; }
2362 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2365 const _CharT* __rhs)
2366 {
return __lhs.
compare(__rhs) > 0; }
2374 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2376 operator>(
const _CharT* __lhs,
2378 {
return __rhs.
compare(__lhs) < 0; }
2387 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2389 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2391 {
return __lhs.
compare(__rhs) <= 0; }
2399 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2401 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2402 const _CharT* __rhs)
2403 {
return __lhs.compare(__rhs) <= 0; }
2411 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2413 operator<=(
const _CharT* __lhs,
2415 {
return __rhs.
compare(__lhs) >= 0; }
2424 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2428 {
return __lhs.
compare(__rhs) >= 0; }
2436 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2439 const _CharT* __rhs)
2440 {
return __lhs.
compare(__rhs) >= 0; }
2448 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2450 operator>=(
const _CharT* __lhs,
2452 {
return __rhs.
compare(__lhs) <= 0; }
2461 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2465 { __lhs.
swap(__rhs); }
2478 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2479 basic_istream<_CharT, _Traits>&
2480 operator>>(basic_istream<_CharT, _Traits>& __is,
2481 basic_string<_CharT, _Traits, _Alloc>& __str);
2484 basic_istream<char>&
2485 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2496 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2497 inline basic_ostream<_CharT, _Traits>&
2498 operator<<(basic_ostream<_CharT, _Traits>& __os,
2503 return __ostream_insert(__os, __str.data(), __str.size());
2519 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2520 basic_istream<_CharT, _Traits>&
2521 getline(basic_istream<_CharT, _Traits>& __is,
2522 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2536 template<
typename _CharT,
typename _Traits,
typename _Alloc>
2537 inline basic_istream<_CharT, _Traits>&
2540 {
return getline(__is, __str, __is.
widen(
'\n')); }
2543 basic_istream<char>&
2544 getline(basic_istream<char>& __in, basic_string<char>& __str,
2547 #ifdef _GLIBCXX_USE_WCHAR_T
2549 basic_istream<wchar_t>&
2550 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2554 _GLIBCXX_END_NAMESPACE
2556 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
2557 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2559 #include <ext/string_conversions.h>
2561 _GLIBCXX_BEGIN_NAMESPACE(std)
2565 stoi(const
string& __str,
size_t* __idx = 0,
int __base = 10)
2566 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
2570 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2571 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
2574 inline unsigned long
2575 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2576 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
2580 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2581 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
2584 inline unsigned long long
2585 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
2586 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
2591 stof(
const string& __str,
size_t* __idx = 0)
2592 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
2595 stod(
const string& __str,
size_t* __idx = 0)
2596 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
2599 stold(
const string& __str,
size_t* __idx = 0)
2600 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
2604 to_string(
long long __val)
2605 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2606 4 *
sizeof(
long long),
2610 to_string(
unsigned long long __val)
2611 {
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
2612 4 *
sizeof(
unsigned long long),
2616 to_string(
long double __val)
2619 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
2620 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
2624 #ifdef _GLIBCXX_USE_WCHAR_T
2626 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2627 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
2631 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2632 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
2635 inline unsigned long
2636 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2637 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
2641 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2642 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
2645 inline unsigned long long
2646 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
2647 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
2652 stof(
const wstring& __str,
size_t* __idx = 0)
2653 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
2656 stod(
const wstring& __str,
size_t* __idx = 0)
2657 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
2660 stold(
const wstring& __str,
size_t* __idx = 0)
2661 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
2664 to_wstring(
long long __val)
2665 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2666 4 *
sizeof(
long long),
2670 to_wstring(
unsigned long long __val)
2671 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
2672 4 *
sizeof(
unsigned long long),
2676 to_wstring(
long double __val)
2679 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
2680 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
2685 _GLIBCXX_END_NAMESPACE