This is the code from the C++ standard library remove code. Why is inequality tested as if (!(*first == val)) instead of if (*first != val)
Some good answers here. I just wanted to add a little note.
Like all good libraries, the standard library is designed with (at least) two very important principles in mind:
Put the least amount of responsibility on users of your library that you can get away with. Part of this has to do with giving them the least amount of work to do when using your interface. (like defining as few operators as you can get away with). The other part of it has to do with not surprising them or requiring them to check error codes (so keep interfaces consistent and throw exceptions from when things go wrong).
Eliminate all logical redundancy. All comparisons can be deduced merely from operator<, so why demand that users define others? e.g:
(a > b) is equivalent to (b < a)
(a >= b) is equivalent to !(a < b)
(a == b) is equivalent to !((a < b) || (b < a))
and so on.
Of course on this note, one might ask why unordered_map requires operator== (at least by default) rather than operator<. The answer is that in a hash table the only comparison we ever require is one for equality. Thus it is more logically consistent (i.e. makes more sense to the library user) to require them to to define an equality operator. Requiring an operator< would be confusing because it's not immediately obvious why you'd need it.