Namespaces (命名空间)
Variants (变体)
Actions (操作)

std::experimental::shared_ptr

From cppreference.cn (来自 cppreference.cn)
 
 
 
 
 
Defined in header <experimental/memory> (定义于头文件 <experimental/memory>)
template< class T > class shared_ptr;
(library fundamentals TS) ((库基础 TS))

std::experimental::shared_ptr is a modified version of std::shared_ptr that adds support for arrays. (std::experimental::shared_ptrstd::shared_ptr 的修改版本,增加了对数组的支持。)

Contents (目录)

[edit (编辑)] Member types (成员类型)

Member type (成员类型) Definition (定义)
element_type std::remove_extent_t<T>

[edit (编辑)] Member functions (成员函数)

constructs new shared_ptr (构造新的 shared_ptr)
(public member function) ((公共成员函数)) [edit (编辑)]
Observers (观察器)
returns the stored pointer (返回存储的指针)
(public member function) ((公共成员函数)) [edit (编辑)]
dereferences the stored pointer (解引用存储的指针)
(public member function) ((公共成员函数)) [edit (编辑)]
provides index access to the array (提供对数组的索引访问)
(public member function) ((公共成员函数)) [edit (编辑)]

[edit (编辑)] Non-member functions (非成员函数)

applies static_cast, dynamic_cast, const_cast, or reinterpret_cast to the stored pointer (将 static_castdynamic_castconst_castreinterpret_cast 应用于存储的指针)
(function template) ((函数模板)) [edit (编辑)]

[edit (编辑)] Helper classes (辅助类)

hash support for std::experimental::shared_ptr (对 std::experimental::shared_ptr 的哈希支持)
(class template specialization) ((类模板特化)) [edit (编辑)]

Members and non-members identical to std::shared_ptr (与 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. (以下成员函数与 std::experimental::shared_ptr 而不是 std::shared_ptr 一起使用,以及与 std::experimental::weak_ptr 而不是 std::weak_ptr 一起使用。其他行为相同。)

destructs the owned object if no more shared_ptrs link to it (如果没有更多的 shared_ptr 链接到它,则析构拥有的对象)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
assigns the shared_ptr (赋值 shared_ptr)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
Modifiers (修改器)
replaces the managed object (替换被管理的对象)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
swaps the managed objects (交换被管理的对象)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
Observers (观察器)
returns the number of shared_ptr objects referring to the same managed object (返回引用同一被管理对象的 shared_ptr 对象的数量)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
(until C++20) ((直到 C++20))
checks whether the managed object is managed only by the current shared_ptr object (检查被管理的对象是否仅由当前的 shared_ptr 对象管理)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
checks if the stored pointer is not null (检查存储的指针是否非空)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [edit (编辑)]
provides owner-based ordering of shared pointers (提供基于所有者的共享指针排序)
(public member function of std::shared_ptr<T>) ((std::shared_ptr<T> 的公共成员函数)) [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. (这些非成员函数在 std::experimental 命名空间中声明,并与 std::experimental::shared_ptr 而不是 std::shared_ptr 一起使用,但在其他方面与相应的 C++14 函数行为相同。)

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 (编辑)]
returns the deleter of specified type, if owned (如果拥有,则返回指定类型的删除器)
(function template) ((函数模板)) [edit (编辑)]
(removed in C++20) ((在 C++20 中移除))(removed in C++20) ((在 C++20 中移除))(removed in C++20) ((在 C++20 中移除))(removed in C++20) ((在 C++20 中移除))(removed in C++20) ((在 C++20 中移除))(C++20)
compares with another shared_ptr or with nullptr (与另一个 shared_ptrnullptr 比较)
(function template) ((函数模板)) [edit (编辑)]
outputs the value of the stored pointer to an output stream (将存储的指针的值输出到输出流)
(function template) ((函数模板)) [edit (编辑)]
specializes the std::swap algorithm (特化 std::swap 算法)
(function template) ((函数模板)) [edit (编辑)]
specializes atomic operations for std::shared_ptr (特化 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. (这些类模板在 std::experimental 命名空间中声明,并与 std::experimental::shared_ptrstd::experimental::weak_ptr 而不是 std::shared_ptrstd::weak_ptr 一起使用,但在其他方面与相应的 C++14 类模板行为相同。)

(C++11) ((C++11))
provides mixed-type owner-based ordering of shared and weak pointers (提供共享指针和弱指针的混合类型、基于所有者的排序)
(class template) ((类模板)) [edit (编辑)]
(C++11) ((C++11))
allows an object to create a shared_ptr referring to itself (允许对象创建引用自身的 shared_ptr)
(class template) ((类模板)) [edit (编辑)]

[edit (编辑)] Example (示例)