What is the difference between equivalence and equality in C++?
There is a very similar question here. However, this question is tagged with math, while I am interested in the meaning in C++ context.
To see the terms in context: Scott Meyers uses them in an example in this video.
Equality is both an equivalence relation and a partial order. Equality is also the only relation on a set that is reflexive, symmetric and antisymmetric. In algebraic expressions, equal variables may be substituted for one another, a facility that is not available for equivalence related variables.
identical means that it only looks the same. equivalent means that they are equal.
In mathematics, an equivalence relation is a kind of binary relation that should be reflexive, symmetric and transitive. The well-known example of an equivalence relation is the “equal to (=)” relation.
On cppreference.com i found the following quote:
For the types that are both EqualityComparable and LessThanComparable, the C++ standard library makes a distinction between equality, which is the value of the expression a == b and equivalence, which is the value of the expression !(a < b) && !(b < a).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With