1

I get range-v3 for MSVC from git. And compile by MSVC C++14 compiler.

Consider code:

auto getter2 = [](const std::string&r) { return r+r; };
std::vector<std::string> vv = { "11","22", "33" };
std::cout << (vv | view::transform(getter2) | action::join) << std::endl;

It works as expected. But I want to add delimiter to join and if I write

std::cout << (vv | view::transform(getter2) | action::join(",")) << std::endl;

The code does not been compiled. What is wrong? Mass of compiler error is below:

1>d:\sources\ranges_test\ranges_test.cpp(28): error C2672: 'operator __surrogate_func': no matching overloaded function found
1>d:\sources\ranges_test\ranges_test.cpp(28): error C2783: 'unknown-type ranges::v3::action::action<ranges::v3::action::join_fn>::operator ()(Rng &,Rest &&...) const': could not deduce template argument for '__formal'
1>d:\sources\fingrad\dev.fingrad\src\vc\lib\range\v3\action\action.hpp(120): note: see declaration of 'ranges::v3::action::action<ranges::v3::action::join_fn>::operator ()'
1>d:\sources\ranges_test\ranges_test.cpp(28): error C2893: Failed to specialize function template 'unknown-type ranges::v3::action::action<ranges::v3::action::join_fn>::operator ()(T &&,Rest &&...) const'
1>d:\sources\ranges_test\ranges_test.cpp(28): note: With the following template arguments:
1>d:\sources\ranges_test\ranges_test.cpp(28): note: 'T=const char (&)[2]'
1>d:\sources\ranges_test\ranges_test.cpp(28): note: 'Rest={}'
1>d:\sources\ranges_test\ranges_test.cpp(28): note: 'A=ranges::v3::action::join_fn'

UPDATE

Not only MSVC port behaviers so but here too

Alexey Subbota
  • 938
  • 6
  • 23

1 Answers1

3

Guessing: A string literal isn't a range. Try passing std::string(",") or view::c_str(",") to view::join instead.

UPDATE: Ah. Try this instead (tested with clang trunk):

#include <range/v3/all.hpp>
#include <vector>
#include <iostream>
int main()
{
    using namespace ranges;
    std::vector<std::string> vv = { "11","22", "33" };
    auto getter2 = [](auto&r) { return view::concat(r, r); };

    std::cout << (vv | view::transform(getter2) 
                     | view::join(',')
                     | to_<std::string>()) << std::endl;
    return 0;
}
Eric Niebler
  • 5,927
  • 2
  • 29
  • 43
  • Unfortunately, this does not work. I've added the runable sample to question. – Alexey Subbota Jan 23 '18 at 08:09
  • 1
    Updated answer. – Eric Niebler Jan 23 '18 at 16:09
  • Thank you for the answer, It really works but problem is that I don't need really concat (it is a sample only) and my getter return temporary string. I think the 'join' is not for my purpose. – Alexey Subbota Jan 24 '18 at 08:39
  • Note this solution doesn't work if there's no way to compose/generate the desired temporary strings with the view API. Like, calling a 3rd party function as transform parameter. Is there any technical limitation that prevents action::join() to have a custom delimiter? – Manu343726 Mar 03 '19 at 13:53
  • Please update this answer again (e.g. see [here](https://godbolt.org/z/z3h48z)). – einpoklum Nov 19 '20 at 22:36