| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Member functions | ||||
shared_ptr::shared_ptr | ||||
| Non-member functions | ||||
Members and non-members identical to those ofstd::shared_ptr |
constexpr shared_ptr()noexcept; | (1) | |
constexpr shared_ptr(std::nullptr_t)noexcept; | (2) | |
template<class Y> explicit shared_ptr( Y* ptr); | (3) | |
template<class Y,class Deleter> shared_ptr( Y* ptr, Deleter d); | (4) | |
template<class Deleter> shared_ptr(std::nullptr_t ptr, Deleter d); | (5) | |
template<class Y,class Deleter,class Alloc> shared_ptr( Y* ptr, Deleter d, Alloc alloc); | (6) | |
template<class Deleter,class Alloc> shared_ptr(std::nullptr_t ptr, Deleter d, Alloc alloc); | (7) | |
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type*ptr)noexcept; | (8) | |
shared_ptr(const shared_ptr& r)noexcept; | (9) | |
template<class Y> shared_ptr(const shared_ptr<Y>& r)noexcept; | (9) | |
shared_ptr( shared_ptr&& r)noexcept; | (10) | |
template<class Y> shared_ptr( shared_ptr<Y>&& r)noexcept; | (10) | |
template<class Y> explicit shared_ptr(conststd::weak_ptr<Y>& r); | (11) | |
template<class Y> shared_ptr(std::auto_ptr<Y>&& r); | (12) | |
template<class Y,class Deleter> shared_ptr(std::unique_ptr<Y,Deleter>&& r); | (13) | |
Constructs newshared_ptr from a variety of pointer types that refer to an object to manage.
For the purposes of the description below, a pointer typeY* is said to be compatible with a pointer typeT* if eitherY* is convertible toT* orY is the array typeU[N] andT isU cv [] (where cv is some set of cv-qualifiers).
shared_ptr with no managed object, i.e. emptyshared_ptr.shared_ptr withptr as the pointer to the managed object. IfT is an array typeU[N],Y(*)[N] must be convertible toT*. IfT is an array typeU[],Y(*)[] must be convertible toT*. Otherwise,Y* must be convertible toT*. Additionally:T is not an array type;delete[] ptr ifT is an array type) as the deleter.Y must be a complete type. That delete expression must be well formed, have well-defined behavior and not throw any exceptions.Deleter must beCopyConstructible, and its copy constructor and destructor must not throw exceptions.Alloc must be aAllocator, and its copy constructor and destructor must not throw exceptions.shared_ptr which shares ownership information withr, but holds an unrelated and unmanaged pointerptr. Even if thisshared_ptr is the last of the group to go out of scope, it will call the destructor for the object originally managed byr. However, callingget() on this will always return a copy ofptr. It is the responsibility of the programmer to make sure that thisptr remains valid as long as this shared_ptr exists, such as in the typical use cases whereptr is a member of the object managed byr or is an alias (e.g., downcast) ofr.get().shared_ptr which shares ownership of the object managed byr. Ifr manages no object,*this manages no object too. The template overload doesn't participate in overload resolution ifY* is notcompatible withT*.shared_ptr fromr. After the construction,*this contains a copy of the previous state ofr,r is empty. The template overload doesn't participate in overload resolution ifY* is notcompatible withT*.shared_ptr which shares ownership of the object managed byr.Y* must becompatible withT*. Note thatr.lock() may be used for the same purpose: the difference is that this constructor throws an exception if the argument is empty, whileweak_ptr<T>::lock() constructs an emptyshared_ptr in that case.shared_ptr that stores and owns the object formerly owned byr.Y* must be convertible toT*. After construction,r is empty.shared_ptr which manages the object currently managed byr. The deleter associated withr is stored for future deletion of the managed object.r manages no object after the call. This overload doesn't participate in overload resolution ifY* is notcompatible withT*.D is a reference type, equivalent toshared_ptr(r.release(),std::ref(r.get_deleter()). Otherwise, equivalent toshared_ptr(r.release(), r.get_deleter()).Contents |
When constructing ashared_ptr from a raw pointer to an object of a type derived fromstd::experimental::enable_shared_from_this, the constructors ofshared_ptr update the privateweak_ptr member of thestd::experimental::enable_shared_from_this base so that future calls toshared_from_this() would share ownership with theshared_ptr created by this raw pointer constructor.
The raw pointer overloads assume ownership of the pointed-to object, and so constructing ashared_ptr using the raw pointer overload for an object that is already managed by ashared_ptr may lead to undefined behavior, even if the object is of a type derived fromstd::experimental::enable_shared_from_this.
| ptr | - | a pointer to an object to manage |
| d | - | a deleter to use to destroy the object |
| alloc | - | an allocator to use for allocations of data for internal use |
| r | - | another smart pointer to share the ownership to or acquire the ownership from |
T is not an array type,delete[] ptr otherwise) is called if an exception occurs.| This section is incomplete Reason: no example |
| creates a shared pointer that manages a new object (function template)[edit] | |
| creates a shared pointer that manages a new object allocated using an allocator (function template)[edit] |