Overload! = Like == negated

I have a piece of code that implemented overload ==. And I had to use it somewhere negatively. But to write !(A == B) for the reader does not seem entirely understandable. Therefore, I implemented this double overload. Does he have any flaws in this? Efficiency wise ?:

 struct Foo{ bool operator==(const Foo& other) const{ .... //Something that sometimes produces "return false" return true; } bool operator!=(const Foo& other) const{ return !(*this == other); } } 

Bonus: Why does the compiler not use != By default using negation == ?

+5
source share

Source: https://habr.com/ru/post/1269260/


All Articles