using T = decltype(std::same_as<int, double>)
我已经在 VS2019 上试过了。结果是 T = bool
.
这是标准定义的,还是特定编译器的属性? 我还没有找到任何关于它的官方信息.. https://en.cppreference.com/w/cpp/concepts
最佳答案
concept-id 像 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
.
关于c++ - concepts(C++20) 可以用作 bool 值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65520935/