<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2998: Requirements on function objects passed to {forward_,}list-specific algorithms</title>
<meta property="og:title" content="Issue 2998: Requirements on function objects passed to {forward_,}list-specific algorithms">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2998.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++20">C++20</a> status.</em></p>
<h3 id="2998"><a href="lwg-defects.html#2998">2998</a>. Requirements on function objects passed to <code>{forward_,}list</code>-specific algorithms</h3>
<p><b>Section:</b> 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>, 23.3.7.6 <a href="https://wg21.link/forward.list.ops">[forward.list.ops]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2017-07-07 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#list.ops">issues</a> in [list.ops].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Some specialized algorithms for <code>forward_list</code> and <code>list</code> take template parameters named <code>Predicate</code>, 
<code>BinaryPredicate</code>, or <code>Compare</code>. 
However, there's no wording importing the full requirements for template type parameters with such names from 
26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a> and 26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a>,
which means, for instance, that there appears to be no rule prohibiting <code>Compare</code> from modifying its arguments, 
because we only refer to 26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a> for the definition of strict weak ordering. Is that intended?
</p>

<p><i>[2017-07 Toronto Tuesday PM issue prioritization]</i></p>

<p>Priority 0; status to Ready</p>


<p id="res-2998"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4659">N4659</a>.
</p>

<ol>
<li><p>Edit 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a> as indicated:</p>
<blockquote>
<p>-1- Since lists allow fast insertion and erasing from the middle of a list, certain operations are provided specifically 
for them.<sup>259)</sup> <ins>In this subclause, arguments for a template parameter named <code>Predicate</code> or 
<code>BinaryPredicate</code> shall meet the corresponding requirements in 26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a>.
For <code>merge</code> and <code>sort</code>, the definitions and requirements in 26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a> apply.</ins>
</p>
</blockquote>
</li>

<li><p>Edit 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a> as indicated:</p>
<blockquote>
<pre>
void merge(list&amp; x);
void merge(list&amp;&amp; x);
template &lt;class Compare&gt; void merge(list&amp; x, Compare comp);
template &lt;class Compare&gt; void merge(list&amp;&amp; x, Compare comp);
</pre>
<blockquote>
<p>-22- <i>Requires:</i> <del><code>comp</code> shall define a strict weak ordering (26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a>), and b</del><ins>B</ins>oth the list and the argument list shall be sorted
<del>according to this ordering</del><ins>with respect to the comparator <code>operator&lt;</code> (for the first two overloads) or <code>comp</code> (for the last two overloads)</ins>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Delete 23.3.11.5 <a href="https://wg21.link/list.ops">[list.ops]</a>/28 as redundant:</p>
<blockquote>
<pre>
void sort();
template &lt;class Compare&gt; void sort(Compare comp);
</pre>
<blockquote>
<p>
<del>-28- <i>Requires:</i> <code>operator&lt;</code> (for the first version) or <code>comp</code> (for the second version) shall 
define a strict weak ordering (26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a>).</del>
</p>
</blockquote>
</blockquote>
</li>

<li><p>Insert a new paragraph at the beginning of  [forwardlist.ops]:</p>
<blockquote>
<p><ins>-?- In this subclause, arguments for a template parameter named <code>Predicate</code> or 
<code>BinaryPredicate</code> shall meet the corresponding requirements in 26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a>.
For <code>merge</code> and <code>sort</code>, the definitions and requirements in 26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a> apply.</ins>
</p>
<pre>
void splice_after(const_iterator position, forward_list&amp; x);
void splice_after(const_iterator position, forward_list&amp;&amp; x);
</pre>
<p>
[&hellip;]
</p>
</blockquote>
</li>
<li><p>Edit  [forwardlist.ops] as indicated:</p>
<blockquote>
<pre>
void merge(forward_list&amp; x);
void merge(forward_list&amp;&amp; x);
template &lt;class Compare&gt; void merge(forward_list&amp; x, Compare comp);
template &lt;class Compare&gt; void merge(forward_list&amp;&amp; x, Compare comp);
</pre>
<blockquote>
<p>-22- <i>Requires:</i> <del><code>comp</code> defines a strict weak ordering (26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a>), and</del> 
<code>*this</code> and <code>x</code> are both sorted <del>according to this ordering</del><ins>with respect to the comparator 
<code>operator&lt;</code> (for the first two overloads) or <code>comp</code> (for the last two overloads)</ins>.
<code>get_allocator() == x.get_allocator()</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Delete  [forwardlist.ops]/23 as redundant:</p>
<blockquote>
<pre>
void sort();
template &lt;class Compare&gt; void sort(Compare comp);
</pre>
<blockquote>
<p>
<del>-23- <i>Requires:</i> <code>operator&lt;</code> (for the version with no arguments) or <code>comp</code> (for the version 
with a comparison argument) defines a strict weak ordering (26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a>).</del>
</p>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
