I can use std::views::transform to create new stream-style
containers and then prints it, like this:
#include<iostream>
#include<vector>
#include<ranges>
using namespace std;
int main() {
// clang -std=c++20
std::vector<int> input = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto output = input
| std::views::filter([](const int n) {return n % 3 == 0; })
| std::views::transform([](const int n) {return n * n; });
for (auto o : output) {
cout << o << endl;
}
return 0;
}
Yes, it works, but I wish to simply my for
loop to write it into the pipelines connected by |
, is there a way to change the code to be like:
input
| std::views::filter([](const int n) {return n % 3 == 0; })
| std::views::transform([](const int n) {return n * n; })
| std::views::SOME_FUNCTION(cout<<n<<endl);
which avoids my for
loop.
So my question is: does std::views
has SOME_FUNCTION that could fulfill my needs?