<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1100: auto_ptr to unique_ptr conversion</title>
<meta property="og:title" content="Issue 1100: auto_ptr to unique_ptr conversion">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1100.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="1100"><a href="lwg-defects.html#1100">1100</a>. <code>auto_ptr</code> to <code>unique_ptr</code> conversion</h3>
<p><b>Section:</b> 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2009-04-25 <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.single.ctor">issues</a> in [unique.ptr.single.ctor].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Message c++std-lib-23182 led to a discussion in which several people
expressed interest in being able to convert an <code>auto_ptr</code> to a
<code>unique_ptr</code> without the need to call <code>release</code>.  Below is
wording to accomplish this.
</p>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
Pete believes it not a good idea to separate parts of a class's definition.
Therefore, if we do this,
it should be part of <code>unique-ptr</code>'s specification.
</p>
<p>
Alisdair believes the lvalue overload may be not necessary.
</p>
<p>
Marc believes it is more than just sugar,
as it does ease the transition to <code>unique-ptr</code>.
</p>
<p>
We agree with the resolution as presented.
Move to Tentatively Ready.
</p>
</blockquote>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Moved from Tentatively Ready to Open only because the wording needs to be
tweaked for concepts removal.
</p></blockquote>

<p><i>[
2009-08-01 Howard deconceptifies wording:
]</i></p>


<blockquote><p>
I also moved the change from 99 [depr.auto.ptr]
to 20.3.1.3 <a href="https://wg21.link/unique.ptr.single">[unique.ptr.single]</a> per the Editor's request
in Batavia (as long as I was making changes anyway).  Set back
to Review.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Move to Ready.
</p></blockquote>

<p><i>[
2010-03-14 Howard adds:
]</i></p>


<blockquote><p>
We moved
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3073.html">N3073</a>
to the formal motions page in Pittsburgh which should obsolete this issue.  I've
moved this issue to NAD Editorial, solved by N3073.
</p></blockquote>



<p><b>Rationale:</b></p>
<p>
Solved by <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3073.html">N3073</a>.
</p>


<p id="res-1100"><b>Proposed resolution:</b></p>
<p>
Add to 20.3.1.3 <a href="https://wg21.link/unique.ptr.single">[unique.ptr.single]</a>:
</p>

<blockquote><pre>
template &lt;class T, class D&gt;
class unique_ptr
{
public:
<ins>    template &lt;class U&gt;
      unique_ptr(auto_ptr&lt;U&gt;&amp; u);
    template &lt;class U&gt;
      unique_ptr(auto_ptr&lt;U&gt;&amp;&amp; u);</ins>
};
</pre></blockquote>

<p>
Add to 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a>:
</p>

<blockquote><pre>
template &lt;class U&gt;
  unique_ptr(auto_ptr&lt;U&gt;&amp; u);
template &lt;class U&gt;
  unique_ptr(auto_ptr&lt;U&gt;&amp;&amp; u);
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs a <code>unique_ptr</code> with <code>u.release()</code>.
</p>

<p>
<i>Postconditions:</i> <code>get() == </code> the value <code>u.get()</code> had before
the construciton, modulo any required offset adjustments resulting from the cast from
<code>U*</code> to <code>T*</code>.  <code>u.get() == nullptr</code>.
</p>

<p>
<i>Throws:</i> nothing.
</p>

<p>
<i>Remarks:</i> <code>U*</code> shall be implicitly convertible to <code>T*</code> and
<code>D</code> shall be the same type as <code>default_delete&lt;T&gt;</code>, else these
constructors shall not participate in overload resolution.
</p>
</blockquote>
</blockquote>






</body>
</html>
