3

This function:

auto foo(const std::vector<std::string>& vec)
{
    auto func = [](auto&r) { return ranges::views::concat(r, r); };
    return vec 
        | ranges::views::transform(func) 
        | ranges::views::join(',')
        | ranges::to<std::string>();
}

compiles (with the range-v3 library v0.11.0 and recent versions of GCC and clang); but this function:

auto bar(const std::vector<float>& vec) 
{
    auto func = [](const auto& f) { return std::to_string(f); };
    return vec 
        | ranges::views::transform(func) 
        | ranges::views::join(',')
        | ranges::to<std::string>();
}

does not compile. I'm told that I don't have valid operands for a binary operator. How come? Do I not have a range of strings in both cases, after transforming?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Can't `join` a range of prvalue ranges, need to use `cache1`. The first one is `join`ing a range of views. – Barry Nov 19 '20 at 22:54
  • @Barry: And I'm guessing the `join()` would use the `std::string` as expandable storage for its intermediate results? – einpoklum Nov 19 '20 at 23:34

0 Answers0