From cppreference.com
Defined in header
template<std::movableVal,classCharT,classTraits=std::char_traits<CharT>>requiresstd::default_initializable<Val>&&/*stream-extractable*/<Val,CharT,Traits>classbasic_istream_view:publicranges::view_interface<basic_istream_view<Val,CharT,Traits>> (1) (since C++20)Helper templates
template<classVal>usingistream_view=ranges::basic_istream_view<Val,char>; (2) (since C++20)template<classVal>usingwistream_view=ranges::basic_istream_view<Val,wchar_t>; (3) (since C++20)Customization point objects
namespaceviews{template<classT>constexpr/* unspecified */istream=/* unspecified */;} (4) (since C++20)Helper concepts
template<classVal,classCharT,classTraits>concept/*stream-extractable*/=requires(std::basic_istream<CharT,Traits>&is,Val&t){is>>t;}; (5)(exposition only*)1) A range factory that generates a sequence of elements by repeatedly calling operator>>.
2,3) Convenience alias templates for character types char and wchar_t.
4)views::istream<T>(e) is
to ranges::basic_istream_view<T,typenameU::char_type,typenameU::traits_type>(e) for any suitable subexpressions e, where U is std::remove_reference_t<decltype(e)>.
The program is ill-formed if U is not both publicly and unambiguously derived from std::basic_istream<typenameU::char_type,typenameU::traits_type>, which may result in a
.
5) The exposition-only concept /*stream-extractable*/<Val,CharT,Traits> is satisfied when lvalue of type Val can be extracted from lvalue of type std::basic_istream<CharT,Traits>.
The iterator type of basic_istream_view is move-only: it does not meet the
requirements, and thus does not work with pre-C++20
.
Customization point objects
The name views::istream<T> denotes a customization point object, which is a const
of a
class type. See
for details.
Data members
Member Description std::basic_istream<CharT,Traits>*stream_a pointer to the input stream
(exposition-only member object*)Valvalue_the stored value
(exposition-only member object*)Member functions
constructs a basic_istream_view
(public member function)
returns an iterator
(public member function)
returns
(public member function) Inherited from
(C++23)
returns a constant iterator to the beginning of the range
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a sentinel for the constant iterator of the range
(public member function of std::ranges::view_interface<D>)
std::ranges::basic_istream_view::basic_istream_view
constexprexplicitbasic_istream_view(std::basic_istream<CharT,Traits>&stream);(since C++20) Initializes
with std::addressof(stream), and value-initializes
.
std::ranges::basic_istream_view::begin
constexprautobegin();(since C++20)Equivalent to *
>>
;return
{*this};.
std::ranges::basic_istream_view::end
constexprstd::default_sentinel_tend()constnoexcept;(since C++20)Returns std::default_sentinel.
Nested classes
the iterator type of basic_istream_view
(exposition-only member class*)Example
Run this code
#include<algorithm>#include<iomanip>#include<iostream>#include<iterator>#include<ranges>#include<sstream>#include<string>intmain(){autowords=std::istringstream{"today is yesterday’s tomorrow"};for(constauto&s:std::views::istream<std::string>(words))std::cout<<std::quoted(s,'/')<<' ';std::cout<<'\n';autofloats=std::istringstream{"1.1 2.2\t3.3\v4.4\f55\n66\r7.7 8.8"};std::ranges::copy(std::views::istream<float>(floats),std::ostream_iterator<float>{std::cout,", "});std::cout<<'\n';}Output:
/today/ /is/ /yesterday’s/ /tomorrow/ 1.1, 2.2, 3.3, 4.4, 55, 66, 7.7, 8.8, Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++20 P2325R3 accidentally made the stored value default-initialized restored to value-initialization
C++20 default constructor was provided as
must be
removed along with
the requirement
C++20 ranges::istream_view was a function template
and did not follow the naming convention made an alias template;
customization point objects added See also