<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3213: for_each_n and copy_n missing requirements for Size</title>
<meta property="og:title" content="Issue 3213: for_each_n and copy_n missing requirements for Size">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3213.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#Resolved">Resolved</a> status.</em></p>
<h3 id="3213"><a href="lwg-defects.html#3213">3213</a>. <code>for_each_n</code> and <code>copy_n</code> missing requirements for <code>Size</code></h3>
<p><b>Section:</b> 26.6.5 <a href="https://wg21.link/alg.foreach">[alg.foreach]</a>, 26.7.1 <a href="https://wg21.link/alg.copy">[alg.copy]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2019-05-31 <b>Last modified:</b> 2020-11-09</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#alg.foreach">active issues</a> in [alg.foreach].</p>
<p><b>View all other</b> <a href="lwg-index.html#alg.foreach">issues</a> in [alg.foreach].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>search_n</code> and <code>fill_n</code> and <code>generate_n</code> require that "The type <code>Size</code> shall be
convertible to integral type", but <code>for_each_n</code> and <code>copy_n</code> have no requirements on
<code>Size</code>. Presumably it should be convertible to an integral type.
</p>

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

<p>Priority to 3 after discussion on the reflector.</p>

<strong>Previous resolution [SUPERSEDED]:</strong>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4810">N4810</a>.</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> Clause [algorithms] has not yet gone through a "Mandating" cleanup of our new wording
style for requirements expressed in <i>Requires</i> and <i>Expects</i> elements. The below wording
changes perform this fix for the touched paragraphs and also replaces here <i>Requires</i> by
<i>Expects</i> to prevent papers that address such wording changes to keep tracking of additional
wording changes caused by proposed wording of issues.]
</p>
</blockquote>

<ol>
<li><p>Modify 26.6.5 <a href="https://wg21.link/alg.foreach">[alg.foreach]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator, class Size, class Function&gt;
  constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
</pre>
<blockquote>
<p>
-16- <i>Requires:</i> shall satisfy the <i>Cpp17MoveConstructible</i> requirements [&hellip;]
<p/>
-17- <i><del>Requires</del><ins>Expects</ins>:</i> <ins>The type <code>Size</code> is convertible to integral type
(7.3.9 <a href="https://wg21.link/conv.integral">[conv.integral]</a>, 11.4.8 <a href="https://wg21.link/class.conv">[class.conv]</a>).</ins> <code>n &gt;= 0</code>.
<p/>
[&hellip;]
</p>
</blockquote>
<pre>
template&lt;class ExecutionPolicy, class ForwardIterator, class Size, class Function&gt;
  ForwardIterator for_each_n(ExecutionPolicy&amp;&amp; exec, ForwardIterator first, Size n,
                             Function f);
</pre>
<blockquote>
<p>
-21- <i>Requires:</i> shall satisfy the <i>Cpp17CopyConstructible</i> requirements [&hellip;]
<p/>
-22- <i><del>Requires</del><ins>Expects</ins>:</i> <ins>The type <code>Size</code> is convertible to integral type
(7.3.9 <a href="https://wg21.link/conv.integral">[conv.integral]</a>, 11.4.8 <a href="https://wg21.link/class.conv">[class.conv]</a>).</ins> <code>n &gt;= 0</code>.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 26.7.1 <a href="https://wg21.link/alg.copy">[alg.copy]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator, class Size, class OutputIterator&gt;
  constexpr OutputIterator copy_n(InputIterator first, Size n,
                                  OutputIterator result);
template&lt;class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2&gt;
  ForwardIterator2 copy_n(ExecutionPolicy&amp;&amp; exec,
                          ForwardIterator1 first, Size n,
                          ForwardIterator2 result);
template&lt;InputIterator I, WeaklyIncrementable O&gt;
  requires IndirectlyCopyable&lt;I, O&gt;
  constexpr ranges::copy_n_result&lt;I, O&gt;
    ranges::copy_n(I first, iter_difference_t&lt;I&gt; n, O result);
</pre>
<blockquote>
<p>
-10- Let <code><i>M</i></code> be <code>max(n, 0)</code>.
<p/>
<ins>-?- <i>Expects:</i> The type <code>Size</code> is convertible to integral type
(7.3.9 <a href="https://wg21.link/conv.integral">[conv.integral]</a>, 11.4.8 <a href="https://wg21.link/class.conv">[class.conv]</a>).</ins>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>

</blockquote>

<p><i>[2020-05-01; Reflector discussions]</i></p>

<p>
There was consensus that this issue has been resolved by <a href="https://wg21.link/p1718r2">P1718R2</a>,
voted in in Belfast 2019.
</p>
<p><i>[2020-11-09 Resolved for C++20. Status changed: Tentatively Resolved &rarr; Resolved.]</i></p>



<p id="res-3213"><b>Proposed resolution:</b></p>
<p>
Resolved by <a href="https://wg21.link/p1718r2">P1718R2</a>
</p>




</body>
</html>
