Document number: N3109=10-0099
Project: Programming Language C++, Library Working Group
Author: Daniel Krügler
Date: 2010-08-06

US 108

Discussion

This proposal addresses US comment 108, thus attempts to resolve the current auto_ptr => unique_ptr/shared_ptr conversion mismatch. The proposed resolution intentionally deviates from the form suggested by the NB comment: Instead of adding an explicit constructor template to shared_ptr that accepts an lvalue of auto_ptr, it suggests to remove the explicit constructor template of unique_ptr instead and allow only movements from rvalues. The rationale for this deviation is that in C++0x it is intended to deprecate auto_ptr and its funny move-from-lvalue semantics. Therefore, the existing constructors should satisfy the following two aims: Providing an easy transition path for users of auto_ptr but doing this in the spirit of C++0x, i.e. users can still move an lvalue, but that requires an explicit usage of std::move().

Proposed resolution

  1. Remove from the class template synopsis, 20.9.10.2 unique_ptr for single objects [unique.ptr.single]:
    namespace std {
      template <class T, class D = default_delete<T>> class unique_ptr {
      public:
        ...
        template <class U, class E>
        unique_ptr(unique_ptr<U, E>&& u);
        template <class U>
        explicit unique_ptr(auto_ptr<U>& u);
        template <class U>
        unique_ptr(auto_ptr<U>&& u);
        ...
      };
    }
    
  2. Remove the superfluous prototype signature from 20.9.10.2.1 [unique.ptr.single.ctor] before p. 27 and fix some plural form that is now supposed to be a singular form:
      template <class U>
      explicit unique_ptr(auto_ptr<U>& u);
      template <class U>
      unique_ptr(auto_ptr<U>&& u);
     

    27 Effects: Constructs a unique_ptr object, initializing the stored pointer with u.release() and value-initializing the stored deleter.

    28 Postconditions: get() yields the value u.get() yielded before the construction. u.get() == nullptr. get_deleter() returns a reference to the stored deleter.

    29 Throws: Nothing.

    30 Remarks: These constructorsThis constructor shall not participate in overload resolution unless U* is implictly convertible to T* and D is the same type as default_delete<T>.