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

Header `execution` and `std::reduce` not found(找不到标头`execution`和`std::reduce`)

本文介绍了找不到标头`execution`和`std::reduce`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译此代码段

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.

这篇关于找不到标头`execution`和`std::reduce`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:找不到标头`execution`和`std::reduce`

基础教程推荐