Header 未找到 `execution` 和 `std::reduce`

Header `execution` and `std::reduce` not found

我正在尝试编译此代码段

#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

分别error: no member named 'reduce' in namespace 'std' auto result = 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;
}

我猜我的编译器太旧了?但是 on cppreference 它没有说明最低需要哪个编译器版本,而且我在 repo 中也没有看到 clang 或 gcc 的任何更新版本。

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

对于大多数编译器,C++17 尚未完全实现。您可以尝试将 clang 与标志 -std=c++1z.

一起使用

我将我的 GCC 升级到版本 10,它编译良好 std::execution::par 和它的包含 <execution>(在 gcc 版本 7.5.0 中无法定位)。我遵循了 link 中的说明:https://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu