boostorg / algorithm

Boost.org algorithm module
http://boost.org/libs/algorithm
Boost Software License 1.0
114 stars 105 forks source link

Docs for is_sorted erroneously state that it defaults to std::less_equal #54

Closed tonyelewis closed 6 years ago

tonyelewis commented 6 years ago

Following on from Trac#13383

Docs for is_sorted() currently say:

If no comparison predicate is specified, then std::less_equal is used (i.e, the test is to see if the sequence is non-decreasing)

…but that's not true—it defaults to std::less—see line 60 of boost/algorithm/cxx11/is_sorted.hpp.

This code confirms the default behaviour matches std::less not std::less_equal.

int main () {
  std::vector<int> a        = { 1, 2, 2, 3 };

  std::cerr << "default   : " << std::boolalpha << boost::algorithm::is_sorted( a                      ) << "\n";
  std::cerr << "less      : " << std::boolalpha << boost::algorithm::is_sorted( a, std::less      <>{} ) << "\n";
  std::cerr << "less_equal: " << std::boolalpha << boost::algorithm::is_sorted( a, std::less_equal<>{} ) << "\n";
}

I vote: change the docs, not the code, because the code matches std::. I'm happy to submit a PR for this - please shout if I should do that.

mclow commented 6 years ago

I'll fix the docs.

tonyelewis commented 6 years ago

Thanks.

mclow commented 6 years ago

Fixed in develop 1cbe285.

tonyelewis commented 6 years ago

Great. Thanks very much.