Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the BOOST_STRONG_TYPEDEF macro, which creates a class that overloads operator==. I'm wondering if I need to overload operator!= as well?

like image 400
jfritz42 Avatar asked Mar 16 '23 08:03

jfritz42


1 Answers

Answer: no!

The reason (that I didn't notice at first) is that BOOST_STRONG_TYPEDEF uses Boost operators (http://www.boost.org/doc/libs/1_38_0/libs/utility/operators.htm), specifically totally_ordered1 and totally_ordered2. So the less than and equality comparison operators are implemented for you.

like image 199
jfritz42 Avatar answered Apr 30 '23 17:04

jfritz42