gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:36:33 26 4
gpt4 key购买 nike

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 isa concept-name. A concept-id is a prvalue of type bool, and does notname a template specialization. A concept-id evaluates to true if theconcept's normalized constraint-expression is satisfied([temp.constr.constr]) by the specified template arguments and falseotherwise.

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com