Opened 5 years ago

Last modified 5 years ago

#13383 new Bugs

Doc for is_sorted() incorrectly states the predicate defaults to std::less_equal

Reported by: Tony Lewis <tonyelewis@…> Owned by: Marshall Clow
Milestone: To Be Determined Component: algorithm
Version: Boost Development Trunk Severity: Problem
Keywords: predicate, is_sorted, algorithm, less, less_equal Cc:

Description

#include <boost/algorithm/cxx11/is_sorted.hpp>

#include <iostream>
#include <vector>

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";
}

Change History (1)

comment:1 by Tony Lewis <tonyelewis@…>, 5 years ago

Component: Nonealgorithm
Keywords: predicate is_sorted algorithm less less_equal added
Owner: set to Marshall Clow
Summary: is_sorted() doc incorrectly says the predicate defaults to std::less_equalDoc for is_sorted() incorrectly states the predicate defaults to std::less_equal
Version: Boost 1.63.0Boost Development Trunk

(Apologies for the description at the top being a mess. My original submission had external links in and I was forced to do a captcha. That failed over and over until I ended up trying to use browser "back" and "reload" to try to recover my original submission and eventually found I'd submitted an early draft.)

Second, terser version of lost text...

Doc for is_sorted() says:

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)

That's not true, it's 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.

#cpp
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 docs, not code. Because: that matches std::.

Note: See TracTickets for help on using tickets.