<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1029: Specialized algorithms for memory management need to be concept-constrained templates</title>
<meta property="og:title" content="Issue 1029: Specialized algorithms for memory management need to be concept-constrained templates">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1029.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#NAD_Concepts">NAD Concepts</a> status.</em></p>
<h3 id="1029"><a href="lwg-closed.html#1029">1029</a>. Specialized algorithms for memory management need to be concept-constrained templates</h3>
<p><b>Section:</b> 26.11 <a href="https://wg21.link/specialized.algorithms">[specialized.algorithms]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-03-11 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#specialized.algorithms">active issues</a> in [specialized.algorithms].</p>
<p><b>View all other</b> <a href="lwg-index.html#specialized.algorithms">issues</a> in [specialized.algorithms].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Concepts">NAD Concepts</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 210 [CD1]</b></p>

<p>Related to <a href="lwg-closed.html#582" title="specialized algorithms and volatile storage (Status: NAD)">582</a><sup><a href="https://cplusplus.github.io/LWG/issue582" title="Latest snapshot">(i)</a></sup></p>

<p>
Specialized algorithms for memory management need requirements to be
easily usable in constrained templates.
</p>

<p><i>[
Summit:
]</i></p>


<blockquote><p>
We look forward to a paper on this topic. We recommend no action until a
paper is available.
</p></blockquote>

<p><i>[
Post Summit Alisdair provided wording.
]</i></p>


<p><i>[
Post Summit:
]</i></p>


<blockquote>
<p>
Daniel adds:
</p>

<blockquote>
<ol>
<li>
I suggest <code>Size</code> should require <code>IntegralLike</code> and not <code>UnsignedIntegralLike</code>,
because otherwise simple int-literals could not be provided as arguments
and it would conflict with other algorithms that only require <code>IntegralLike</code>.
</li>
<li>
<p>
The current for-loop-test relies on evaluation in boolean context which is
not provided by <code>ArithmeticLike</code> and it's refinements. I propose to change the
corresponding for-loop-headers to:
</p>
<ol style="list-style-type:lower-alpha">
<li>
for <code>uninitialized_copy_n</code>: <code>for ( ; n &gt; Size(0); ++result, ++first, --n) {</code>
</li>
<li>
for <code>uninitialized_fill_n</code>: <code>for (; n &gt; Size(0); ++first, --n) {</code>
</li>
</ol>
</li>
</ol>
</blockquote>

<p>
Alisdair adds:
</p>
<blockquote><p>
For the record I agree with Daniel's suggestion.
</p></blockquote>

</blockquote>



<p id="res-1029"><b>Proposed resolution:</b></p>
<p>
20.2 <a href="https://wg21.link/memory">[memory]</a> p2
</p>
<p>
Update the synopsis for <code>&lt;memory&gt;</code>
</p>
<blockquote><pre>
template &lt;<del>class</del> InputIterator <ins>InIter</ins>,
         <del>class ForwardIterator</del> <ins>OutputIterator&lt;auto, InIter::reference&gt; OutIter</ins>&gt; 
   <ins>requires ForwardIterator&lt;OutIter&gt;</ins>
   <del>ForwardIterator</del> <ins>OutIter</ins>
   uninitialized_copy(<del>InputIterator</del> <ins>InIter</ins> first, <del>InputIterator</del> <ins>InIter</ins> last, 
                      <del>ForwardIterator</del> <ins>OutIter</ins> result);

template &lt;<del>class</del> InputIterator <ins>InIter</ins>,
          <del>class</del> <ins>IntegralLike</ins> Size,
          <del>class ForwardIterator</del> <ins>OutputIterator&lt;auto, InIter::reference&gt; OutIter</ins>&gt; 
  <ins>requires ForwardIterator&lt;OutIter&gt;</ins>
  <del>ForwardIterator</del> <ins>OutIter</ins>
  uninitialized_copy_n(<del>InputIterator</del> <ins>InIter</ins> first, Size n, 
                       <del>ForwardIterator</del> <ins>OutIter</ins> result);

template &lt;<del>class</del> ForwardIterator <ins>Iter</ins>, <del>class</del> <ins>ObjectType</ins> T&gt;
  <ins>requires Constructible&lt; Iter::value_type, const T&amp; &gt;</ins>
  void uninitialized_fill(<del>ForwardIterator</del> <ins>Iter</ins> first, <del>ForwardIterator</del> <ins>Iter</ins> last, 
                          const T&amp; x);

template &lt;<del>class</del> ForwardIterator <ins>Iter</ins>, <del>class</del> <ins>IntegralLike</ins> Size, <del>class</del> <ins>ObjectType</ins> T&gt; 
  <ins>requires Constructible&lt; Iter::value_type, const T&amp; &gt;</ins>
  void
  uninitialized_fill_n(<del>ForwardIterator</del> <ins>Iter</ins> first, Size n, const T&amp; x);
</pre></blockquote>

<p>
Update as follows:
</p>

<p>
uninitialized_copy 26.11.5 <a href="https://wg21.link/uninitialized.copy">[uninitialized.copy]</a>
</p>

<blockquote><pre>
template &lt;<del>class</del> InputIterator <ins>InIter</ins>,
         <del>class ForwardIterator</del> <ins>OutputIterator&lt;auto, InIter::reference&gt; OutIter</ins>&gt; 
   <ins>requires ForwardIterator&lt;OutIter&gt;</ins>
   <del>ForwardIterator</del> <ins>OutIter</ins>
   uninitialized_copy(<del>InputIterator</del> <ins>InIter</ins> first, <del>InputIterator</del> <ins>InIter</ins> last, 
                      <del>ForwardIterator</del> <ins>OutIter</ins> result);
</pre>

<blockquote>
<p>
-1- <i>Effects:</i>
</p>
<blockquote><pre>
for (; first != last; ++result, ++first)  {
   new (static_cast&lt;void*&gt;(&amp;*result))
       <del>typename iterator_traits&lt;ForwardIterator&gt;</del> <ins>OutIter</ins>::value_type(*first);
}
</pre></blockquote>

<p>
-2- <i>Returns:</i> <code>result</code>
</p>

</blockquote>

<pre>
template &lt;<del>class</del> InputIterator <ins>InIter</ins>,
          <del>class</del> <ins>IntegralLike</ins> Size,
          <del>class ForwardIterator</del> <ins>OutputIterator&lt;auto, InIter::reference&gt; OutIter</ins>&gt; 
  <ins>requires ForwardIterator&lt;OutIter&gt;</ins>
  <del>ForwardIterator</del> <ins>OutIter</ins>
  uninitialized_copy_n(<del>InputIterator</del> <ins>InIter</ins> first, Size n, 
                       <del>ForwardIterator</del> <ins>OutIter</ins> result);
</pre>

<blockquote>
<p>
-3- Effects:
</p>
<blockquote><pre>
for ( ; n &gt; <ins>Size(</ins>0<ins>)</ins>; ++result, ++first, --n) {
   new (static_cast&lt;void*&gt;(&amp;*result))
       <del>typename iterator_traits&lt;ForwardIterator&gt;</del> <ins>OutIter</ins>::value_type(*first);
}
</pre></blockquote>
<p>
-4- <i>Returns:</i> result
</p>
</blockquote>

</blockquote>


<p>
uninitialized_fill 26.11.7 <a href="https://wg21.link/uninitialized.fill">[uninitialized.fill]</a>
</p>

<blockquote><pre>
template &lt;<del>class</del> ForwardIterator <ins>Iter</ins>, <del>class</del> <ins>ObjectType</ins> T&gt;
  <ins>requires Constructible&lt; Iter::value_type, const T&amp; &gt;</ins>
  void uninitialized_fill(<del>ForwardIterator</del> <ins>Iter</ins> first, <del>ForwardIterator</del> <ins>Iter</ins> last, 
                          const T&amp; x);
</pre>

<blockquote>
<p>
-1- <i>Effects:</i>
</p>
<blockquote><pre>
for (; first != last; ++first) {
   new ( static_cast&lt;void*&gt;( &amp;*first) ) 
       <del>typename iterator_traits&lt;ForwardIterator&gt;</del> <ins>Iter</ins>::value_type(x);
}
</pre></blockquote>
</blockquote>
</blockquote>


<p>
uninitialized_fill_n  [uninitialized.fill.n]
</p>

<blockquote><pre>
template &lt;<del>class</del> ForwardIterator <ins>Iter</ins>, <del>class</del> <ins>IntegralLike</ins> Size, <del>class</del> <ins>ObjectType</ins> T&gt; 
  <ins>requires Constructible&lt; Iter::value_type, const T&amp; &gt;</ins>
  void
  uninitialized_fill_n(<del>ForwardIterator</del> <ins>Iter</ins> first, Size n, const T&amp; x);
</pre>

<blockquote>
<p>
-1- <i>Effects:</i>
</p>
<blockquote><pre>
for (; n<del>--</del> <ins>&gt; Size(0)</ins>; ++first<ins>, --n</ins>) {
   new ( static_cast&lt;void*&gt;( &amp;*first) ) 
       <del>typename iterator_traits&lt;ForwardIterator&gt;</del> <ins>Iter</ins>::value_type(x);
}
</pre></blockquote>
</blockquote>
</blockquote>






</body>
</html>
