How do I enable C++17 in Xcode for Mac OSX?

别等时光非礼了梦想. 提交于 2019-11-30 18:41:51

Steps to use C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5):

  1. Open existing or create a new C++ project in Xcode
  2. Click on the "show project navigator" button. It is located on the top-left section of Xcode window just below the minimize/maximize/close window buttons. It is the left-most icon and looks like a folder.
  3. Click on "Build Settings" and scroll down to find and expand the section "Apple LLVM 9.0 - Language - C++"
  4. Change the C++ Language Dialect combobox selection to "C++17 [-std=c++17]"

Verification steps:

Now when I output __cplusplus, I see 201703, and I am able to compile C++17 features, such as if constexpr.

template<class T>
int compute(T x) {
    if constexpr( supportsAPI(T{}) ) {
        // only gets compiled if the condition is true
        return x.Method();
    } else {
        return 0;
    }
}

int main(){
    cout << __cplusplus << endl;
    return 0;
}

Output:

201703
Program ended with exit code: 0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!