26 Ranges library [ranges]

26.6 Range factories [range.factories]

26.6.6 Istream view [range.istream]

26.6.6.1 Overview [range.istream.overview]

basic_istream_view models input_range and reads (using operator>>) successive elements from its corresponding input stream.
The name views​::​istream<T> denotes a customization point object ([customization.point.object]).
Given a type T and a subexpression E of type U, if U models derived_from<basic_istream<typename U​::​char_type, typename U​::​traits_type>>, then the expression views​::​istream<T>(E) is expression-equivalent to basic_istream_view<T, typename U​::​char_type, typename U​::​traits_type>(E); otherwise, views​::​istream<T>(E) is ill-formed.
[Example 1: auto ints = istringstream{"0 1 2 3 4"}; ranges::copy(views::istream<int>(ints), ostream_iterator<int>{cout, "-"}); // prints 0-1-2-3-4- — end example]

26.6.6.2 Class template basic_istream_view [range.istream.view]

namespace std::ranges { template<class Val, class CharT, class Traits> concept stream-extractable = // exposition only requires(basic_istream<CharT, Traits>& is, Val& t) { is >> t; }; template<movable Val, class CharT, class Traits = char_traits<CharT>> requires default_initializable<Val> && stream-extractable<Val, CharT, Traits> class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> { public: constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream); constexpr auto begin() { *stream_ >> value_; return iterator{*this}; } constexpr default_sentinel_t end() const noexcept; private: // [range.istream.iterator], class basic_istream_view​::​iterator struct iterator; // exposition only basic_istream<CharT, Traits>* stream_; // exposition only Val value_ = Val(); // exposition only }; }
constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
Effects: Initializes stream_ with addressof(stream).
constexpr default_sentinel_t end() const noexcept;
Effects: Equivalent to: return default_sentinel;

26.6.6.3 Class basic_istream_view​::​iterator [range.istream.iterator]

namespace std::ranges { template<movable Val, class CharT, class Traits> requires default_initializable<Val> && stream-extractable<Val, CharT, Traits> class basic_istream_view<Val, CharT, Traits>::iterator { public: using iterator_concept = input_iterator_tag; using difference_type = ptrdiff_t; using value_type = Val; constexpr explicit iterator(basic_istream_view& parent) noexcept; iterator(const iterator&) = delete; iterator(iterator&&) = default; iterator& operator=(const iterator&) = delete; iterator& operator=(iterator&&) = default; iterator& operator++(); void operator++(int); Val& operator*() const; friend bool operator==(const iterator& x, default_sentinel_t); private: basic_istream_view* parent_; // exposition only }; }
constexpr explicit iterator(basic_istream_view& parent) noexcept;
Effects: Initializes parent_ with addressof(parent).
iterator& operator++();
Effects: Equivalent to: *parent_->stream_ >> parent_->value_; return *this;
void operator++(int);
Effects: Equivalent to ++*this.
Val& operator*() const;
Effects: Equivalent to: return parent_->value_;
friend bool operator==(const iterator& x, default_sentinel_t);
Effects: Equivalent to: return !*x.parent_->stream_;