c++ - 如何在 Xcode for Mac OSX 中启用 C++17?

标签 c++ xcode c++17 macos-high-sierra xcode9.4

如何在 OSX High Sierra (10.13.5) 上的 Xcode (9.4.1) 中启用 C++17?

最佳答案

在 OSX High Sierra (10.13.5) 上的 Xcode (9.4.1) 中使用 C++17 的步骤:

  1. 在 Xcode 中打开现有的或创建一个新的 C++ 项目
  2. 点击“显示项目导航器”按钮。它位于 Xcode 窗口的左上部分,就在最小化/最大化/关闭窗口按钮的下方。它位于最左侧的图标,看起来像一个文件夹。
  3. 点击“Build Settings”并向下滚动以查找并展开“Apple LLVM 9.0 - Language - C++”部分
  4. 将 C++ 语言方言组合框选择更改为“C++17 [-std=c++17]”

Xcode Build Settings

验证步骤:

现在当我输出 __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

关于c++ - 如何在 Xcode for Mac OSX 中启用 C++17?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51288230/

相关文章:

objective-c - 透明图像叠加在下方 View 上

ios - 静默警告“无法为[symbol]创建紧凑展开:堆栈subl指令与侏儒堆栈大小太大不同”

c++ - 为什么 cout 不打印这个字符串?

c++ - 在 C++ 中实现 is_same_type 类型特征的程序

c++ - OpenGL 3.1 使用索引绘图发布渲染纹理

c++ - 在后端中止 Boost Graph DFS

iphone - 用图像掩盖图像?

c++ - tellg 在文件中写操作后移动

c++ - 从样板代码到模板实现

c++ - std::array<const T, n> 与 std::array<T, n> 重载解析