If I define operator== and operator=< all other operators can be logically implied.
Does the compiler handle this for me or do I have to write them on my own?
If I define operator== and operator=< all other operators can be logically implied.
Does the compiler handle this for me or do I have to write them on my own?
No it doesn't, you'll have to overload those as well if you plan to use them.
It doesn't even know that a != b
is actually !(a==b)
.
No; the standard would have to assume that you wish for all your operators to follow this branch of mathematics' rules, and it has no right doing that.
However, in some situations, rules like this are used to simplify implementation. For example, the default comparator for std::map
keys is std::less
— where the underlying tree implementation needs to know whether key A is greater than or equal to key B, the logic is reformed to whether key B is less than A; in this way, only one comparator is required.