std::ranges...tream_view,(3)
π std::ranges...tream_view,(3) π
okay bestie, this is the std::ranges...tream_view,(3) page from the C++ Standard Libary manual β yes, that's the manual name, typo and all, no cap. It's giving stream-view realness, and we're gonna get through every detail together. π¦
πΈ NAME πΈ
The names this page is serving are:
std::ranges::views::istreamstd::ranges::basic_istream_viewstd::ranges::istream_view
And the original NAME line also has a dash and repeats those three names, so here's the full cast exactly as listed:
std::ranges::views::istream,std::ranges::basic_istream_view,std::ranges::istream_view,
-
std::ranges::views::istream,std::ranges::basic_istream_view,std::ranges::istream_view,
β¨ Synopsis β¨
Defined in header <ranges>.
template< std::movable Val, class CharT, class Traits =
std::char_traits<CharT> >
requires std::default_initializable<Val> &&
/*stream-extractable*/<Val,CharT,Traits>
(1) (since C++20)
class basic_istream_view
: public
ranges::view_interface<basic_istream_view<Val,CharT,Traits>>
Helper templates
template< class Val >
(2) (since C++20)
using istream_view = ranges::basic_istream_view<Val, char>;
template< class Val >
(3) (since C++20)
using wistream_view = ranges::basic_istream_view<Val, wchar_t>;
Customization point objects
namespace views {
template< class T >
(4) (since C++20)
inline constexpr /*unspecified*/ istream = /*unspecified*/;
}
Helper concepts
template< class Val, class CharT, class Traits >
concept /*stream-extractable*/ =
(exposition
requires(std::basic_istream<CharT,Traits>& is, Val& t) {
(5) only*)
is >> t;
};
1)β A range factory that generates a sequence of elements by repeatedly callingoperator>>.2,3)β Convenience alias templates for character typescharandwchar_t.4)βviews::istream<T>(e)is expression-equivalent to (has the same effect as)ranges::basic_istream_view<T, typename U::char_type, typename U::traits_type>(e)for any suitable subexpressionse, whereUisstd::remove_reference_t<decltype(e)>. The program is ill-formed ifUis not both publicly and unambiguously derived fromstd::basic_istream<typename U::char_type, typename U::traits_type>, which may result in a substitution failure.5)β The exposition-only concept/*stream-extractable*/<Val,CharT,Traits>is satisfied when lvalue ofValcan be extracted from lvalue ofstd::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.
π Member functions π
- constructor β constructs a
basic_istream_view(public member function) - begin β returns an iterator (public member function)
- end β returns
std::default_sentinel(public member function)
Inherited from std::ranges::view_interface:
(none)β althoughbasic_istream_viewis derived fromstd::ranges::view_interface, it cannot use any of inherited member functions.
π std::ranges::basic_istream_view::basic_istream_view π
constexpr explicit
(since C++20)
basic_istream_view( std::basic_istream<CharT, Traits>& stream );
Initializes the stored pointer to stream with std::addressof(stream), and value-initializes the stored value of Val.
π std::ranges::basic_istream_view::begin π
constexpr auto begin(); (since C++20)
Equivalent to *stream_ >> value_; return /*iterator*/{*this};, where stream_ is the stored pointer to stream and value_ is the stored value of Val.
π std::ranges::basic_istream_view::end π
constexpr std::default_sentinel_t end() const noexcept; (since C++20)
Equivalent to return std::default_sentinel;.
π Nested classes π
iteratorβ the iterator type ofbasic_istream_view(C++20) (exposition-only member class*)
π Example π
// Run this code
#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,
π§ Defect reports π§
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
P2325R3β applied to C++20; behavior as published: default constructor was provided as view; correct behavior: removed along with the requirement must be default_initializable.LWG 3568β applied to C++20; behavior as published:P2325R3accidentally made the stored value default-initialized; correct behavior: restored to value-initialization.P2432R1β applied to C++20; behavior as published:ranges::istream_viewwas a function template and customization point objects did not follow the naming convention; correct behavior: made an alias template; added.
π See also π
istream_iteratorβ input iterator that reads fromstd::basic_istream(class template)
okay that's the whole page, bestie π β source/version: http://cppreference.com; date: 2024.06.10. Mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms