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