gpt4 book ai didi

C++ 概念 没有 noexcept 和 return-type-requirement 的复合需求与简单需求

转载 作者:行者123 更新时间:2023-12-04 16:24:27 24 4
gpt4 key购买 nike

template<class T>
concept C1 = requires(T a, T b) { a + b; };

template<class T>
concept C2 = requires(T a, T b) { { a + b }; };

C1 和 C2 在功能上会有区别吗?

编辑:语法

最佳答案

它们是等价的。标准偶has an example of it :

template<typename T> concept C1 = requires(T x) {
{x++};
};

The compound-requirement in C1 requires that x++ is a valid expression. It is equivalent to the simple-requirement x++;.

Compound requirements能够测试表达式的某些方面,例如它是否为 noexcept 或结果类型是否满足某些概念。但如果这些测试都不存在,它只是将模板参数替换为表达式,验证其有效性,然后就结束了。

关于C++ 概念 没有 noexcept 和 return-type-requirement 的复合需求与简单需求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68086323/

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