39 #ifndef _BASIC_STRING_TCC
40 #define _BASIC_STRING_TCC 1
42 #pragma GCC system_header
46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _CharT,
typename _Traits,
typename _Alloc>
51 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
52 basic_string<_CharT, _Traits, _Alloc>::
53 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
55 template<
typename _CharT,
typename _Traits,
typename _Alloc>
57 basic_string<_CharT, _Traits, _Alloc>::
58 _Rep::_S_terminal = _CharT();
60 template<
typename _CharT,
typename _Traits,
typename _Alloc>
61 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
62 basic_string<_CharT, _Traits, _Alloc>::npos;
66 template<
typename _CharT,
typename _Traits,
typename _Alloc>
67 typename basic_string<_CharT, _Traits, _Alloc>::size_type
68 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
69 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
76 template<
typename _CharT,
typename _Traits,
typename _Alloc>
77 template<
typename _InIterator>
79 basic_string<_CharT, _Traits, _Alloc>::
80 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
83 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
84 if (__beg == __end && __a == _Alloc())
85 return _S_empty_rep()._M_refdata();
90 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
92 __buf[__len++] = *__beg;
95 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
96 _M_copy(__r->_M_refdata(), __buf, __len);
99 while (__beg != __end)
101 if (__len == __r->_M_capacity)
104 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
105 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
106 __r->_M_destroy(__a);
109 __r->_M_refdata()[__len++] = *__beg;
115 __r->_M_destroy(__a);
116 __throw_exception_again;
118 __r->_M_set_length_and_sharable(__len);
119 return __r->_M_refdata();
122 template<
typename _CharT,
typename _Traits,
typename _Alloc>
123 template <
typename _InIterator>
125 basic_string<_CharT, _Traits, _Alloc>::
126 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
127 forward_iterator_tag)
129 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
130 if (__beg == __end && __a == _Alloc())
131 return _S_empty_rep()._M_refdata();
134 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
135 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
137 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
140 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
142 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
145 __r->_M_destroy(__a);
146 __throw_exception_again;
148 __r->_M_set_length_and_sharable(__dnew);
149 return __r->_M_refdata();
152 template<
typename _CharT,
typename _Traits,
typename _Alloc>
154 basic_string<_CharT, _Traits, _Alloc>::
155 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
157 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
158 if (__n == 0 && __a == _Alloc())
159 return _S_empty_rep()._M_refdata();
162 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
164 _M_assign(__r->_M_refdata(), __n, __c);
166 __r->_M_set_length_and_sharable(__n);
167 return __r->_M_refdata();
170 template<
typename _CharT,
typename _Traits,
typename _Alloc>
173 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()),
174 __str.get_allocator()),
175 __str.get_allocator())
178 template<
typename _CharT,
typename _Traits,
typename _Alloc>
181 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
184 template<
typename _CharT,
typename _Traits,
typename _Alloc>
187 : _M_dataplus(_S_construct(__str._M_data()
188 + __str._M_check(__pos,
189 "basic_string::basic_string"),
190 __str._M_data() + __str._M_limit(__pos, __n)
191 + __pos, _Alloc()), _Alloc())
194 template<
typename _CharT,
typename _Traits,
typename _Alloc>
197 size_type __n,
const _Alloc& __a)
198 : _M_dataplus(_S_construct(__str._M_data()
199 + __str._M_check(__pos,
200 "basic_string::basic_string"),
201 __str._M_data() + __str._M_limit(__pos, __n)
206 template<
typename _CharT,
typename _Traits,
typename _Alloc>
209 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
213 template<
typename _CharT,
typename _Traits,
typename _Alloc>
216 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
217 __s + npos, __a), __a)
220 template<
typename _CharT,
typename _Traits,
typename _Alloc>
223 : _M_dataplus(_S_construct(__n, __c, __a), __a)
227 template<
typename _CharT,
typename _Traits,
typename _Alloc>
228 template<
typename _InputIterator>
230 basic_string(_InputIterator __beg, _InputIterator __end,
const _Alloc& __a)
231 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
234 #ifdef __GXX_EXPERIMENTAL_CXX0X__
235 template<
typename _CharT,
typename _Traits,
typename _Alloc>
238 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
242 template<
typename _CharT,
typename _Traits,
typename _Alloc>
247 if (_M_rep() != __str._M_rep())
250 const allocator_type __a = this->get_allocator();
251 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
252 _M_rep()->_M_dispose(__a);
258 template<
typename _CharT,
typename _Traits,
typename _Alloc>
263 __glibcxx_requires_string_len(__s, __n);
264 _M_check_length(this->
size(), __n,
"basic_string::assign");
265 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
266 return _M_replace_safe(size_type(0), this->
size(), __s, __n);
270 const size_type __pos = __s - _M_data();
272 _M_copy(_M_data(), __s, __n);
274 _M_move(_M_data(), __s, __n);
275 _M_rep()->_M_set_length_and_sharable(__n);
280 template<
typename _CharT,
typename _Traits,
typename _Alloc>
287 _M_check_length(size_type(0), __n,
"basic_string::append");
288 const size_type __len = __n + this->
size();
289 if (__len > this->capacity() || _M_rep()->_M_is_shared())
290 this->reserve(__len);
291 _M_assign(_M_data() + this->
size(), __n, __c);
292 _M_rep()->_M_set_length_and_sharable(__len);
297 template<
typename _CharT,
typename _Traits,
typename _Alloc>
302 __glibcxx_requires_string_len(__s, __n);
305 _M_check_length(size_type(0), __n,
"basic_string::append");
306 const size_type __len = __n + this->
size();
307 if (__len > this->capacity() || _M_rep()->_M_is_shared())
309 if (_M_disjunct(__s))
310 this->reserve(__len);
313 const size_type __off = __s - _M_data();
314 this->reserve(__len);
315 __s = _M_data() + __off;
318 _M_copy(_M_data() + this->
size(), __s, __n);
319 _M_rep()->_M_set_length_and_sharable(__len);
324 template<
typename _CharT,
typename _Traits,
typename _Alloc>
329 const size_type __size = __str.
size();
332 const size_type __len = __size + this->
size();
333 if (__len > this->capacity() || _M_rep()->_M_is_shared())
334 this->reserve(__len);
335 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
336 _M_rep()->_M_set_length_and_sharable(__len);
341 template<
typename _CharT,
typename _Traits,
typename _Alloc>
346 __str._M_check(__pos,
"basic_string::append");
347 __n = __str._M_limit(__pos, __n);
350 const size_type __len = __n + this->
size();
351 if (__len > this->capacity() || _M_rep()->_M_is_shared())
352 this->reserve(__len);
353 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
354 _M_rep()->_M_set_length_and_sharable(__len);
359 template<
typename _CharT,
typename _Traits,
typename _Alloc>
362 insert(size_type __pos,
const _CharT* __s, size_type __n)
364 __glibcxx_requires_string_len(__s, __n);
365 _M_check(__pos,
"basic_string::insert");
366 _M_check_length(size_type(0), __n,
"basic_string::insert");
367 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
368 return _M_replace_safe(__pos, size_type(0), __s, __n);
372 const size_type __off = __s - _M_data();
373 _M_mutate(__pos, 0, __n);
374 __s = _M_data() + __off;
375 _CharT* __p = _M_data() + __pos;
376 if (__s + __n <= __p)
377 _M_copy(__p, __s, __n);
379 _M_copy(__p, __s + __n, __n);
382 const size_type __nleft = __p - __s;
383 _M_copy(__p, __s, __nleft);
384 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
390 template<
typename _CharT,
typename _Traits,
typename _Alloc>
391 typename basic_string<_CharT, _Traits, _Alloc>::iterator
393 erase(iterator __first, iterator __last)
395 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
396 && __last <= _M_iend());
401 const size_type __size = __last - __first;
404 const size_type __pos = __first - _M_ibegin();
405 _M_mutate(__pos, __size, size_type(0));
406 _M_rep()->_M_set_leaked();
407 return iterator(_M_data() + __pos);
413 template<
typename _CharT,
typename _Traits,
typename _Alloc>
416 replace(size_type __pos, size_type __n1,
const _CharT* __s,
419 __glibcxx_requires_string_len(__s, __n2);
420 _M_check(__pos,
"basic_string::replace");
421 __n1 = _M_limit(__pos, __n1);
422 _M_check_length(__n1, __n2,
"basic_string::replace");
424 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
425 return _M_replace_safe(__pos, __n1, __s, __n2);
426 else if ((__left = __s + __n2 <= _M_data() + __pos)
427 || _M_data() + __pos + __n1 <= __s)
430 size_type __off = __s - _M_data();
431 __left ? __off : (__off += __n2 - __n1);
432 _M_mutate(__pos, __n1, __n2);
433 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
440 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
444 template<
typename _CharT,
typename _Traits,
typename _Alloc>
449 const size_type __size =
sizeof(_Rep_base) +
450 (this->_M_capacity + 1) *
sizeof(_CharT);
451 _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(
this), __size);
454 template<
typename _CharT,
typename _Traits,
typename _Alloc>
456 basic_string<_CharT, _Traits, _Alloc>::
459 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
460 if (_M_rep() == &_S_empty_rep())
463 if (_M_rep()->_M_is_shared())
465 _M_rep()->_M_set_leaked();
468 template<
typename _CharT,
typename _Traits,
typename _Alloc>
470 basic_string<_CharT, _Traits, _Alloc>::
471 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
473 const size_type __old_size = this->
size();
474 const size_type __new_size = __old_size + __len2 - __len1;
475 const size_type __how_much = __old_size - __pos - __len1;
477 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
480 const allocator_type __a = get_allocator();
481 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
484 _M_copy(__r->_M_refdata(), _M_data(), __pos);
486 _M_copy(__r->_M_refdata() + __pos + __len2,
487 _M_data() + __pos + __len1, __how_much);
489 _M_rep()->_M_dispose(__a);
490 _M_data(__r->_M_refdata());
492 else if (__how_much && __len1 != __len2)
495 _M_move(_M_data() + __pos + __len2,
496 _M_data() + __pos + __len1, __how_much);
498 _M_rep()->_M_set_length_and_sharable(__new_size);
501 template<
typename _CharT,
typename _Traits,
typename _Alloc>
506 if (__res != this->capacity() || _M_rep()->_M_is_shared())
509 if (__res < this->
size())
510 __res = this->
size();
511 const allocator_type __a = get_allocator();
512 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
513 _M_rep()->_M_dispose(__a);
518 template<
typename _CharT,
typename _Traits,
typename _Alloc>
523 if (_M_rep()->_M_is_leaked())
524 _M_rep()->_M_set_sharable();
525 if (__s._M_rep()->_M_is_leaked())
526 __s._M_rep()->_M_set_sharable();
529 _CharT* __tmp = _M_data();
530 _M_data(__s._M_data());
538 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
539 this->get_allocator());
545 template<
typename _CharT,
typename _Traits,
typename _Alloc>
548 _S_create(size_type __capacity, size_type __old_capacity,
549 const _Alloc& __alloc)
553 if (__capacity > _S_max_size)
554 __throw_length_error(__N(
"basic_string::_S_create"));
579 const size_type __pagesize = 4096;
580 const size_type __malloc_header_size = 4 *
sizeof(
void*);
588 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
589 __capacity = 2 * __old_capacity;
594 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
596 const size_type __adj_size = __size + __malloc_header_size;
597 if (__adj_size > __pagesize && __capacity > __old_capacity)
599 const size_type __extra = __pagesize - __adj_size % __pagesize;
600 __capacity += __extra /
sizeof(_CharT);
602 if (__capacity > _S_max_size)
603 __capacity = _S_max_size;
604 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
609 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
610 _Rep *__p =
new (__place) _Rep;
611 __p->_M_capacity = __capacity;
619 __p->_M_set_sharable();
623 template<
typename _CharT,
typename _Traits,
typename _Alloc>
625 basic_string<_CharT, _Traits, _Alloc>::_Rep::
626 _M_clone(
const _Alloc& __alloc, size_type __res)
629 const size_type __requested_cap = this->_M_length + __res;
630 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
633 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
635 __r->_M_set_length_and_sharable(this->_M_length);
636 return __r->_M_refdata();
639 template<
typename _CharT,
typename _Traits,
typename _Alloc>
644 const size_type __size = this->
size();
645 _M_check_length(__size, __n,
"basic_string::resize");
647 this->append(__n - __size, __c);
648 else if (__n < __size)
653 template<
typename _CharT,
typename _Traits,
typename _Alloc>
654 template<
typename _InputIterator>
658 _InputIterator __k2, __false_type)
661 const size_type __n1 = __i2 - __i1;
662 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
663 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
667 template<
typename _CharT,
typename _Traits,
typename _Alloc>
668 basic_string<_CharT, _Traits, _Alloc>&
669 basic_string<_CharT, _Traits, _Alloc>::
670 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
673 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
674 _M_mutate(__pos1, __n1, __n2);
676 _M_assign(_M_data() + __pos1, __n2, __c);
680 template<
typename _CharT,
typename _Traits,
typename _Alloc>
681 basic_string<_CharT, _Traits, _Alloc>&
682 basic_string<_CharT, _Traits, _Alloc>::
683 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
686 _M_mutate(__pos1, __n1, __n2);
688 _M_copy(_M_data() + __pos1, __s, __n2);
692 template<
typename _CharT,
typename _Traits,
typename _Alloc>
693 basic_string<_CharT, _Traits, _Alloc>
697 __glibcxx_requires_string(__lhs);
699 typedef typename __string_type::size_type __size_type;
700 const __size_type __len = _Traits::length(__lhs);
702 __str.reserve(__len + __rhs.
size());
703 __str.append(__lhs, __len);
708 template<
typename _CharT,
typename _Traits,
typename _Alloc>
709 basic_string<_CharT, _Traits, _Alloc>
713 typedef typename __string_type::size_type __size_type;
715 const __size_type __len = __rhs.
size();
716 __str.reserve(__len + 1);
717 __str.append(__size_type(1), __lhs);
722 template<
typename _CharT,
typename _Traits,
typename _Alloc>
723 typename basic_string<_CharT, _Traits, _Alloc>::size_type
725 copy(_CharT* __s, size_type __n, size_type __pos)
const
727 _M_check(__pos,
"basic_string::copy");
728 __n = _M_limit(__pos, __n);
729 __glibcxx_requires_string_len(__s, __n);
731 _M_copy(__s, _M_data() + __pos, __n);
736 template<
typename _CharT,
typename _Traits,
typename _Alloc>
737 typename basic_string<_CharT, _Traits, _Alloc>::size_type
739 find(
const _CharT* __s, size_type __pos, size_type __n)
const
741 __glibcxx_requires_string_len(__s, __n);
742 const size_type __size = this->
size();
743 const _CharT* __data = _M_data();
746 return __pos <= __size ? __pos : npos;
750 for (; __pos <= __size - __n; ++__pos)
751 if (traits_type::eq(__data[__pos], __s[0])
752 && traits_type::compare(__data + __pos + 1,
753 __s + 1, __n - 1) == 0)
759 template<
typename _CharT,
typename _Traits,
typename _Alloc>
760 typename basic_string<_CharT, _Traits, _Alloc>::size_type
762 find(_CharT __c, size_type __pos)
const
764 size_type __ret = npos;
765 const size_type __size = this->
size();
768 const _CharT* __data = _M_data();
769 const size_type __n = __size - __pos;
770 const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
772 __ret = __p - __data;
777 template<
typename _CharT,
typename _Traits,
typename _Alloc>
778 typename basic_string<_CharT, _Traits, _Alloc>::size_type
780 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
782 __glibcxx_requires_string_len(__s, __n);
783 const size_type __size = this->
size();
786 __pos =
std::min(size_type(__size - __n), __pos);
787 const _CharT* __data = _M_data();
790 if (traits_type::compare(__data + __pos, __s, __n) == 0)
798 template<
typename _CharT,
typename _Traits,
typename _Alloc>
799 typename basic_string<_CharT, _Traits, _Alloc>::size_type
801 rfind(_CharT __c, size_type __pos)
const
803 size_type __size = this->
size();
806 if (--__size > __pos)
808 for (++__size; __size-- > 0; )
809 if (traits_type::eq(_M_data()[__size], __c))
815 template<
typename _CharT,
typename _Traits,
typename _Alloc>
816 typename basic_string<_CharT, _Traits, _Alloc>::size_type
820 __glibcxx_requires_string_len(__s, __n);
821 for (; __n && __pos < this->
size(); ++__pos)
823 const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
830 template<
typename _CharT,
typename _Traits,
typename _Alloc>
831 typename basic_string<_CharT, _Traits, _Alloc>::size_type
835 __glibcxx_requires_string_len(__s, __n);
836 size_type __size = this->
size();
839 if (--__size > __pos)
843 if (traits_type::find(__s, __n, _M_data()[__size]))
846 while (__size-- != 0);
851 template<
typename _CharT,
typename _Traits,
typename _Alloc>
852 typename basic_string<_CharT, _Traits, _Alloc>::size_type
856 __glibcxx_requires_string_len(__s, __n);
857 for (; __pos < this->
size(); ++__pos)
858 if (!traits_type::find(__s, __n, _M_data()[__pos]))
863 template<
typename _CharT,
typename _Traits,
typename _Alloc>
864 typename basic_string<_CharT, _Traits, _Alloc>::size_type
868 for (; __pos < this->
size(); ++__pos)
869 if (!traits_type::eq(_M_data()[__pos], __c))
874 template<
typename _CharT,
typename _Traits,
typename _Alloc>
875 typename basic_string<_CharT, _Traits, _Alloc>::size_type
879 __glibcxx_requires_string_len(__s, __n);
880 size_type __size = this->
size();
883 if (--__size > __pos)
887 if (!traits_type::find(__s, __n, _M_data()[__size]))
895 template<
typename _CharT,
typename _Traits,
typename _Alloc>
896 typename basic_string<_CharT, _Traits, _Alloc>::size_type
900 size_type __size = this->
size();
903 if (--__size > __pos)
907 if (!traits_type::eq(_M_data()[__size], __c))
915 template<
typename _CharT,
typename _Traits,
typename _Alloc>
920 _M_check(__pos,
"basic_string::compare");
921 __n = _M_limit(__pos, __n);
922 const size_type __osize = __str.
size();
923 const size_type __len =
std::min(__n, __osize);
924 int __r = traits_type::compare(_M_data() + __pos, __str.
data(), __len);
926 __r = _S_compare(__n, __osize);
930 template<
typename _CharT,
typename _Traits,
typename _Alloc>
934 size_type __pos2, size_type __n2)
const
936 _M_check(__pos1,
"basic_string::compare");
937 __str._M_check(__pos2,
"basic_string::compare");
938 __n1 = _M_limit(__pos1, __n1);
939 __n2 = __str._M_limit(__pos2, __n2);
940 const size_type __len =
std::min(__n1, __n2);
941 int __r = traits_type::compare(_M_data() + __pos1,
942 __str.
data() + __pos2, __len);
944 __r = _S_compare(__n1, __n2);
948 template<
typename _CharT,
typename _Traits,
typename _Alloc>
953 __glibcxx_requires_string(__s);
954 const size_type __size = this->
size();
955 const size_type __osize = traits_type::length(__s);
956 const size_type __len =
std::min(__size, __osize);
957 int __r = traits_type::compare(_M_data(), __s, __len);
959 __r = _S_compare(__size, __osize);
963 template<
typename _CharT,
typename _Traits,
typename _Alloc>
966 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
968 __glibcxx_requires_string(__s);
969 _M_check(__pos,
"basic_string::compare");
970 __n1 = _M_limit(__pos, __n1);
971 const size_type __osize = traits_type::length(__s);
972 const size_type __len =
std::min(__n1, __osize);
973 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
975 __r = _S_compare(__n1, __osize);
979 template<
typename _CharT,
typename _Traits,
typename _Alloc>
982 compare(size_type __pos, size_type __n1,
const _CharT* __s,
983 size_type __n2)
const
985 __glibcxx_requires_string_len(__s, __n2);
986 _M_check(__pos,
"basic_string::compare");
987 __n1 = _M_limit(__pos, __n1);
988 const size_type __len =
std::min(__n1, __n2);
989 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
991 __r = _S_compare(__n1, __n2);
996 template<
typename _CharT,
typename _Traits,
typename _Alloc>
1003 typedef typename __istream_type::ios_base __ios_base;
1004 typedef typename __istream_type::int_type __int_type;
1005 typedef typename __string_type::size_type __size_type;
1007 typedef typename __ctype_type::ctype_base __ctype_base;
1009 __size_type __extracted = 0;
1010 typename __ios_base::iostate __err = __ios_base::goodbit;
1011 typename __istream_type::sentry __cerb(__in,
false);
1019 __size_type __len = 0;
1021 const __size_type __n = __w > 0 ?
static_cast<__size_type
>(__w)
1023 const __ctype_type& __ct = use_facet<__ctype_type>(__in.
getloc());
1024 const __int_type __eof = _Traits::eof();
1025 __int_type __c = __in.
rdbuf()->sgetc();
1027 while (__extracted < __n
1028 && !_Traits::eq_int_type(__c, __eof)
1029 && !__ct.is(__ctype_base::space,
1030 _Traits::to_char_type(__c)))
1032 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
1034 __str.
append(__buf,
sizeof(__buf) /
sizeof(_CharT));
1037 __buf[__len++] = _Traits::to_char_type(__c);
1039 __c = __in.
rdbuf()->snextc();
1041 __str.
append(__buf, __len);
1043 if (_Traits::eq_int_type(__c, __eof))
1044 __err |= __ios_base::eofbit;
1049 __in._M_setstate(__ios_base::badbit);
1050 __throw_exception_again;
1057 __in._M_setstate(__ios_base::badbit);
1062 __err |= __ios_base::failbit;
1068 template<
typename _CharT,
typename _Traits,
typename _Alloc>
1069 basic_istream<_CharT, _Traits>&
1075 typedef typename __istream_type::ios_base __ios_base;
1076 typedef typename __istream_type::int_type __int_type;
1077 typedef typename __string_type::size_type __size_type;
1079 __size_type __extracted = 0;
1080 const __size_type __n = __str.
max_size();
1081 typename __ios_base::iostate __err = __ios_base::goodbit;
1082 typename __istream_type::sentry __cerb(__in,
true);
1088 const __int_type __idelim = _Traits::to_int_type(__delim);
1089 const __int_type __eof = _Traits::eof();
1090 __int_type __c = __in.
rdbuf()->sgetc();
1092 while (__extracted < __n
1093 && !_Traits::eq_int_type(__c, __eof)
1094 && !_Traits::eq_int_type(__c, __idelim))
1096 __str += _Traits::to_char_type(__c);
1098 __c = __in.
rdbuf()->snextc();
1101 if (_Traits::eq_int_type(__c, __eof))
1102 __err |= __ios_base::eofbit;
1103 else if (_Traits::eq_int_type(__c, __idelim))
1106 __in.
rdbuf()->sbumpc();
1109 __err |= __ios_base::failbit;
1113 __in._M_setstate(__ios_base::badbit);
1114 __throw_exception_again;
1121 __in._M_setstate(__ios_base::badbit);
1125 __err |= __ios_base::failbit;
1133 #if _GLIBCXX_EXTERN_TEMPLATE > 0
1134 extern template class basic_string<char>;
1136 basic_istream<char>&
1139 basic_ostream<char>&
1140 operator<<(basic_ostream<char>&,
const string&);
1142 basic_istream<char>&
1143 getline(basic_istream<char>&,
string&,
char);
1145 basic_istream<char>&
1146 getline(basic_istream<char>&,
string&);
1148 #ifdef _GLIBCXX_USE_WCHAR_T
1149 extern template class basic_string<wchar_t>;
1151 basic_istream<wchar_t>&
1152 operator>>(basic_istream<wchar_t>&, wstring&);
1154 basic_ostream<wchar_t>&
1155 operator<<(basic_ostream<wchar_t>&,
const wstring&);
1157 basic_istream<wchar_t>&
1158 getline(basic_istream<wchar_t>&, wstring&,
wchar_t);
1160 basic_istream<wchar_t>&
1161 getline(basic_istream<wchar_t>&, wstring&);
1165 _GLIBCXX_END_NAMESPACE_VERSION