std::experimental::pmr::resource_adaptor, std::pmr::experimental::resource_adaptor
定義於標頭檔案 <experimental/memory_resource> |
||
template< class Alloc > using resource_adaptor = /*resource-adaptor-imp*/< |
(庫基礎 TS) | |
template< class Alloc > class /*resource-adaptor-imp*/ : public memory_resource; // 僅用於解釋 |
(庫基礎 TS) | |
別名模板 resource_adaptor
將分配器型別 Alloc
適配到 memory_resource
介面。在實際適配之前(使用 resource-adaptor-imp
類模板),分配器會重新繫結到 char
值型別,這樣無論分配器模板最初使用何種值型別例項化,適配相同分配器模板的特化總是產生相同的型別。
|
(庫基礎 TS) (直到 library fundamentals TS v3) |
|
(庫基礎 TS v3) |
resource-adaptor-imp
是一個類模板,其成員如下所述。名稱 resource-adaptor-imp
僅用於解釋,不具規範性。
除了滿足 分配器 (Allocator) 要求外,Alloc
還必須滿足以下要求:
- std::allocator_traits<Alloc>::pointer 應與 Alloc::value_type* 相同。
- std::allocator_traits<Alloc>::const_pointer 應與 Alloc::value_type const* 相同。
- std::allocator_traits<Alloc>::void_pointer 應與 void* 相同。
- std::allocator_traits<Alloc>::const_const_pointer 應與 void const* 相同。
[編輯] resource-adaptor-imp 的成員型別
成員型別 | 定義 |
allocator_type
|
Alloc
|
[編輯] resource-adaptor-imp 的成員函式
resource-adaptor-imp::resource-adaptor-imp
/*resource-adaptor-imp*/() = default; |
(1) | (庫基礎 TS) |
/*resource-adaptor-imp*/(const /*resource-adaptor-imp*/& other) = default; |
(2) | (庫基礎 TS) |
/*resource-adaptor-imp*/(/*resource-adaptor-imp*/&& other) = default; |
(3) | (庫基礎 TS) |
explicit /*resource-adaptor-imp*/(const Alloc& a2); |
(4) | (庫基礎 TS) |
explicit /*resource-adaptor-imp*/(Alloc&& a2); |
(5) | (庫基礎 TS) |
other
所包裝的分配器複製構造所包裝的分配器。other
所包裝的分配器移動構造所包裝的分配器。a2
初始化所包裝的分配器。引數
其他 | - | 另一個 resource-adaptor-imp 物件,用於複製或移動 |
a2 | - | 另一個 Alloc 物件,用於複製或移動 |
resource-adaptor-imp::get_allocator
allocator_type get_allocator() const; |
(庫基礎 TS) | |
返回所包裝分配器的一個副本。
resource-adaptor-imp::operator=
/*resource-adaptor-imp*/& operator=(const /*resource-adaptor-imp*/& other) = default; |
(庫基礎 TS) | |
預設的複製賦值運算子。從 other
的所包裝分配器複製賦值。
resource-adaptor-imp::do_allocate
protected: virtual void* do_allocate(std::size_t bytes, std::size_t alignment); |
(庫基礎 TS) | |
使用所包裝分配器的 allocate
成員函式分配記憶體。
resource-adaptor-imp::do_deallocate
protected: virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment); |
(庫基礎 TS) | |
使用所包裝分配器的 deallocate
成員函式釋放 p
所指向的儲存。
p
必須是使用與所包裝分配器比較相等的分配器的 allocate
成員函式分配的,並且此後不得被釋放。
resource-adaptor-imp::do_is_equal
protected: virtual bool do_is_equal(const memory_resource& other) const noexcept; |
(庫基礎 TS) | |
令 p
為 dynamic_cast<const /*resource-adaptor-imp*/*>(&other)。如果 p
為空指標值,則返回 false。否則,返回使用 operator== 比較 *p 和 *this 所包裝的分配器的結果。