I would like to apply a projection prior to piping a range into an action or view. Consider the following example:
#include <iostream>
#include <range/v3/view/map.hpp>
#include <range/v3/action/sort.hpp>
#include <range/v3/algorithm/for_each.hpp>
int main()
{
std::vector<std::string> strings{"1.2","100.2","11.2","0.2","2.2"};
ranges::for_each(strings, [](const auto& str) { std::cout << str << std::endl; });
strings | ranges::views::all | ranges::actions::sort;
std::cout << std::endl;
ranges::for_each(strings, [](const auto& str) { std::cout << str << std::endl; });
return 0;
}
Say that I wish to convert the string to a double prior to sorting. Using the functional approach, this is possible:
strings |= ranges::actions::sort(std::less{}, [](const auto& str) { return std::stod(str); });
However I'm wondering if there is a pipeline format which allows this instead, which applies this projection for all following operations, for example:
strings | ranges::views::projection([](const auto&str ) { return std::stod(str); }) | ranges::actions::sort;
Note that using ranges::views::transform
doesn't work as it creates a new range instead of a projection.
I'm also not sure if there's a caveat for using strings | ranges::views::all | ranges::actions::sort
instead of strings |= ranges::actions::sort
which is recommended in the range-v3 documentation.