30#ifndef _STREAMBUF_ITERATOR_H
31#define _STREAMBUF_ITERATOR_H 1
34#pragma GCC system_header
41namespace std _GLIBCXX_VISIBILITY(default)
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
51#pragma GCC diagnostic push
52#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
55 template<
typename _CharT,
typename _Traits>
57 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
64#if __cplusplus < 201103L
66#elif __cplusplus > 201703L
79 template<
typename _CharT2>
80 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
85 template<
bool _IsMove,
typename _CharT2>
86 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
91 template<
typename _CharT2,
typename _Size>
92 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
96 template<
typename _CharT2>
97 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
102 template<
typename _CharT2,
typename _Distance>
103 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
123#if __cplusplus > 201703L && __cpp_lib_concepts
128#if __cplusplus >= 201103L
131 ~istreambuf_iterator() =
default;
136 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
140 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
142#if __cplusplus >= 201103L
156#ifdef _GLIBCXX_DEBUG_PEDANTIC
159 __glibcxx_requires_cond(!_S_is_eof(__c),
160 _M_message(__gnu_debug::__msg_deref_istreambuf)
161 ._M_iterator(*
this));
163 return traits_type::to_char_type(__c);
170 __glibcxx_requires_cond(_M_sbuf &&
171 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->sgetc())),
172 _M_message(__gnu_debug::__msg_inc_istreambuf)
173 ._M_iterator(*
this));
176 _M_c = traits_type::eof();
184 __glibcxx_requires_cond(_M_sbuf &&
185 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->sgetc())),
186 _M_message(__gnu_debug::__msg_inc_istreambuf)
187 ._M_iterator(*
this));
190 __old._M_c = _M_sbuf->sbumpc();
191 _M_c = traits_type::eof();
202 {
return _M_at_eof() == __b._M_at_eof(); }
209 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
216 {
return _S_is_eof(_M_get()); }
221 const int_type __eof = traits_type::eof();
222 return traits_type::eq_int_type(__c, __eof);
225#if __cplusplus > 201703L && __cpp_lib_concepts
229 {
return __i._M_at_eof(); }
233 template<
typename _CharT,
typename _Traits>
238 {
return __a.equal(__b); }
240#if __cpp_impl_three_way_comparison < 201907L
241 template<
typename _CharT,
typename _Traits>
246 {
return !__a.equal(__b); }
250 template<
typename _CharT,
typename _Traits>
251 class ostreambuf_iterator
252 :
public iterator<output_iterator_tag, void, void, void, void>
258#if __cplusplus > 201703L
267 template<
typename _CharT2>
268 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
269 ostreambuf_iterator<_CharT2> >::__type
271 ostreambuf_iterator<_CharT2>);
279#if __cplusplus > 201703L
281 ostreambuf_iterator() noexcept
282 : _M_sbuf(
nullptr), _M_failed(true) { }
287 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
291 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
298 _Traits::eq_int_type(_M_sbuf->sputc(__c), _Traits::eof()))
323 {
return _M_failed; }
328 if (__builtin_expect(!_M_failed,
true)
329 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
335#pragma GCC diagnostic pop
338 template<
typename _CharT>
339 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
345 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
348 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
350 __result._M_failed =
true;
355 template<
bool _IsMove,
typename _CharT>
356 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
358 __copy_move_a2(_CharT* __first, _CharT* __last,
363 __result._M_put(__first, __num);
367 template<
bool _IsMove,
typename _CharT>
368 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
370 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
375 __result._M_put(__first, __num);
379 template<
bool _IsMove,
typename _CharT>
380 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
386 typedef typename __is_iterator_type::traits_type traits_type;
387 typedef typename __is_iterator_type::streambuf_type streambuf_type;
388 typedef typename traits_type::int_type
int_type;
390 if (__first._M_sbuf && !__last._M_sbuf)
392 streambuf_type* __sb = __first._M_sbuf;
394 while (!traits_type::eq_int_type(__c, traits_type::eof()))
396 const streamsize __n = __sb->egptr() - __sb->gptr();
399 traits_type::copy(__result, __sb->gptr(), __n);
400 __sb->__safe_gbump(__n);
402 __c = __sb->underflow();
406 *__result++ = traits_type::to_char_type(__c);
407 __c = __sb->snextc();
414 template<
typename _CharT,
typename _Size>
415 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
418 bool __strict __attribute__((__unused__)))
423 __glibcxx_requires_cond(__it._M_sbuf,
424 _M_message(__gnu_debug::__msg_inc_istreambuf)
426 _CharT* __beg = __result;
427 __result += __it._M_sbuf->sgetn(__beg, __n);
428 __glibcxx_requires_cond(!__strict || __result - __beg == __n,
429 _M_message(__gnu_debug::__msg_inc_istreambuf)
434 template<
typename _CharT>
435 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
441 typedef typename __is_iterator_type::traits_type traits_type;
442 typedef typename __is_iterator_type::streambuf_type streambuf_type;
443 typedef typename traits_type::int_type
int_type;
444 const int_type __eof = traits_type::eof();
446 if (__first._M_sbuf && !__last._M_sbuf)
448 const int_type __ival = traits_type::to_int_type(__val);
449 streambuf_type* __sb = __first._M_sbuf;
451 while (!traits_type::eq_int_type(__c, __eof)
452 && !traits_type::eq_int_type(__c, __ival))
454 streamsize __n = __sb->egptr() - __sb->gptr();
457 const _CharT* __p = traits_type::find(__sb->gptr(),
460 __n = __p - __sb->gptr();
461 __sb->__safe_gbump(__n);
465 __c = __sb->snextc();
468 __first._M_c = __eof;
474 template<
typename _CharT,
typename _Distance>
475 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
482 __glibcxx_assert(__n > 0);
483 __glibcxx_requires_cond(!__i._M_at_eof(),
484 _M_message(__gnu_debug::__msg_inc_istreambuf)
488 typedef typename __is_iterator_type::traits_type traits_type;
489 typedef typename __is_iterator_type::streambuf_type streambuf_type;
490 typedef typename traits_type::int_type
int_type;
491 const int_type __eof = traits_type::eof();
493 streambuf_type* __sb = __i._M_sbuf;
496 streamsize __size = __sb->egptr() - __sb->gptr();
499 __sb->__safe_gbump(__n);
503 __sb->__safe_gbump(__size);
505 if (traits_type::eq_int_type(__sb->underflow(), __eof))
507 __glibcxx_requires_cond(__n == 0,
508 _M_message(__gnu_debug::__msg_inc_istreambuf)
519_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
The actual work of input and output (interface).
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
int_type sgetc()
Getting the next character.
Template class basic_istream.
Template class basic_ostream.
Provides input iterator semantics for streambufs.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
void pointer
Public typedefs.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
char_type operator*() const
Return the current character pointed to by iterator. This returns streambuf.sgetc()....
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
_Traits traits_type
Public typedefs.
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
_CharT char_type
Public typedefs.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
_Traits::int_type int_type
Public typedefs.
Provides output iterator semantics for streambufs.
ostreambuf_iterator & operator++(int)
Return *this.
ptrdiff_t difference_type
Public typedefs.
ostreambuf_iterator & operator++()
Return *this.
bool failed() const noexcept
Return true if previous operator=() failed.
_Traits traits_type
Public typedefs.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
ostreambuf_iterator & operator*()
Return *this.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
_CharT char_type
Public typedefs.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.