30#ifndef _STREAMBUF_ITERATOR_H
31#define _STREAMBUF_ITERATOR_H 1
33#pragma GCC system_header
39namespace std _GLIBCXX_VISIBILITY(default)
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
53 template<
typename _CharT,
typename _Traits>
55 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
62#if __cplusplus < 201103L
64#elif __cplusplus > 201703L
77 template<
typename _CharT2>
78 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
83 template<
bool _IsMove,
typename _CharT2>
84 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
89 template<
typename _CharT2,
typename _Size>
90 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
94 template<
typename _CharT2>
95 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
100 template<
typename _CharT2,
typename _Distance>
101 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
121#if __cplusplus > 201703L && __cpp_lib_concepts
126#if __cplusplus >= 201103L
129 ~istreambuf_iterator() =
default;
134 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
138 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
140#if __cplusplus >= 201103L
154#ifdef _GLIBCXX_DEBUG_PEDANTIC
157 __glibcxx_requires_cond(!_S_is_eof(__c),
158 _M_message(__gnu_debug::__msg_deref_istreambuf)
159 ._M_iterator(*
this));
161 return traits_type::to_char_type(__c);
168 __glibcxx_requires_cond(_M_sbuf &&
169 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
170 _M_message(__gnu_debug::__msg_inc_istreambuf)
171 ._M_iterator(*
this));
174 _M_c = traits_type::eof();
182 __glibcxx_requires_cond(_M_sbuf &&
183 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
184 _M_message(__gnu_debug::__msg_inc_istreambuf)
185 ._M_iterator(*
this));
188 __old._M_c = _M_sbuf->
sbumpc();
189 _M_c = traits_type::eof();
200 {
return _M_at_eof() == __b._M_at_eof(); }
207 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
214 {
return _S_is_eof(_M_get()); }
219 const int_type __eof = traits_type::eof();
220 return traits_type::eq_int_type(__c, __eof);
223#if __cplusplus > 201703L && __cpp_lib_concepts
227 {
return __i._M_at_eof(); }
231 template<
typename _CharT,
typename _Traits>
234 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
235 const istreambuf_iterator<_CharT, _Traits>& __b)
236 {
return __a.equal(__b); }
238#if __cpp_impl_three_way_comparison < 201907L
239 template<
typename _CharT,
typename _Traits>
242 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
243 const istreambuf_iterator<_CharT, _Traits>& __b)
244 {
return !__a.equal(__b); }
248 template<
typename _CharT,
typename _Traits>
250 :
public iterator<output_iterator_tag, void, void, void, void>
256#if __cplusplus > 201703L
265 template<
typename _CharT2>
266 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
277#if __cplusplus > 201703L
280 : _M_sbuf(
nullptr), _M_failed(true) { }
285 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
289 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
296 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
321 {
return _M_failed; }
326 if (__builtin_expect(!_M_failed,
true)
327 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
333#pragma GCC diagnostic pop
336 template<
typename _CharT>
337 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
338 ostreambuf_iterator<_CharT> >::__type
339 copy(istreambuf_iterator<_CharT> __first,
340 istreambuf_iterator<_CharT> __last,
341 ostreambuf_iterator<_CharT> __result)
343 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
346 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
348 __result._M_failed =
true;
353 template<
bool _IsMove,
typename _CharT>
354 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
355 ostreambuf_iterator<_CharT> >::__type
356 __copy_move_a2(_CharT* __first, _CharT* __last,
357 ostreambuf_iterator<_CharT> __result)
361 __result._M_put(__first, __num);
365 template<
bool _IsMove,
typename _CharT>
366 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
367 ostreambuf_iterator<_CharT> >::__type
368 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
369 ostreambuf_iterator<_CharT> __result)
373 __result._M_put(__first, __num);
377 template<
bool _IsMove,
typename _CharT>
378 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
380 __copy_move_a2(istreambuf_iterator<_CharT> __first,
381 istreambuf_iterator<_CharT> __last, _CharT* __result)
383 typedef istreambuf_iterator<_CharT> __is_iterator_type;
384 typedef typename __is_iterator_type::traits_type traits_type;
385 typedef typename __is_iterator_type::streambuf_type streambuf_type;
386 typedef typename traits_type::int_type int_type;
388 if (__first._M_sbuf && !__last._M_sbuf)
390 streambuf_type* __sb = __first._M_sbuf;
391 int_type __c = __sb->sgetc();
392 while (!traits_type::eq_int_type(__c, traits_type::eof()))
394 const streamsize __n = __sb->egptr() - __sb->gptr();
397 traits_type::copy(__result, __sb->gptr(), __n);
398 __sb->__safe_gbump(__n);
400 __c = __sb->underflow();
404 *__result++ = traits_type::to_char_type(__c);
405 __c = __sb->snextc();
412 template<
typename _CharT,
typename _Size>
413 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
415 __copy_n_a(istreambuf_iterator<_CharT> __it, _Size __n, _CharT* __result,
416 bool __strict __attribute__((__unused__)))
421 __glibcxx_requires_cond(__it._M_sbuf,
422 _M_message(__gnu_debug::__msg_inc_istreambuf)
424 _CharT* __beg = __result;
425 __result += __it._M_sbuf->sgetn(__beg, __n);
426 __glibcxx_requires_cond(!__strict || __result - __beg == __n,
427 _M_message(__gnu_debug::__msg_inc_istreambuf)
432 template<
typename _CharT>
433 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
434 istreambuf_iterator<_CharT> >::__type
435 find(istreambuf_iterator<_CharT> __first,
436 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
438 typedef istreambuf_iterator<_CharT> __is_iterator_type;
439 typedef typename __is_iterator_type::traits_type traits_type;
440 typedef typename __is_iterator_type::streambuf_type streambuf_type;
441 typedef typename traits_type::int_type int_type;
442 const int_type __eof = traits_type::eof();
444 if (__first._M_sbuf && !__last._M_sbuf)
446 const int_type __ival = traits_type::to_int_type(__val);
447 streambuf_type* __sb = __first._M_sbuf;
448 int_type __c = __sb->sgetc();
449 while (!traits_type::eq_int_type(__c, __eof)
450 && !traits_type::eq_int_type(__c, __ival))
452 streamsize __n = __sb->egptr() - __sb->gptr();
455 const _CharT* __p = traits_type::find(__sb->gptr(),
458 __n = __p - __sb->gptr();
459 __sb->__safe_gbump(__n);
463 __c = __sb->snextc();
466 __first._M_c = __eof;
472 template<
typename _CharT,
typename _Distance>
473 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
475 advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
480 __glibcxx_assert(__n > 0);
481 __glibcxx_requires_cond(!__i._M_at_eof(),
482 _M_message(__gnu_debug::__msg_inc_istreambuf)
485 typedef istreambuf_iterator<_CharT> __is_iterator_type;
486 typedef typename __is_iterator_type::traits_type traits_type;
487 typedef typename __is_iterator_type::streambuf_type streambuf_type;
488 typedef typename traits_type::int_type int_type;
489 const int_type __eof = traits_type::eof();
491 streambuf_type* __sb = __i._M_sbuf;
494 streamsize __size = __sb->egptr() - __sb->gptr();
497 __sb->__safe_gbump(__n);
501 __sb->__safe_gbump(__size);
503 if (traits_type::eq_int_type(__sb->underflow(), __eof))
505 __glibcxx_requires_cond(__n == 0,
506 _M_message(__gnu_debug::__msg_inc_istreambuf)
517_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.