Namespaces
Variants
Views
Actions

std::shared_ptr::reset

From cppreference.com
 
 
 
 
 
void reset();
(1) (since C++11)
template< class Y >
void reset( Y* ptr );
(2) (since C++11)
template< class Y, class Deleter >
void reset( Y* ptr, Deleter d );
(3) (since C++11)
template< class Y, class Deleter, class Alloc >
void reset( Y* ptr, Deleter d, Alloc alloc );
(4) (since C++11)

Replaces the managed object with an object pointed to by ptr. Optional deleter d can be supplied, which is later used to destroy the new object when no shared_ptr objects own it. By default, delete expression is used as deleter. Proper delete expression corresponding to the supplied type is always selected, this is the reason why the function is implemented as template using a separate parameter Y.

If *this already owns an object and it is the last shared_ptr owning it, the object is destroyed through the owned deleter.

If the object pointed to by ptr is already owned, the function results in undefined behavior.

1) Releases the ownership of the managed object, if any. After the call, *this manages no object.

2-4) Replaces the managed object with an object pointed to by ptr. Y must be a complete type and implicitly convertible to T. Additionally:

2) Uses the delete expression as the deleter. A valid delete expression must be available, i.e. delete ptr must be well formed, have well-defined behavior and not throw any exceptions. Effectively calls shared_ptr<T>(ptr).swap(*this);.
3) Uses the specified deleter d as the deleter. Deleter must be callable for the type T, i.e. d(ptr) must be well formed, have well-defined behavior and not throw any exceptions. Deleter must be CopyConstructible. Effectively calls shared_ptr<T>(ptr, d).swap(*this);.
4) Same as (3), but additionally uses a copy of alloc for allocation of data for internal use. Alloc must be a Allocator. The copy constructor and destructor must not throw exceptions. Effectively calls shared_ptr<T>(ptr, d, alloc).swap(*this);.

Contents

[edit] Parameters

ptr - pointer to an object to acquire ownership of
d - deleter to store for deletion of the object
alloc - allocator to use for internal allocations

[edit] Return value

(none)

[edit] Exceptions

1)
noexcept specification:  
noexcept
  (since C++11)
2-4) As specified by the relevant constructor .

[edit] Example

[edit] See also

constructs new shared_ptr
(public member function) [edit]