1

我从 git 获得 MSVC 的 range-v3。并由 MSVC C++14 编译器编译。

考虑代码:

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;

它按预期工作。但我想添加分隔符加入,如果我写

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

代码未编译。怎么了?大量编译器错误如下:

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'

更新

不仅 MSVC 端口行为如此,这里也是如此

4

1 回答 1

2

猜测:字符串文字不是范围。尝试通过std::string(",")view::c_str(",")改为view::join

更新:啊。试试这个(用 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;
}
于 2018-01-22T14:40:46.657 回答