From badecd6938de5ed0c497e7ce6e9c50768e4d4040 Mon Sep 17 00:00:00 2001 From: Tetsuro Matsumura Date: Mon, 26 Feb 2024 02:06:21 +0900 Subject: [PATCH] =?UTF-8?q?transform=5Fview:=20=E4=BE=8B=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/ranges/transform_view.md | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/reference/ranges/transform_view.md b/reference/ranges/transform_view.md index 928b74277..fd2d1accb 100644 --- a/reference/ranges/transform_view.md +++ b/reference/ranges/transform_view.md @@ -104,6 +104,40 @@ int main() { 149 ``` +## 例 特定のメンバを選択する + +```cpp example +#include +#include +#include + +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'; + } +} +``` +* views::transform[color ff0000] + +### 出力 +``` +1 +2 +3 +``` + ## バージョン ### 言語 - C++20