How do I enable C++17?

Answered

Hello folks,

This maybe more of a C++ ecosystem question than specific to CLion, but since I'm using CLion, I thought I'll post here.

I wanted to try out this code from the "Functional Programming in C++" book:

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


double average_score(const std::vector<int>& scores)
{
return std::reduce(std::execution::par, scores.cbegin(), scores.cend(), 0) / (double) scores.size();
}

But I get `fatal error: 'execution' file not found`.

 

Setup:

Using latest macOS, with `brew install cmake --HEAD`, configured CLion to use that cmake and then changed `CMakeLists.txt` to have the line:

set(CMAKE_CXX_STANDARD 17)
3 comments
Comment actions Permalink

The reason of the issue is the fact that for most of the compilers C++17 isn't fully implemented yet. Please take a look at GCC and Clang C++17 implementation statuses, for example. According to this article std::reduce and std::execution::par are not supported in any compiler at the moment.

0
Comment actions Permalink

@Anna Thank you for helping me understand the situation!

0
Comment actions Permalink

Also notice that the LLVM toolchain, which is used by default , comes with the Xcode package, where the compiler is tuned to the needs and requirements of Xcode app (as of now (c++1z works but not c++17. although latest Clang has support for it)). If you want the latest toolchain you need to manually install and set it up.

0

Please sign in to leave a comment.