[#BloombergLP-bslma-ManagedPtr-0fa] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::ManagedPtr :relfileprefix: ../../ :mrdocs: 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. == Synopsis Declared in `<bslma_managedptr.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class TARGET_TYPE> class ManagedPtr; ---- == Description 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 [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/ManagedPtr-0fa/DeleterFunc.adoc[`DeleterFunc`] | Alias for a function‐pointer type for functions used to destroy the object managed by a `ManagedPtr` object. | xref:BloombergLP/bslma/ManagedPtr-0fa/element_type.adoc[`element_type`] | Alias to the `TARGET_TYPE` template parameter. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0c.adoc[`ManagedPtr`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bslma/ManagedPtr-0fa/2destructor.adoc[`~ManagedPtr`] [.small]#[destructor]# | Destroy this managed pointer object. Destroy the object managed by this managed pointer by invoking the user‐supplied deleter, unless this managed pointer is empty, in which case the deleter will _not_ be called. | xref:BloombergLP/bslma/ManagedPtr-0fa/operator_assign-09.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bslma/ManagedPtr-0fa/clear.adoc[`clear`] | Destroy the current managed object (if any) and reset this managed pointer to empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/deleter.adoc[`deleter`] | Return a reference to the non‐modifiable deleter information associated with this managed pointer. The behavior is undefined if this managed pointer is empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/get.adoc[`get`] | Return the address of the target object, or 0 if this managed pointer is empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/load-0b.adoc[`load`] | `load` overloads | xref:BloombergLP/bslma/ManagedPtr-0fa/loadAlias.adoc[`loadAlias`] | If the specified `alias` manages the same object as this managed pointer, set the target object of this managed pointer to be that referenced by the specified `ptr`; otherwise, destroy the currently managed object (if any), and if `alias` is empty, reset this managed pointer to empty; otherwise, transfer ownership (and the deleter) of the object managed by `alias`, and set the target object of this managed pointer to be that referenced by `ptr`. The behavior is undefined if `0 == ptr` and `alias` is not empty, or if `0 != ptr` and `alias` is empty, or if `ptr` is already managed by a managed pointer other than `alias`. Note that this establishes a managed pointer where `ptr` aliases `alias`. The managed object for `alias` will ultimately be destroyed, and the destructor for `ptr` is not called directly. | xref:BloombergLP/bslma/ManagedPtr-0fa/operator_star.adoc[`operator*`] | Return a reference to the target object. The behavior is undefined if this managed pointer is empty, or if `TARGET_TYPE` is `void` or `const void`. | xref:BloombergLP/bslma/ManagedPtr-0fa/operator_ptr.adoc[`operator‐>`] | Return the address of the target object, or 0 if this managed pointer is empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/ptr.adoc[`ptr`] | Return the address of the target object, or 0 if this managed pointer is empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/release-05.adoc[`release`] | `release` overloads | xref:BloombergLP/bslma/ManagedPtr-0fa/reset.adoc[`reset`] | Destroy the current managed object (if any) and reset this managed pointer to empty. | xref:BloombergLP/bslma/ManagedPtr-0fa/swap.adoc[`swap`] | Exchange the value and ownership of this managed pointer with the specified `other` managed pointer. | xref:BloombergLP/bslma/ManagedPtr-0fa/2conversion-0a.adoc[`operator BoolType`] | Return a value of "unspecified bool" type that evaluates to `false` if this managed pointer is empty, and `true` otherwise. Note that this conversion operator allows a managed pointer to be used within a conditional context, such as within an `if` or `while` statement, but does _not_ allow managed pointers to be compared (e.g., via `<` or `>`). Also note that a superior solution is available in C++11 using the `explicit operator bool()` syntax, that removes the need for a special boolean‐like type and private equality‐comparison operators. | xref:BloombergLP/bslma/ManagedPtr-0fa/2conversion-0b.adoc[`operator ManagedPtr_Ref<REFERENCED_TYPE>`] | Return a managed pointer reference, referring to this object. Note that this conversion operator is used implicitly to allow the construction of managed pointers from rvalues because temporaries cannot be passed by references offering modifiable access. | xref:BloombergLP/bslma/ManagedPtr-0fa/operator_eq.adoc[`operator==`] | Return `true` if this managed pointer is empty, and `false` otherwise. | xref:BloombergLP/bslma/ManagedPtr-0fa/operator_not_eq.adoc[`operator!=`] | Return `false` if this managed pointer is empty, and `true` otherwise. |=== == Specializations [cols="1"] |=== | Name | xref:BloombergLP/bslma/ManagedPtr-0fd.adoc[`ManagedPtr<TARGET_TYPE volatile>`] | xref:BloombergLP/bslma/ManagedPtr-04.adoc[`ManagedPtr<TARGET_TYPE&>`] | xref:BloombergLP/bslma/ManagedPtr-09.adoc[`ManagedPtr<TARGET_TYPE&&>`] |=== == Friends [cols="1,4"] |=== | Name| Description | `BloombergLP::bslma::ManagedPtr` | 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. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/swap.adoc[`swap`] | Efficiently exchange the values of the specified `a` and `b` objects. This function provides the no‐throw exception‐safety guarantee. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#