The
class template
istreambuf_iterator
defines an input iterator (
[input.iterators]) that
reads successive
characters
from the streambuf for which it was constructed
. operator*
provides access to the current input character, if any
. Each time
operator++
is evaluated, the iterator advances to the next input character
. If the end of stream is reached (
streambuf_type::sgetc() returns
traits::eof()),
the iterator becomes equal to the
end-of-stream
iterator value
. The default constructor
istreambuf_iterator()
and the constructor
istreambuf_iterator(0)
both construct an end-of-stream iterator object suitable for use
as an end-of-range
. All specializations of
istreambuf_iterator shall have a trivial copy
constructor, a
constexpr default constructor, and a trivial destructor
.The result of
operator*()
on an end-of-stream iterator is undefined
. For any other iterator value a
char_type
value is returned
. It is impossible to assign a character via an input iterator
.
namespace std {
template<class charT, class traits = char_traits<charT>>
class istreambuf_iterator {
public:
using iterator_category = input_iterator_tag;
using value_type = charT;
using difference_type = typename traits::off_type;
using pointer = unspecified;
using reference = charT;
using char_type = charT;
using traits_type = traits;
using int_type = typename traits::int_type;
using streambuf_type = basic_streambuf<charT,traits>;
using istream_type = basic_istream<charT,traits>;
class proxy;
constexpr istreambuf_iterator() noexcept;
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
~istreambuf_iterator() = default;
istreambuf_iterator(istream_type& s) noexcept;
istreambuf_iterator(streambuf_type* s) noexcept;
istreambuf_iterator(const proxy& p) noexcept;
charT operator*() const;
istreambuf_iterator& operator++();
proxy operator++(int);
bool equal(const istreambuf_iterator& b) const;
private:
streambuf_type* sbuf_; };
template <class charT, class traits>
bool operator==(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);
template <class charT, class traits>
bool operator!=(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);
}
For each
istreambuf_iterator constructor in this section,
an end-of-stream iterator is constructed if and only if
the exposition-only member
sbuf_ is initialized with a null pointer value
. constexpr istreambuf_iterator() noexcept;
Effects:
Initializes
sbuf_ with
nullptr. istreambuf_iterator(istream_type& s) noexcept;
Effects:
Initializes
sbuf_ with
s.rdbuf(). istreambuf_iterator(streambuf_type* s) noexcept;
Effects:
Initializes
sbuf_ with
s. istreambuf_iterator(const proxy& p) noexcept;
Effects:
Initializes
sbuf_ with
p.sbuf_. charT operator*() const
Returns:
The character obtained via the
streambuf
member
sbuf_->sgetc(). istreambuf_iterator& operator++();
Effects:
As if by
sbuf_->sbumpc(). proxy operator++(int);
Returns:
proxy(sbuf_->sbumpc(), sbuf_). bool equal(const istreambuf_iterator& b) const;
Returns:
true
if and only if both iterators are at end-of-stream,
or neither is at end-of-stream, regardless of what
streambuf
object they use
. template <class charT, class traits>
bool operator==(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);
template <class charT, class traits>
bool operator!=(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);