Reputation: 12259
I have found multiple times, while reading some concepts definitions, the use of the term equal, like in Swappable
:
Let
t1
andt2
be equality-preserving expressions that denote distinct equal objects of typeT
,
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).
Upvotes: 4
Views: 632
Reputation: 20579
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. The operations I supply must reflect this semantics.
Equality isn't defined based on operator==
; on the contrary, operator==
is (in a sense) defined based on equality. [concept.equalitycomparable]/equality_comparable:
template<class T> concept equality_comparable = weakly-equality-comparable-with<T, T>;
Let
a
andb
be objects of typeT
.T
modelsequality_comparable
only ifbool(a == b)
istrue
whena
is equal tob
([concepts.equality]), andfalse
otherwise.[ Note: The requirement that the expression
a == b
is equality-preserving implies that==
is transitive and symmetric. — end note ]
Upvotes: 3