无法在 Mac OSX 上使用 clang++ 编译 C++17

lol*_*ter 5 c++ macos g++ clang++ c++17

铿锵++版本:

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)

尝试一些 C++ 并行性:

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)

我尝试过使用所有这些进行编译:

#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
#include <random>
#include <math.h>

#define N 10000000

double myFunction(double x) {
    return pow(x, x) / (int(x) % 3);
}

int main() {
    std::random_device rd;
    std::uniform_real_distribution<double> uniform(0.0, 20.0);

    std::vector<double> inputs;
    std::vector<double> returnValues;
    for (int i = 0; i < N; ++i) {
        double r = uniform(rd);
        inputs.push_back(r);
    }

    std::transform(std::execution::par_unseq,
                    inputs.begin(), inputs.end(), 
                    returnValues.begin(), 
                    myFunction);
}
Run Code Online (Sandbox Code Playgroud)

有和没有#include <optional>。但所有的编译器都会出现相同的错误:

go.cpp:93:25: error: no member named 'execution' in namespace 'std'; did you mean 'exception'?
    std::transform(std::execution::par_unseq,
                   ~~~~~^~~~~~~~~
                        exception
/Library/Developer/CommandLineTools/usr/include/c++/v1/exception:97:29: note: 'exception' declared here
class _LIBCPP_EXCEPTION_ABI exception
                            ^
go.cpp:93:36: error: no member named 'par_unseq' in 'std::exception'
    std::transform(std::execution::par_unseq,
                   ~~~~~~~~~~~~~~~~^
2 errors generated.
make: *** [parallel] Error 1
Run Code Online (Sandbox Code Playgroud)

编辑:

尝试使用gcc也不起作用:

$ clang++ -std=c++1z go.cpp -o run
$ clang++ -std=c++17 go.cpp -o run
Run Code Online (Sandbox Code Playgroud)

生成错误:

go.cpp:69:10: fatal error: 'execution' file not found
#include <execution>
         ^~~~~~~~~~~
1 error generated.
Run Code Online (Sandbox Code Playgroud)

有人知道怎么修这个东西吗?

Zuo*_* Hu 8

如果您查看cppreference 上的编译器支持页面,您会发现 Apple Clang 仍然不支持并行算法。


wal*_*nut 1

你失踪了

#include<algorithm>
#include<execution>
Run Code Online (Sandbox Code Playgroud)

话虽这么说,根据cppreference.com 上的编译器支持概述, Apple Clang 尚不支持并行算法扩展。(在页面上查找“并行性 TS”。)