【发布时间】:2020-07-30 02:41:23
【问题描述】:
我写了一个小程序来使 map/reduce 在 C++ 中工作。 这里是结构:
struct Point {
int x = 0;
int y = 0;
};
我想选择每个点的“x”并将它们乘以一个 int。然后,我想用最终的lamba(或通过std::multiples)减少值
std::vector<Point> p = {{10,20},{20,40}};
std::vector<int> p3 (p.size());
auto totalx = transform_reduce(p.begin(), p.end(),p3.begin(), 0.0, [](Point& p){ return p.x * 23;}, [](int a, int b){return a * b;});
cout << totalx << endl;
我有这个错误:
main.cpp:28: candidate function not viable: requires single argument 'p', but 2 arguments were provided
conversion candidate of type 'int (*)(Point &)'
我真的不明白我做错了什么。
【问题讨论】:
-
transform_reduce给出单个值,而不是输出范围。p3的目的是什么? -
我认为我需要提供一个临时列表来存储 int 值。就像一个临时的整数列表。我错了……
标签: c++ lambda mapreduce c++17 reduce