std::allocator_traits
來自 cppreference.com
定義於標頭檔案 <memory> |
||
template< class Alloc > struct allocator_traits; |
(C++11 起) | |
allocator_traits
類模板提供了一種標準化的方式來訪問 Allocator 的各種屬性。標準容器和其他標準庫元件透過此模板訪問分配器,從而可以使用任何類型別作為分配器,只要使用者提供的 std::allocator_traits
特化實現了所有必需的功能。
宣告 |
(C++23 起) |
預設的、非特化的 std::allocator_traits
包含以下成員
目錄 |
[編輯] 成員型別
型別 | 定義 |
allocator_type
|
Alloc
|
value_type
|
Alloc::value_type
|
pointer
|
如果存在,則為 Alloc::pointer ,否則為 value_type* |
const_pointer
|
如果存在,則為 Alloc::const_pointer ,否則為 std::pointer_traits<pointer>::rebind<const value_type> |
void_pointer
|
如果存在,則為 Alloc::void_pointer ,否則為 std::pointer_traits<pointer>::rebind<void> |
const_void_pointer
|
如果存在,則為 Alloc::const_void_pointer ,否則為 std::pointer_traits<pointer>::rebind<const void> |
difference_type
|
如果存在,則為 Alloc::difference_type ,否則為 std::pointer_traits<pointer>::difference_type |
size_type
|
如果存在,則為 Alloc::size_type ,否則為 std::make_unsigned<difference_type>::type |
propagate_on_container_copy_assignment
|
如果存在,則為 Alloc::propagate_on_container_copy_assignment ,否則為 std::false_type |
propagate_on_container_move_assignment
|
如果存在,則為 Alloc::propagate_on_container_move_assignment ,否則為 std::false_type |
propagate_on_container_swap
|
如果存在,則為 Alloc::propagate_on_container_swap ,否則為 std::false_type |
is_always_equal
|
如果存在,則為 Alloc::is_always_equal ,否則為 std::is_empty<Alloc>::type |
[編輯] 成員別名模板
型別 | 定義 |
rebind_alloc<T>
|
如果存在,則為 Alloc::rebind<T>::other ,否則如果此 Alloc 形式為 SomeAllocator<U, Args>,則為 SomeAllocator<T, Args> ,其中 Args 是零個或多個 型別引數 |
rebind_traits<T>
|
std::allocator_traits<rebind_alloc<T>> |
[編輯] 成員函式
[靜態] |
使用分配器分配未初始化的儲存 (public static member function) |
[static] (C++23) |
透過分配器分配至少請求大小的儲存空間 (public static member function) |
[靜態] |
使用分配器釋放儲存 (public static member function) |
[靜態] |
在已分配的儲存中構造一個物件 (function template) |
[靜態] |
銷燬儲存在已分配儲存中的物件 (function template) |
[靜態] |
返回分配器支援的最大物件大小 (public static member function) |
獲取複製標準容器後使用的分配器 (public static member function) |
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2108 | C++11 | 無法顯示分配器是無狀態的 | 提供 is_always_equal |
[編輯] 另請參閱
使用分配器的容器;相關特性(例如 propagate_on_container_swap )用法(命名要求) | |
預設分配器 (類模板) | |
(C++11) |
為多層容器實現多層分配器 (類模板) |
(C++11) |
提供有關類指標型別的資訊 (類模板) |