Skip to main content

std::auto_ptr<T>::operator=

Deprecated in C++11, Removed in C++17
auto_ptr& operator=( auto_ptr& r ) throw();         (1)	

template< class Y >
auto_ptr& operator=( auto_ptr<Y>& r ) throw(); (2)

auto_ptr& operator=( auto_ptr_ref<T> m ) throw(); (3)

Replaces the managed object with the one managed by r or m.

  1. Effectively calls reset(r.release()).

  2. Effectively calls reset(r.release()). Y* must be implicitly convertible to T*.

  3. Effectively calls reset(m.release()). auto_ptr_ref is an implementation-defined type that holds a reference to auto_ptr. std::auto_ptr is implicitly convertible to and from this type. The implementation is allowed to provide the template with a different name or implement equivalent functionality in other ways.

Parameters

r - another auto_ptr to transfer the ownership of the object from m - an object of implementation-defined type that holds a reference to auto_ptr

Return value

*this.

Notes

The constructor and the copy assignment operator from auto_ptr_ref is provided to allow copy-constructing and assigning std::auto_ptr from nameless temporaries. Since its copy constructor and copy assignment operator take the argument as non-const reference, they cannot bind rvalue arguments directly. However, a user-defined conversion can be executed (which releases the original auto_ptr), followed by a call to the constructor or copy-assignment operator that take auto_ptr_ref by value. This is an early implementation of move semantics.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 127C++98auto_ptr was not assignable from auto_ptr_refadded overload (3)

std::auto_ptr<T>::operator=

Deprecated in C++11, Removed in C++17
auto_ptr& operator=( auto_ptr& r ) throw();         (1)	

template< class Y >
auto_ptr& operator=( auto_ptr<Y>& r ) throw(); (2)

auto_ptr& operator=( auto_ptr_ref<T> m ) throw(); (3)

Replaces the managed object with the one managed by r or m.

  1. Effectively calls reset(r.release()).

  2. Effectively calls reset(r.release()). Y* must be implicitly convertible to T*.

  3. Effectively calls reset(m.release()). auto_ptr_ref is an implementation-defined type that holds a reference to auto_ptr. std::auto_ptr is implicitly convertible to and from this type. The implementation is allowed to provide the template with a different name or implement equivalent functionality in other ways.

Parameters

r - another auto_ptr to transfer the ownership of the object from m - an object of implementation-defined type that holds a reference to auto_ptr

Return value

*this.

Notes

The constructor and the copy assignment operator from auto_ptr_ref is provided to allow copy-constructing and assigning std::auto_ptr from nameless temporaries. Since its copy constructor and copy assignment operator take the argument as non-const reference, they cannot bind rvalue arguments directly. However, a user-defined conversion can be executed (which releases the original auto_ptr), followed by a call to the constructor or copy-assignment operator that take auto_ptr_ref by value. This is an early implementation of move semantics.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 127C++98auto_ptr was not assignable from auto_ptr_refadded overload (3)