std::allocator_traits<Alloc>::destroy
来自 cppreference.cn
定义于头文件 <memory> |
||
template< class T > static void destroy( Alloc& a, T* p ); |
(C++11 起) (C++20 起为 constexpr) |
|
调用 p 所指向对象的析构函数。如果可能,通过调用 a.destroy(p) 来实现。如果不可能(例如 Alloc
没有成员函数 destroy()
),则直接调用 *p 的析构函数,即 p->~T()(C++20 前)调用 std::destroy_at(p)(C++20 起)。
目录 |
[编辑] 参数
a | - | 用于析构的分配器 |
p | - | - 指向要被销毁的对象的指针 |
[编辑] 返回值
(无)
[编辑] 注解
因为此函数提供了自动回退到直接调用析构函数的功能,所以从 C++11 起,成员函数 destroy()
是可选的 Allocator 要求。
[编辑] 示例
本节不完整 原因:无示例 |
[编辑] 参阅
(C++20 前) |
在已分配的存储中销毁对象 ( std::allocator<T> 的公开成员函数) |