##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::shared_ptr

From cppreference.com
< cpp‎ | experimental

Defined in header `<experimental/memory>` |  |
template< class T > class shared_ptr; |  | (library fundamentals TS)

`std::experimental::shared_ptr` is a modified version of std::shared_ptr that adds support for arrays.

### [edit] Member types

Member type | Definition
element_type | std::remove_extent_t<T>

### [edit] Member functions

(constructor) | constructs new `shared_ptr` (public member function) [edit]
##### Observers
get | returns the stored pointer (public member function) [edit]
operator*operator-> | dereferences the stored pointer (public member function) [edit]
operator[] | provides index access to the array (public member function) [edit]

### [edit] Non-member functions

static_pointer_cast dynamic_pointer_cast const_pointer_cast reinterpret_pointer_cast | applies `static_cast`, `dynamic_cast`, `const_cast`, or `reinterpret_cast` to the stored pointer (function template) [edit]

### [edit] Helper classes

std::hash<std::experimental::shared_ptr> | hash support for std::experimental::shared_ptr (class template specialization) [edit]

## Members and non-members identical to std::shared_ptr

### Member functions

The following member functions work with std::experimental::shared_ptr instead of std::shared_ptr and std::experimental::weak_ptr instead of std::weak_ptr. The behavior is otherwise identical.

(destructor) | destructs the owned object if no more `shared_ptr`s link to it (public member function of `std::shared_ptr`) [edit]
operator= | assigns the `shared_ptr` (public member function of `std::shared_ptr`) [edit]
##### Modifiers
reset | replaces the managed object (public member function of `std::shared_ptr`) [edit]
swap | swaps the managed objects (public member function of `std::shared_ptr`) [edit]
##### Observers
use_count | returns the number of `shared_ptr` objects referring to the same managed object (public member function of `std::shared_ptr`) [edit]
unique (deprecated) | checks whether the managed object is managed only by the current `shared_ptr` instance (public member function of `std::shared_ptr`) [edit]
operator bool | checks if the stored pointer is not null (public member function of `std::shared_ptr`) [edit]
owner_before | provides owner-based ordering of shared pointers (public member function of `std::shared_ptr`) [edit]

### Non-member functions

These non-member functions are declared in the `std::experimental` namespace, and work with `std::experimental::shared_ptr` rather than std::shared_ptr, but otherwise behaves identically to the corresponding C++14 function.

make_shared | creates a shared pointer that manages a new object (function template) [edit]
allocate_shared | creates a shared pointer that manages a new object allocated using an allocator (function template) [edit]
get_deleter | returns the deleter of specified type, if owned (function template) [edit]
operator==operator!=operator<operator<=operator>operator>= | compares with another `shared_ptr` or with nullptr (function template) [edit]
operator<< | outputs the value of the stored pointer to an output stream (function template) [edit]
std::swap(std::shared_ptr) (C++11) | specializes the std::swap algorithm (function template) [edit]

std::atomic_is_lock_free(std::shared_ptr)std::atomic_load(std::shared_ptr)std::atomic_load_explicit(std::shared_ptr)std::atomic_store(std::shared_ptr)std::atomic_store_explicit(std::shared_ptr)std::atomic_exchange(std::shared_ptr)std::atomic_exchange_explicit(std::shared_ptr)std::atomic_compare_exchange_weak(std::shared_ptr)std::atomic_compare_exchange_strong(std::shared_ptr)std::atomic_compare_exchange_weak_explicit(std::shared_ptr)std::atomic_compare_exchange_strong_explicit(std::shared_ptr) | specializes atomic operations for std::shared_ptr (function template) [edit]

### Helper class templates

These class templates are declared in the `std::experimental` namespace, and work with `std::experimental::shared_ptr` and std::experimental::weak_ptr rather than std::shared_ptr and std::weak_ptr, but otherwise behaves identically to the corresponding C++14 class template.

owner_less (C++11) | provides mixed-type owner-based ordering of shared and weak pointers (class template) [edit]
enable_shared_from_this (C++11) | allows an object to create a `shared_ptr` referring to itself (class template) [edit]

### [edit] Example

| This section is incomplete Reason: no example

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/shared_ptr&oldid=82300"
Category:

- Todo no example