Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

header

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());

I tried these compilers:

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

All three give me 'execution' file not found

respectively error: no member named 'reduce' in namespace 'std' auto result = std::reduce(v.begin(), v.end());

for this snippet

#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;
}

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.

like image 953
lo tolmencre Avatar asked Apr 28 '17 21:04

lo tolmencre


2 Answers

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

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

like image 86
chema989 Avatar answered Oct 20 '22 08:10

chema989


I upgraded my GCC to version 10 and it compiled fine the std::execution::par with its include <execution> (which was failing to locate with gcc version 7.5.0). I followed to the instructions in this link: https://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu

like image 21
Hack06 Avatar answered Oct 20 '22 06:10

Hack06