Constructors

Synopses

Declared in <bslma_managedptr.h>

Create an empty managed pointer.

Create a managed pointer having the same target object as the specified original.

ManagedPtr(ManagedPtr& original) noexcept;

Create an empty managed pointer from a null pointer literal.

Create a managed pointer having the same target object as the managed pointer referenced by the specified ref, transfer ownership of the managed object owned by the managed pointer referenced by ref, and reset the managed pointer referenced by ref to empty. This constructor is used to create a managed pointer from a managed pointer rvalue, or from a managed pointer to a "compatible" type, where "compatible" means a built‐in conversion from COMPATIBLE_TYPE * to TARGET_TYPE * is defined, e.g., derived * to base *, T * to const T *, or T * to void *.

Create a managed pointer having the same target object as the specified original, transfer ownership of the object managed by original (if any) to this managed pointer, and reset original to empty.

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will call delete ptr to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case create an empty managed pointer. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. Note that this behavior allows ManagedPtr to be defined for void pointers, and to call the correct destructor for the managed object, even if the destructor for TARGET_TYPE is not declared as virtual. The behavior is undefined unless the managed object (if any) can be destroyed by delete, or if the lifetime of the managed object is already managed by another object.

template<class MANAGED_TYPE>
explicit
ManagedPtr(MANAGED_TYPE* ptr);

Create an empty managed pointer. Note that this constructor is necessary to match null‐pointer literal arguments, in order to break ambiguities and provide valid type deduction with the other constructor templates in this class.

Create an empty managed pointer. Note that the specified factory is ignored, as an empty managed pointer does not call its deleter.

template<class FACTORY_TYPE>
ManagedPtr(
    bsl::nullptr_t,
    FACTORY_TYPE* factory);

Create a managed pointer that takes ownership of the object managed by the specified alias, but which uses the specified ptr to refer to its target object, unless 0 == ptr, in which case create an empty managed pointer. Reset alias to empty if ownership of its managed object is transferred. The behavior is undefined if alias is empty, but 0 != ptr. Note that destroying or re‐assigning a managed pointer created with this constructor will destroy the object originally managed by alias (unless release is called first); the destructor for *ptr is not called directly.

template<class ALIASED_TYPE>
ManagedPtr(
    ManagedPtr<ALIASED_TYPE>& alias,
    TARGET_TYPE* ptr);

Move‐construct an aliasing managed pointer from the specified alias and ptr.

template<class ALIASED_TYPE>
ManagedPtr(
    ManagedPtr<ALIASED_TYPE>&& alias,
    TARGET_TYPE* ptr);

Move‐construct from a compatible managed pointer, transferring ownership from original.

template<class BDE_OTHER_TYPE>
ManagedPtr(
    ManagedPtr<BDE_OTHER_TYPE>&& original,
    ManagedPtr_TraitConstraint = ManagedPtr_TraitConstraint()) noexcept
requires bsl::is_convertible<BDE_OTHER_TYPE *, TARGET_TYPE *>::value;

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will call factory‐>deleteObject(ptr) to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case create an empty managed pointer. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The behavior is undefined unless the managed object (if any) can be destroyed by the specified factory, or if 0 == factory && 0 != ptr, or if the lifetime of the managed object is already managed by another object. Note that bslma::Allocator, and any class publicly and unambiguously derived from bslma::Allocator, meets the requirements for FACTORY_TYPE.

template<
    class MANAGED_TYPE,
    class FACTORY_TYPE>
ManagedPtr(
    MANAGED_TYPE* ptr,
    FACTORY_TYPE* factory);

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this constructor is required only because the deprecated overloads cause an ambiguity in its absence; it should be removed when the deprecated overloads are removed.

ManagedPtr(
    TARGET_TYPE* ptr,
    void* cookie,
    DeleterFunc deleter);

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr.

template<class MANAGED_TYPE>
ManagedPtr(
    MANAGED_TYPE* ptr,
    void* cookie,
    DeleterFunc deleter);

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *, and MANAGED_TYPE * is convertible to MANAGED_BASE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this constructor is needed only to avoid ambiguous type deductions when passing a null pointer literal as the cookie when the user passes a deleter taking a type other than void * for its object type. Also note that this function is deprecated as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE).

template<
    class MANAGED_TYPE,
    class MANAGED_BASE>
ManagedPtr(
    MANAGED_TYPE* ptr,
    void* cookie,
    void(* deleter)(MANAGED_BASE*, void*));

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *, and MANAGED_TYPE * is convertible to MANAGED_BASE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this function is deprecated as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE).

template<
    class MANAGED_TYPE,
    class MANAGED_BASE,
    class COOKIE_TYPE,
    class COOKIE_BASE>
ManagedPtr(
    MANAGED_TYPE* ptr,
    COOKIE_TYPE* cookie,
    void(* deleter)(MANAGED_BASE*, COOKIE_BASE*));

Created with MrDocs