未找到标题`execution`和`std :: reduce`

lo *_*cre 11 c++ header c++17

我试图让这个片段编译

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

double result = std::reduce(std::execution::par, v.begin(), v.end());
Run Code Online (Sandbox Code Playgroud)

我试过这些编译器:

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
Run Code Online (Sandbox Code Playgroud)

这三个人都给了我 '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;
}
Run Code Online (Sandbox Code Playgroud)

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

che*_*989 11

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

对于大多数编译器来说,C++ 17还没有完全实现.你可以尝试使用clang with flag -std=c++1z.

  • 谨防。如果clang ++使用系统libstdc ++而不是libc ++,您仍然可能会遇到clang ++错误。 (2认同)

Hac*_*k06 5

我将 GCC 升级到版本 10,并且它std::execution::par通过包含文件编译得很好<execution>(无法使用 gcc 版本 7.5.0 找到它)。我按照此链接中的说明进行操作:https://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu