Files
2025-10-25 03:02:53 +03:00

8.0 KiB
Raw Permalink Blame History

[istreambuf.iterator]

24 Iterators library [iterators]

24.6 Stream iterators [stream.iterators]

24.6.4 Class template istreambuf_iterator [istreambuf.iterator]

24.6.4.1 General [istreambuf.iterator.general]

1

#

The class templateistreambuf_iterator defines an input iterator that reads successivecharacters from the streambuf for which it was constructed.

operator* provides access to the current input character, if any.

Each timeoperator++ is evaluated, the iterator advances to the next input character.

If the end of stream is reached (streambuf_type::sgetc() returnstraits::eof()), the iterator becomes equal to theend-of-stream iterator value.

The default constructoristreambuf_iterator() and the constructoristreambuf_iterator(nullptr) 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.

2

#

The result ofoperator*() on an end-of-stream iterator is undefined.

For any other iterator value achar_type value is returned.

It is impossible to assign a character via an input iterator.

🔗

namespace std {template<class charT, class traits = char_traits>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>; // [istreambuf.iterator.proxy], class istreambuf_iterator::proxyclass proxy; // exposition onlyconstexpr istreambuf_iterator() noexcept; constexpr istreambuf_iterator(default_sentinel_t) 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; istreambuf_iterator& operator=(const istreambuf_iterator&) noexcept = default; charT operator*() const; istreambuf_iterator& operator++(); proxy operator++(int); bool equal(const istreambuf_iterator& b) const; friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); private: streambuf_type* sbuf_; // exposition only};}

24.6.4.2 Class istreambuf_iterator::proxy [istreambuf.iterator.proxy]

1

#

Classistreambuf_iterator<charT,traits>::proxy is for exposition only.

An implementation is permitted to provide equivalent functionality without providing a class with this name.

Classistreambuf_iterator<charT, traits>::proxy provides a temporary placeholder as the return value of the post-increment operator (operator++).

It keeps the character pointed to by the previous value of the iterator for some possible future access to get the character.

🔗

namespace std {template<class charT, class traits>class istreambuf_iterator<charT, traits>::proxy { // exposition only charT keep_; basic_streambuf<charT,traits>* sbuf_; proxy(charT c, basic_streambuf<charT,traits>* sbuf): keep_(c), sbuf_(sbuf) { }public: charT operator*() { return keep_; }};}

24.6.4.3 Constructors [istreambuf.iterator.cons]

1

#

For each istreambuf_iterator constructor in this subclause, 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; constexpr istreambuf_iterator(default_sentinel_t) noexcept;

2

#

Effects: Initializes sbuf_ with nullptr.

🔗

istreambuf_iterator(istream_type& s) noexcept;

3

#

Effects: Initializes sbuf_ with s.rdbuf().

🔗

istreambuf_iterator(streambuf_type* s) noexcept;

4

#

Effects: Initializes sbuf_ with s.

🔗

istreambuf_iterator(const proxy& p) noexcept;

5

#

Effects: Initializes sbuf_ with p.sbuf_.

24.6.4.4 Operations [istreambuf.iterator.ops]

🔗

charT operator*() const;

1

#

Returns: The character obtained via thestreambuf membersbuf_->sgetc().

🔗

istreambuf_iterator& operator++();

2

#

Effects: As if by sbuf_->sbumpc().

3

#

Returns: *this.

🔗

proxy operator++(int);

4

#

Returns: proxy(sbuf_->sbumpc(), sbuf_).

🔗

bool equal(const istreambuf_iterator& b) const;

5

#

Returns: true if and only if both iterators are at end-of-stream, or neither is at end-of-stream, regardless of whatstreambuf object they use.

🔗

template<class charT, class traits> bool operator==(const istreambuf_iterator<charT,traits>& a, const istreambuf_iterator<charT,traits>& b);

6

#

Returns: a.equal(b).

🔗

friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s);

7

#

Returns: i.equal(s).