55* cpp20[ meta cpp]
66
77``` cpp
8- template <class T , class Alloc, class... Args>
9- auto uses_allocator_construction_args(const Alloc& alloc, Args&&... args) -> see below; // (1)
10-
11- template<class T, class Alloc, class Tuple1, class Tuple2>
12- auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
13- Tuple1&& x, Tuple2&& y) -> see below; // (2)
14-
15- template<class T, class Alloc>
16- auto uses_allocator_construction_args(const Alloc& alloc) -> see below; // (3)
17-
18- template<class T, class Alloc, class U, class V>
19- auto uses_allocator_construction_args(const Alloc& alloc, U&& u, V&& v) -> see below; // (4)
20-
21- template<class T, class Alloc, class U, class V>
22- auto uses_allocator_construction_args(const Alloc& alloc, const pair<U, V>& pr) -> see below; // (5)
23-
24- template<class T, class Alloc, class U, class V>
25- auto uses_allocator_construction_args(const Alloc& alloc, pair<U, V>&& pr) -> see below; // (6)
8+ template <class T , class Alloc, class... Args>
9+ constexpr auto
10+ uses_allocator_construction_args(
11+ const Alloc& alloc,
12+ Args&&... args) -> see below; // (1) C++20
13+
14+ template <class T, class Alloc, class Tuple1, class Tuple2>
15+ constexpr auto
16+ uses_allocator_construction_args(
17+ const Alloc& alloc,
18+ piecewise_construct_t,
19+ Tuple1&& x,
20+ Tuple2&& y) -> see below; // (2) C++20
21+
22+ template <class T, class Alloc>
23+ constexpr auto
24+ uses_allocator_construction_args(
25+ const Alloc& alloc) -> see below; // (3) C++20
26+
27+ template <class T, class Alloc, class U, class V>
28+ constexpr auto
29+ uses_allocator_construction_args(
30+ const Alloc& alloc,
31+ U&& u,
32+ V&& v) -> see below; // (4) C++20
33+
34+ template <class T, class Alloc, class U, class V>
35+ constexpr auto
36+ uses_allocator_construction_args(
37+ const Alloc& alloc,
38+ pair<U,V>& pr) noexcept; // (5) C++23
39+
40+ template <class T, class Alloc, class U, class V>
41+ constexpr auto
42+ uses_allocator_construction_args(
43+ const Alloc& alloc,
44+ const pair<U, V>& pr) -> see below; // (6) C++20
45+
46+ template <class T, class Alloc, class U, class V>
47+ constexpr auto
48+ uses_allocator_construction_args(
49+ const Alloc& alloc,
50+ pair<U, V>&& pr) -> see below; // (7) C++20
51+
52+ template <class T, class Alloc, class U, class V>
53+ constexpr auto
54+ uses_allocator_construction_args(
55+ const Alloc& alloc,
56+ const pair<U,V>&& pr) noexcept; // (8) C++23
57+
58+ template <class T, class Alloc, pair-like P>
59+ constexpr auto
60+ uses_allocator_construction_args(
61+ const Alloc& alloc,
62+ P&& p) noexcept; // (9) C++23
63+
64+ template <class T, class Alloc, class U>
65+ constexpr auto
66+ uses_allocator_construction_args(
67+ const Alloc& alloc,
68+ U&& u) noexcept; // (10) C++23
2669```
2770* see below[italic]
2871
2972## 概要
3073`Alloc` 型のアロケータオブジェクト `alloc` を使用した `T` 型オブジェクトの uses-allocator 構築のために必要なコンストラクタ引数を、[`tuple`](../tuple/tuple.md) 型にして返す。
74+
3175また、`T` が [`pair`](../utility/pair.md) だった場合は、それぞれの要素に対して uses-allocator 構築するために必要なコンストラクタ引数を、[`tuple`](../tuple/tuple.md) 型にして返す。
3276
3377構築対象の型 `T` は関数引数からは推論できないため、明示的に指定する必要がある。
3478
3579
3680## テンプレートパラメータ制約
3781- (1) : `T` が [`pair`](../utility/pair.md) の特殊化**ではない**場合のみオーバーロード解決に参加する
38- - (2)-(6) : `T` が [`pair`](../utility/pair.md) の特殊化**である**場合のみオーバーロード解決に参加する
82+ - (2)-(10) : `T` が [`pair`](../utility/pair.md) の特殊化**である**場合のみオーバーロード解決に参加する
83+ - (9) : `P`が[`std::ranges::subrange`](/reference/ranges/subrange.md)の特殊化である場合のみオーバーロード解決に参加する
84+ - (10) : 以下のいずれかを満たす場合のみオーバーロード解決に参加する
85+ - `P`が[`std::ranges::subrange`](/reference/ranges/subrange.md)の特殊化であること。もしくは
86+ - `U`が`pair-like`の要件を満たさず、関数`template<class A, class B> void FUN (const pair<A, B>&);`に`FUN(u)`した場合に適格ではないこと
3987
4088
4189## 戻り値
42- - (1) : 以下のいずれかと同等
90+ - (1) : 以下のいずれかと等価
4391 - もし [`uses_allocator_v`](uses_allocator.md)`<T, Alloc>` が `false` で、かつ、[`is_constructible_v`](../type_traits/is_constructible.md)`<T, Args...>` が `true` の場合、
4492
4593 ```cpp
@@ -69,7 +117,7 @@ forward_as_tuple(std::forward<Args>(args)..., alloc)
69117
70118 - 上記以外の場合、不適格となる。
71119
72- - (2) : ` T ` を [ ` pair ` ] ( ../utility/pair.md ) ` <T1, T2> ` とすると、以下と同等
120+ - (2) : ` T ` を [ ` pair ` ] ( ../utility/pair.md ) ` <T1, T2> ` とすると、以下と等価
73121
74122 ```cpp
75123make_tuple(
@@ -89,7 +137,7 @@ make_tuple(
89137* apply[link ../tuple/apply.md]
90138* make_tuple[link ../tuple/make_tuple.md]
91139
92- - (3) : 以下と同等
140+ - (3) : 以下と等価
93141
94142 ```cpp
95143uses_allocator_construction_args<T>(alloc, piecewise_construct,
@@ -99,7 +147,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
99147* tuple[ link ../tuple/tuple/op_constructor.md]
100148* uses_allocator_construction_args[ color ff0000]
101149
102- - (4) : 以下と同等
150+ - (4) : 以下と等価
103151
104152 ```cpp
105153uses_allocator_construction_args<T >(alloc, piecewise_construct,
@@ -111,7 +159,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
111159* forward[link ../utility/forward.md]
112160* uses_allocator_construction_args[color ff0000]
113161
114- - (5) : 以下と同等
162+ - (5), (6) : 以下と等価
115163
116164 ```cpp
117165uses_allocator_construction_args<T>(alloc, piecewise_construct,
@@ -122,7 +170,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
122170* forward_as_tuple[ link ../tuple/forward_as_tuple.md]
123171* uses_allocator_construction_args[ color ff0000]
124172
125- - (6) : 以下と同等
173+ - (7), (8) : 以下と等価
126174
127175 ```cpp
128176uses_allocator_construction_args<T >(alloc, piecewise_construct,
@@ -134,6 +182,39 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
134182* move[link ../utility/move.md]
135183* uses_allocator_construction_args[color ff0000]
136184
185+ - (9) : 以下と等価
186+
187+ ```cpp
188+ return uses_allocator_construction_args<T>(alloc, piecewise_construct,
189+ forward_as_tuple(get<0>(std::forward<P>(p))),
190+ forward_as_tuple(get<1>(std::forward<P>(p))));
191+ ```
192+ * piecewise_construct[ link ../utility/piecewise_construct_t.md]
193+ * forward_as_tuple[ link ../tuple/forward_as_tuple.md]
194+
195+ - (10) : 以下の説明用クラスを定義し、
196+ ``` cpp
197+ class pair -constructor {
198+ using pair-type = remove_cv_t<T >;
199+ constexpr auto do-construct(const pair-type& p) const {
200+ return make_obj_using_allocator<pair-type >(alloc_ , p);
201+ }
202+
203+ constexpr auto do-construct(pair-type&& p) const {
204+ return make_obj_using_allocator<pair-type>(alloc_, std::move(p));
205+ }
206+
207+ const Alloc& alloc_;
208+ U& u_;
209+ public:
210+ constexpr operator pair-type() const {
211+ return do-construct(std::forward<U>(u_));
212+ }
213+ };
214+ ```
215+
216+ - `u`で`u_`、`alloc`で`alloc_`初期化した`pair-constructor`オブジェクト`pc`を生成し、`make_tuple(pc)`を返す
217+
137218
138219## 備考
139220- 本関数は、uses-allocator 構築をサポートするために C++20 で導入された。
@@ -248,3 +329,4 @@ tuple(piecewise_construct_t, tuple(allocator_arg_t, MyAlloc, 3, ), tuple(4, MyAl
248329
249330## 参照
250331- [P0591R4 Utility functions to implement uses-allocator construction](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0591r4.pdf)
332+ - [P2321R2 zip](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2321r2.html)
0 commit comments