__cplusplus 扩展最小值

3 c++ language-lawyer c++03 c++98 c++20

我说得对不对明白,这些都是最低__cplusplusC与++ 98具有相同的值有C ++ 03?

// C++ 98
#define __cplusplus 199711L
// C++ 03
#define __cplusplus 199711L
// C++ 11
#define __cplusplus 201103L
// C++ 14
#define __cplusplus 201402L
// C++ 17
#define __cplusplus 201500L
// C++ 20
#define __cplusplus 201704L
// looks like the format is YEAR*100+something
Run Code Online (Sandbox Code Playgroud)

另外,既然标准已经发布,C++20 是否具有官方价值?

Bar*_*rry 7

另外,既然标准已经发布,C++20 是否具有官方价值?

它确实:202002L。此处的格式是日期:YYYYMM(C++20 于 2020 年 2 月正式发布)。C++17 的值是 201703L,而不是 201500。其余都是正确的(C++03 没有更改__cplusplus宏)。

然而,这个宏过于粗糙,无法普遍使用。实现不仅仅是一次性添加所有功能,它们会随着时间的推移而添加。因此,您最好使用功能测试宏来测试您实际需要的内容。