cpp/memory/shared ptr/shared ptr

Constructs new from a variety of pointer types that refer to an object to manage.

@1-2@ Constructs a with no managed object, i.e. empty

@3-7@ Constructs a with  as the pointer to the managed object.

Additionally:


 * @3@ Uses the delete-expression  as the deleter.  must be a complete type. The delete expression must be well-formed, have well-defined behavior and not throw any exceptions.


 * @4-5@ Uses the specified deleter as the deleter. The expression  must be well formed, have well-defined behavior and not throw any exceptions. The construction of  and of the stored deleter copied from it must not throw exceptions.


 * @6-7@ Same as, but additionally uses a copy of  for allocation of data for internal use.  must be an.

@8@ The aliasing constructor: constructs a which shares ownership information with the initial value of, but holds an unrelated and unmanaged pointer. If this is the last of the group to go out of scope, it will call the stored deleter for the object originally managed by. However, calling on this  will always return a copy of. It is the responsibility of the programmer to make sure that this remains valid as long as this shared_ptr exists, such as in the typical use cases where  is a member of the object managed by  or is an alias (e.g., downcast) of

@9@ Constructs a which shares ownership of the object managed by. If manages no object,  manages no object either. The template overload doesn't participate in overload resolution if is not.

@10@ Move-constructs a from. After the construction, contains a copy of the previous state of,  is empty and its stored pointer is null. The template overload doesn't participate in overload resolution if is not.

@11@ Constructs a which shares ownership of the object managed by. Note that may be used for the same purpose: the difference is that this constructor throws an exception if the argument is empty, while  constructs an empty  in that case.

@12@ Constructs a that stores and owns the object formerly owned by. must be convertible to. After construction, is empty.

@13@ Constructs a which manages the object currently managed by. The deleter associated with is stored for future deletion of the managed object. manages no object after the call. If is a reference type, it is equivalent to. Otherwise, it is equivalent to

When is not an array type, the overloads, , and  enable  with , and the overload  enables  with the pointer returned by.

Exceptions
@3@ std if required additional memory could not be obtained. May throw implementation-defined exception for other errors. If an exception occurs, this calls.

@4-7@ std if required additional memory could not be obtained. May throw implementation-defined exception for other errors. is called if an exception occurs.

@11@ std if. The constructor has no effect in this case.

@12@ std if required additional memory could not be obtained. May throw implementation-defined exception for other errors. This constructor has no effect if an exception occurs.

@13@ If an exception is thrown, the constructor has no effects.