[#BloombergLP-bslma-ManagedPtr-0fa-2constructor-0c] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr]::ManagedPtr :relfileprefix: ../../../ :mrdocs: Constructors == Synopses Declared in `<bslma_managedptr.h>` Create an empty managed pointer. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-01f.adoc[ManagedPtr](); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-01f.adoc[_» more..._]# Create a managed pointer having the same target object as the specified `original`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-008.adoc[ManagedPtr](xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr]& original) noexcept; ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-008.adoc[_» more..._]# Create an empty managed pointer from a null pointer literal. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-06.adoc[ManagedPtr](xref:bsl/nullptr_t-08.adoc[bsl::nullptr_t]); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-06.adoc[_» more..._]# 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 *`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0b.adoc[ManagedPtr](xref:BloombergLP/bslma/ManagedPtr_Ref.adoc[ManagedPtr_Ref<TARGET_TYPE>] ref) noexcept; ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0b.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-052c.adoc[ManagedPtr](xref:BloombergLP/bslmf/MovableRef.adoc[bslmf::MovableRef<ManagedPtr>] original) noexcept; ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-052c.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class MANAGED_TYPE> explicit xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-083.adoc[ManagedPtr](MANAGED_TYPE* ptr); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-083.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- explicit xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-012.adoc[ManagedPtr]( xref:bsl/nullptr_t-08.adoc[bsl::nullptr_t], xref:bsl/nullptr_t-08.adoc[bsl::nullptr_t]); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-012.adoc[_» more..._]# Create an empty managed pointer. Note that the specified `factory` is ignored, as an empty managed pointer does not call its deleter. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class FACTORY_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0a.adoc[ManagedPtr]( xref:bsl/nullptr_t-08.adoc[bsl::nullptr_t], FACTORY_TYPE* factory); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0a.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ALIASED_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0524.adoc[ManagedPtr]( xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr<ALIASED_TYPE>]& alias, TARGET_TYPE* ptr); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0524.adoc[_» more..._]# Move‐construct an aliasing managed pointer from the specified `alias` and `ptr`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ALIASED_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d3.adoc[ManagedPtr]( xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr<ALIASED_TYPE>]&& alias, TARGET_TYPE* ptr); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d3.adoc[_» more..._]# Move‐construct from a compatible managed pointer, transferring ownership from `original`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class BDE_OTHER_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-09.adoc[ManagedPtr]( xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr<BDE_OTHER_TYPE>]&& original, xref:BloombergLP/bslma/ManagedPtr_TraitConstraint.adoc[ManagedPtr_TraitConstraint] = ManagedPtr_TraitConstraint()) noexcept requires bsl::is_convertible<BDE_OTHER_TYPE *, TARGET_TYPE *>::value; ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-09.adoc[_» more..._]# 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`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class MANAGED_TYPE, class FACTORY_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-07.adoc[ManagedPtr]( MANAGED_TYPE* ptr, FACTORY_TYPE* factory); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-07.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0e.adoc[ManagedPtr]( TARGET_TYPE* ptr, void* cookie, xref:BloombergLP/bslma/ManagedPtr-0fa/DeleterFunc.adoc[DeleterFunc] deleter); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0e.adoc[_» more..._]# 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`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class MANAGED_TYPE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-006.adoc[ManagedPtr]( MANAGED_TYPE* ptr, void* cookie, xref:BloombergLP/bslma/ManagedPtr-0fa/DeleterFunc.adoc[DeleterFunc] deleter); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-006.adoc[_» more..._]# 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). [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class MANAGED_TYPE, class MANAGED_BASE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-086.adoc[ManagedPtr]( MANAGED_TYPE* ptr, void* cookie, void(* deleter)(MANAGED_BASE*, void*)); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-086.adoc[_» more..._]# 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). [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class MANAGED_TYPE, class MANAGED_BASE, class COOKIE_TYPE, class COOKIE_BASE> xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d9.adoc[ManagedPtr]( MANAGED_TYPE* ptr, COOKIE_TYPE* cookie, void(* deleter)(MANAGED_BASE*, COOKIE_BASE*)); ---- [.small]#xref:BloombergLP/bslma/ManagedPtr-0fa/2constructor-0d9.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#