Skip to content

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

@tonyelewis

Description

@tonyelewis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions