30#ifndef _STREAMBUF_ITERATOR_H
31#define _STREAMBUF_ITERATOR_H 1
33#pragma GCC system_header
38namespace std _GLIBCXX_VISIBILITY(default)
40_GLIBCXX_BEGIN_NAMESPACE_VERSION
48#pragma GCC diagnostic push
49#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
52 template<
typename _CharT,
typename _Traits>
54 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
61#if __cplusplus < 201103L
63#elif __cplusplus > 201703L
76 template<
typename _CharT2>
77 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
82 template<
bool _IsMove,
typename _CharT2>
83 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
88 template<
typename _CharT2,
typename _Size>
89 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
93 template<
typename _CharT2>
94 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
99 template<
typename _CharT2,
typename _Distance>
100 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
120#if __cplusplus > 201703L && __cpp_lib_concepts
125#if __cplusplus >= 201103L
128 ~istreambuf_iterator() =
default;
133 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
137 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
139#if __cplusplus >= 201103L
153#ifdef _GLIBCXX_DEBUG_PEDANTIC
156 __glibcxx_requires_cond(!_S_is_eof(__c),
157 _M_message(__gnu_debug::__msg_deref_istreambuf)
158 ._M_iterator(*
this));
160 return traits_type::to_char_type(__c);
167 __glibcxx_requires_cond(_M_sbuf &&
168 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
169 _M_message(__gnu_debug::__msg_inc_istreambuf)
170 ._M_iterator(*
this));
173 _M_c = traits_type::eof();
181 __glibcxx_requires_cond(_M_sbuf &&
182 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
183 _M_message(__gnu_debug::__msg_inc_istreambuf)
184 ._M_iterator(*
this));
187 __old._M_c = _M_sbuf->
sbumpc();
188 _M_c = traits_type::eof();
199 {
return _M_at_eof() == __b._M_at_eof(); }
206 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
213 {
return _S_is_eof(_M_get()); }
218 const int_type __eof = traits_type::eof();
219 return traits_type::eq_int_type(__c, __eof);
222#if __cplusplus > 201703L && __cpp_lib_concepts
226 {
return __i._M_at_eof(); }
230 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); }
237#if __cpp_impl_three_way_comparison < 201907L
238 template<
typename _CharT,
typename _Traits>
241 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
242 const istreambuf_iterator<_CharT, _Traits>& __b)
243 {
return !__a.equal(__b); }
247 template<
typename _CharT,
typename _Traits>
249 :
public iterator<output_iterator_tag, void, void, void, void>
255#if __cplusplus > 201703L
264 template<
typename _CharT2>
265 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
276#if __cplusplus > 201703L
279 : _M_sbuf(
nullptr), _M_failed(true) { }
284 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
288 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
295 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
320 {
return _M_failed; }
325 if (__builtin_expect(!_M_failed,
true)
326 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
332#pragma GCC diagnostic pop
335 template<
typename _CharT>
336 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
337 ostreambuf_iterator<_CharT> >::__type
338 copy(istreambuf_iterator<_CharT> __first,
339 istreambuf_iterator<_CharT> __last,
340 ostreambuf_iterator<_CharT> __result)
342 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
345 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
347 __result._M_failed =
true;
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(_CharT* __first, _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,
366 ostreambuf_iterator<_CharT> >::__type
367 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
368 ostreambuf_iterator<_CharT> __result)
372 __result._M_put(__first, __num);
376 template<
bool _IsMove,
typename _CharT>
377 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
379 __copy_move_a2(istreambuf_iterator<_CharT> __first,
380 istreambuf_iterator<_CharT> __last, _CharT* __result)
382 typedef istreambuf_iterator<_CharT> __is_iterator_type;
383 typedef typename __is_iterator_type::traits_type traits_type;
384 typedef typename __is_iterator_type::streambuf_type streambuf_type;
385 typedef typename traits_type::int_type int_type;
387 if (__first._M_sbuf && !__last._M_sbuf)
389 streambuf_type* __sb = __first._M_sbuf;
390 int_type __c = __sb->sgetc();
391 while (!traits_type::eq_int_type(__c, traits_type::eof()))
393 const streamsize __n = __sb->egptr() - __sb->gptr();
396 traits_type::copy(__result, __sb->gptr(), __n);
397 __sb->__safe_gbump(__n);
399 __c = __sb->underflow();
403 *__result++ = traits_type::to_char_type(__c);
404 __c = __sb->snextc();
411 template<
typename _CharT,
typename _Size>
412 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
414 __copy_n_a(istreambuf_iterator<_CharT> __it, _Size __n, _CharT* __result,
415 bool __strict __attribute__((__unused__)))
420 __glibcxx_requires_cond(__it._M_sbuf,
421 _M_message(__gnu_debug::__msg_inc_istreambuf)
423 _CharT* __beg = __result;
424 __result += __it._M_sbuf->sgetn(__beg, __n);
425 __glibcxx_requires_cond(!__strict || __result - __beg == __n,
426 _M_message(__gnu_debug::__msg_inc_istreambuf)
431 template<
typename _CharT>
432 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
433 istreambuf_iterator<_CharT> >::__type
434 find(istreambuf_iterator<_CharT> __first,
435 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
437 typedef istreambuf_iterator<_CharT> __is_iterator_type;
438 typedef typename __is_iterator_type::traits_type traits_type;
439 typedef typename __is_iterator_type::streambuf_type streambuf_type;
440 typedef typename traits_type::int_type int_type;
441 const int_type __eof = traits_type::eof();
443 if (__first._M_sbuf && !__last._M_sbuf)
445 const int_type __ival = traits_type::to_int_type(__val);
446 streambuf_type* __sb = __first._M_sbuf;
447 int_type __c = __sb->sgetc();
448 while (!traits_type::eq_int_type(__c, __eof)
449 && !traits_type::eq_int_type(__c, __ival))
451 streamsize __n = __sb->egptr() - __sb->gptr();
454 const _CharT* __p = traits_type::find(__sb->gptr(),
457 __n = __p - __sb->gptr();
458 __sb->__safe_gbump(__n);
462 __c = __sb->snextc();
465 __first._M_c = __eof;
471 template<
typename _CharT,
typename _Distance>
472 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
474 advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
479 __glibcxx_assert(__n > 0);
480 __glibcxx_requires_cond(!__i._M_at_eof(),
481 _M_message(__gnu_debug::__msg_inc_istreambuf)
484 typedef istreambuf_iterator<_CharT> __is_iterator_type;
485 typedef typename __is_iterator_type::traits_type traits_type;
486 typedef typename __is_iterator_type::streambuf_type streambuf_type;
487 typedef typename traits_type::int_type int_type;
488 const int_type __eof = traits_type::eof();
490 streambuf_type* __sb = __i._M_sbuf;
493 streamsize __size = __sb->egptr() - __sb->gptr();
496 __sb->__safe_gbump(__n);
500 __sb->__safe_gbump(__size);
502 if (traits_type::eq_int_type(__sb->underflow(), __eof))
504 __glibcxx_requires_cond(__n == 0,
505 _M_message(__gnu_debug::__msg_inc_istreambuf)
516_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.
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.
_CharT reference
This type represents a reference-to-value_type.