【发布时间】:2016-12-10 23:13:31
【问题描述】:
谁能告诉我如何编译std::reduce 的示例代码,它位于cppreference 上?
#include <iostream>
#include <chrono>
#include <vector>
#include <numeric>
#include <execution_policy>
int main()
{
std::vector<double> v(10'000'007, 0.5);
{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::accumulate(v.begin(), v.end(), 0.0);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << std::fixed << "std::accumulate result " << result
<< " took " << ms.count() << " ms\n";
}
{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::reduce(std::par, v.begin(), v.end());
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << "std::reduce result "
<< result << " took " << ms.count() << " ms\n";
}
}
我在安装了新的 g++6.2 的 Mint18 下工作。在编译期间,我只使用 -std=c++17 标志。如果我想使用execution_policy(#include <execution_policy>)怎么办?目前我的编译器告诉我reduce 不是命名空间std 的成员,并且没有execution_policy 这样的文件。
【问题讨论】:
-
大多数库供应商尚未实现许多 C++17 功能。您不必等待太久。
-
当你在等待 libstdc++ 赶上来时,已经有HPX了。
-
@ildjarn 这是我在编写该示例时使用的(然后发布了它应该在 C++ 中的外观。现在已编辑以匹配当前草稿)