On this site it states that one of the constraints for a binary predicate passed into std::search is that:
The types Type1 and Type2 must be such that objects of types ForwardIt1 and ForwardIt2 can be dereferenced and then implicitly converted to both Type1 and Type2.
However, in the C++ International Standard documentation I see no reference to such a constraint. I am wondering if this constraint is explicitly stated in the C++ International Standard documentation which section it is under. In addition if it is not then why is this constraint placed upon the std::search function as isn't it possible to have two distinct types that while not implicitly convertible have an equality operator overload defined?
It's a mistake on the site.
That parameter description is populated from this template. It doesn't distinguish between binary predicates that are only called as pred(*first1, *first2) from those that are called as both pred(*first1, *first2) and pred(*first2, *first1)
Further digging:
It appears that this edit added a named parameter to the parent template's use of cast req2, which controls whether it says "both" or "respectively". The eq variant does not have a passthrough of this new parameter. I don't have edit privileges to add it in to the template and the entry for std::search
The requirement of a BinaryPredicate is stated in [algorithms.requirements]/7:
The
BinaryPredicateparameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing two corresponding iterators or to dereferencing an iterator and typeTwhenTis part of the signature returns a value testable astrue. In other words, if an algorithm takesBinaryPredicatebinary_predas its argument andfirst1andfirst2as its iterator arguments, it should work correctly in the constructbinary_pred(*first1, *first2)contextually converted tobool([conv]).BinaryPredicatealways takes the first iterator'svalue_typeas its first argument, that is, in those cases whenT valueis part of the signature, it should work correctly in the constructbinary_pred(*first1, value)contextually converted tobool([conv]).binary_predshall not apply any non-constant function through the dereferenced iterators.
There is no requirement for constructing Type1 from dereferencing ForwardIt2. The word 'both' in OP's quotation from cppreference is inaccurate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With