std::unique_ptr<T,Deleter>::reset (3) - Linux Manuals
std::unique_ptr<T,Deleter>::reset: std::unique_ptr<T,Deleter>::reset
NAME
std::unique_ptr<T,Deleter>::reset - std::unique_ptr<T,Deleter>::reset
Synopsis
members of the primary template, unique_ptr<T>
void reset( pointer ptr = pointer() ) noexcept; (1)
members of the specialization unique_ptr<T[]>
void reset( pointer ptr = pointer() ) noexcept; (2) (until C++17)
template< class U > (until C++17)
void reset( U ) = delete;
template< class U > (3) (since C++17)
void reset( U ) noexcept;
void reset( std::nullptr_t p ) noexcept; (4) (until C++17)
void reset( std::nullptr_t p = nullptr ) noexcept; (since C++17)
Replaces the managed object.
1) Given current_ptr, the pointer that was managed by *this, performs the following actions, in this order:
2) Behaves the same as the reset member of the primary template.
3) In the specialization for dynamic arrays, std::unique_ptr<T[]>, this template member is provided to prevent using reset() with a pointer to derived (which would result in undefined behavior with arrays). (until C++17)
4) In the specialization for dynamic arrays, std::unique_ptr<T[]>, this overload is necessary to allow reset to nullptr (which would otherwise be prohibited by the template overload). Equivalent to reset(pointer())
3) Behaves the same as the reset member of the primary template, except that it will only participate in overload resolution if either
4) Equivalent to reset(pointer())
Parameters
ptr - pointer to a new object to manage
Return value
(none)
Notes
To replace the managed object while supplying a new deleter as well, move assignment operator may be used.
A test for self-reset, i.e. whether ptr points to an object already managed by *this, is not performed, except where provided as a compiler extension or as a debugging assert. Note that code such as p.reset(p.release()) does not involve self-reset, only code like p.reset(p.get()) does.
Example
// Run this code
Output:
See also
release (public member function)