std::ranges::basic_istream_view, std::ranges::istream_view
Defined in header <ranges>
|
||
template< std::movable Val, class CharT, class Traits = std::char_traits<CharT> > requires std::default_initializable<Val> && |
(1) | (since C++20) |
template< class Val, class CharT, class Traits > basic_istream_view<Val,CharT,Traits> istream_view( std::basic_istream<CharT,Traits>& s ); |
(2) | (since C++20) |
basic_istream_view
, deducing CharT
and Traits
from s
. Equivalent to return basic_istream_view<Val, CharT, Traits>{s}.The exposition-only concept /*stream-extractable*/<Val,CharT,Traits> is satisfied when lvalue of Val can be extracted from lvalue of std::basic_istream<CharT,Traits>. Its definition is equivalent to
template< class Val, class CharT, class Traits > concept /*stream-extractable*/ = |
||
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. Furthermore, because its std::iterator_traits does not provide a iterator_category
, it does not work with standard iterator adaptors.
[edit] 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) |
std::ranges::basic_istream_view::basic_istream_view
basic_istream_view() = default; |
(1) | |
constexpr explicit basic_istream_view( std::basic_istream<CharT, Traits>& stream ); |
(2) | |
Val
. Use of an iterator to default constructed istream view is undefined behavior.Val
.std::ranges::basic_istream_view::begin
constexpr auto begin(); |
||
Equivalent to:
if (stream_) {
*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; |
||
Equivalent to return std::default_sentinel;.
[edit] Nested classes
std::ranges::basic_istream_view::iterator
struct /*iterator*/; |
||
The return type of basic_istream_view::begin
.
This is an input_iterator.
Member types | |
Member type | Definition |
iterator_concept
|
std::input_iterator_tag |
difference_type
|
std::ptrdiff_t |
value_type
|
Val |
Member functions | |
(constructor) |
constructs an iterator (public member function) |
operator= |
the copy assignment operator is deleted (public member function) |
operator++ |
advances or decrements the iterator (public member function) |
operator* |
returns the current element (public member function) |
Non-member functions | |
operator== |
compares with a std::default_sentinel_t (public member function) |
std::ranges::basic_istream_view::iterator::iterator
/*iterator*/() = default; |
(1) | |
constexpr explicit /*iterator*/( basic_istream_view& parent ); |
(2) | |
/*iterator*/( const /*iterator*/& ) = delete; |
(3) | |
/*iterator*/( /*iterator*/&& ) = default; |
(4) | |
basic_istream_view
.std::ranges::basic_istream_view::iterator::operator=
/*iterator*/& operator=( const /*iterator*/& ) = delete; |
(1) | |
/*iterator*/& operator=( /*iterator*/&& ) = default; |
(2) | |
std::ranges::basic_istream_view::iterator::operator++
/*iterator*/& operator++(); |
(1) | |
void operator++(int); |
(2) | |
Reads a value from the underlying stream and stores it into the parent basic_istream_view
.
Return value
*this
std::ranges::basic_istream_view::iterator::operator*
Val& operator*() const; |
||
Returns a reference to the stored value.
operator==(std::ranges::basic_istream_view::iterator, std::default_sentinel)
friend bool operator==( const /*iterator*/& x, std::default_sentinel_t ); |
||
Compares an iterator with std::default_sentinel_t
.
Returns true if *this
does not have a parent basic_istream_view, or if an error has occurred on the underlying stream.
This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::basic_istream_view::iterator
is an associated class of the arguments.
[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::ranges::istream_view<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::ranges::istream_view<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] See also
input iterator that reads from std::basic_istream (class template) |