The extra checks are actually legal under the current standard.
Heterogeneous search of the kind you attempt is not well defined: the
standard requires the comparator to be a strict weak ordering, and the
definition of the latter talks about comparisons between objects of the
same type. Technically, your predicate is not a strict weak ordering,
and your code is invalid.
Most STL implementation will accept and work correctly for a
heterogeneous search, but your predicate should implement three
overloads of operator(): taking (B, B), (B, A) and (A, B).
Future version of the standard will likely clarify the situation, and
make your code good as written. For more details, see DR270:
With best wishes,
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925