找不到标头`execution`和`std::reduce`

2022-01-11 00:00:00 header c++ c++17

我正在尝试编译此代码段

I am trying to get this snippet to compile

#include <vector>
#include <numeric>
#include <execution>

double result = std::reduce(std::execution::par, v.begin(), v.end());

我尝试了这些编译器:

Apple LLVM version 8.1.0 (clang-802.0.42)

clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)

g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

三个都给我'execution' file not found

分别错误:命名空间std"中没有名为reduce"的成员自动结果 = std::reduce(v.begin(), v.end());

对于这个片段

#include<numeric>
#include<vector>

int main(int argc, char *argv[])
{
    std::vector<double> v(10, 1);

    auto result = std::reduce(v.begin(), v.end());
    return 0;
}

我猜我的编译器太旧了?但是 关于 cppreference 它并没有说明最低要求哪个编译器版本,我也这样做了在 repo 中看不到任何更新的 clang 或 gcc 版本.

I guess my compilers are too old? But on cppreference it does not say which compiler version is requiered minimum and also I do not see any newer versions for clang or gcc in the repo.

推荐答案

std::reducestd::execution::par 自 C++17 起可用.

std::reduce and std::execution::par are available since C++17.

对于大多数编译器,C++17 还没有完全实现.您可以尝试使用带有标志 -std=c++1z 的 clang.

For most of the compilers C++17 isn't fully implemented yet. You can try using clang with flag -std=c++1z.

相关文章