<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3419: &sect;[algorithms.requirements]/15 doesn't reserve as many rights as it intends to</title>
<meta property="og:title" content="Issue 3419: &sect;[algorithms.requirements]/15 doesn't reserve as many rights as it intends to">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3419.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++23">C++23</a> status.</em></p>
<h3 id="3419"><a href="lwg-defects.html#3419">3419</a>. &sect;[algorithms.requirements]/15 doesn't reserve as many rights as it intends to</h3>
<p><b>Section:</b> 26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2020-03-24 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>0
</p>
<p><b>View other</b> <a href="lwg-index-open.html#algorithms.requirements">active issues</a> in [algorithms.requirements].</p>
<p><b>View all other</b> <a href="lwg-index.html#algorithms.requirements">issues</a> in [algorithms.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a>/15 says:
</p>
<blockquote><p>
"The number and order of deducible template parameters for algorithm declarations are unspecified, except 
where explicitly stated otherwise. [<i>Note:</i> Consequently, the algorithms may not be called with 
explicitly-specified template argument lists. &mdash; <i>end note</i>]"
</p></blockquote>
<p>
But the note doesn't follow from the normative rule. For example, we felt the need to explicitly allow 
deduction for <code>min</code>'s template parameter:
</p>
<blockquote><pre>
template&lt;typename T&gt; const T&amp; min(const T&amp;, const T&amp;);
</pre></blockquote>
<p>
&hellip; but if only the order and number of <em>deducible</em> template parameters is permitted to vary, 
then because of the required deduction behavior of this function template, there are only three possible 
valid declarations:
</p>
<blockquote><pre>
template&lt;typename T&gt; ??? min(const T&amp;, const T&amp;);
template&lt;typename T, typename U&gt; ??? min(const T&amp;, const U&amp;);
template&lt;typename T, typename U&gt; ??? min(const U&amp;, const T&amp;);
</pre></blockquote>
<p>
(up to minor differences in the parameter type). This doesn't prohibit calls with an explicitly-specified 
template argument list, contrary to the claim in the note. (Indeed, because a call such as <code>min(1, {})</code> 
is valid, either the first of the above three overloads must be present or there must be a default template 
argument <code>typename U = T</code>, which further adds to the fact that there may be valid calls with an 
explicitly-specified template argument list.)
<p/>
Also, the "explicitly stated otherwise" cases use phrasing such as: "An invocation may explicitly specify 
an argument for the template parameter <code>T</code> of the overloads in namespace <code>std</code>." which 
doesn't "specify otherwise" the normative rule, but does "specify otherwise" the claim in the note.
<p/>
All this leads me to believe that [algorithms.requirements]/15 is backwards: the normative rule should be a 
note and the note should be the normative rule.
</p>

<p><i>[2020-04-04 Issue Prioritization]</i></p>
 
<p>
Status set to Tentatively Ready after six positive votes on the reflector.
</p>
<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



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

<ol>
<li><p>Modify 26.2 <a href="https://wg21.link/algorithms.requirements">[algorithms.requirements]</a> as indicated:</p>

<blockquote>
<p>
-15- The <ins>well-formedness and behavior of a call to an algorithm with an explicitly-specified template 
argument list is</ins><del>number and order of deducible template parameters for algorithm declarations are</del> 
unspecified, except where explicitly stated otherwise. [<i>Note:</i> Consequently, <ins>an implementation can 
declare an algorithm with different template parameters than those presented</ins><del>the algorithms may not be 
called with explicitly-specified template argument lists</del>. &mdash; <i>end note</i>]
</p>
</blockquote>
</li>
</ol>




</body>
</html>
