[range.istream]

# 25 Ranges library [[ranges]](./#ranges)

## 25.6 Range factories [[range.factories]](range.factories#range.istream)

### 25.6.6 Istream view [range.istream]

#### [25.6.6.1](#overview) Overview [[range.istream.overview]](range.istream.overview)

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3997)

basic_istream_view models [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") and
reads (using operator>>) successive elements
from its corresponding input stream[.](#overview-1.sentence-1)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4002)

The name views​::​istream<T> denotes
a customization point object ([[customization.point.object]](customization.point.object "16.3.3.3.5 Customization Point Object types"))[.](#overview-2.sentence-1)

Given a type T and a subexpression E of type U,
if U models[derived_from](concept.derived#concept:derived_from "18.4.3 Concept derived_­from [concept.derived]")<basic_istream<typename U​::​char_type,typename U​::​traits_type>>,
then the expression views​::​istream<T>(E) is expression-equivalent tobasic_istream_view<T, typename U​::​char_type,typename U​::​traits_type>(E);
otherwise, views​::​istream<T>(E) is ill-formed[.](#overview-2.sentence-2)

[3](#overview-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4014)

[*Example [1](#overview-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*]

#### [25.6.6.2](#view) Class template basic_istream_view [[range.istream.view]](range.istream.view)

[ð](#lib:basic_istream_view)

namespace std::ranges {template<class Val, class CharT, class Traits>concept [*stream-extractable*](#concept:stream-extractable "25.6.6.2 Class template basic_­istream_­view [range.istream.view]") = // *exposition only*requires(basic_istream<CharT, Traits>& is, Val& t) { is >> t; }; template<[movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]") Val, class CharT, class Traits = char_traits<CharT>>requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<Val> &&[*stream-extractable*](#concept:stream-extractable "25.6.6.2 Class template basic_­istream_­view [range.istream.view]")<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]](#iterator "25.6.6.3 Class basic_­istream_­view​::​iterator"), class basic_istream_view​::​*iterator*struct *iterator*; // *exposition only* basic_istream<CharT, Traits>* *stream_*; // *exposition only* Val *value_* = Val(); // *exposition only*};}

[ð](#lib:basic_istream_view,constructor)

`constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
`

[1](#view-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4063)

*Effects*: Initializes *stream_* with addressof(stream)[.](#view-1.sentence-1)

[ð](#lib:end,basic_istream_view)

`constexpr default_sentinel_t end() const noexcept;
`

[2](#view-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4074)

*Effects*: Equivalent to: return default_sentinel;

#### [25.6.6.3](#iterator) Class basic_istream_view​::​*iterator* [[range.istream.iterator]](range.istream.iterator)

[ð](#lib:basic_istream_view::iterator)

namespace std::ranges {template<[movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]") Val, class CharT, class Traits>requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<Val> &&[*stream-extractable*](#concept:stream-extractable "25.6.6.2 Class template basic_­istream_­view [range.istream.view]")<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*};}

[ð](#lib:basic_istream_view::iterator,constructor)

`constexpr explicit iterator(basic_istream_view& parent) noexcept;
`

[1](#iterator-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4120)

*Effects*: Initializes *parent_* with addressof(parent)[.](#iterator-1.sentence-1)

[ð](#lib:operator++,basic_istream_view::iterator)

`iterator& operator++();
`

[2](#iterator-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4131)

*Effects*: Equivalent to:**parent_*->*stream_* >> *parent_*->*value_*;return *this;

[ð](#lib:operator++,basic_istream_view::iterator_)

`void operator++(int);
`

[3](#iterator-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4146)

*Effects*: Equivalent to ++*this[.](#iterator-3.sentence-1)

[ð](#lib:operator*,basic_istream_view::iterator)

`Val& operator*() const;
`

[4](#iterator-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4157)

*Effects*: Equivalent to: return *parent_*->*value_*;

[ð](#lib:operator==,basic_istream_view::iterator)

`friend bool operator==(const iterator& x, default_sentinel_t);
`

[5](#iterator-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4168)

*Effects*: Equivalent to: return !*x.*parent_*->*stream_*;
