range-v3如何操作::与定界符结合 [英] range-v3 how to action::join with delimiter
本文介绍了range-v3如何操作::与定界符结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从git获得了MSVC的range-v3.并通过MSVC C ++ 14编译器进行编译.
I get range-v3 for MSVC from git. And compile by MSVC C++14 compiler.
考虑代码:
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'
更新
不仅MSVC端口的行为如此,而且此处也
Not only MSVC port behaviers so but here too
推荐答案
猜测:字符串文字不是范围.尝试改为将 std::string(",")
或view::c_str(",")
传递给view::join
.
Guessing: A string literal isn't a range. Try passing std::string(",")
or view::c_str(",")
to view::join
instead.
更新:啊.尝试以下方法(通过clang干线测试):
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;
}
这篇关于range-v3如何操作::与定界符结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文