Smart pointer with sole ownership of a managed object and a possibly distinct target.
Synopsis
Declared in <bslma_managedptr.h>
template<class TARGET_TYPE>
class ManagedPtr;
Description
This class is a "smart pointer" that refers to a target object accessed via a pointer to the specified parameter type, TARGET_TYPE, and that supports sole ownership of a managed object that is potentially of a different type, and may be an entirely different object from the target object. A managed pointer ensures that the object it manages is destroyed when the managed pointer is destroyed (or re‐assigned), using the "deleter" supplied along with the managed object. The target object referenced by a managed pointer may be accessed using either the ‐> operator, or the dereference operator (operator *). The specified TARGET_TYPE may be const‐qualified, but may not be volatile‐qualified, nor may it be a reference type.
A managed pointer may be empty, in which case it neither refers to a target object nor owns a managed object. An empty managed pointer is the equivalent of a null pointer: Such a managed pointer is not de‐referenceable, and tests as false in boolean expressions.
A managed pointer for which the managed object is not the same object as the target is said to alias the managed object (see the section "Aliasing" in the component‐level documentation).
Type Aliases
Name |
Description |
Alias for a function‐pointer type for functions used to destroy the object managed by a |
|
Alias to the |
Member Functions
Name |
Description |
|
Constructors |
|
Destroy this managed pointer and its managed object (if any). |
Assignment operators |
|
Destroy the current managed object (if any) and reset this managed pointer to empty. |
|
Return a reference to the non‐modifiable deleter information associated with this managed pointer. The behavior is undefined if this managed pointer is empty. |
|
Return the address of the target object, or 0 if this managed pointer is empty. |
|
|
|
Retarget or transfer ownership using the aliasing pointer |
|
Return a reference to the target object. The behavior is undefined if this managed pointer is empty, or if |
|
Return the address of the target object, or 0 if this managed pointer is empty. |
|
Return the address of the target object, or 0 if this managed pointer is empty. |
|
|
|
Destroy the current managed object (if any) and reset this managed pointer to empty. |
|
Exchange the value and ownership of this managed pointer with |
|
Return whether this managed pointer is non‐empty. |
|
Return a managed‐pointer reference to this object. |
|
Return |
|
Return |
Specializations
Name |
Description |
Incomplete specialization that rejects |
|
Incomplete specialization that rejects |
|
Incomplete specialization that rejects |
Friends
Name |
Description |
|
Smart pointer with sole ownership of a managed object and a possibly distinct target. |