From 987134bee1a13f0b79390b1fab10a17812e0a658 Mon Sep 17 00:00:00 2001 From: Weicheng Pei Date: Tue, 5 Dec 2023 21:24:23 +0800 Subject: [PATCH] Demo the pointer-to-reference view. --- programming/languages/cpp/template/concept.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/programming/languages/cpp/template/concept.md b/programming/languages/cpp/template/concept.md index ff0561a5..d496d54a 100644 --- a/programming/languages/cpp/template/concept.md +++ b/programming/languages/cpp/template/concept.md @@ -471,5 +471,14 @@ int main() { std::cout << score << ' '; } std::cout << '\n'; // print 400 300 500 200 100 + auto range_of_score_ref = range_of_score_ptr + | std::views::transform([](int *i) -> int & { return *i; }); + for (int &score_ref : range_of_score_ref) { + score_ref /= 10; + } + for (int score : range_of_score) { + std::cout << score << ' '; + } + std::cout << '\n'; // print 40 30 50 20 10 } ```