名稱空間
變體
操作

std::uses_allocator_construction_args

來自 cppreference.com
< cpp‎ | 記憶體
 
 
記憶體管理庫
(僅作說明*)
未初始化記憶體演算法
(C++17)
(C++17)
(C++17)
受約束的未初始化
記憶體演算法
C 庫

分配器
uses_allocator_construction_args
(C++20)
記憶體資源
垃圾回收支援
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
未初始化儲存
(直到 C++20*)
(直到 C++20*)
顯式生命週期管理
 
定義於標頭檔案 <memory>
T 不是 std::pair 的特化
template< class T, class Alloc, class... Args >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    Args&&... args ) noexcept;
(1) (C++20 起)
Tstd::pair 的特化
template< class T, class Alloc, class Tuple1, class Tuple2 >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::piecewise_construct_t, Tuple1&& x, Tuple2&& y ) noexcept;
(2) (C++20 起)
template< class T, class Alloc >
constexpr auto uses_allocator_construction_args( const Alloc& alloc ) noexcept;
(3) (C++20 起)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    U&& u, V&& v ) noexcept;
(4) (C++20 起)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::pair<U, V>& pr ) noexcept;
(5) (C++23 起)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    const std::pair<U, V>& pr ) noexcept;
(6) (C++20 起)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    std::pair<U, V>&& pr ) noexcept;
(7) (C++20 起)
template< class T, class Alloc, class U, class V >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    const std::pair<U, V>&& pr ) noexcept;
(8) (C++23 起)
template< class T, class Alloc, class NonPair >

constexpr auto uses_allocator_construction_args( const Alloc& alloc,

    NonPair&& non_pair ) noexcept;
(9) (C++20 起)

準備透過 uses-allocator 構造 建立給定型別 T 物件所需的引數列表。

1) 僅當 T 不是 std::pair 的特化時,此過載才參與過載決議。返回如下確定的 std::tuple
2) 僅當 Tstd::pair 的特化時,此過載才參與過載決議。對於 std::pair<T1, T2>T,等價於
return std::make_tuple(std::piecewise_construct,
    std::apply([&alloc](auto&&... args1)
        {
            return std::uses_allocator_construction_args<T1>(alloc,
                       std::forward<decltype(args1)>(args1)...);
        }, std::forward<Tuple1>(x)
    ),
    std::apply([&alloc](auto&&... args2)
        {
            return std::uses_allocator_construction_args<T2>(alloc,
                       std::forward<decltype(args2)>(args2)...);
        }, std::forward<Tuple2>(y)
    )
);
3) 僅當 Tstd::pair 的特化時,此過載才參與過載決議。等價於
return std::uses_allocator_construction_args<T>(alloc,
    std::piecewise_construct, std::tuple<>{}, std::tuple<>{}
);
4) 僅當 Tstd::pair 的特化時,此過載才參與過載決議。等價於
return std::uses_allocator_construction_args<T>(alloc,
    std::piecewise_construct,
    std::forward_as_tuple(std::forward<U>(u)),
    std::forward_as_tuple(std::forward<V>(v))
);
5,6) 僅當 Tstd::pair 的特化時,此過載才參與過載決議。等價於
return std::uses_allocator_construction_args<T>(alloc,
    std::piecewise_construct,
    std::forward_as_tuple(pr.first),
    std::forward_as_tuple(pr.second)
);
7,8) 僅當 Tstd::pair 的特化時,此過載才參與過載決議。等價於
return std::uses_allocator_construction_args<T>(alloc,
    std::piecewise_construct,
    std::forward_as_tuple(std::get<0>(std::move(pr))),
    std::forward_as_tuple(std::get<1>(std::move(pr)))
);
9) 僅當 Tstd::pair 的特化時,此過載才參與過載決議,並且給定僅用於展示的函式模板
template<class A, class B>
void /*deduce-as-pair*/(const std::pair<A, B>&);

,當作為未求值的運算元時,/*deduce-as-pair*/(non_pair) 是非良構的。
令僅用於展示的類 pair-constructor 定義為

class /*pair-constructor*/
{
    const Alloc& alloc_; // exposition only
    NonPair&     u_;     // exposition only
 
    constexpr reconstruct(const std::remove_cv<T>& p) const // exposition only
    {
        return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, p);
    }
 
    constexpr reconstruct(std::remove_cv<T>&& p) const // exposition only
    {
        return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, std::move(p));
    }
 
public:
    constexpr operator std::remove_cv<T>() const
    {
        return reconstruct(std::forward<NonPair>(u_));
    }
};
此過載等價於 return std::make_tuple(pair_construction);,其中 pair_constructionpair-constructor 型別的值,其 alloc_u_ 成員分別為 allocnon_pair

目錄

[編輯] 引數

alloc - 要使用的分配器
args - 要傳遞給 T 建構函式的引數
x - 要傳遞給 Tfirst 資料成員建構函式的引數元組
y - 要傳遞給 Tsecond 資料成員建構函式的引數元組
u - 要傳遞給 Tfirst 資料成員建構函式的單個引數
v - 要傳遞給 Tsecond 資料成員建構函式的單個引數
pr - 一個 pair,其 first 資料成員將傳遞給 Tfirst 資料成員的建構函式,其 second 資料成員將傳遞給 Tsecond 資料成員的建構函式
non_pair - 要轉換為 std::pair 以進行進一步構造的單個引數

[編輯] 返回值

適合傳遞給 T 建構函式的引數 std::tuple

[編輯] 注意

過載 (2-9) 提供分配器傳播到 std::pair 中,它不支援前置分配器或後置分配器呼叫約定(與例如使用前置分配器約定的 std::tuple 不同)。

當在 uses-allocator 構造中使用時,pair-constructor 的轉換函式首先將提供的引數轉換為 std::pair,然後透過 uses-allocator 構造從該 std::pair 構造結果。

[編輯] 示例

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3525 C++20 沒有過載可以處理可轉換為 pair 的非 pair 型別 添加了重構過載

[編輯] 參閱

檢查指定型別是否支援 uses-allocator 構造
(類模板) [編輯]
透過 uses-allocator 構造建立給定型別的物件
(函式模板) [編輯]
透過使用分配器構造在指定記憶體位置建立給定型別的物件
(函式模板) [編輯]