According to cppreference, std::type_info::operator!=
gets removed with C++20, however, std::type_info::operator==
apparently remains.
What's the reasoning behind? I might agree on comparing for inequality being meaningless, but then comparing for equality would be just as meaningless as well, wouldn't it?
Similarly, operator!=
of many other standard library types, including containers such as std::unordered_map::operator!=
and std::unordered_set::operator!=
will be removed in C++20 according to cppreference.
Having to write if(!(id1 == id2))
doesn't make any code any clearer compared to if(id1 != id2)
, in contrast, just the opposite...
In C++20 the way that the relational operators work was changed, notably with the introduction of the spaceship
<=>
operator. In particular, If you only provideoperator==
, thena != b
is rewritten to!(a == b)
.From [over.match.oper]/3.4:
And [over.match.oper]/9:
As such, an explicit overload for
operator!=
is no longer necessary. The removal of the operator has not changed comparison semantics.All containers have had their
operator!=
removed, as far as I can tell (check e.g. the vector synopsis). The only exceptions are the container adaptorsstd::queue
andstd::stack
: my guess is that it is to preserve backwards compatibility when used with third-party containers, in case the equality operators are not symmetric.We don't need a library provided
operator!=
anymore. Providingoperator==
allows the compiler to do some juggling and evaluatea != b
in terms ofa == b
, all on its own.std::type_info
and many more library types had theiroperator!=
removed as part of P1614 - The Mothership has Landed.