memory
标准库标头<memory>
此标头是动态内存管理图书馆。
智能指针类别
*。
独树一帜[医]PTR%28C++11%29智能指针,具有唯一对象所有权语义%28类模板%29
共享[医]具有共享对象所有权语义的PTR%28C++11%29智能指针%28类模板%29
弱[医]ptr%28C++11%29弱引用到由std::Shared管理的对象[医]PTR%28类模板%29
汽车[医]PTR%28,直到C++17%29智能指针具有严格的对象所有权语义%28类模板%29
帮助者类
业主[医]减%28c++11%29提供了基于混合类型所有者的共享和弱指针排序%28类模板%29。
使能[医]共享[医]从[医]此%28C++11%29允许对象创建共享[医]PTR指的是它自己%28类模板%29
坏[医]弱[医]访问弱时引发的PTR%28C++11%29异常[医]PTR,指已销毁的对象%28级%29
违约[医]删除%28C++11%29默认删除[医]PTR%28类模板%29
分配器
默认分配器%28类模板%29
分配器[医]属性%28C++11%29提供有关分配程序类型的信息%28类模板%29
分配器[医]阿格[医]t%28C++11%29标记类型,用于选择分配器感知的构造函数重载%28class%29
分配器[医]Arg%28C++11%29是std类型的对象::[医]阿格[医]t用于选择分配器感知构造函数%28常量%29
使用[医]分配器%28C++11%29检查指定类型是否支持使用-分配程序构造%28类模板%29
未初始化存储
未初始化[医]将一系列对象复制到未初始化的内存区域%28函数模板%29
未初始化[医]复制[医]n%28C++11%29将多个对象复制到未初始化的内存区域%28函数模板%29
未初始化[医]填充将对象复制到未初始化的内存区域,该区域由范围%28函数模板%29定义
未初始化[医]填充[医]n将对象复制到未初始化的内存区域,该区域由开始和计数%28函数模板%29定义。
未初始化[医]移动%28C++17%29将一系列对象移动到未初始化的内存区域%28函数模板%29
未初始化[医]移动[医]n%28C++17%29将多个对象移动到未初始化的内存区域%28函数模板%29
未初始化[医]违约[医]构造%28C++17%29默认情况下在未初始化的内存区域中构造对象,该区域由范围%28函数模板%29定义
未初始化[医]违约[医]构造[医]默认情况下,n%28C++17%29在未初始化的内存区域中构造对象,由启动和计数%28函数模板%29定义。
未初始化[医]价值[医]构造%28C++17%29在未初始化的内存区域中通过值初始化构造对象,该区域由范围%28函数模板%29定义
未初始化[医]价值[医]构造[医]n%28C++17%29通过值初始化在未初始化的内存区域中构造对象,该区域由启动和计数%28函数模板%29定义
毁灭[医]在%28C++17%29中销毁给定地址的对象%28函数模板%29
销毁%28C++17%29销毁一系列对象%28功能模板%29
毁灭[医]n%28C++17%29销毁范围%28功能模板%29中的多个对象
生[医]储物[医]迭代器%28在C++17%29中不推荐,它允许标准算法存储未初始化内存%28类模板%29的结果
弄到[医]暂时性[医]C++17%29中不推荐的缓冲区%28获得未初始化的存储%28功能模板%29
回归[医]暂时性[医]缓冲区%28在C++17%29中不推荐使用,释放未初始化的存储%28功能模板%29
垃圾收集器支持
申报[医]可访问的%28C++11%29声明一个对象不能回收%28功能%29
未申报[医]可达%28C++11%29声明可以回收对象%28功能模板%29
申报[医]否[医]指针%28C++11%29声明内存区域不包含可跟踪指针%28函数%29
未申报[医]否[医]指针%28C++11%29取消std::[医]否[医]指针%28函数%29
指针[医]安全%28C++11%29列出指针安全模型%28类%29
弄到[医]指针[医]安全%28C++11%29返回当前指针安全模型%28函数%29
杂类
指针[医]属性%28C++11%29提供了关于类指针类型%28类模板%29的信息。
%28C++11%29的地址获得对象的实际地址,即使运算符重载%28函数模板%29
对齐%28C++11%29在缓冲区%28功能%29中对齐指针
智能指针非成员操作
*。
制造[医]唯一%28C++14%29创建一个管理新对象%28函数模板%29的唯一指针
运算符==运算符%21=运算符<运算符<=运算符>>=与另一个唯一的运算符比较[医]PTR或带Nullptr%28函数模板%29
制造[医]Shared创建一个管理新对象%28函数模板%29的共享指针
分配[医]Shared创建一个共享指针,该指针管理使用分配器%28函数模板%29分配的新对象。
静态[医]指针[医]浇注动力学[医]指针[医]蓖麻[医]指针[医]蓖麻解释[医]指针[医]铸造%28C++17%29应用静态[医]铸造、动态的[医]卡斯特[医]重释[医]转换到存储的指针%28函数模板%29
弄到[医]如果拥有%28函数模板%29,则Deleter返回指定类型的删除器。
运算符==运算符%21=运算符<运算符<=运算符>>=与另一个共享运算符比较[医]PTR或带Nullptr%28函数模板%29
运算符<<将存储指针的值输出到输出流%28函数模板%29
STD::原子[医]是[医]锁[医]免费%28 std::Shared[医]PTR%29 std::原子[医]Load%28std::Shared[医]PTR%29 std::原子[医]负载[医]显式%28std::Shared[医]PTR%29 std::原子[医]存储%28std::Shared[医]PTR%29 std::原子[医]商店[医]显式%28std::Shared[医]PTR%29 std::原子[医]Exchange%28std::Shared[医]PTR%29 std::原子[医]交换[医]显式%28std::Shared[医]PTR%29 std::原子[医]比较[医]交换[医]弱%28 std::共享[医]PTR%29 std::原子[医]比较[医]交换[医]强%28 std::Shared[医]PTR%29 std::原子[医]比较[医]交换[医]弱[医]显式%28std::Shared[医]PTR%29 std::原子[医]比较[医]交换[医]强[医]显式%28std::Shared[医]PTR%29专门针对STD::Shared进行原子操作[医]PTR%28功能模板%29
STD::SWAP%28std::UNIQUE[医]PTR%29%28C++11%29专门开发STD::交换算法%28函数模板%29
STD::交换%28 std::弱[医]PTR%29%28C++11%29专门开发STD::交换算法%28函数模板%29
STD::SWAP%28std::Shared[医]PTR%29%28C++11%29专门开发STD::交换算法%28函数模板%29
智能指针助手类
std::散列<std::UNIQUE[医]ptr>%28C++11%29散列支持[医]PTR%28类模板专门化%29
散列<std::共享[医]ptr>%28C++11%29散列支持[医]PTR%28类模板专门化%29
简介
二次
namespace std {
// pointer traits
template <class Ptr> struct pointer_traits;
template <class T> struct pointer_traits<T*>;
// pointer safety
enum class pointer_safety { relaxed, preferred, strict };
void declare_reachable(void* p
template <class T> T* undeclare_reachable(T* p
void declare_no_pointers(char* p, size_t n
void undeclare_no_pointers(char* p, size_t n
pointer_safety get_pointer_safety() noexcept;
// pointer alignment function
void* align(size_t alignment, size_t size, void*& ptr, size_t& space
// allocator argument tag
struct allocator_arg_t { explicit allocator_arg_t() = default; };
constexpr allocator_arg_t allocator_arg{};
// uses_allocator
template <class T, class Alloc> struct uses_allocator;
// allocator traits
template <class Alloc> struct allocator_traits;
// the default allocator
template <class T> class allocator;
template <class T, class U>
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
template <class T, class U>
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
// specialized algorithms
template <class T> constexpr T* addressof(T& r) noexcept;
template <class T> const T* addressof(const T&&) = delete;
template <class ForwardIterator>
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last
template <class ExecutionPolicy, class ForwardIterator>
void uninitialized_default_construct(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n
template <class ExecutionPolicy, class ForwardIterator, class Size>
ForwardIterator uninitialized_default_construct_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n
template <class ForwardIterator>
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last
template <class ExecutionPolicy, class ForwardIterator>
void uninitialized_value_construct(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n
template <class ExecutionPolicy, class ForwardIterator, class Size>
ForwardIterator uninitialized_value_construct_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n
template <class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
ForwardIterator result
template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_copy(ExecutionPolicy&& exec,
InputIterator first, InputIterator last,
ForwardIterator result
template <class InputIterator, class Size, class ForwardIterator>
ForwardIterator uninitialized_copy_n(InputIterator first, Size n,
ForwardIterator result
template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
ForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec,
InputIterator first, Size n,
ForwardIterator result
template <class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_move(InputIterator first, InputIterator last,
ForwardIterator result
template <class ExecutionPolicy, class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_move(ExecutionPolicy&& exec,
InputIterator first, InputIterator last,
ForwardIterator result
template <class InputIterator, class Size, class ForwardIterator>
pair<InputIterator, ForwardIterator>
uninitialized_move_n(InputIterator first, Size n, ForwardIterator result
template <class ExecutionPolicy, class InputIterator, class Size, class ForwardIterator>
pair<InputIterator, ForwardIterator>
uninitialized_move_n(ExecutionPolicy&& exec,
InputIterator first, Size n, ForwardIterator result
template <class ForwardIterator, class T>
void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x
template <class ExecutionPolicy, class ForwardIterator, class T>
void uninitialized_fill(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, const T& x
template <class ForwardIterator, class Size, class T>
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x
template <class ExecutionPolicy, class ForwardIterator, class Size, class T>
ForwardIterator uninitialized_fill_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n, const T& x
template <class T>
void destroy_at(T* location
template <class ForwardIterator>
void destroy(ForwardIterator first, ForwardIterator last
template <class ExecutionPolicy, class ForwardIterator>
void destroy(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last
template <class ForwardIterator, class Size>
ForwardIterator destroy_n(ForwardIterator first, Size n
template <class ExecutionPolicy, class ForwardIterator, class Size>
ForwardIterator destroy_n(ExecutionPolicy&& exec, ForwardIterator first, Size n
// class template unique_ptr
template <class T> struct default_delete;
template <class T> struct default_delete<T[]>;
template <class T, class D = default_delete<T>> class unique_ptr;
template <class T, class D> class unique_ptr<T[], D>;
template <class T, class... Args> unique_ptr<T> make_unique(Args&&... args
template <class T> unique_ptr<T> make_unique(size_t n
template <class T, class... Args> /*unspecified*/ make_unique(Args&&...) = delete;
template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
template <class T1, class D1, class T2, class D2>
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T1, class D1, class T2, class D2>
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T1, class D1, class T2, class D2>
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T1, class D1, class T2, class D2>
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T1, class D1, class T2, class D2>
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T1, class D1, class T2, class D2>
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y
template <class T, class D>
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
template <class T, class D>
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
template <class T, class D>
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
template <class T, class D>
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
template <class T, class D>
bool operator<(const unique_ptr<T, D>& x, nullptr_t
template <class T, class D>
bool operator<(nullptr_t, const unique_ptr<T, D>& y
template <class T, class D>
bool operator<=(const unique_ptr<T, D>& x, nullptr_t
template <class T, class D>
bool operator<=(nullptr_t, const unique_ptr<T, D>& y
template <class T, class D>
bool operator>(const unique_ptr<T, D>& x, nullptr_t
template <class T, class D>
bool operator>(nullptr_t, const unique_ptr<T, D>& y
template <class T, class D>
bool operator>=(const unique_ptr<T, D>& x, nullptr_t
template <class T, class D>
bool operator>=(nullptr_t, const unique_ptr<T, D>& y
// class bad_weak_ptr
class bad_weak_ptr;
// class template shared_ptr
template<class T> class shared_ptr;
// shared_ptr creation
template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args
template<class T, class A, class... Args>
shared_ptr<T> allocate_shared(const A& a, Args&&... args
// shared_ptr comparisons
template<class T, class U>
bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template<class T, class U>
bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template<class T, class U>
bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template<class T, class U>
bool operator>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template<class T, class U>
bool operator<=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template<class T, class U>
bool operator>=(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;
template <class T>
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
// shared_ptr specialized algorithms
template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
// shared_ptr casts
template<class T, class U>
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;
template<class T, class U>
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
template<class T, class U>
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;
// shared_ptr get_deleter
template<class D, class T> D* get_deleter(const shared_ptr<T>& p) noexcept;
// shared_ptr I/O
template<class E, class T, class Y>
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const shared_ptr<Y>& p
// class template weak_ptr
template<class T> class weak_ptr;
// weak_ptr specialized algorithms
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
// class template owner_less
template<class T = void> struct owner_less;
// class template enable_shared_from_this
template<class T> class enable_shared_from_this;
// shared_ptr atomic access
template<class T>
bool atomic_is_lock_free(const shared_ptr<T>* p
template<class T>
shared_ptr<T> atomic_load(const shared_ptr<T>* p
template<class T>
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo
template<class T>
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r
template<class T>
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo
template<class T>
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r
template<class T>
shared_ptr<T> atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r,
memory_order mo
template<class T>
bool atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w
template<class T>
bool atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w
template<class T>
bool atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
shared_ptr<T> w, memory_order success,
memory_order failure
template<class T>
bool atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
shared_ptr<T> w, memory_order success,
memory_order failure
// hash support
template <class T> struct hash;
template <class T, class D> struct hash<unique_ptr<T, D>>;
template <class T> struct hash<shared_ptr<T>>;
// uses_allocator
template <class T, class Alloc>
constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
}
二次
类模板std::pointer_traits
二次
namespace std {
template <class Ptr> struct pointer_traits {
using pointer = Ptr;
using element_type = /*see definition*/ ;
using difference_type = /*see definition*/ ;
template <class U> using rebind = /*see definition*/ ;
static pointer pointer_to(/*see definition*/ r
};
template <class T> struct pointer_traits<T*> {
using pointer = T*;
using element_type = T;
using difference_type = ptrdiff_t;
template <class U> using rebind = U*;
static pointer pointer_to(/*see definition*/ r) noexcept;
};
}
二次
类模板std::allocator_traits
二次
namespace std {
template <class Alloc> struct allocator_traits {
using allocator_type = Alloc;
using value_type = typename Alloc::value_type;
using pointer = /*see definition*/ ;
using const_pointer = /*see definition*/ ;
using void_pointer = /*see definition*/ ;
using const_void_pointer = /*see definition*/ ;
using difference_type = /*see definition*/ ;
using size_type = /*see definition*/ ;
using propagate_on_container_copy_assignment = /*see definition*/ ;
using propagate_on_container_move_assignment = /*see definition*/ ;
using propagate_on_container_swap = /*see definition*/ ;
using is_always_equal = /*see definition*/ ;
template <class T> using rebind_alloc = /*see definition*/ ;
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
static pointer allocate(Alloc& a, size_type n
static pointer allocate(Alloc& a, size_type n, const_void_pointer hint
static void deallocate(Alloc& a, pointer p, size_type n
template <class T, class... Args>
static void construct(Alloc& a, T* p, Args&&... args
template <class T>
static void destroy(Alloc& a, T* p
static size_type max_size(const Alloc& a) noexcept;
static Alloc select_on_container_copy_construction(const Alloc& rhs
};
}
二次
类模板std::allocator
二次
namespace std {
template <class T> class allocator {
public:
using value_type = T;
using propagate_on_container_move_assignment = true_type;
using is_always_equal = true_type;
allocator() noexcept;
allocator(const allocator&) noexcept;
template <class U> allocator(const allocator<U>&) noexcept;
~allocator(
T* allocate(size_t n
void deallocate(T* p, size_t n
};
}
二次
类模板std::default_delete
二次
namespace std {
template <class T>
struct default_delete {
constexpr default_delete() noexcept = default;
template <class U> default_delete(const default_delete<U>&) noexcept;
void operator()(T*) const;
};
template <class T>
struct default_delete<T[]> {
constexpr default_delete() noexcept = default;
template <class U> default_delete(const default_delete<U[]>&) noexcept;
template <class U> void operator()(U* ptr) const;
};
}
二次
类模板std::unique_ptr
二次
namespace std {
template <class T, class D = default_delete<T>>
class unique_ptr {
public:
using pointer = /*see definition*/ ;
using element_type = T;
using deleter_type = D;
// constructors
constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
unique_ptr(pointer p, /*see definition*/ d1) noexcept;
unique_ptr(pointer p, /*see definition*/ d2) noexcept;
unique_ptr(unique_ptr&& u) noexcept;
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
template <class U, class E>
unique_ptr(unique_ptr<U, E>&& u) noexcept;
// destructor
~unique_ptr(
// assignment
unique_ptr& operator=(unique_ptr&& u) noexcept;
template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
unique_ptr& operator=(nullptr_t) noexcept;
// observers
add_lvalue_reference_t<T> operator*() const;
pointer operator->() const noexcept;
pointer get() const noexcept;
deleter_type& get_deleter() noexcept;
const deleter_type& get_deleter() const noexcept;
explicit operator bool() const noexcept;
// modifiers
pointer release() noexcept;
void reset(pointer p = pointer()) noexcept;
void swap(unique_ptr& u) noexcept;
// disable copy from lvalue
unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
};
template <class T, class D>
class unique_ptr<T[], D> {
public:
using pointer = /*see definition*/ ;
using element_type = T;
using deleter_type = D;
// constructors
constexpr unique_ptr() noexcept;
template <class U> explicit unique_ptr(U p) noexcept;
template <class U> unique_ptr(U p, /*see definition*/d) noexcept;
template <class U> unique_ptr(U p, /*see definition*/d) noexcept;
unique_ptr(unique_ptr&& u) noexcept;
template <class U, class E>
unique_ptr(unique_ptr<U, E>&& u) noexcept;
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
// destructor
~unique_ptr(
// assignment
unique_ptr& operator=(unique_ptr&& u) noexcept;
template <class U, class E>
unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
unique_ptr& operator=(nullptr_t) noexcept;
// observers
T& operator[](size_t i) const;
pointer get() const noexcept;
deleter_type& get_deleter() noexcept;
const deleter_type& get_deleter() const noexcept;
explicit operator bool() const noexcept;
// modifiers
pointer release() noexcept;
template <class U> void reset(U p) noexcept;
void reset(nullptr_t = nullptr) noexcept;
void swap(unique_ptr& u) noexcept;
// disable copy from lvalue
unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
};
}
二次
类std::bad_weak_ptr
二次
namespace std {
class bad_weak_ptr : public exception {
public:
bad_weak_ptr() noexcept;
};
}
二次
类模板std::shared_ptr
二次
namespace std {
template<class T>
class shared_ptr {
public:
using element_type = remove_extent_t<T>;
using weak_type = weak_ptr<T>;
// constructors
constexpr shared_ptr() noexcept;
template<class Y> explicit shared_ptr(Y* p
template<class Y, class D> shared_ptr(Y* p, D d
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a
template <class D> shared_ptr(nullptr_t p, D d
template <class D, class A> shared_ptr(nullptr_t p, D d, A a
template<class Y> shared_ptr(const shared_ptr<Y>& r, element_type* p) noexcept;
shared_ptr(const shared_ptr& r) noexcept;
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
shared_ptr(shared_ptr&& r) noexcept;
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r
constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
// destructor
~shared_ptr(
// assignment
shared_ptr& operator=(const shared_ptr& r) noexcept;
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
shared_ptr& operator=(shared_ptr&& r) noexcept;
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r) noexcept;
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r
// modifiers
void swap(shared_ptr& r) noexcept;
void reset() noexcept;
template<class Y> void reset(Y* p
template<class Y, class D> void reset(Y* p, D d
template<class Y, class D, class A> void reset(Y* p, D d, A a
// observers
element_type* get() const noexcept;
T& operator*() const noexcept;
T* operator->() const noexcept;
element_type& operator[](ptrdiff_t i) const;
long use_count() const noexcept;
explicit operator bool() const noexcept;
template<class U> bool owner_before(const shared_ptr<U>& b) const;
template<class U> bool owner_before(const weak_ptr<U>& b) const;
};
}
二次
类模板std::weak_ptr
二次
namespace std {
template<class T>
class weak_ptr {
public:
using element_type = T;
// constructors
constexpr weak_ptr() noexcept;
template<class Y> weak_ptr(const shared_ptr<Y>& r) noexcept;
weak_ptr(const weak_ptr& r) noexcept;
template<class Y> weak_ptr(const weak_ptr<Y>& r) noexcept;
weak_ptr(weak_ptr&& r) noexcept;
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;
// destructor
~weak_ptr(
// assignment
weak_ptr& operator=(const weak_ptr& r) noexcept;
template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
weak_ptr& operator=(weak_ptr&& r) noexcept;
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
// modifiers
void swap(weak_ptr& r) noexcept;
void reset() noexcept;
// observers
long use_count() const noexcept;
bool expired() const noexcept;
shared_ptr<T> lock() const noexcept;
template<class U> bool owner_before(const shared_ptr<U>& b) const;
template<class U> bool owner_before(const weak_ptr<U>& b) const;
};
}
二次
类模板std::owner_less
二次
namespace std {
template<class T = void> struct owner_less;
template<class T> struct owner_less<shared_ptr<T>> {
bool operator()(const shared_ptr<T>&, const shared_ptr<T>&) const;
bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const;
bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const;
};
template<class T> struct owner_less<weak_ptr<T>> {
bool operator()(const weak_ptr<T>&, const weak_ptr<T>&) const;
bool operator()(const shared_ptr<T>&, const weak_ptr<T>&) const;
bool operator()(const weak_ptr<T>&, const shared_ptr<T>&) const;
};
template<> struct owner_less<void> {
template<class T, class U>
bool operator()(const shared_ptr<T>&, const shared_ptr<U>&) const;
template<class T, class U>
bool operator()(const shared_ptr<T>&, const weak_ptr<U>&) const;
template<class T, class U>
bool operator()(const weak_ptr<T>&, const shared_ptr<U>&) const;
template<class T, class U>
bool operator()(const weak_ptr<T>&, const weak_ptr<U>&) const;
using is_transparent = /*unspecified*/ ;
};
}
二次
类模板std::enable_shared_from_this
二次
namespace std {
template<class T> class enable_shared_from_this {
protected:
constexpr enable_shared_from_this() noexcept;
enable_shared_from_this(const enable_shared_from_this&) noexcept;
enable_shared_from_this& operator=(const enable_shared_from_this&) noexcept;
~enable_shared_from_this(
public:
shared_ptr<T> shared_from_this(
shared_ptr<T const> shared_from_this() const;
weak_ptr<T> weak_from_this() noexcept;
weak_ptr<T const> weak_from_this() const noexcept;
private:
mutable weak_ptr<T> weak_this; // exposition only
};
}
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。