This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

1100. auto_ptr to unique_ptr conversion

Section: 20.3.1.3.2 [unique.ptr.single.ctor] Status: Resolved Submitter: Howard Hinnant Opened: 2009-04-25 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [unique.ptr.single.ctor].

View all issues with Resolved status.

Discussion:

Message c++std-lib-23182 led to a discussion in which several people expressed interest in being able to convert an auto_ptr to a unique_ptr without the need to call release. Below is wording to accomplish this.

[ Batavia (2009-05): ]

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 unique-ptr's specification.

Alisdair believes the lvalue overload may be not necessary.

Marc believes it is more than just sugar, as it does ease the transition to unique-ptr.

We agree with the resolution as presented. Move to Tentatively Ready.

[ 2009-07 Frankfurt ]

Moved from Tentatively Ready to Open only because the wording needs to be tweaked for concepts removal.

[ 2009-08-01 Howard deconceptifies wording: ]

I also moved the change from 99 [depr.auto.ptr] to 20.3.1.3 [unique.ptr.single] per the Editor's request in Batavia (as long as I was making changes anyway). Set back to Review.

[ 2009-10 Santa Cruz: ]

Move to Ready.

[ 2010-03-14 Howard adds: ]

We moved N3073 to the formal motions page in Pittsburgh which should obsolete this issue. I've moved this issue to NAD Editorial, solved by N3073.

Rationale:

Solved by N3073.

Proposed resolution:

Add to 20.3.1.3 [unique.ptr.single]:

template <class T, class D>
class unique_ptr
{
public:
    template <class U>
      unique_ptr(auto_ptr<U>& u);
    template <class U>
      unique_ptr(auto_ptr<U>&& u);
};

Add to 20.3.1.3.2 [unique.ptr.single.ctor]:

template <class U>
  unique_ptr(auto_ptr<U>& u);
template <class U>
  unique_ptr(auto_ptr<U>&& u);

Effects: Constructs a unique_ptr with u.release().

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

Throws: nothing.

Remarks: U* shall be implicitly convertible to T* and D shall be the same type as default_delete<T>, else these constructors shall not participate in overload resolution.