Why can't I use a vector-of-floats like a vector-of-strings with range-joining?

Viewed 52

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?

0 Answers
Related