【问题标题】:Detecting the Concepts TS with GCC 6.1使用 GCC 6.1 检测概念 TS
【发布时间】:2016-07-20 11:13:55
【问题描述】:

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

This page 建议宏 __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 关键字无法识别。)

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

【问题讨论】:

  • 你可以通过echo | g++ -E -dM -fconcepts -x c++ - | fgrep concepts找到宏

标签: c++ g++ c++-concepts


【解决方案1】:

对于 GCC,正确的宏是 __cpp_concepts

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

根据this,最近的草稿中更改了宏的名称。

正确的名称来自GCC support page(感谢Jonathan Wakely),但linked draft(2015-02-09)仍然需要__cpp_experimental_concepts(这很奇怪......)。但是,在这个more recent draft(2015-09-25)里,名字居然改成了__cpp_concepts

【讨论】:

  • 奇怪的是,考虑到它仍然是一个 TS,它不再被认为是实验性的,但这正是我所需要的——非常感谢您的快速响应。
  • 宏及其官方值记录在gcc.gnu.org/projects/cxx-status.html#tses (g++ 似乎现在将其设置为 201500 而不是 201507)
  • @JonathanWakely 看起来这里有一个不一致的地方,因为这个值来自一个旧草稿,__cpp_experimental_concepts 仍在使用。
猜你喜欢
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 2016-09-07
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 2022-06-14
相关资源
最近更新 更多