Namespaces
Variants

std::ranges::views::istream, std::ranges::basic_istream_view, std::ranges::istream_view, std::ranges::wistream_view

ja.cppreference.net から
 
 
Ranges ライブラリ
Range アダプタ
 
 
ヘッダ <ranges>
template< std::movable Val, class CharT,
          class Traits = std::char_traits<CharT> >
    requires std::default_initializable<Val> &&
             /*stream-extractable*/<Val, CharT, Traits>
class basic_istream_view
    : public ranges::view_interface<basic_istream_view<Val, CharT, Traits>>
で定義 (1) (C++20 から)
ヘルパーテンプレート
template< class Val >
using istream_view = ranges::basic_istream_view<Val, char>;
(2) (C++20 から)
template< class Val >
using wistream_view = ranges::basic_istream_view<Val, wchar_t>;
(3) (C++20 から)
カスタマイゼーションポイントオブジェクト
namespace views {
    template< class T >
    constexpr /* unspecified */ istream = /* unspecified */;
}
(4) (C++20 から)
ヘルパーコンセプト
template< class Val, class CharT, class Traits >
concept /*stream-extractable*/ =
    requires(std::basic_istream<CharT, Traits>& is, Val& t) {
        is >> t;
    };
(5) (説明専用*)
1) operator>> を繰り返し呼び出すことによって要素のシーケンスを生成する Range ファクトリ。
2,3) 文字型 char および wchar_t のための便利なエイリアステンプレート。
4) views::istream<T>(e) は 式等価 への ranges::basic_istream_view<T, typename U::char_type, typename U::traits_type>(e) 任意の適切な部分式 e に対して、ここで U は std::remove_reference_t<decltype(e)> である。
U が std::basic_istream<typename U::char_type, typename U::traits_type> から public かつ曖昧でなく派生されていない場合、プログラムは ill-formed である。これは 置換失敗 を引き起こす可能性がある。
5) 説明専用コンセプト /*stream-extractable*/<Val, CharT, Traits> は、型 Val の左辺値が型 std::basic_istream<CharT, Traits> の左辺値から抽出できる場合に満たされる。

basic_istream_view のイテレータ型はムーブオンリーである。つまり、LegacyIterator の要件を満たさず、したがって C++20 より前の アルゴリズム では動作しない。

カスタマイゼーションポイントオブジェクト

名前 views::istream<T> は カスタマイゼーションポイントオブジェクト を表し、これは 関数オブジェクト のconstな リテラル semiregular クラス型である。詳細は CustomizationPointObject を参照。

データメンバ

メンバ 説明
std::basic_istream<CharT, Traits>* stream_ 入力ストリームへのポインタ
(説明専用メンバオブジェクト*)
Val value_ 格納された値
(説明専用メンバオブジェクト*)

メンバー関数

basic_istream_viewを構築する
(public member function)
イテレータを返す
(公開メンバ関数)
を返す std::default_sentinel
(公開メンバ関数)
から継承 ranges::view_interface
(C++23)
は範囲の先頭への定数イテレータを返します
(のパブリックメンバ関数 std::ranges::view_interface<D>)
(C++23)
は範囲の定数イテレータの番兵を返します
(のパブリックメンバ関数 std::ranges::view_interface<D>)

basic_istream_view は ranges::view_interface から派生していますが、継承されたメンバ関数を使用することはできません。

(C++23まで)

std::ranges::basic_istream_view:: basic_istream_view

constexpr explicit
basic_istream_view ( std:: basic_istream < CharT, Traits > & stream ) ;
(C++20以降)

stream_ を std:: addressof ( stream ) で初期化し、 value_ を値初期化します。

std::ranges::basic_istream_view:: begin

constexpr auto begin ( ) ;
(C++20以降)

以下と等価: * stream_ >> value_  ; return iterator  { * this } ; .

std::ranges::basic_istream_view:: end

constexpr std:: default_sentinel_t end ( ) const noexcept ;
(C++20以降)

std:: default_sentinel を返します。

ネストされたクラス

basic_istream_viewのイテレータ型
( 説明専用メンバクラス* )

例

#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';
}

出力:

/today/ /is/ /yesterday’s/ /tomorrow/
1.1, 2.2, 3.3, 4.4, 55, 66, 7.7, 8.8,

欠陥報告

以下の動作変更欠陥報告書は、以前に公開された C++ 標準に対して遡及的に適用されました。

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 as
view must be default_initializable
removed along with
the requirement
P2432R1 C++20 ranges::istream_view was a function template
and did not follow the naming convention
made an alias template;
customization point objects added

関連項目

std::basic_istream から読み込む入力イテレータ
(クラステンプレート)