std::ranges::views::istream, std::ranges::basic_istream_view, std::ranges::istream_view, std::ranges::wistream_view
<ranges>
class Traits = std::char_traits <CharT> >
requires std::default_initializable <Val> &&
/*stream-extractable*/<Val, CharT, Traits>
class basic_istream_view
using istream_view = ranges::basic_istream_view<Val, char>;
using wistream_view = ranges::basic_istream_view<Val, wchar_t>;
template< class T >
constexpr /* unspecified */ istream = /* unspecified */;
concept /*stream-extractable*/ =
requires(std::basic_istream <CharT, Traits>& is, Val& t) {
is >> t;
U
is std::remove_reference_t <decltype(e)>.U
is not both publicly and unambiguously derived from std::basic_istream <typename U::char_type, typename U::traits_type>, which may result in a substitution failure.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 LegacyIterator requirements, and thus does not work with pre-C++20 algorithms.
Contents
Customization point objects
The name views::istream<T>
denotes a customization point object, which is a const function object of a literal semiregular
class type. See CustomizationPointObject for details.
[edit] Data members
stream_
a pointer to the input stream(exposition-only member object*)
Val
value_
the stored value(exposition-only member object*)
[edit] Member functions
Inherited from std::ranges::view_interface
(public member function of
std::ranges::view_interface<D>
) [edit]
(public member function of
std::ranges::view_interface<D>
) [edit]
Although basic_istream_view
is derived from std::ranges::view_interface , it cannot use any of inherited member functions.
std::ranges::basic_istream_view::basic_istream_view
basic_istream_view( std::basic_istream <CharT, Traits>& stream );
Initializes stream_
with std::addressof (stream), and value-initializes value_
.
std::ranges::basic_istream_view::begin
Equivalent to *stream_
>>
value_
; return
iterator
{*this};.
std::ranges::basic_istream_view::end
Returns std::default_sentinel .
[edit] Nested classes
[edit] Example
#include <algorithm> #include <iomanip> #include <iostream> #include <iterator> #include <ranges> #include <sstream> #include <string> int main() { auto words = std::istringstream {"today is yesterday’s tomorrow"}; for (const auto& s : std::views::istream<std::string >(words)) std::cout << std::quoted (s, '/') << ' '; std::cout << '\n'; auto floats = 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,
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3568 | C++20 | P2325R3 accidentally made the stored value default-initialized | restored to value-initialization |
P2325R3 | C++20 | default constructor was provided asview must be default_initializable
|
removed along with the requirement |
P2432R1 | C++20 | ranges::istream_view was a function templateand did not follow the naming convention |
made an alias template; customization point objects added |