What is the difference between equivalence and equality?
Asked Answered
F

1

22

What is the difference between equivalence and equality in C++?

There is a very similar question here. However, this question is tagged with , 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.

Flasket answered 12/8, 2015 at 20:38 Comment(1)
The video is not available anymore. Probably, this is a video of the same talk.Swink
F
21

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).

Flasket answered 12/8, 2015 at 20:41 Comment(1)
More generally, for each Compare comp you can synthesise an equivalence !comp(a, b) && !comp(b, a). There is only one "equality", but there can be any number of "equivalences"Extern

© 2022 - 2024 — McMap. All rights reserved.