If you overload operator ==, you also need to overload operator! =?

I use a macro BOOST_STRONG_TYPEDEFthat creates a class that overloads operator==. I wonder if I need to overload operator!=?

+4
source share
2 answers

The answer is no!

The reason I didn't notice at first is because BOOST_STRONG_TYPEDEF uses Boost operators ( http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm ), in particular total_ordered1 and whole_ordered2, Thus, less comparison and equality operators are implemented for you.

+5
source

, . , , , .

+2

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


All Articles