I had always thought that the standard required the non-specialized template for std::equal_to<T>
to call T::operator==
, but I noticed the description at cppreference.com almost implies it's the other way around; certainly it doesn't mention it as a requirement. I also checked the C++11 draft standard N3337 and couldn't find any guarantees there either.
If you create a class with an operator==
you'd hope it would get used in all circumstances.
I can't honestly think of a way to implement std::equal_to
that wouldn't work this way, but am I missing something?
Yes.
If not specialized,
equal_to
's call operator will invokeoperator ==
. From Paragraph 20.8.5 of the C++11 Standard:std::equal_to
is defined as:So yes, if
T
is a class type with anoperator==
overload defined for it as the left operand, it will be used.