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
 
1
+ ### Class template `inplace_vector` <a id="inplace.vector">[[inplace.vector]]</a>
2
+
3
+ #### Overview <a id="inplace.vector.overview">[[inplace.vector.overview]]</a>
4
+
5
+ An `inplace_vector` is a contiguous container. Its capacity is fixed and
6
+ its elements are stored within the `inplace_vector` object itself.
7
+
8
+ An `inplace_vector` meets all of the requirements of a container
9
+ [[container.reqmts]], of a reversible container
10
+ [[container.rev.reqmts]], of a contiguous container, and of a sequence
11
+ container, including most of the optional sequence container
12
+ requirements [[sequence.reqmts]]. The exceptions are the `push_front`,
13
+ `prepend_range`, `pop_front`, and `emplace_front` member functions,
14
+ which are not provided. Descriptions are provided here only for
15
+ operations on `inplace_vector` that are not described in one of these
16
+ tables or for operations where there is additional semantic information.
17
+
18
+ For any `N`, `inplace_vector<T, N>::iterator` and
19
+ `inplace_vector<T, N>::const_iterator` meet the constexpr iterator
20
+ requirements.
21
+
22
+ Any member function of `inplace_vector<T, N>` that would cause the size
23
+ to exceed `N` throws an exception of type `bad_alloc`.
24
+
25
+ Let `IV` denote a specialization of `inplace_vector<T, N>`. If `N` is
26
+ zero, then `IV` is trivially copyable and empty, and
27
+ `std::is_trivially_default_constructible_v<IV>` is `true`. Otherwise:
28
+
29
+ - If `is_trivially_copy_constructible_v<T>` is `true`, then `IV` has a
30
+ trivial copy constructor.
31
+ - If `is_trivially_move_constructible_v<T>` is `true`, then `IV` has a
32
+ trivial move constructor.
33
+ - If `is_trivially_destructible_v<T>` is `true`, then:
34
+ - `IV` has a trivial destructor.
35
+ - If
36
+ ``` cpp
37
+ is_trivially_copy_constructible_v<T> && is_trivially_copy_assignable_v<T>
38
+ ```
39
+
40
+ is `true`, then `IV` has a trivial copy assignment operator.
41
+ - If
42
+ ``` cpp
43
+ is_trivially_move_constructible_v<T> && is_trivially_move_assignable_v<T>
44
+ ```
45
+
46
+ is `true`, then `IV` has a trivial move assignment operator.
47
+
48
+ ``` cpp
49
+ namespace std {
50
+ template<class T, size_t N>
51
+ class inplace_vector {
52
+ public:
53
+ // types:
54
+ using value_type = T;
55
+ using pointer = T*;
56
+ using const_pointer = const T*;
57
+ using reference = value_type&;
58
+ using const_reference = const value_type&;
59
+ using size_type = size_t;
60
+ using difference_type = ptrdiff_t;
61
+ using iterator = implementation-defined // type of inplace_vector::iterator; // see [container.requirements]
62
+ using const_iterator = implementation-defined // type of inplace_vector::const_iterator; // see [container.requirements]
63
+ using reverse_iterator = std::reverse_iterator<iterator>;
64
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
65
+
66
+ // [inplace.vector.cons], construct/copy/destroy
67
+ constexpr inplace_vector() noexcept;
68
+ constexpr explicit inplace_vector(size_type n); // freestanding-deleted
69
+ constexpr inplace_vector(size_type n, const T& value); // freestanding-deleted
70
+ template<class InputIterator>
71
+ constexpr inplace_vector(InputIterator first, InputIterator last); // freestanding-deleted
72
+ template<container-compatible-range<T> R>
73
+ constexpr inplace_vector(from_range_t, R&& rg); // freestanding-deleted
74
+ constexpr inplace_vector(const inplace_vector&);
75
+ constexpr inplace_vector(inplace_vector&&)
76
+ noexcept(N == 0 || is_nothrow_move_constructible_v<T>);
77
+ constexpr inplace_vector(initializer_list<T> il); // freestanding-deleted
78
+ constexpr ~inplace_vector();
79
+ constexpr inplace_vector& operator=(const inplace_vector& other);
80
+ constexpr inplace_vector& operator=(inplace_vector&& other)
81
+ noexcept(N == 0 || (is_nothrow_move_assignable_v<T> &&
82
+ is_nothrow_move_constructible_v<T>));
83
+ constexpr inplace_vector& operator=(initializer_list<T>); // freestanding-deleted
84
+ template<class InputIterator>
85
+ constexpr void assign(InputIterator first, InputIterator last); // freestanding-deleted
86
+ template<container-compatible-range<T> R>
87
+ constexpr void assign_range(R&& rg); // freestanding-deleted
88
+ constexpr void assign(size_type n, const T& u); // freestanding-deleted
89
+ constexpr void assign(initializer_list<T> il); // freestanding-deleted
90
+
91
+ // iterators
92
+ constexpr iterator begin() noexcept;
93
+ constexpr const_iterator begin() const noexcept;
94
+ constexpr iterator end() noexcept;
95
+ constexpr const_iterator end() const noexcept;
96
+ constexpr reverse_iterator rbegin() noexcept;
97
+ constexpr const_reverse_iterator rbegin() const noexcept;
98
+ constexpr reverse_iterator rend() noexcept;
99
+ constexpr const_reverse_iterator rend() const noexcept;
100
+
101
+ constexpr const_iterator cbegin() const noexcept;
102
+ constexpr const_iterator cend() const noexcept;
103
+ constexpr const_reverse_iterator crbegin() const noexcept;
104
+ constexpr const_reverse_iterator crend() const noexcept;
105
+
106
+ // [inplace.vector.capacity], capacity
107
+ constexpr bool empty() const noexcept;
108
+ constexpr size_type size() const noexcept;
109
+ static constexpr size_type max_size() noexcept;
110
+ static constexpr size_type capacity() noexcept;
111
+ constexpr void resize(size_type sz); // freestanding-deleted
112
+ constexpr void resize(size_type sz, const T& c); // freestanding-deleted
113
+ static constexpr void reserve(size_type n); // freestanding-deleted
114
+ static constexpr void shrink_to_fit() noexcept;
115
+
116
+ // element access
117
+ constexpr reference operator[](size_type n);
118
+ constexpr const_reference operator[](size_type n) const;
119
+ constexpr reference at(size_type n); // freestanding-deleted
120
+ constexpr const_reference at(size_type n) const; // freestanding-deleted
121
+ constexpr reference front();
122
+ constexpr const_reference front() const;
123
+ constexpr reference back();
124
+ constexpr const_reference back() const;
125
+
126
+ // [inplace.vector.data], data access
127
+ constexpr T* data() noexcept;
128
+ constexpr const T* data() const noexcept;
129
+
130
+ // [inplace.vector.modifiers], modifiers
131
+ template<class... Args>
132
+ constexpr reference emplace_back(Args&&... args); // freestanding-deleted
133
+ constexpr reference push_back(const T& x); // freestanding-deleted
134
+ constexpr reference push_back(T&& x); // freestanding-deleted
135
+ template<container-compatible-range<T> R>
136
+ constexpr void append_range(R&& rg); // freestanding-deleted
137
+ constexpr void pop_back();
138
+
139
+ template<class... Args>
140
+ constexpr pointer try_emplace_back(Args&&... args);
141
+ constexpr pointer try_push_back(const T& x);
142
+ constexpr pointer try_push_back(T&& x);
143
+ template<container-compatible-range<T> R>
144
+ constexpr ranges::borrowed_iterator_t<R> try_append_range(R&& rg);
145
+
146
+ template<class... Args>
147
+ constexpr reference unchecked_emplace_back(Args&&... args);
148
+ constexpr reference unchecked_push_back(const T& x);
149
+ constexpr reference unchecked_push_back(T&& x);
150
+
151
+ template<class... Args>
152
+ constexpr iterator emplace(const_iterator position, Args&&... args); // freestanding-deleted
153
+ constexpr iterator insert(const_iterator position, const T& x); // freestanding-deleted
154
+ constexpr iterator insert(const_iterator position, T&& x); // freestanding-deleted
155
+ constexpr iterator insert(const_iterator position, size_type n, // freestanding-deleted
156
+ const T& x);
157
+ template<class InputIterator>
158
+ constexpr iterator insert(const_iterator position, // freestanding-deleted
159
+ InputIterator first, InputIterator last);
160
+ template<container-compatible-range<T> R>
161
+ constexpr iterator insert_range(const_iterator position, R&& rg); // freestanding-deleted
162
+ constexpr iterator insert(const_iterator position, // freestanding-deleted
163
+ initializer_list<T> il);
164
+ constexpr iterator erase(const_iterator position);
165
+ constexpr iterator erase(const_iterator first, const_iterator last);
166
+ constexpr void swap(inplace_vector& x)
167
+ noexcept(N == 0 || (is_nothrow_swappable_v<T> &&
168
+ is_nothrow_move_constructible_v<T>));
169
+ constexpr void clear() noexcept;
170
+
171
+ friend constexpr bool operator==(const inplace_vector& x,
172
+ const inplace_vector& y);
173
+ friend constexpr synth-three-way-result<T>
174
+ operator<=>(const inplace_vector& x, const inplace_vector& y);
175
+ friend constexpr void swap(inplace_vector& x, inplace_vector& y)
176
+ noexcept(N == 0 || (is_nothrow_swappable_v<T> &&
177
+ is_nothrow_move_constructible_v<T>))
178
+ { x.swap(y); }
179
+ };
180
+ }
181
+ ```
182
+
183
+ #### Constructors <a id="inplace.vector.cons">[[inplace.vector.cons]]</a>
184
+
185
+ ``` cpp
186
+ constexpr explicit inplace_vector(size_type n);
187
+ ```
188
+
189
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `inplace_vector`.
190
+
191
+ *Effects:* Constructs an `inplace_vector` with `n` default-inserted
192
+ elements.
193
+
194
+ *Complexity:* Linear in `n`.
195
+
196
+ ``` cpp
197
+ constexpr inplace_vector(size_type n, const T& value);
198
+ ```
199
+
200
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `inplace_vector`.
201
+
202
+ *Effects:* Constructs an `inplace_vector` with `n` copies of `value`.
203
+
204
+ *Complexity:* Linear in `n`.
205
+
206
+ ``` cpp
207
+ template<class InputIterator>
208
+ constexpr inplace_vector(InputIterator first, InputIterator last);
209
+ ```
210
+
211
+ *Effects:* Constructs an `inplace_vector` equal to the range \[`first`,
212
+ `last`).
213
+
214
+ *Complexity:* Linear in `distance(first, last)`.
215
+
216
+ ``` cpp
217
+ template<container-compatible-range<T> R>
218
+ constexpr inplace_vector(from_range_t, R&& rg);
219
+ ```
220
+
221
+ *Effects:* Constructs an `inplace_vector` with the elements of the range
222
+ `rg`.
223
+
224
+ *Complexity:* Linear in `ranges::distance(rg)`.
225
+
226
+ #### Capacity <a id="inplace.vector.capacity">[[inplace.vector.capacity]]</a>
227
+
228
+ ``` cpp
229
+ static constexpr size_type capacity() noexcept;
230
+ static constexpr size_type max_size() noexcept;
231
+ ```
232
+
233
+ *Returns:* `N`.
234
+
235
+ ``` cpp
236
+ constexpr void resize(size_type sz);
237
+ ```
238
+
239
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `inplace_vector`.
240
+
241
+ *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
242
+ the sequence. Otherwise, appends `sz - size()` default-inserted elements
243
+ to the sequence.
244
+
245
+ *Remarks:* If an exception is thrown, there are no effects on `*this`.
246
+
247
+ ``` cpp
248
+ constexpr void resize(size_type sz, const T& c);
249
+ ```
250
+
251
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `inplace_vector`.
252
+
253
+ *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
254
+ the sequence. Otherwise, appends `sz - size()` copies of `c` to the
255
+ sequence.
256
+
257
+ *Remarks:* If an exception is thrown, there are no effects on `*this`.
258
+
259
+ ``` cpp
260
+ static constexpr void reserve(size_type n);
261
+ ```
262
+
263
+ *Effects:* None.
264
+
265
+ *Throws:* `bad_alloc` if `n > capacity()` is `true`.
266
+
267
+ ``` cpp
268
+ static constexpr void shrink_to_fit() noexcept;
269
+ ```
270
+
271
+ *Effects:* None.
272
+
273
+ #### Data <a id="inplace.vector.data">[[inplace.vector.data]]</a>
274
+
275
+ ``` cpp
276
+ constexpr T* data() noexcept;
277
+ constexpr const T* data() const noexcept;
278
+ ```
279
+
280
+ *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
281
+ range. For a non-empty `inplace_vector`, `data() == addressof(front())`
282
+ is `true`.
283
+
284
+ *Complexity:* Constant time.
285
+
286
+ #### Modifiers <a id="inplace.vector.modifiers">[[inplace.vector.modifiers]]</a>
287
+
288
+ ``` cpp
289
+ constexpr iterator insert(const_iterator position, const T& x);
290
+ constexpr iterator insert(const_iterator position, T&& x);
291
+ constexpr iterator insert(const_iterator position, size_type n, const T& x);
292
+ template<class InputIterator>
293
+ constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last);
294
+ template<container-compatible-range<T> R>
295
+ constexpr iterator insert_range(const_iterator position, R&& rg);
296
+ constexpr iterator insert(const_iterator position, initializer_list<T> il);
297
+
298
+ template<class... Args>
299
+ constexpr iterator emplace(const_iterator position, Args&&... args);
300
+ template<container-compatible-range<T> R>
301
+ constexpr void append_range(R&& rg);
302
+ ```
303
+
304
+ Let n be the value of `size()` before this call for the `append_range`
305
+ overload, and `distance(begin, position)` otherwise.
306
+
307
+ *Complexity:* Linear in the number of elements inserted plus the
308
+ distance to the end of the vector.
309
+
310
+ *Remarks:* If an exception is thrown other than by the copy constructor,
311
+ move constructor, assignment operator, or move assignment operator of
312
+ `T` or by any `InputIterator` operation, there are no effects.
313
+ Otherwise, if an exception is thrown, then `size()` ≥ n and elements in
314
+ the range `begin() + ``[``0, `n`)` are not modified.
315
+
316
+ ``` cpp
317
+ constexpr reference push_back(const T& x);
318
+ constexpr reference push_back(T&& x);
319
+ template<class... Args>
320
+ constexpr reference emplace_back(Args&&... args);
321
+ ```
322
+
323
+ *Returns:* `back()`.
324
+
325
+ *Throws:* `bad_alloc` or any exception thrown by the initialization of
326
+ the inserted element.
327
+
328
+ *Complexity:* Constant.
329
+
330
+ *Remarks:* If an exception is thrown, there are no effects on `*this`.
331
+
332
+ ``` cpp
333
+ template<class... Args>
334
+ constexpr pointer try_emplace_back(Args&&... args);
335
+ constexpr pointer try_push_back(const T& x);
336
+ constexpr pointer try_push_back(T&& x);
337
+ ```
338
+
339
+ Let `vals` denote a pack:
340
+
341
+ - `std::forward<Args>(args)...` for the first overload,
342
+ - `x` for the second overload,
343
+ - `std::move(x)` for the third overload.
344
+
345
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
346
+ `inplace_vector` from `vals...`.
347
+
348
+ *Effects:* If `size() < capacity()` is `true`, appends an object of type
349
+ `T` direct-non-list-initialized with `vals...`. Otherwise, there are no
350
+ effects.
351
+
352
+ *Returns:* `nullptr` if `size() == capacity()` is `true`, otherwise
353
+ `addressof(back())`.
354
+
355
+ *Throws:* Nothing unless an exception is thrown by the initialization of
356
+ the inserted element.
357
+
358
+ *Complexity:* Constant.
359
+
360
+ *Remarks:* If an exception is thrown, there are no effects on `*this`.
361
+
362
+ ``` cpp
363
+ template<container-compatible-range<T> R>
364
+ constexpr ranges::borrowed_iterator_t<R> try_append_range(R&& rg);
365
+ ```
366
+
367
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
368
+ `inplace_vector` from
369
+ `*ranges::begin(rg)`.
370
+
371
+ *Effects:* Appends copies of initial elements in `rg` before `end()`,
372
+ until all elements are inserted or `size() == capacity()` is `true`.
373
+ Each iterator in the range `rg` is dereferenced at most once.
374
+
375
+ *Returns:* The first iterator in the range `ranges::begin(rg)`+\[0, `n`)
376
+ that was not inserted into `*this`, where `n` is the number of elements
377
+ in `rg`.
378
+
379
+ *Complexity:* Linear in the number of elements inserted.
380
+
381
+ *Remarks:* Let n be the value of `size()` prior to this call. If an
382
+ exception is thrown after the insertion of k elements, then `size()`
383
+ equals n + k, elements in the range `begin() + ``[``0, `n`)` are not
384
+ modified, and elements in the range `begin() + ``[`n`, `n + k`)`
385
+ correspond to the inserted elements.
386
+
387
+ ``` cpp
388
+ template<class... Args>
389
+ constexpr reference unchecked_emplace_back(Args&&... args);
390
+ ```
391
+
392
+ *Preconditions:* `size() < capacity()` is `true`.
393
+
394
+ *Effects:* Equivalent to:
395
+ `return *try_emplace_back(std::forward<Args>(args)...);`
396
+
397
+ ``` cpp
398
+ constexpr reference unchecked_push_back(const T& x);
399
+ constexpr reference unchecked_push_back(T&& x);
400
+ ```
401
+
402
+ *Preconditions:* `size() < capacity()` is `true`.
403
+
404
+ *Effects:* Equivalent to:
405
+ `return *try_push_back(std::forward<decltype(x)>(x));`
406
+
407
+ ``` cpp
408
+ constexpr iterator erase(const_iterator position);
409
+ constexpr iterator erase(const_iterator first, const_iterator last);
410
+ constexpr void pop_back();
411
+ ```
412
+
413
+ *Effects:* Invalidates iterators and references at or after the point of
414
+ the erase.
415
+
416
+ *Throws:* Nothing unless an exception is thrown by the assignment
417
+ operator or move assignment operator of `T`.
418
+
419
+ *Complexity:* The destructor of `T` is called the number of times equal
420
+ to the number of the elements erased, but the assignment operator of `T`
421
+ is called the number of times equal to the number of elements after the
422
+ erased elements.
423
+
424
+ #### Erasure <a id="inplace.vector.erasure">[[inplace.vector.erasure]]</a>
425
+
426
+ ``` cpp
427
+ template<class T, size_t N, class U = T>
428
+ constexpr size_t erase(inplace_vector<T, N>& c, const U& value);
429
+ ```
430
+
431
+ *Effects:* Equivalent to:
432
+
433
+ ``` cpp
434
+ auto it = remove(c.begin(), c.end(), value);
435
+ auto r = distance(it, c.end());
436
+ c.erase(it, c.end());
437
+ return r;
438
+ ```
439
+
440
+ ``` cpp
441
+ template<class T, size_t N, class Predicate>
442
+ constexpr size_t erase_if(inplace_vector<T, N>& c, Predicate pred);
443
+ ```
444
+
445
+ *Effects:* Equivalent to:
446
+
447
+ ``` cpp
448
+ auto it = remove_if(c.begin(), c.end(), pred);
449
+ auto r = distance(it, c.end());
450
+ c.erase(it, c.end());
451
+ return r;
452
+ ```
453
+