<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 740: Please remove *_ptr&lt;T[N]&gt;</title>
<meta property="og:title" content="Issue 740: Please remove *_ptr&lt;T[N]&gt;">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue740.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#CD1">CD1</a> status.</em></p>
<h3 id="740"><a href="lwg-defects.html#740">740</a>. Please remove <code>*_ptr&lt;T[N]&gt;</code></h3>
<p><b>Section:</b> 20.3.1 <a href="https://wg21.link/unique.ptr">[unique.ptr]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Herb Sutter <b>Opened:</b> 2007-10-04 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#unique.ptr">issues</a> in [unique.ptr].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Please don't provide <code>*_ptr&lt;T[N]&gt;</code>. It doesn't enable any useful
bounds-checking (e.g., you could imagine that doing <code>op++</code> on a
<code>shared_ptr&lt;T[N]&gt;</code> yields a <code>shared_ptr&lt;T[N-1]&gt;</code>, but that promising path
immediately falters on <code>op--</code> which can't reliably dereference because we
don't know the lower bound). Also, most buffers you'd want to point to
don't have a compile-time known size.
</p>

<p>
To enable any bounds-checking would require run-time information, with
the usual triplet: base (lower bound), current offset, and max offset
(upper  bound). And I can sympathize with the point of view that you
wouldn't want to require this on <code>*_ptr</code> itself. But please let's not
follow the <code>&lt;T[N]&gt;</code> path, especially not with additional functions to
query the bounds etc., because this sets wrong user expectations by
embarking on a path that doesn't go all the way to bounds checking as it
seems to imply.
</p>

<p>
If bounds checking is desired, consider a <code>checked_*_ptr</code> instead (e.g.,
<code>checked_shared_ptr</code>). And make the interfaces otherwise identical so that
user code could easily <code>#define/typedef</code> between prepending <code>checked_</code> on
debug builds and not doing so on release builds (for example).
</p>

<p>
Note that some may object that <code>checked_*_ptr</code> may seem to make the smart
pointer more like <code>vector</code>, and we don't want two ways to spell <code>vector</code>. I
don't agree, but if that were true that would be another reason to
remove <code>*_ptr&lt;T[N]&gt;</code> which equally makes the smart pointer more like
<code>std::array.</code> :-)
</p>

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


<blockquote>
<p>
Suggestion that fixed-size array instantiations are going to fail at compile time anyway (if we remove specialization) due to pointer decay, at least that appears to be result from available compilers.
</p>
<p>
So concerns about about requiring static_assert seem unfounded.
</p>
<p>
After a little more experimentation with compiler, it appears that fixed size arrays would only work at all if we supply these explicit specialization. So removing them appears less breaking than originally thought.
</p>
<p>
straw poll unanimous move to Ready.
</p>
</blockquote>



<p id="res-740"><b>Proposed resolution:</b></p>
<p>
Change the synopsis under 20.3.1 <a href="https://wg21.link/unique.ptr">[unique.ptr]</a> p2:
</p>

<blockquote><pre>
...
template&lt;class T&gt; struct default_delete; 
template&lt;class T&gt; struct default_delete&lt;T[]&gt;; 
<del>template&lt;class T, size_t N&gt; struct default_delete&lt;T[N]&gt;;</del>

template&lt;class T, class D = default_delete&lt;T&gt;&gt; class unique_ptr; 
template&lt;class T, class D&gt; class unique_ptr&lt;T[], D&gt;; 
<del>template&lt;class T, class D, size_t N&gt; class unique_ptr&lt;T[N], D&gt;;</del>
...
</pre></blockquote>

<p>
Remove the entire section  [unique.ptr.dltr.dflt2] <b><code>default_delete&lt;T[N]&gt;</code></b>.
</p>

<p>
Remove the entire section  [unique.ptr.compiletime] <b><code>unique_ptr</code> for array objects with a compile time length</b>
and its subsections:  [unique.ptr.compiletime.dtor],  [unique.ptr.compiletime.observers],
 [unique.ptr.compiletime.modifiers].
</p>






</body>
</html>
