c++ - concepts(C++20) 可以用作 bool 值吗?

标签 c++ c++20 c++-concepts

using T = decltype(std::same_as<int, double>) 我已经在 VS2019 上试过了。结果是 T = bool .

这是标准定义的,还是特定编译器的属性? 我还没有找到任何关于它的官方信息.. https://en.cppreference.com/w/cpp/concepts

最佳答案

concept-idstd::same_as<int, double>像表达式一样被评估。它产生 bool 类型的纯右值.

[temp.names]

8 A concept-id is a simple-template-id where the template-name is a concept-name. A concept-id is a prvalue of type bool, and does not name a template specialization. A concept-id evaluates to true if the concept's normalized constraint-expression is satisfied ([temp.constr.constr]) by the specified template arguments and false otherwise.

所以 decltype报告正确。在表达式中,它是 bool .

关于c++ - concepts(C++20) 可以用作 bool 值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65520935/

相关文章:

c++ - 大括号初始化时 GCC 出现编译错误

c++ - 如何方便地初始化函数指针数组?

c++ - libfmt 和 std::format 之间有什么区别?

c++ - 内仿函数概念或接口(interface)

C++ 可变参数模板来替换类型列表

c++ - 更改 QT 上的主窗口内容

c++ - constexpr const 与 constexpr 变量?

c++ - QMainWindow中选择 "central widget"的规则是什么?为什么它很重要?

c++ - 什么是 C++ 技术规范?

c++ - C++20 中采用模板参数的成员函数的概念