用GCC 6.1检测概念TS

Detecting the Concepts TS with GCC 6.1

本文关键字:TS 检测 GCC      更新时间:2023-10-16

如何使用GCC 6.1检测概念TS的存在?

此页面建议在支持Concepts TS的实现中预定义宏__cpp_experimental_concepts。但是,以下测试程序在带有-fconcepts标志的GCC 6.1上编译时没有出现错误:

#ifdef __cpp_experimental_concepts
static_assert(false, "Concepts TS found");
#endif
template <typename T>
concept bool Identity = true;
int main() {}

(我预计static_assert会被激发,或者concept关键字将无法识别。)

有人知道有其他方法可以根据Concepts是否可用来有条件地编译代码吗?

对于GCC,正确的宏是__cpp_concepts

#ifdef __cpp_concepts
static_assert(false, "Concepts TS found");
#endif

据此,宏的名称在最近的一份草案中进行了更改。

正确的名称来自GCC支持页面(感谢Jonathan Wakely),但链接的草案(2015-02-09)仍然需要__cpp_experimental_concepts(这很奇怪…)。然而,在最近的草案(2015-09-25)中,名称实际上已更改为__cpp_concepts