如何在Mac OSX的Xcode中启用C ++ 17? [英] How do I enable C++17 in Xcode for Mac OSX?
本文介绍了如何在Mac OSX的Xcode中启用C ++ 17?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在OSX High Sierra(10.13.5)的Xcode(9.4.1)中启用C ++ 17?
How do I enable C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5)?
推荐答案
在OSX High Sierra(10.13.5)的Xcode(9.4.1)中使用C ++ 17的步骤:
- 在Xcode中打开现有项目或创建一个新的C ++项目
- 单击显示项目导航器按钮。它位于Xcode窗口的左上部分,就在最小化/最大化/关闭窗口按钮的下方。它是最左侧的图标,看起来像一个文件夹。
- 单击构建设置,然后向下滚动以查找和展开 Apple LLVM 9.0-语言-C ++部分。 li>
- 将C ++语言方言组合框选择更改为 C ++ 17 [-std = c ++ 17]
- Open existing or create a new C++ project in Xcode
- 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.
- Click on "Build Settings" and scroll down to find and expand the section "Apple LLVM 9.0 - Language - C++"
- Change the C++ Language Dialect combobox selection to "C++17 [-std=c++17]"
验证步骤:
现在当我输出__cplusplus时,我看到了201703,并且能够编译C ++ 17功能,例如constexpr。
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;
}
输出:
201703
Program ended with exit code: 0
这篇关于如何在Mac OSX的Xcode中启用C ++ 17?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文