std::allocator_traits<Alloc>::destroy

定义于头文件 <memory>
template< class T >
static void destroy( Alloc& a, T* p );
(C++11 起)
(C++20 前)
template< class T >
static constexpr void destroy( Alloc& a, T* p );
(C++20 起)

调用 p 所指向对象的析构函数。若可能,则通过调用 a.destroy(p) 这么做。若不可能(例如 Alloc 无成员函数 destroy() ),则直接调用 *p 的析构函数,同 p->~T() (C++20 前) std::destroy_at(p) (C++20 起)

参数

a - 用于析构的分配器
p - 指向要被销毁的对象的指针

返回值

(无)

注解

因为此函数提供到析构函数的自动回落,故 C++11 起成员函数 destroy()分配器 (Allocator) 的可选要求。

参阅

(C++17 中弃用)(C++20 中移除)
析构在已分配存储中的对象
(std::allocator<T> 的公开成员函数)