30 #ifndef _STREAMBUF_ITERATOR_H
31 #define _STREAMBUF_ITERATOR_H 1
33 #pragma GCC system_header
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _CharT,
typename _Traits>
51 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
58 #if __cplusplus < 201103L
60 #elif __cplusplus > 201703L
73 template<
typename _CharT2>
74 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
79 template<
bool _IsMove,
typename _CharT2>
80 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
85 #if __cplusplus >= 201103L
86 template<
typename _CharT2,
typename _Size>
87 friend __enable_if_t<__is_char<_CharT2>::__value, _CharT2*>
91 template<
typename _CharT2>
92 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
97 template<
typename _CharT2,
typename _Distance>
98 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
118 #if __cplusplus > 201703L && __cpp_lib_concepts
123 #if __cplusplus >= 201103L
131 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
135 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
137 #if __cplusplus >= 201103L
150 #ifdef _GLIBCXX_DEBUG_PEDANTIC
153 __glibcxx_requires_cond(!_S_is_eof(__c),
154 _M_message(__gnu_debug::__msg_deref_istreambuf)
155 ._M_iterator(*
this));
157 return traits_type::to_char_type(__c);
164 __glibcxx_requires_cond(_M_sbuf &&
165 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
166 _M_message(__gnu_debug::__msg_inc_istreambuf)
167 ._M_iterator(*
this));
170 _M_c = traits_type::eof();
178 __glibcxx_requires_cond(_M_sbuf &&
179 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
180 _M_message(__gnu_debug::__msg_inc_istreambuf)
181 ._M_iterator(*
this));
184 __old._M_c = _M_sbuf->
sbumpc();
185 _M_c = traits_type::eof();
195 {
return _M_at_eof() == __b._M_at_eof(); }
202 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
209 {
return _S_is_eof(_M_get()); }
214 const int_type __eof = traits_type::eof();
215 return traits_type::eq_int_type(__c, __eof);
218 #if __cplusplus > 201703L && __cpp_lib_concepts
221 {
return __i._M_at_eof(); }
225 template<
typename _CharT,
typename _Traits>
227 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
228 const istreambuf_iterator<_CharT, _Traits>& __b)
229 {
return __a.equal(__b); }
231 template<
typename _CharT,
typename _Traits>
233 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
234 const istreambuf_iterator<_CharT, _Traits>& __b)
235 {
return !__a.equal(__b); }
238 template<
typename _CharT,
typename _Traits>
240 :
public iterator<output_iterator_tag, void, void, void, void>
246 #if __cplusplus > 201703L
255 template<
typename _CharT2>
256 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
267 #if __cplusplus > 201703L
270 : _M_sbuf(
nullptr), _M_failed(true) { }
275 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
279 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
286 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
309 {
return _M_failed; }
314 if (__builtin_expect(!_M_failed,
true)
315 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
323 template<
typename _CharT>
324 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
325 ostreambuf_iterator<_CharT> >::__type
326 copy(istreambuf_iterator<_CharT> __first,
327 istreambuf_iterator<_CharT> __last,
328 ostreambuf_iterator<_CharT> __result)
330 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
333 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
335 __result._M_failed =
true;
340 template<
bool _IsMove,
typename _CharT>
341 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
342 ostreambuf_iterator<_CharT> >::__type
343 __copy_move_a2(_CharT* __first, _CharT* __last,
344 ostreambuf_iterator<_CharT> __result)
348 __result._M_put(__first, __num);
352 template<
bool _IsMove,
typename _CharT>
353 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
354 ostreambuf_iterator<_CharT> >::__type
355 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
356 ostreambuf_iterator<_CharT> __result)
360 __result._M_put(__first, __num);
364 template<
bool _IsMove,
typename _CharT>
365 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
367 __copy_move_a2(istreambuf_iterator<_CharT> __first,
368 istreambuf_iterator<_CharT> __last, _CharT* __result)
370 typedef istreambuf_iterator<_CharT> __is_iterator_type;
371 typedef typename __is_iterator_type::traits_type traits_type;
372 typedef typename __is_iterator_type::streambuf_type streambuf_type;
373 typedef typename traits_type::int_type int_type;
375 if (__first._M_sbuf && !__last._M_sbuf)
377 streambuf_type* __sb = __first._M_sbuf;
378 int_type __c = __sb->sgetc();
379 while (!traits_type::eq_int_type(__c, traits_type::eof()))
381 const streamsize __n = __sb->egptr() - __sb->gptr();
384 traits_type::copy(__result, __sb->gptr(), __n);
385 __sb->__safe_gbump(__n);
387 __c = __sb->underflow();
391 *__result++ = traits_type::to_char_type(__c);
392 __c = __sb->snextc();
399 #if __cplusplus >= 201103L
400 template<
typename _CharT,
typename _Size>
401 __enable_if_t<__is_char<_CharT>::__value, _CharT*>
402 __copy_n_a(istreambuf_iterator<_CharT> __it, _Size __n, _CharT* __result)
407 __glibcxx_requires_cond(__it._M_sbuf,
408 _M_message(__gnu_debug::__msg_inc_istreambuf)
410 _CharT* __beg = __result;
411 __result += __it._M_sbuf->sgetn(__beg, __n);
412 __glibcxx_requires_cond(__result - __beg == __n,
413 _M_message(__gnu_debug::__msg_inc_istreambuf)
419 template<
typename _CharT>
420 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
421 istreambuf_iterator<_CharT> >::__type
422 find(istreambuf_iterator<_CharT> __first,
423 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
425 typedef istreambuf_iterator<_CharT> __is_iterator_type;
426 typedef typename __is_iterator_type::traits_type traits_type;
427 typedef typename __is_iterator_type::streambuf_type streambuf_type;
428 typedef typename traits_type::int_type int_type;
429 const int_type __eof = traits_type::eof();
431 if (__first._M_sbuf && !__last._M_sbuf)
433 const int_type __ival = traits_type::to_int_type(__val);
434 streambuf_type* __sb = __first._M_sbuf;
435 int_type __c = __sb->sgetc();
436 while (!traits_type::eq_int_type(__c, __eof)
437 && !traits_type::eq_int_type(__c, __ival))
439 streamsize __n = __sb->egptr() - __sb->gptr();
442 const _CharT* __p = traits_type::find(__sb->gptr(),
445 __n = __p - __sb->gptr();
446 __sb->__safe_gbump(__n);
450 __c = __sb->snextc();
453 __first._M_c = __eof;
459 template<
typename _CharT,
typename _Distance>
460 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
462 advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
467 __glibcxx_assert(__n > 0);
468 __glibcxx_requires_cond(!__i._M_at_eof(),
469 _M_message(__gnu_debug::__msg_inc_istreambuf)
472 typedef istreambuf_iterator<_CharT> __is_iterator_type;
473 typedef typename __is_iterator_type::traits_type traits_type;
474 typedef typename __is_iterator_type::streambuf_type streambuf_type;
475 typedef typename traits_type::int_type int_type;
476 const int_type __eof = traits_type::eof();
478 streambuf_type* __sb = __i._M_sbuf;
481 streamsize __size = __sb->egptr() - __sb->gptr();
484 __sb->__safe_gbump(__n);
488 __sb->__safe_gbump(__size);
490 if (traits_type::eq_int_type(__sb->underflow(), __eof))
492 __glibcxx_requires_cond(__n == 0,
493 _M_message(__gnu_debug::__msg_inc_istreambuf)
504 _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 sbumpc()
Getting the next character.
int_type sgetc()
Getting the next character.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
Template class basic_istream.
Template class basic_ostream.
Provides input iterator semantics for streambufs.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
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.
_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++()
Return *this.
ostreambuf_iterator & operator*()
Return *this.
bool failed() const noexcept
Return true if previous operator=() failed.
_Traits traits_type
Public typedefs.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
ostreambuf_iterator & operator++(int)
Return *this.
_CharT char_type
Public typedefs.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
_CharT * pointer
This type represents a pointer-to-value_type.
void difference_type
Distance between iterators is represented as this type.
_CharT reference
This type represents a reference-to-value_type.