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
45#ifdef __glibcxx_format
47 template<
typename,
typename>
class _Iter_sink;
48 template<
typename _CharT>
49 class _Iter_sink<_CharT, ostreambuf_iterator<_CharT>>;
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
63 template<
typename _CharT,
typename _Traits>
65 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
72#if __cplusplus < 201103L
74#elif __cplusplus > 201703L
87 template<
typename _CharT2>
88 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
93 template<
bool _IsMove,
typename _CharT2>
94 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
99 template<
typename _CharT2,
typename _Size>
100 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
104 template<
typename _CharT2>
105 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
110 template<
typename _CharT2,
typename _Distance>
111 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
131#if __cplusplus > 201703L && __cpp_lib_concepts
136#if __cplusplus >= 201103L
139 ~istreambuf_iterator() =
default;
144 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
148 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
150#if __cplusplus >= 201103L
164#ifdef _GLIBCXX_DEBUG_PEDANTIC
167 __glibcxx_requires_cond(!_S_is_eof(__c),
168 _M_message(__gnu_debug::__msg_deref_istreambuf)
169 ._M_iterator(*
this));
171 return traits_type::to_char_type(__c);
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));
183 if (_S_is_eof(_M_sbuf->snextc()))
185 _M_c = traits_type::eof();
194 __old._M_c = _M_sbuf->sgetc();
206 {
return _M_at_eof() == __b._M_at_eof(); }
213 if (_M_sbuf && _S_is_eof(__ret))
214 __ret = _M_sbuf->
sgetc();
220 {
return _S_is_eof(_M_get()); }
225 const int_type __eof = traits_type::eof();
226 return traits_type::eq_int_type(__c, __eof);
229#if __cplusplus > 201703L && __cpp_lib_concepts
233 {
return __i._M_at_eof(); }
237 template<
typename _CharT,
typename _Traits>
242 {
return __a.equal(__b); }
244#if __cpp_impl_three_way_comparison < 201907L
245 template<
typename _CharT,
typename _Traits>
250 {
return !__a.equal(__b); }
254 template<
typename _CharT,
typename _Traits>
255 class ostreambuf_iterator
256 :
public iterator<output_iterator_tag, void, void, void, void>
262#if __cplusplus > 201703L
271 template<
typename _CharT2>
272 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
273 ostreambuf_iterator<_CharT2> >::__type
275 ostreambuf_iterator<_CharT2>);
277#ifdef __glibcxx_format
287#if __cplusplus > 201703L
289 ostreambuf_iterator() noexcept
290 : _M_sbuf(
nullptr), _M_failed(true) { }
295 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
299 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
306 _Traits::eq_int_type(_M_sbuf->sputc(__c), _Traits::eof()))
331 {
return _M_failed; }
336 if (__builtin_expect(!_M_failed,
true)
337 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
343#pragma GCC diagnostic pop
346 template<
typename _CharT>
347 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
353 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
356 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
358 __result._M_failed =
true;
363 template<
bool _IsMove,
typename _CharT>
364 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
366 __copy_move_a2(_CharT* __first, _CharT* __last,
371 __result._M_put(__first, __num);
375 template<
bool _IsMove,
typename _CharT>
376 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
378 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
383 __result._M_put(__first, __num);
387 template<
bool _IsMove,
typename _CharT>
388 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
394 typedef typename __is_iterator_type::traits_type traits_type;
395 typedef typename __is_iterator_type::streambuf_type streambuf_type;
396 typedef typename traits_type::int_type
int_type;
398 if (__first._M_sbuf && !__last._M_sbuf)
400 streambuf_type* __sb = __first._M_sbuf;
402 while (!traits_type::eq_int_type(__c, traits_type::eof()))
404 const streamsize __n = __sb->egptr() - __sb->gptr();
407 traits_type::copy(__result, __sb->gptr(), __n);
408 __sb->__safe_gbump(__n);
410 __c = __sb->underflow();
414 *__result++ = traits_type::to_char_type(__c);
415 __c = __sb->snextc();
422 template<
typename _CharT,
typename _Size>
423 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
426 bool __strict __attribute__((__unused__)))
431 __glibcxx_requires_cond(__it._M_sbuf,
432 _M_message(__gnu_debug::__msg_inc_istreambuf)
434 _CharT* __beg = __result;
435 __result += __it._M_sbuf->sgetn(__beg, __n);
436 __glibcxx_requires_cond(!__strict || __result - __beg == __n,
437 _M_message(__gnu_debug::__msg_inc_istreambuf)
442 template<
typename _CharT>
443 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
449 typedef typename __is_iterator_type::traits_type traits_type;
450 typedef typename __is_iterator_type::streambuf_type streambuf_type;
451 typedef typename traits_type::int_type
int_type;
452 const int_type __eof = traits_type::eof();
454 if (__first._M_sbuf && !__last._M_sbuf)
456 const int_type __ival = traits_type::to_int_type(__val);
457 streambuf_type* __sb = __first._M_sbuf;
459 while (!traits_type::eq_int_type(__c, __eof)
460 && !traits_type::eq_int_type(__c, __ival))
462 streamsize __n = __sb->egptr() - __sb->gptr();
465 const _CharT* __p = traits_type::find(__sb->gptr(),
468 __n = __p - __sb->gptr();
469 __sb->__safe_gbump(__n);
473 __c = __sb->snextc();
476 __first._M_c = __eof;
482 template<
typename _CharT,
typename _Distance>
483 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
490 __glibcxx_assert(__n > 0);
491 __glibcxx_requires_cond(!__i._M_at_eof(),
492 _M_message(__gnu_debug::__msg_inc_istreambuf)
496 typedef typename __is_iterator_type::traits_type traits_type;
497 typedef typename __is_iterator_type::streambuf_type streambuf_type;
498 typedef typename traits_type::int_type
int_type;
499 const int_type __eof = traits_type::eof();
501 streambuf_type* __sb = __i._M_sbuf;
504 streamsize __size = __sb->egptr() - __sb->gptr();
507 __sb->__safe_gbump(__n);
511 __sb->__safe_gbump(__size);
513 if (traits_type::eq_int_type(__sb->underflow(), __eof))
515 __glibcxx_requires_cond(__n == 0,
516 _M_message(__gnu_debug::__msg_inc_istreambuf)
527_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.
Template class basic_istream.
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_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.