[#bsl-shared_ptr-0a-reset-0c8]
= xref:bsl.adoc[bsl]::xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]::reset
:relfileprefix: ../../
:mrdocs:

`reset` overloads

== Synopses

Declared in `&lt;bslstl&lowbar;sharedptr&period;h&gt;`

Reset this shared pointer to the empty state&period; If this shared pointer is managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last shared reference&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
xref:bsl/shared_ptr-0a/reset-0cc.adoc[reset]() noexcept;
----

[.small]#xref:bsl/shared_ptr-0a/reset-0cc.adoc[_» more&period;&period;&period;_]#

Modify this shared pointer to manage the modifiable object of the (template parameter) type `COMPATIBLE&lowbar;TYPE` at the specified `ptr` address and to refer to `(ELEMENT&lowbar;TYPE &ast;)ptr`&period; If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage `ptr`, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference&period; The currently installed default allocator is used to allocate the internal representation of this shared pointer, and the shared object will be destroyed by a call to `delete ptr` when all references have been released&period; If an exception is thrown allocating the internal representation, then `delete ptr` is called and this shared pointer retains ownership of its original object&period; If `COMPATIBLE&lowbar;TYPE&ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE&ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that if `ptr` is 0, then this shared pointer will still allocate an internal representation to share ownership of that empty state, which will be reclaimed when the last reference is destroyed&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class COMPATIBLE&lowbar;TYPE&gt;
void
xref:bsl/shared_ptr-0a/reset-07.adoc[reset](COMPATIBLE&lowbar;TYPE* ptr)
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/reset-07.adoc[_» more&period;&period;&period;_]#

Modify this shared pointer to manage the same modifiable object (if any) as the specified `source` shared pointer to the (template parameter) type `ANY&lowbar;TYPE`, and refer to the modifiable object at the specified `ptr` address (i&period;e&period;, make this shared pointer an &quot;alias&quot; of `source`)&period; If this shared pointer is already managing a (possibly shared) object, then release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference&period; Note that typically the objects referred to by `source` and `ptr` have identical lifetimes (e&period;g&period;, one might be a part of the other), so that the deleter for `source` will destroy them both, but do not necessarily have the same type&period; Also note that if `source` is empty, then this shared pointer will be reset to an empty state, even if `ptr` is not null (in which case this empty shared pointer will refer to the same object as `ptr`)&period; Also note that if `ptr` is null and `source` is not empty, then this shared pointer will be reset to a (reference&hyphen;counted) null pointer alias&period; Further note that the behavior of this method is the same as `loadAlias(source, ptr)`&period; Finally note that this is a non&hyphen;standard BDE extension to the C&plus;&plus; Standard `shared&lowbar;ptr` interface, which does not provide an alias overload for the `reset` function&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class ANY&lowbar;TYPE&gt;
void
xref:bsl/shared_ptr-0a/reset-04.adoc[reset](
    xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr&lt;ANY&lowbar;TYPE&gt;] const& source,
    ELEMENT&lowbar;TYPE* ptr);
----

[.small]#xref:bsl/shared_ptr-0a/reset-04.adoc[_» more&period;&period;&period;_]#

Modify this shared pointer to manage the modifiable object of the (template parameter) type `COMPATIBLE&lowbar;TYPE` at the specified `ptr` address, refer to `(ELEMENT&lowbar;TYPE &ast;)ptr`, and use the specified `deleter` to delete the shared object when all references have been released&period; If this shared pointer is already managing a (possibly shared) object, then unless an exception is thrown allocating memory to manage `ptr`, release the reference to the shared object, calling the associated deleter to destroy the shared object if this shared pointer is the last reference&period; If `DELETER` is an object type, then `deleter` is assumed to be a function&hyphen;like deleter that may be invoked to destroy the object referred to by a single argument of type `COMPATIBLE&lowbar;TYPE &ast;` (i&period;e&period;, `deleter(ptr)` will be called to destroy the shared object)&period; If `DELETER` is a pointer type that is not a function pointer, then `deleter` shall be a pointer to a factory object that exposes a member function that can be invoked as `deleteObject(ptr)` that will be called to destroy the object at the `ptr` address (i&period;e&period;, `deleter&hyphen;&gt;deleteObject(ptr)` will be called to delete the shared object)&period; (See the &quot;Deleters&quot; section in the component&hyphen;level documentation&period;) If `DELETER` is also a pointer to `bslma&colon;&colon;Allocator` or to a class derived from `bslma&colon;&colon;Allocator`, then that allocator will also be used to allocate and destroy the internal representation of this shared pointer when all references have been released&semi; otherwise, the currently installed default allocator is used to allocate and destroy the internal representation of this shared pointer when all references have been released&period; If an exception is thrown allocating the internal representation, then `deleter(ptr)` is called (or `deleter&hyphen;&gt;deleteObject(ptr)` for factory&hyphen;type deleters) and this shared pointer retains ownership of its original object&period; If `COMPATIBLE&lowbar;TYPE&ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE&ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that, for factory deleters, `deleter` must remain valid until all references to `ptr` have been released&period; If `ptr` is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of `deleter`&period; Further note that this function is logically equivalent to&colon; &grave; &ast;this &equals; shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;(ptr, deleter)&semi; &grave;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class COMPATIBLE&lowbar;TYPE,
    class DELETER&gt;
void
xref:bsl/shared_ptr-0a/reset-0e.adoc[reset](
    COMPATIBLE&lowbar;TYPE* ptr,
    DELETER deleter)
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/reset-0e.adoc[_» more&period;&period;&period;_]#

Modify this shared pointer to manage the modifiable object of the (template parameter) type `COMPATIBLE&lowbar;TYPE` at the specified `ptr` address, refer to `(ELEMENT&lowbar;TYPE &ast;)ptr` and use the specified `deleter` to delete the shared object when all references have been released&period; Use the specified `basicAllocator` to allocate and deallocate the internal representation of the shared pointer&period; If this shared pointer is already managing a (possibly shared) object, then, unless an exception is thrown allocating memory to manage `ptr`, release the shared reference to that shared object, and destroy it using its associated deleter if this shared pointer held the last shared reference to that object&period; If `DELETER` is a reference type, then `deleter` is assumed to be a function&hyphen;like deleter that may be invoked to destroy the object referred to by a single argument of type `COMPATIBLE&lowbar;TYPE &ast;` (i&period;e&period;, `deleter(ptr)` will be called to destroy the shared object)&period; If `DELETER` is a pointer type, then `deleter` is assumed to be a pointer to a factory object that exposes a member function that can be invoked as `deleteObject(ptr)` that will be called to destroy the object at the `ptr` address (i&period;e&period;, `deleter&hyphen;&gt;deleteObject(ptr)` will be called to delete the shared object)&period; (See the &quot;Deleters&quot; section in the component&hyphen;level documentation&period;) If an exception is thrown allocating the internal representation, then `deleter(ptr)` is called (or `deleter&hyphen;&gt;deleteObject(ptr)` for factory&hyphen;type deleters) and this shared pointer retains ownership of its original object&period; The behavior is undefined unless `deleter(ptr)` is a well&hyphen;defined expression (or `deleter&hyphen;&gt;deleteObject(ptr)` for factory&hyphen;type deleters), and unless the copy constructor for `deleter` does not throw an exception&period; If `COMPATIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; Note that, for factory deleters, the `deleter` must remain valid until all references to `ptr` have been released&period; Also note that if `ptr` is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of `deleter`&period; Further note that this function is logically equivalent to&colon; &grave; &ast;this &equals; shared&lowbar;ptr&lt;ELEMENT&lowbar;TYPE&gt;(ptr, deleter, basicAllocator)&semi; &grave;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class COMPATIBLE&lowbar;TYPE,
    class DELETER,
    class ALLOCATOR&gt;
void
xref:bsl/shared_ptr-0a/reset-06.adoc[reset](
    COMPATIBLE&lowbar;TYPE* ptr,
    DELETER deleter,
    ALLOCATOR basicAllocator)
requires is&lowbar;convertible&lt;COMPATIBLE&lowbar;TYPE &ast;, ELEMENT&lowbar;TYPE &ast;&gt;&colon;&colon;value;
----

[.small]#xref:bsl/shared_ptr-0a/reset-06.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
