I heard C++ enables overriding both operator== and operator!= because in certain cases a != b can be implemented to be more efficient than !(a == b).
I've thought about this and can't imagine a case where this is true.
What are some examples where it makes sense, performance-wise or other, to have separate implementations for operator== and operator!=?
The first example which comes to mind is implementations analogous to the NULL value for SQL. In that, comparing two objects—either of which are NULL—does not mean they are equal. Only if both are not NULL does it makes sense to return equality.
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