gpt4 book ai didi

c++ - 如何检查 C++11 支持?

转载 作者:IT老高 更新时间:2023-10-28 11:55:50 28 4
gpt4 key购买 nike

有没有办法在编译时检测编译器是否支持 C++11 的某些特性?例如,像这样:

#ifndef VARIADIC_TEMPLATES_SUPPORTED

#error "Your compiler doesn't support variadic templates. :("

#else

template <typename... DatatypeList>
class Tuple
{
// ...
}

#endif

最佳答案

有一个名为 __cplusplus 的常量,C++ 编译器应将其设置为支持的 C++ 标准版本 see this

#if __cplusplus <= 199711L
#error This library needs at least a C++11 compliant compiler
#endif

它在 Visual Studio 2010 SP1 中设置为 199711L,但我不知道供应商是否会如此大胆地增加它,如果他们只有(部分)编译器级别支持而不是标准 C++ 库与所有 C+ +11 变化。

因此,另一个答案中提到的 Boost 定义仍然是确定是否支持 C++11 线程和标准的其他特定部分等唯一明智的方法。

关于c++ - 如何检查 C++11 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5047971/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com