std::uses_allocator_construction_args
定義於標頭檔案 <memory> |
||
T 不是 std::pair 的特化 |
||
template< class T, class Alloc, class... Args > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(1) | (C++20 起) |
T 是 std::pair 的特化 |
||
template< class T, class Alloc, class Tuple1, class Tuple2 > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(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, |
(4) | (C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(5) | (C++23 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(6) | (C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(7) | (C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(8) | (C++23 起) |
template< class T, class Alloc, class NonPair > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(9) | (C++20 起) |
準備透過 uses-allocator 構造 建立給定型別 T
物件所需的引數列表。
T
不是 std::pair 的特化時,此過載才參與過載決議。返回如下確定的 std::tuple- 如果 std::uses_allocator_v<T, Alloc> 為 false 且 std::is_constructible_v<T, Args...> 為 true,則返回 std::forward_as_tuple(std::forward<Args>(args)...)。
- 否則,如果 std::uses_allocator_v<T, Alloc> 為 true 且 std::is_constructible_v<T, std::allocator_arg_t, const Alloc&, Args...> 為 true,則返回
std::tuple<std::allocator_arg_t, const Alloc&, Args&&...>(std::allocator_arg, alloc,
std::forward<Args>(args)...). - 否則,如果 std::uses_allocator_v<T, Alloc> 為 true 且 std::is_constructible_v<T, Args..., const Alloc&> 為 true,則返回 std::forward_as_tuple(std::forward<Args>(args)..., alloc)。
- 否則,程式格式錯誤。
T
是 std::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) ) );
T
是 std::pair 的特化時,此過載才參與過載決議。等價於return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::tuple<>{}, std::tuple<>{} );
T
是 std::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)) );
T
是 std::pair 的特化時,此過載才參與過載決議。等價於return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::forward_as_tuple(pr.first), std::forward_as_tuple(pr.second) );
T
是 std::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))) );
T
是 std::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_)); } };
pair_construction
是 pair-constructor
型別的值,其 alloc_
和 u_
成員分別為 alloc
和 non_pair
。目錄 |
[編輯] 引數
alloc | - | 要使用的分配器 |
args | - | 要傳遞給 T 建構函式的引數 |
x | - | 要傳遞給 T 的 first 資料成員建構函式的引數元組 |
y | - | 要傳遞給 T 的 second 資料成員建構函式的引數元組 |
u | - | 要傳遞給 T 的 first 資料成員建構函式的單個引數 |
v | - | 要傳遞給 T 的 second 資料成員建構函式的單個引數 |
pr | - | 一個 pair,其 first 資料成員將傳遞給 T 的 first 資料成員的建構函式,其 second 資料成員將傳遞給 T 的 second 資料成員的建構函式 |
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 型別 |
添加了重構過載 |
[編輯] 參閱
(C++11) |
檢查指定型別是否支援 uses-allocator 構造 (類模板) |
(C++20) |
透過 uses-allocator 構造建立給定型別的物件 (函式模板) |
透過使用分配器構造在指定記憶體位置建立給定型別的物件 (函式模板) |