Composing adaptors in Boost::range
- by bruno nery
I started playing with Boost::Range in order to have a pipeline of lazy transforms in C++]1. My problem now is how to split a pipeline in smaller parts. Suppose I have:
int main(){
auto map = boost::adaptors::transformed; // shorten the name
auto sink = generate(1) | map([](int x){ return 2*x; })
| map([](int x){ return x+1; })
| map([](int x){ return 3*x; });
for(auto i : sink)
std::cout << i << "\n";
}
And I want to replace the first two maps with a magic_transform, i.e.:
int main(){
auto map = boost::adaptors::transformed; // shorten the name
auto sink = generate(1) | magic_transform()
| map([](int x){ return 3*x; });
for(auto i : sink)
std::cout << i << "\n";
}
How would one write magic_transform? I looked up Boost::Range's documentation, but I can't get a good grasp of it.