简体   繁体   English

C ++ 20概念中“相等”的概念

[英]Concept of “equal” in C++20 concepts

I have found multiple times, while reading some concepts definitions, the use of the term equal , like in Swappable : 我已经多次发现,在阅读一些概念定义时,使用术语相等 ,就像在Swappable

Let t1 and t2 be equality-preserving expressions that denote distinct equal objects of type T , t1t2保持等式的表达式,表示T类型的不同相等对象,

Is equal defined somewhere in the standard? 等于某处定义的标准是什么? I guess it means that the semantics of two objects, or the value they refer (the human semantics given to their represented domain value) are the same, even if the objects are not comparable (no operator== overloaded), or something abstract like that (like, two objects a and b are equal if a == b would yield true assuming it is a valid expression --for example, because operator== is not defined because it's not required). 我想这意味着两个对象的语义或它们引用的值(给出它们表示的域值的人类语义)是相同的,即使这些对象不具有可比性(没有operator==重载),或类似抽象的东西那个(就像两个对象ab是相等的,如果a == b会产生真假,假设它是一个有效的表达式 - 例如,因为operator==没有被定义,因为它不是必需的)。

Since templates are going to work on the semantics the user gives, the concept of equality is largely defined by the program. 由于模板将用于用户提供的语义,因此相等的概念主要由程序定义。 For example, if I am working with case insensitive strings, I can consider the strings FoO and fOo to be equal and FoO and bAr to be unequal. 例如,如果我使用不区分大小写的字符串,我可以认为字符串FoOfOo相等,而FoObAr不相等。 The operations I supply must reflect this semantics. 我提供的操作必须反映这种语义。

Equality isn't defined based on operator== ; 基于operator== ,未定义等式; on the contrary, operator== is (in a sense) defined based on equality. 相反, operator== (在某种意义上)是基于相等定义的。 [concept.equalitycomparable]/equality_comparable : [concept.equalitycomparable] / equality_comparable

 template<class T> concept equality_comparable = weakly-equality-comparable-with<T, T>; 

Let a and b be objects of type T . abT类型的对象。 T models equality_comparable only if bool(a == b) is true when a is equal to b ([concepts.equality]), and false otherwise. 只有当a等于b ([concepts.equality]) bool(a == b)true时, T模型才为equality_comparable ,否则为false

[ Note: The requirement that the expression a == b is equality-preserving implies that == is transitive and symmetric. [ 注意:表达式a == b是等式保留的要求意味着==是传递和对称的。 end note ] - 结束说明 ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM