Namespaces
Variants

std::allocator_traits<Alloc>:: destroy

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
定义于头文件 <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 - 指向待销毁对象的指针

返回值

(无)

注释

由于此函数提供了自动回退至直接调用析构函数的功能,成员函数 destroy() 自 C++11 起成为可选的 Allocator 要求。

示例

参见

(C++20 前)
销毁已分配存储中的对象
( std::allocator<T> 的公开成员函数)