我如何在OSX High Sierra(10.13.5)上的Xcode(9.4.1)中启用C++17?
我如何在OSX High Sierra(10.13.5)上的Xcode(9.4.1)中启用C++17?
在OSX High Sierra(10.13.5)上使用Xcode(9.4.1)进行C++17的步骤:
验证步骤:
现在当我输出__cplusplus时,我会看到201703,并且我能够编译C++17功能,例如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
spec.xcconfig = {
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"CLANG_CXX_LIBRARY" => "libc++"
}