2

This is a follow-up to my previous question

Under std::lower_bound, for the following the overload

template< class ForwardIt, class T, class Compare > ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value, Compare comp ); (until C++20)

template< class ForwardIt, class T, class Compare > constexpr ForwardIt lower_bound( ForwardIt first, ForwardIt last, const T& value, Compare comp ); (since C++20)

under section

Type requirements

it is mentioned

Compare must meet the requirements of BinaryPredicate. it is not required to satisfy Compare

Under the requirements description for the latter Compare

std::lower_bound mentioned among the standard library facilities that expect a Compare type.

Is this discrepancy a mere oversight or is there more to it than that?

Vinod
  • 925
  • 8
  • 9
  • Is there a discrepancy? There is a wording difference: "required" vs. "expect". (It is possible to expect to be given a gratuity without requiring a gratuity be given.) I don't know how intentional that word choice is. – JaMiT Oct 04 '19 at 05:34
  • @JaMiT doesn't that leave the reader with a sense of ambiguity? If the stricter requirement of Compare does not apply in the case of lower_bound, then shouldn't the documentation mention about in what way the requirement has been relaxed? – Vinod Oct 04 '19 at 05:50
  • If the reader is me, it does not leave me with a sense of ambiguity. I read it as `std::lower_bound` was written with the expectation that the Compare concept was satisfied. After writing the code, analysis showed that a sensible result required only satisfying the BinaryPredicate concept. Hence, expect Compare (and keep the parameter names), but require BinaryPredicate. Whether or not more should be explicitly called out -- assuming my reading is accurate -- would be up to the editors of cppreference.com. – JaMiT Oct 04 '19 at 18:00

0 Answers0