5
5
* cpp20[ meta cpp]
6
6
7
7
``` 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
26
69
```
27
70
* see below[italic]
28
71
29
72
## 概要
30
73
`Alloc` 型のアロケータオブジェクト `alloc` を使用した `T` 型オブジェクトの uses-allocator 構築のために必要なコンストラクタ引数を、[`tuple`](../tuple/tuple.md) 型にして返す。
74
+
31
75
また、`T` が [`pair`](../utility/pair.md) だった場合は、それぞれの要素に対して uses-allocator 構築するために必要なコンストラクタ引数を、[`tuple`](../tuple/tuple.md) 型にして返す。
32
76
33
77
構築対象の型 `T` は関数引数からは推論できないため、明示的に指定する必要がある。
34
78
35
79
36
80
## テンプレートパラメータ制約
37
81
- (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)`した場合に適格ではないこと
39
87
40
88
41
89
## 戻り値
42
- - (1) : 以下のいずれかと同等
90
+ - (1) : 以下のいずれかと等価
43
91
- もし [`uses_allocator_v`](uses_allocator.md)`<T, Alloc>` が `false` で、かつ、[`is_constructible_v`](../type_traits/is_constructible.md)`<T, Args...>` が `true` の場合、
44
92
45
93
```cpp
@@ -69,7 +117,7 @@ forward_as_tuple(std::forward<Args>(args)..., alloc)
69
117
70
118
- 上記以外の場合、不適格となる。
71
119
72
- - (2) : ` T ` を [ ` pair ` ] ( ../utility/pair.md ) ` <T1, T2> ` とすると、以下と同等
120
+ - (2) : ` T ` を [ ` pair ` ] ( ../utility/pair.md ) ` <T1, T2> ` とすると、以下と等価
73
121
74
122
```cpp
75
123
make_tuple(
@@ -89,7 +137,7 @@ make_tuple(
89
137
* apply[link ../tuple/apply.md]
90
138
* make_tuple[link ../tuple/make_tuple.md]
91
139
92
- - (3) : 以下と同等
140
+ - (3) : 以下と等価
93
141
94
142
```cpp
95
143
uses_allocator_construction_args<T>(alloc, piecewise_construct,
@@ -99,7 +147,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
99
147
* tuple[ link ../tuple/tuple/op_constructor.md]
100
148
* uses_allocator_construction_args[ color ff0000]
101
149
102
- - (4) : 以下と同等
150
+ - (4) : 以下と等価
103
151
104
152
```cpp
105
153
uses_allocator_construction_args<T >(alloc, piecewise_construct,
@@ -111,7 +159,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
111
159
* forward[link ../utility/forward.md]
112
160
* uses_allocator_construction_args[color ff0000]
113
161
114
- - (5) : 以下と同等
162
+ - (5), (6) : 以下と等価
115
163
116
164
```cpp
117
165
uses_allocator_construction_args<T>(alloc, piecewise_construct,
@@ -122,7 +170,7 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
122
170
* forward_as_tuple[ link ../tuple/forward_as_tuple.md]
123
171
* uses_allocator_construction_args[ color ff0000]
124
172
125
- - (6) : 以下と同等
173
+ - (7), (8) : 以下と等価
126
174
127
175
```cpp
128
176
uses_allocator_construction_args<T >(alloc, piecewise_construct,
@@ -134,6 +182,39 @@ uses_allocator_construction_args<T>(alloc, piecewise_construct,
134
182
* move[link ../utility/move.md]
135
183
* uses_allocator_construction_args[color ff0000]
136
184
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
+
137
218
138
219
## 備考
139
220
- 本関数は、uses-allocator 構築をサポートするために C++20 で導入された。
@@ -248,3 +329,4 @@ tuple(piecewise_construct_t, tuple(allocator_arg_t, MyAlloc, 3, ), tuple(4, MyAl
248
329
249
330
## 参照
250
331
- [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