Closed tonyelewis closed 6 years ago
Following on from Trac#13383…
Docs for is_sorted() currently say:
is_sorted()
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.
std::less
boost/algorithm/cxx11/is_sorted.hpp
This code confirms the default behaviour matches std::less not std::less_equal.
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.
std::
I'll fix the docs.
Thanks.
Fixed in develop 1cbe285.
Great. Thanks very much.
Following on from Trac#13383…
Docs for
is_sorted()
currently say:…but that's not true—it defaults to
std::less
—see line 60 ofboost/algorithm/cxx11/is_sorted.hpp
.This code confirms the default behaviour matches
std::less
notstd::less_equal
.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.