1

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

此页面建议__cpp_experimental_concepts应在支持概念 TS 的实现中预定义宏。但是,以下测试程序在带有-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关键字无法识别。)

有谁知道根据概念是否可用有条件地编译代码的任何其他方法?

4

1 回答 1

4

正确的宏__cpp_concepts适用于 GCC:

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

据此,在最近的草案中更改了宏的名称

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

于 2016-07-20T11:18:22.870 回答