30 #ifndef _STREAMBUF_ITERATOR_H 31 #define _STREAMBUF_ITERATOR_H 1 33 #pragma GCC system_header 39 namespace 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>
54 class istreambuf_iterator
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,
113 mutable streambuf_type* _M_sbuf;
119 : _M_sbuf(0), _M_c(traits_type::eof()) { }
121 #if __cplusplus > 201703L && __cpp_lib_concepts 126 #if __cplusplus >= 201103L 134 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
138 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
140 #if __cplusplus >= 201103L 152 int_type __c = _M_get();
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(); }
206 int_type __ret = _M_c;
207 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
214 {
return _S_is_eof(_M_get()); }
217 _S_is_eof(int_type __c)
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>
236 {
return __a.equal(__b); }
238 #if __cpp_impl_three_way_comparison < 201907L 239 template<
typename _CharT,
typename _Traits>
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,
272 streambuf_type* _M_sbuf;
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,
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,
356 __copy_move_a2(_CharT* __first, _CharT* __last,
361 __result._M_put(__first, __num);
365 template<
bool _IsMove,
typename _CharT>
366 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
368 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
373 __result._M_put(__first, __num);
377 template<
bool _IsMove,
typename _CharT>
378 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
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()))
397 traits_type::copy(__result, __sb->
gptr(), __n);
398 __sb->__safe_gbump(__n);
404 *__result++ = traits_type::to_char_type(__c);
412 template<
typename _CharT,
typename _Size>
413 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
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,
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))
455 const _CharT* __p = traits_type::find(__sb->
gptr(),
458 __n = __p - __sb->
gptr();
459 __sb->__safe_gbump(__n);
466 __first._M_c = __eof;
472 template<
typename _CharT,
typename _Distance>
473 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
480 __glibcxx_assert(__n > 0);
481 __glibcxx_requires_cond(!__i._M_at_eof(),
482 _M_message(__gnu_debug::__msg_inc_istreambuf)
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;
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
_CharT char_type
Public typedefs.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
_Traits traits_type
Public typedefs.
void pointer
Public typedefs.
ostreambuf_iterator & operator*()
Return *this.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
Provides input iterator semantics for streambufs.
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
int_type sbumpc()
Getting the next character.
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
ISO C++ entities toplevel namespace is std.
char_type * egptr() const
Access to the get area.
The actual work of input and output (interface).
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
Template class basic_ostream.
int_type sgetc()
Getting the next character.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
Template class basic_istream.
_CharT reference
This type represents a reference-to-value_type.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
ptrdiff_t difference_type
Public typedefs.
bool failed() const noexcept
Return true if previous operator=() failed.
Provides output iterator semantics for streambufs.
_CharT char_type
Public typedefs.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
char_type operator*() const
Return the current character pointed to by iterator. This returns streambuf.sgetc(). It cannot be assigned. NB: The result of operator*() on an end of stream is undefined.
ostreambuf_iterator & operator++()
Return *this.
char_type * gptr() const
Access to the get area.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
ostreambuf_iterator & operator++(int)
Return *this.
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
virtual int_type underflow()
Fetches more data from the controlled sequence.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
_Traits traits_type
Public typedefs.
int_type snextc()
Getting the next character.
_Traits::int_type int_type
Public typedefs.