bsl::shared_ptr::reset

reset overloads

Synopses

Declared in <bslstl_sharedptr.h>

Reset this shared pointer to the empty state. 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.

void
reset() noexcept;
» more...

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address and to refer to (ELEMENT_TYPE *)ptr. 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. 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. If an exception is thrown allocating the internal representation, then delete ptr is called and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE* is not implicitly convertible to ELEMENT_TYPE*, then a compiler diagnostic will be emitted indicating the error. 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.

template<class COMPATIBLE_TYPE>
void
reset(COMPATIBLE_TYPE* ptr)
requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value;
» more...

Modify this shared pointer to manage the same modifiable object (if any) as the specified source shared pointer to the (template parameter) type ANY_TYPE, and refer to the modifiable object at the specified ptr address (i.e., make this shared pointer an "alias" of source). 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. Note that typically the objects referred to by source and ptr have identical lifetimes (e.g., 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. 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). Also note that if ptr is null and source is not empty, then this shared pointer will be reset to a (reference-counted) null pointer alias. Further note that the behavior of this method is the same as loadAlias(source, ptr). Finally note that this is a non-standard BDE extension to the C++ Standard shared_ptr interface, which does not provide an alias overload for the reset function.

template<class ANY_TYPE>
void
reset(
    shared_ptr<ANY_TYPE> const& source,
    ELEMENT_TYPE* ptr);
» more...

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address, refer to (ELEMENT_TYPE *)ptr, and use the specified deleter to delete the shared object when all references have been released. 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. If DELETER is an object type, then deleter is assumed to be a function-like deleter that may be invoked to destroy the object referred to by a single argument of type COMPATIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). 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.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If DELETER is also a pointer to bslma::Allocator or to a class derived from bslma::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; 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. If an exception is thrown allocating the internal representation, then deleter(ptr) is called (or deleter->deleteObject(ptr) for factory-type deleters) and this shared pointer retains ownership of its original object. If COMPATIBLE_TYPE* is not implicitly convertible to ELEMENT_TYPE*, then a compiler diagnostic will be emitted indicating the error. Note that, for factory deleters, deleter must remain valid until all references to ptr have been released. If ptr is 0, then an internal representation will still be allocated, and this shared pointer will share ownership of a copy of deleter. Further note that this function is logically equivalent to: ` *this = shared_ptr<ELEMENT_TYPE>(ptr, deleter); `

template<
    class COMPATIBLE_TYPE,
    class DELETER>
void
reset(
    COMPATIBLE_TYPE* ptr,
    DELETER deleter)
requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value;
» more...

Modify this shared pointer to manage the modifiable object of the (template parameter) type COMPATIBLE_TYPE at the specified ptr address, refer to (ELEMENT_TYPE *)ptr and use the specified deleter to delete the shared object when all references have been released. Use the specified basicAllocator to allocate and deallocate the internal representation of the shared pointer. 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. If DELETER is a reference type, then deleter is assumed to be a function-like deleter that may be invoked to destroy the object referred to by a single argument of type COMPATIBLE_TYPE * (i.e., deleter(ptr) will be called to destroy the shared object). 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.e., deleter->deleteObject(ptr) will be called to delete the shared object). (See the "Deleters" section in the component-level documentation.) If an exception is thrown allocating the internal representation, then deleter(ptr) is called (or deleter->deleteObject(ptr) for factory-type deleters) and this shared pointer retains ownership of its original object. The behavior is undefined unless deleter(ptr) is a well-defined expression (or deleter->deleteObject(ptr) for factory-type deleters), and unless the copy constructor for deleter does not throw an exception. If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted indicating the error. Note that, for factory deleters, the deleter must remain valid until all references to ptr have been released. 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. Further note that this function is logically equivalent to: ` *this = shared_ptr<ELEMENT_TYPE>(ptr, deleter, basicAllocator); `

template<
    class COMPATIBLE_TYPE,
    class DELETER,
    class ALLOCATOR>
void
reset(
    COMPATIBLE_TYPE* ptr,
    DELETER deleter,
    ALLOCATOR basicAllocator)
requires is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value;
» more...