Boost C++ Libraries: Ticket #13383: Doc for is_sorted() incorrectly states the predicate defaults to std::less_equal https://svn.boost.org/trac10/ticket/13383 <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/algorithm/cxx11/is_sorted.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">a</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span> <span class="p">};</span> <span class="n">std</span><span class="o">::</span><span class="n">cerr</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;default : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">boolalpha</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">algorithm</span><span class="o">::</span><span class="n">is_sorted</span><span class="p">(</span> <span class="n">a</span> <span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cerr</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;less : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">boolalpha</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">algorithm</span><span class="o">::</span><span class="n">is_sorted</span><span class="p">(</span> <span class="n">a</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">less</span> <span class="o">&lt;&gt;</span><span class="p">{}</span> <span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cerr</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;less_equal: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">boolalpha</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">algorithm</span><span class="o">::</span><span class="n">is_sorted</span><span class="p">(</span> <span class="n">a</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">less_equal</span><span class="o">&lt;&gt;</span><span class="p">{}</span> <span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13383 Trac 1.4.3 Tony Lewis <tonyelewis@…> Tue, 09 Jan 2018 11:50:46 GMT version, component, summary changed; keywords, owner set https://svn.boost.org/trac10/ticket/13383#comment:1 https://svn.boost.org/trac10/ticket/13383#comment:1 <ul> <li><strong>keywords</strong> predicate is_sorted algorithm less less_equal added </li> <li><strong>owner</strong> set to <span class="trac-author">Marshall Clow</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.63.0</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">algorithm</span> </li> <li><strong>summary</strong> <span class="trac-field-old">is_sorted() doc incorrectly says the predicate defaults to std::less_equal</span> → <span class="trac-field-new">Doc for is_sorted() incorrectly states the predicate defaults to std::less_equal</span> </li> </ul> <p> (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.) </p> <p> Second, terser version of lost text... </p> <p> Doc for <code>is_sorted()</code> says: </p> <blockquote class="citation"> <p> 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) </p> </blockquote> <p> That's not true, it's <code>std::less</code> - see line 60 of <code>boost/algorithm/cxx11/is_sorted.hpp</code>. </p> <p> This code confirms the default behaviour matches <code>std::less</code> not <code>std::less_equal</code>. </p> <pre class="wiki">#cpp int main () { std::vector&lt;int&gt; a = { 1, 2, 2, 3 }; std::cerr &lt;&lt; "default : " &lt;&lt; std::boolalpha &lt;&lt; boost::algorithm::is_sorted( a ) &lt;&lt; "\n"; std::cerr &lt;&lt; "less : " &lt;&lt; std::boolalpha &lt;&lt; boost::algorithm::is_sorted( a, std::less &lt;&gt;{} ) &lt;&lt; "\n"; std::cerr &lt;&lt; "less_equal: " &lt;&lt; std::boolalpha &lt;&lt; boost::algorithm::is_sorted( a, std::less_equal&lt;&gt;{} ) &lt;&lt; "\n"; } </pre><p> I vote: change docs, not code. Because: that matches <code>std::</code>. </p> Ticket