GeezerVison is showing cpprefjp.github.io — std::ranges::transform_view - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
class template
<ranges>
std::ranges:: transform_view (C++20)
概要
(1): 指定した関数で各要素を変換した値のRangeとして振る舞うview
(2): transform_viewを生成するRangeアダプタオブジェクト
Rangeコンセプト
borrowed
sized
output
input
forward
bidirectional
random_access
contiguous
common
viewable
view
(1)
(2)
○
(1)
(1)
(1)
(1)
○
○
(1): Vに従う
(2): 述語が参照を返す場合
効果
(2): 式views::transform(E, P)の効果はtransform_view(E, P)と等しい
メンバ関数
rを元のRangeとする。sizeはranges::size (r)が有効な式であるときに定義される。
継承しているメンバ関数
メンバ型
名前
説明
対応バージョン
template <bool Const> iterator;
イテレータ型(説明専用)
C++20
template <bool Const> sentinel;
番兵型(説明専用)
C++20
推論補助
例
#include <ranges>
#include <iostream>
int main () {
using namespace std ;
int a [] = { 1 , 2 , 3 };
for ( int i : a | views::transform ([]( int x ){ return x * x ; })) {
cout << i ;
}
}
出力
149
例 特定のメンバを選択する
#include <ranges>
#include <string>
#include <iostream>
struct Record {
int id = 0 ;
std::string name ;
};
int main () {
using namespace std ;
Record records [] = {
{ 1 , "Alice" },
{ 2 , "Bob" },
{ 3 , "Charlie" }
};
for ( int id : records | views::transform ( & Record :: id )) {
cout << id << '\n' ;
}
}
出力
1
2
3
バージョン
言語
処理系
関連項目
参照