名稱空間
變體
操作

std::experimental::pmr::resource_adaptor, std::pmr::experimental::resource_adaptor

來自 cppreference.com
< cpp‎ | 實驗性
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (併發 TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
 
定義於標頭檔案 <experimental/memory_resource>
template< class Alloc >

using resource_adaptor = /*resource-adaptor-imp*/<
                             typename std::allocator_traits<Alloc>::

                             template rebind_alloc<char>>;
(庫基礎 TS)
template< class Alloc >
class /*resource-adaptor-imp*/ : public memory_resource; // 僅用於解釋
(庫基礎 TS)

別名模板 resource_adaptor 將分配器型別 Alloc 適配到 memory_resource 介面。在實際適配之前(使用 resource-adaptor-imp 類模板),分配器會重新繫結到 char 值型別,這樣無論分配器模板最初使用何種值型別例項化,適配相同分配器模板的特化總是產生相同的型別。

resource_adaptor 定義在名稱空間 std::experimental::pmr 中,此頁面中的基型別 memory_resourcestd::experimental::pmr::memory_resource

(庫基礎 TS)
(直到 library fundamentals TS v3)

resource_adaptor 定義在名稱空間 std::pmr::experimental 中,此頁面中的基型別 memory_resourcestd::pmr::memory_resource

(庫基礎 TS v3)

resource-adaptor-imp 是一個類模板,其成員如下所述。名稱 resource-adaptor-imp 僅用於解釋,不具規範性。

除了滿足 分配器 (Allocator) 要求外,Alloc 還必須滿足以下要求:

[編輯] 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)
1) 預設建構函式。預設構造所包裝的分配器。
2) 複製建構函式。從 other 所包裝的分配器複製構造所包裝的分配器。
3) 移動建構函式。從 other 所包裝的分配器移動構造所包裝的分配器。
4) 使用 a2 初始化所包裝的分配器。
5) 使用 std::move(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)

pdynamic_cast<const /*resource-adaptor-imp*/*>(&other)。如果 p 為空指標值,則返回 false。否則,返回使用 operator== 比較 *p*this 所包裝的分配器的結果。