<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3222: P0574R1 introduced preconditions on non-existent parameters</title>
<meta property="og:title" content="Issue 3222: P0574R1 introduced preconditions on non-existent parameters">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3222.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="3222"><a href="lwg-defects.html#3222">3222</a>. P0574R1 introduced preconditions on non-existent parameters</h3>
<p><b>Section:</b> 26.10.9 <a href="https://wg21.link/inclusive.scan">[inclusive.scan]</a>, 26.10.11 <a href="https://wg21.link/transform.inclusive.scan">[transform.inclusive.scan]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2019-06-18 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</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>
after applying <a href="https://wg21.link/p0574r1">P0574R1</a> to the working draft,
26.10.11 <a href="https://wg21.link/transform.inclusive.scan">[transform.inclusive.scan]</a> bullet 1.1 says "If <code>init</code> is provided, [&hellip;];
otherwise, <code>ForwardIterator1</code>'s value type shall be [&hellip;]."
26.10.11 <a href="https://wg21.link/transform.inclusive.scan">[transform.inclusive.scan]</a> bullet 1.2 says "If <code>init</code> is provided, [&hellip;];
otherwise, [&hellip;] shall be convertible to <code>ForwardIterator1</code>'s value type."
<p/>
For the first overload <code>init</code> is not provided, but there is no <code>ForwardIterator1</code>, so
these requirements cannot be met. The requirements for the first overload need to be stated in terms
of <code>InputIterator</code>'s value type, not <code>ForwardIterator1</code>'s value type.
<p/>
The same problem exists in 26.10.9 <a href="https://wg21.link/inclusive.scan">[inclusive.scan]</a>. 26.10.12 <a href="https://wg21.link/adjacent.difference">[adjacent.difference]</a> solves
this problem by saying "Let <code>T</code> be the value type of <code>decltype(first)</code>".
</p>

<p><i>[2019-07 Issue Prioritization]</i></p>

<p>Status to Tentatively Ready after five positive votes on the reflector.</p>


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

<ol>
<li><p>Modify 26.10.9 <a href="https://wg21.link/inclusive.scan">[inclusive.scan]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator, class OutputIterator, class BinaryOperation&gt;
  OutputIterator inclusive_scan(InputIterator first, InputIterator last,
                                OutputIterator result, BinaryOperation binary_op);
template&lt;class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
         class BinaryOperation&gt;
  ForwardIterator2 inclusive_scan(ExecutionPolicy&amp;&amp; exec,
                                  ForwardIterator1 first, ForwardIterator1 last,
                                  ForwardIterator2 result, BinaryOperation binary_op);
template&lt;class InputIterator, class OutputIterator, class BinaryOperation, class T&gt;
  OutputIterator inclusive_scan(InputIterator first, InputIterator last,
                                OutputIterator result, BinaryOperation binary_op, T init);
template&lt;class ExecutionPolicy,
         class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class T&gt;
  ForwardIterator2 inclusive_scan(ExecutionPolicy&amp;&amp; exec,
                                  ForwardIterator1 first, ForwardIterator1 last,
                                  ForwardIterator2 result, BinaryOperation binary_op, T init);
</pre>
<blockquote>
<p>
<ins>-?- Let <code>U</code> be the value type of <code>decltype(first)</code>.</ins>
<p/>
-3- <i>Requires:</i>
</p>
<ol style="list-style-type:none">
<li><p>(3.1) &mdash; If <code>init</code> is provided, <code>T</code> shall be <i>Cpp17MoveConstructible</i> (Table 26); otherwise, <del><code>ForwardIterator1</code>'s value type</del><ins><code>U</code></ins> shall be
<i>Cpp17MoveConstructible</i>.</p></li>
<li><p>(3.2) &mdash; If <code>init</code> is provided, all of <code>binary_op(init, init)</code>, <code>binary_op(init,
*first)</code>, and <code>binary_op(*first, *first)</code> shall be convertible to <code>T</code>; otherwise,
<code>binary_op(*first, *first)</code> shall be convertible to <del><code>ForwardIterator1</code>'s value
type</del><ins><code>U</code></ins>.</p></li>
<li><p>(3.3) &mdash; <code>binary_op</code> shall neither invalidate iterators or subranges, nor modify elements
in the ranges <code>[first, last]</code> or <code>[result, result + (last - first)]</code>.</p></li>
</ol>
</blockquote>
</blockquote>
</li>

<li><p>Modify 26.10.11 <a href="https://wg21.link/transform.inclusive.scan">[transform.inclusive.scan]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator, class OutputIterator,
         class BinaryOperation, class UnaryOperation&gt;
  OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
                                          OutputIterator result,
                                          BinaryOperation binary_op, UnaryOperation unary_op);
template&lt;class ExecutionPolicy,
         class ForwardIterator1, class ForwardIterator2,
         class BinaryOperation, class UnaryOperation&gt;
  ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&amp;&amp; exec,
                                            ForwardIterator1 first, ForwardIterator1 last,
                                            ForwardIterator2 result,
                                            BinaryOperation binary_op, UnaryOperation unary_op);
template&lt;class InputIterator, class OutputIterator,
         class BinaryOperation, class UnaryOperation, class T&gt;
  OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
                                          OutputIterator result,
                                          BinaryOperation binary_op, UnaryOperation unary_op,
                                          T init);
template&lt;class ExecutionPolicy,
         class ForwardIterator1, class ForwardIterator2,
         class BinaryOperation, class UnaryOperation, class T&gt;
  ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&amp;&amp; exec,
                                            ForwardIterator1 first, ForwardIterator1 last,
                                            ForwardIterator2 result,
                                            BinaryOperation binary_op, UnaryOperation unary_op,
                                            T init);
</pre>
<blockquote>
<p>
<ins>-?- Let <code>U</code> be the value type of <code>decltype(first)</code>.</ins>
<p/>
-1- <i>Requires:</i>
</p>
<ol style="list-style-type:none">
<li><p>(1.1) &mdash; If <code>init</code> is provided, <code>T</code> shall be <i>Cpp17MoveConstructible</i> (Table 26); otherwise, <del><code>ForwardIterator1</code>'s value type</del><ins><code>U</code></ins> shall be
<i>Cpp17MoveConstructible</i>.</p></li>
<li><p>(1.2) &mdash; If <code>init</code> is provided, all of</p>
<ol style="list-style-type:none">
<li><p>(1.2.1) &mdash; <code>binary_op(init, init)</code>,</p></li>
<li><p>(1.2.2) &mdash; <code>binary_op(init, unary_op(*first))</code>, and</p></li>
<li><p>(1.2.3) &mdash; <code>binary_op(unary_op(*first), unary_op(*first))</code></p></li>
</ol>
<p>shall be convertible to <code>T</code>; otherwise, <code>binary_op(unary_op(*first), unary_op(*first))</code>
shall be convertible to <del><code>ForwardIterator1</code>'s value type</del><ins><code>U</code></ins>.</p></li>
<li><p>(1.3) &mdash; Neither <code>unary_op</code> nor <code>binary_op</code> shall invalidate iterators or subranges,
nor modify elements in the ranges <code>[first, last]</code> or <code>[result, result + (last - first)]</code>.</p></li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
