Constructors

Synopses

Declared in <bslstl_sharedptr.h>

Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.

constexpr
shared_ptr() noexcept;

Copy‐construct a shared_ptr from original.

shared_ptr(shared_ptr const& original) noexcept;

Create a shared_ptr sharing ownership with a compatible other.

template<class COMPATIBLE_TYPE>
shared_ptr(shared_ptr<COMPATIBLE_TYPE> const& other) noexcept;

Move‐construct a shared_ptr from a compatible other.

template<class COMPATIBLE_TYPE>
shared_ptr(shared_ptr<COMPATIBLE_TYPE>&& other) noexcept;

Create an empty shared pointer, i.e., a shared pointer with no representation that does not refer to any object and has no deleter.

constexpr
shared_ptr(bsl::nullptr_t nullPointerLiteral) noexcept;

Move‐construct a shared_ptr from original.

Create a shared_ptr from a weak_ptr, or empty if expired.

template<class COMPATIBLE_TYPE>
explicit
shared_ptr(weak_ptr<COMPATIBLE_TYPE> const& ptr);

Create a shared_ptr that manages the object at ptr.

template<class CONVERTIBLE_TYPE>
explicit
shared_ptr(CONVERTIBLE_TYPE* ptr);

Create an empty shared pointer.

shared_ptr(
    nullptr_t nullPointerLiteral,
    BloombergLP::bslma::Allocator* basicAllocator);

Create a shared_ptr from the specified arguments.

explicit
shared_ptr(
    std::auto_ptr_ref<ELEMENT_TYPE> autoRef,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create a shared_ptr from the specified arguments.

Create a shared_ptr by adopting ownership from a managed pointer.

template<class CONVERTIBLE_TYPE>
shared_ptr(
    BloombergLP::bslma::ManagedPtr<CONVERTIBLE_TYPE> managedPtr,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create a shared_ptr from the specified arguments.

template<class CONVERTIBLE_TYPE>
explicit
shared_ptr(
    std::auto_ptr<CONVERTIBLE_TYPE>& autoPtr,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create an aliased shared_ptr sharing ownership with source.

template<class ANY_TYPE>
shared_ptr(
    shared_ptr<ANY_TYPE> const& source,
    ELEMENT_TYPE* object) noexcept;

Create a shared_ptr managing ptr using basicAllocator.

template<class CONVERTIBLE_TYPE>
shared_ptr(
    CONVERTIBLE_TYPE* ptr,
    BloombergLP::bslma::Allocator* basicAllocator);

Create a shared_ptr by adopting ownership from a unique pointer.

template<
    class COMPATIBLE_TYPE,
    class UNIQUE_DELETER>
requires is_convertible<
                      typename std::unique_ptr<COMPATIBLE_TYPE,
                                               UNIQUE_DELETER>::pointer,
                      ELEMENT_TYPE *>::value
shared_ptr(
    std::unique_ptr<COMPATIBLE_TYPE, UNIQUE_DELETER>&& adoptee,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create a shared_ptr managing ptr with a custom deleter.

template<
    class CONVERTIBLE_TYPE,
    class DELETER>
shared_ptr(
    CONVERTIBLE_TYPE* ptr,
    DELETER* deleter);

Create a shared_ptr from the specified arguments.

Create a shared_ptr owning null with a deleter.

template<class DELETER>
shared_ptr(
    nullptr_t nullPointerLiteral,
    DELETER deleter,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create a shared_ptr managing ptr with a deleter and allocator.

template<
    class CONVERTIBLE_TYPE,
    class DELETER>
shared_ptr(
    CONVERTIBLE_TYPE* ptr,
    DELETER deleter,
    BloombergLP::bslma::Allocator* basicAllocator = 0);

Create a shared_ptr owning null with a deleter and allocator.

template<
    class DELETER,
    class ALLOCATOR>
shared_ptr(
    nullptr_t nullPointerLiteral,
    DELETER deleter,
    ALLOCATOR basicAllocator,
    ALLOCATOR::value_type* sfinae = 0);

Create a shared_ptr managing ptr with a custom deleter.

template<
    class CONVERTIBLE_TYPE,
    class DELETER,
    class ALLOCATOR>
shared_ptr(
    CONVERTIBLE_TYPE* ptr,
    DELETER deleter,
    ALLOCATOR basicAllocator,
    ALLOCATOR::value_type* sfinae = 0);

Parameters

Name

Description

original

source object to copy or move from

other

other pointer to compare or share ownership with

nullPointerLiteral

null‐pointer literal (unused; selects this overload)

ptr

pointer to the object to manage or refer to

basicAllocator

allocator used to supply memory

rep

shared‐pointer representation object

managedPtr

managed pointer whose ownership is transferred

source

source shared pointer that supplies ownership

object

object to refer to while sharing ownership with source

adoptee

unique pointer whose ownership is transferred

deleter

deleter invoked when the last shared reference is released

tag

tag selecting the existing‐representation constructor

sfinae

unused SFINAE discriminator

Created with MrDocs