concepts(C++20) 可以用作布尔值吗?
Can concepts(C++20) be used as a boolean?
using T = decltype(std::same_as<int, double>)
我已经在 VS2019 上试过了。结果是T = bool
.
这是标准定义的,还是特定编译器的属性?
我还没有找到任何关于它的官方信息..
https://en.cppreference.com/w/cpp/concepts
A concept-id like std::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
.
using T = decltype(std::same_as<int, double>)
我已经在 VS2019 上试过了。结果是T = bool
.
这是标准定义的,还是特定编译器的属性? 我还没有找到任何关于它的官方信息.. https://en.cppreference.com/w/cpp/concepts
A concept-id like std::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
.