[英]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
andt2
be equality-preserving expressions that denote distinct equal objects of typeT
,设
t1
和t2
是保持等式的表达式,表示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==
重载),或类似抽象的东西那个(就像两个对象a
和b
是相等的,如果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. 例如,如果我使用不区分大小写的字符串,我可以认为字符串
FoO
和fOo
相等,而FoO
和bAr
不相等。 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
andb
be objects of typeT
.设
a
和b
为T
类型的对象。T
modelsequality_comparable
only ifbool(a == b)
istrue
whena
is equal tob
([concepts.equality]), andfalse
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.