【发布时间】:2020-05-13 21:46:13
【问题描述】:
我需要总结一些向量;也就是说,我想对每个向量的nth 元素求和,并用结果创建一个新向量。 (我已经确保输入向量的大小都相同。)我想用优秀的range-v3 库来做到这一点。我试过this:
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <map>
#include <range/v3/all.hpp>
int main()
{
std::cout << "Hello, Wandbox!" << std::endl;
std::vector< int > v1{ 1,1,1};
std::vector< int> v2{1,1,1};
auto va = ranges::view::zip( v1, v2 )
| ranges::view::transform(
[](auto&& tuple){ return ranges::accumulate( tuple, 0.0 ); }
);
}
我收到无法像这样调用ranges::accumulate 的错误。我觉得这是一件简单的事情,我只是不太了解。
请指教
编辑: 我在这里问一个后续问题:How to zip vector of vector with range-v3
【问题讨论】:
标签: c++ accumulate range-v3