Search code examples
macosc++17

Recognize std::execution::par C++ feature in MacOS


Does someone have any chance to make the C++ IDE on macOS Sonoma 14.5 (M3 Macbook) recognize std::execution::par from #include <execution>?

What I want is to simply compile this chunk of code:

std::transform(
        std::execution::par,
        input.begin() + start,
        input.begin() + end,
        output.begin() + start,
        [](float x) {
            return pow(x, 2);
        }
    );

Notably, I can easily compile it on Microsoft Visual Studio Community Edition on Windows 10 and 11 using C++17 language standard.

However when I select the same standard on Xcode or CLion, or VS Code, these IDEs cannot recognize and build that code part.

What I have tried in different IDEs for MacOS:

  1. Xcode xcode settings
    xcode result
  2. CLion trial
    CMake settings were set to handle C++17 standard, but still it does not help producing the same error:
    clion settings
  3. VS Code (not Visual Studio Community!) has similar settings packed into a json file, but still the same error:
    vs code settings

Solution

  • It appears that the Apple's default C++ compiler clang has a partial support of the C++17 features according to this table.

    The correct way to make it actually compile the code with std::execution::par feature is just to append the -fexperimental-library flag as follows:

    clang++ main.cpp -std=c++17 -stdlib=libc++ -fexperimental-library
    

    The solution regarding that undocumented but mandatory compilation rule was founded in an issue #65125 of the llvm-project thanks to Nikolas Klauser!

    To force the IntelliSence to understand experimental compiler features, the compiler flag should be appended into the compilerArgs array in the c_cpp_properties.json when using the Visual Studio Code IDE:

    vs code props

    And the code editor will properly recognize the std::execution::par: enter image description here