I have a vector of ints and I'd like to print it as a comma separated list. I would like to do it using ranges and since clang doesn't the necessary features I'd like to use rangesv3:
https://godbolt.org/z/esM5sPe6a
std::vector<int> v{6, 2, 3, 4, 5, 6};
// doesn't compile
std::cout << (
v | ranges::transform_view( [](int val){return fmt::format("{}",val);})
| ranges::join_with_view(", ")
| ranges::to<std::string>)
) << std::endl;
This doesn't compile and gives me some template deduction error. However
// works
auto a = ranges::transform_view(v, [](int val){return fmt::format("{}",val);});
std::cout << (ranges::join_with_view(a, ", ") | ranges::to<std::string>) << std::endl;
If I don't pipe v
in, but instead pass it as an argument and do the same for the transformed range it works.
What am I doing wrong? I am the only one likes ranges, but finds the cumbersome due to these kind of problems?