33 #ifndef _GLIBCXX_SSTREAM
34 #define _GLIBCXX_SSTREAM 1
36 #ifdef _GLIBCXX_SYSHDR
37 #pragma GCC system_header
47 #define __glibcxx_want_sstream_from_string_view
50 #ifdef __cpp_lib_sstream_from_string_view
51 # include <string_view>
54 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
55 # define _GLIBCXX_LVAL_REF_QUAL &
56 # define _GLIBCXX_SSTREAM_ALWAYS_INLINE
58 # define _GLIBCXX_LVAL_REF_QUAL
60 # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]]
63 namespace std _GLIBCXX_VISIBILITY(default)
65 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 _GLIBCXX_BEGIN_NAMESPACE_CXX11
86 template<
typename _CharT,
typename _Traits,
typename _Alloc>
87 class basic_stringbuf :
public basic_streambuf<_CharT, _Traits>
89 struct __xfer_bufptrs;
91 #if __cplusplus >= 201103L
100 typedef _CharT char_type;
101 typedef _Traits traits_type;
104 typedef _Alloc allocator_type;
105 typedef typename traits_type::int_type int_type;
106 typedef typename traits_type::pos_type pos_type;
107 typedef typename traits_type::off_type off_type;
109 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
110 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
111 typedef typename __string_type::size_type __size_type;
157 _M_string(__str.
data(), __str.
size(), __str.get_allocator())
158 { _M_stringbuf_init(__mode); }
160 #if __cplusplus >= 201103L
165 { __rhs._M_sync(
const_cast<char_type*
>(__rhs._M_string.data()), 0, 0); }
167 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
175 const allocator_type& __a)
176 : __streambuf_type(),
_M_mode(__mode), _M_string(__a)
184 { _M_stringbuf_init(__mode); }
186 template<
typename _SAlloc>
188 const allocator_type& __a)
192 template<
typename _SAlloc>
195 const allocator_type& __a)
196 : __streambuf_type(),
_M_mode(__mode),
197 _M_string(__s.
data(), __s.
size(), __a)
198 { _M_stringbuf_init(__mode); }
200 template<
typename _SAlloc>
209 #ifdef __cpp_lib_sstream_from_string_view
210 template<
typename _Tp>
214 requires (is_convertible_v<
const _Tp&,
215 basic_string_view<_CharT, _Traits>>)
219 template<
typename _Tp>
221 requires (is_convertible_v<
const _Tp&,
222 basic_string_view<_CharT, _Traits>>)
226 template<
typename _Tp>
228 const allocator_type& __a)
229 requires (is_convertible_v<
const _Tp&,
230 basic_string_view<_CharT, _Traits>>)
231 : _M_string(__t, __a)
232 { _M_stringbuf_init(__mode); }
235 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
239 { __rhs._M_sync(
const_cast<char_type*
>(__rhs._M_string.data()), 0, 0); }
241 allocator_type get_allocator() const noexcept
253 __xfer_bufptrs __st{__rhs,
this};
254 const __streambuf_type&
__base = __rhs;
255 __streambuf_type::operator=(
__base);
256 this->pubimbue(__rhs.getloc());
259 __rhs._M_sync(
const_cast<char_type*
>(__rhs._M_string.data()), 0, 0);
267 __xfer_bufptrs __r_st{__rhs,
this};
268 __streambuf_type&
__base = __rhs;
270 __rhs.pubimbue(this->pubimbue(__rhs.getloc()));
271 std::swap(
_M_mode, __rhs._M_mode);
272 std::swap(_M_string, __rhs._M_string);
288 str() const _GLIBCXX_LVAL_REF_QUAL
291 if (char_type* __hi = _M_high_mark())
292 __ret.
assign(this->pbase(), __hi);
298 #if __cplusplus > 201703L
299 #if _GLIBCXX_USE_CXX11_ABI
302 template<__allocator_like _SAlloc>
305 str(
const _SAlloc& __sa)
const
308 return { __sv.data(), __sv.size(), __sa };
316 if (char_type* __hi = _M_high_mark())
318 if (_M_string.
data() == this->pbase()) [[likely]]
320 _M_string._M_set_length(__hi - this->pbase());
322 _M_string.
assign(this->pbase(), __hi);
326 _M_sync(_M_string.
data(), 0, 0);
331 _GLIBCXX_SSTREAM_ALWAYS_INLINE
332 basic_string_view<char_type, traits_type>
333 view() const noexcept
335 if (char_type* __hi = _M_high_mark())
336 return { this->pbase(), __hi };
358 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
361 template<__allocator_like _SAlloc>
362 requires (!is_same_v<_SAlloc, _Alloc>)
372 str(__string_type&& __s)
379 #ifdef __cpp_lib_sstream_from_string_view
380 template <
typename _Tp>
383 requires (is_convertible_v<
const _Tp&,
384 basic_string_view<_CharT, _Traits>>)
386 basic_string_view<_CharT, _Traits> __sv{__t};
398 __size_type __len = 0;
400 __len = _M_string.
size();
401 _M_sync(
const_cast<char_type*
>(_M_string.
data()), 0, __len);
411 __ret = this->egptr() - this->gptr();
420 pbackfail(int_type __c = traits_type::eof());
423 overflow(int_type __c = traits_type::eof());
436 virtual __streambuf_type*
450 _M_sync(__s, __n, 0);
456 seekoff(off_type __off, ios_base::seekdir __way,
460 seekpos(pos_type __sp,
467 _M_sync(char_type*
__base, __size_type __i, __size_type __o);
474 if (char_type* __pptr = this->pptr())
476 char_type* __egptr = this->egptr();
477 if (!__egptr || __pptr > __egptr)
480 this->setg(this->eback(), this->gptr(), __pptr);
482 this->setg(__pptr, __pptr, __pptr);
490 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
497 __attribute__((__always_inline__))
499 _M_high_mark() const _GLIBCXX_NOEXCEPT
501 if (char_type* __pptr = this->pptr())
503 char_type* __egptr = this->egptr();
504 if (!__egptr || __pptr > __egptr)
512 #if __cplusplus >= 201103L
513 #if _GLIBCXX_USE_CXX11_ABI
516 struct __xfer_bufptrs
519 : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}
521 const _CharT*
const __str = __from._M_string.data();
522 const _CharT* __end =
nullptr;
525 _M_goff[0] = __from.eback() - __str;
526 _M_goff[1] = __from.gptr() - __str;
527 _M_goff[2] = __from.egptr() - __str;
528 __end = __from.egptr();
532 _M_poff[0] = __from.pbase() - __str;
533 _M_poff[1] = __from.pptr() - __from.pbase();
534 _M_poff[2] = __from.epptr() - __str;
535 if (!__end || __from.pptr() > __end)
536 __end = __from.pptr();
545 __mut_from._M_string._M_length(__end - __str);
551 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
552 if (_M_goff[0] != -1)
553 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
554 if (_M_poff[0] != -1)
555 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
564 struct __xfer_bufptrs
573 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
577 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
584 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
607 template<
typename _CharT,
typename _Traits,
typename _Alloc>
608 class basic_istringstream :
public basic_istream<_CharT, _Traits>
612 typedef _CharT char_type;
613 typedef _Traits traits_type;
616 typedef _Alloc allocator_type;
617 typedef typename traits_type::int_type int_type;
618 typedef typename traits_type::pos_type pos_type;
619 typedef typename traits_type::off_type off_type;
622 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
623 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
624 typedef basic_istream<char_type, traits_type> __istream_type;
627 __stringbuf_type _M_stringbuf;
690 #if __cplusplus >= 201103L
694 : __istream_type(
std::
move(__rhs)),
695 _M_stringbuf(
std::
move(__rhs._M_stringbuf))
698 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
701 : __istream_type(), _M_stringbuf(__mode | ios_base::in, __a)
707 : __istream_type(), _M_stringbuf(
std::
move(__str), __mode | ios_base::in)
710 template<
typename _SAlloc>
712 const allocator_type& __a)
716 template<
typename _SAlloc>
719 const allocator_type& __a)
720 : __istream_type(), _M_stringbuf(__str, __mode | ios_base::in, __a)
723 template<
typename _SAlloc>
731 #ifdef __cpp_lib_sstream_from_string_view
732 template <
typename _Tp>
736 requires (is_convertible_v<
const _Tp&,
737 basic_string_view<_CharT, _Traits>>)
741 template <
typename _Tp>
743 requires (is_convertible_v<
const _Tp&,
744 basic_string_view<_CharT, _Traits>>)
748 template <
typename _Tp>
750 const allocator_type& __a)
751 requires (is_convertible_v<
const _Tp&,
752 basic_string_view<_CharT, _Traits>>)
753 : __istream_type(), _M_stringbuf(__t, __mode | ios_base::in, __a)
765 __istream_type::operator=(
std::move(__rhs));
766 _M_stringbuf =
std::move(__rhs._M_stringbuf);
773 __istream_type::swap(__rhs);
774 _M_stringbuf.swap(__rhs._M_stringbuf);
796 str() const _GLIBCXX_LVAL_REF_QUAL
797 {
return _M_stringbuf.str(); }
799 #if __cplusplus > 201703L
800 #if _GLIBCXX_USE_CXX11_ABI
803 template<__allocator_like _SAlloc>
806 str(
const _SAlloc& __sa)
const
807 {
return _M_stringbuf.str(__sa); }
813 {
return std::move(_M_stringbuf).str(); }
816 _GLIBCXX_SSTREAM_ALWAYS_INLINE
817 basic_string_view<char_type, traits_type>
818 view() const noexcept
819 {
return _M_stringbuf.view(); }
830 { _M_stringbuf.str(__s); }
832 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
835 template<__allocator_like _SAlloc>
836 requires (!is_same_v<_SAlloc, _Alloc>)
839 { _M_stringbuf.str(__s); }
843 str(__string_type&& __s)
847 #ifdef __cpp_lib_sstream_from_string_view
848 template<
typename _Tp>
851 requires (is_convertible_v<
const _Tp&,
852 basic_string_view<_CharT, _Traits>>)
853 { _M_stringbuf.str(__t); }
873 template <
typename _CharT,
typename _Traits,
typename _Alloc>
874 class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
878 typedef _CharT char_type;
879 typedef _Traits traits_type;
882 typedef _Alloc allocator_type;
883 typedef typename traits_type::int_type int_type;
884 typedef typename traits_type::pos_type pos_type;
885 typedef typename traits_type::off_type off_type;
888 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
889 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
890 typedef basic_ostream<char_type, traits_type> __ostream_type;
893 __stringbuf_type _M_stringbuf;
956 #if __cplusplus >= 201103L
960 : __ostream_type(
std::
move(__rhs)),
961 _M_stringbuf(
std::
move(__rhs._M_stringbuf))
964 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
967 : __ostream_type(), _M_stringbuf(__mode | ios_base::out, __a)
973 : __ostream_type(), _M_stringbuf(
std::
move(__str), __mode | ios_base::out)
976 template<
typename _SAlloc>
978 const allocator_type& __a)
982 template<
typename _SAlloc>
985 const allocator_type& __a)
986 : __ostream_type(), _M_stringbuf(__str, __mode | ios_base::out, __a)
989 template<
typename _SAlloc>
997 #ifdef __cpp_lib_sstream_from_string_view
998 template <
typename _Tp>
1002 requires (is_convertible_v<
const _Tp&,
1003 basic_string_view<_CharT, _Traits>>)
1007 template <
typename _Tp>
1009 requires (is_convertible_v<
const _Tp&,
1010 basic_string_view<_CharT, _Traits>>)
1014 template <
typename _Tp>
1016 const allocator_type& __a)
1017 requires (is_convertible_v<
const _Tp&,
1018 basic_string_view<_CharT, _Traits>>)
1019 : __ostream_type(), _M_stringbuf(__t, __mode | ios_base::out, __a)
1031 __ostream_type::operator=(
std::move(__rhs));
1032 _M_stringbuf =
std::move(__rhs._M_stringbuf);
1039 __ostream_type::swap(__rhs);
1040 _M_stringbuf.swap(__rhs._M_stringbuf);
1062 str() const _GLIBCXX_LVAL_REF_QUAL
1063 {
return _M_stringbuf.str(); }
1065 #if __cplusplus > 201703L
1066 #if _GLIBCXX_USE_CXX11_ABI
1069 template<__allocator_like _SAlloc>
1072 str(
const _SAlloc& __sa)
const
1073 {
return _M_stringbuf.str(__sa); }
1079 {
return std::move(_M_stringbuf).str(); }
1082 _GLIBCXX_SSTREAM_ALWAYS_INLINE
1083 basic_string_view<char_type, traits_type>
1084 view() const noexcept
1085 {
return _M_stringbuf.view(); }
1096 { _M_stringbuf.str(__s); }
1098 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1101 template<__allocator_like _SAlloc>
1102 requires (!is_same_v<_SAlloc, _Alloc>)
1105 { _M_stringbuf.str(__s); }
1109 str(__string_type&& __s)
1113 #ifdef __cpp_lib_sstream_from_string_view
1114 template<
typename _Tp>
1117 requires (is_convertible_v<
const _Tp&,
1118 basic_string_view<_CharT, _Traits>>)
1119 { _M_stringbuf.str(__t); }
1139 template <
typename _CharT,
typename _Traits,
typename _Alloc>
1140 class basic_stringstream :
public basic_iostream<_CharT, _Traits>
1144 typedef _CharT char_type;
1145 typedef _Traits traits_type;
1148 typedef _Alloc allocator_type;
1149 typedef typename traits_type::int_type int_type;
1150 typedef typename traits_type::pos_type pos_type;
1151 typedef typename traits_type::off_type off_type;
1154 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1155 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
1156 typedef basic_iostream<char_type, traits_type> __iostream_type;
1159 __stringbuf_type _M_stringbuf;
1218 #if __cplusplus >= 201103L
1222 : __iostream_type(
std::
move(__rhs)),
1223 _M_stringbuf(
std::
move(__rhs._M_stringbuf))
1226 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1229 : __iostream_type(), _M_stringbuf(__mode, __a)
1236 : __iostream_type(), _M_stringbuf(
std::
move(__str), __mode)
1239 template<
typename _SAlloc>
1241 const allocator_type& __a)
1245 template<
typename _SAlloc>
1248 const allocator_type& __a)
1249 : __iostream_type(), _M_stringbuf(__str, __mode, __a)
1252 template<
typename _SAlloc>
1261 #ifdef __cpp_lib_sstream_from_string_view
1262 template <
typename _Tp>
1266 requires (is_convertible_v<
const _Tp&,
1267 basic_string_view<_CharT, _Traits>>)
1271 template <
typename _Tp>
1273 requires (is_convertible_v<
const _Tp&,
1274 basic_string_view<_CharT, _Traits>>)
1278 template <
typename _Tp>
1280 const allocator_type& __a)
1281 requires (is_convertible_v<
const _Tp&, basic_string_view<_CharT, _Traits>>)
1282 : __iostream_type(), _M_stringbuf(__t, __mode, __a)
1294 __iostream_type::operator=(
std::move(__rhs));
1295 _M_stringbuf =
std::move(__rhs._M_stringbuf);
1302 __iostream_type::swap(__rhs);
1303 _M_stringbuf.swap(__rhs._M_stringbuf);
1325 str() const _GLIBCXX_LVAL_REF_QUAL
1326 {
return _M_stringbuf.str(); }
1328 #if __cplusplus > 201703L
1329 #if _GLIBCXX_USE_CXX11_ABI
1332 template<__allocator_like _SAlloc>
1335 str(
const _SAlloc& __sa)
const
1336 {
return _M_stringbuf.str(__sa); }
1342 {
return std::move(_M_stringbuf).str(); }
1345 _GLIBCXX_SSTREAM_ALWAYS_INLINE
1346 basic_string_view<char_type, traits_type>
1347 view() const noexcept
1348 {
return _M_stringbuf.view(); }
1359 { _M_stringbuf.str(__s); }
1361 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1364 template<__allocator_like _SAlloc>
1365 requires (!is_same_v<_SAlloc, _Alloc>)
1368 { _M_stringbuf.str(__s); }
1372 str(__string_type&& __s)
1376 #ifdef __cpp_lib_sstream_from_string_view
1377 template<
typename _Tp>
1380 requires (is_convertible_v<
const _Tp&,
1381 basic_string_view<_CharT, _Traits>>)
1382 { _M_stringbuf.str(__t); }
1386 #if __cplusplus >= 201103L
1388 template <
class _CharT,
class _Traits,
class _Allocator>
1392 noexcept(noexcept(__x.swap(__y)))
1396 template <
class _CharT,
class _Traits,
class _Allocator>
1403 template <
class _CharT,
class _Traits,
class _Allocator>
1410 template <
class _CharT,
class _Traits,
class _Allocator>
1417 _GLIBCXX_END_NAMESPACE_CXX11
1418 _GLIBCXX_END_NAMESPACE_VERSION
1421 #undef _GLIBCXX_SSTREAM_ALWAYS_INLINE
1422 #undef _GLIBCXX_LVAL_REF_QUAL