Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_VECTOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_VECTOR_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
9
10// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
18#include "arene/base/detail/exceptions.hpp"
19#include "arene/base/detail/wrapped_iterator.hpp" // IWYU pragma: keep
20#include "arene/base/inline_container/detail/unsafe_element_storage.hpp"
27#include "arene/base/stdlib_choice/cstddef.hpp"
28#include "arene/base/stdlib_choice/enable_if.hpp"
29#include "arene/base/stdlib_choice/forward.hpp"
30#include "arene/base/stdlib_choice/initializer_list.hpp"
31#include "arene/base/stdlib_choice/integral_constant.hpp"
32#include "arene/base/stdlib_choice/is_assignable.hpp"
33#include "arene/base/stdlib_choice/is_constructible.hpp"
34#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
35#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
36#include "arene/base/stdlib_choice/is_default_constructible.hpp"
37#include "arene/base/stdlib_choice/is_destructible.hpp"
38#include "arene/base/stdlib_choice/is_move_assignable.hpp"
39#include "arene/base/stdlib_choice/is_move_constructible.hpp"
40#include "arene/base/stdlib_choice/is_same.hpp"
41#include "arene/base/stdlib_choice/iterator_traits.hpp"
42#include "arene/base/stdlib_choice/min_value_overload.hpp"
43#include "arene/base/stdlib_choice/move.hpp"
44#include "arene/base/stdlib_choice/move_iterator.hpp"
54
55// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
56
57// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
58// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
59// parasoft-begin-suppress CERT_CPP-ERR55-a-2 "False positive: Exception specification is conditional"
60// parasoft-begin-suppress CERT_CPP-ERR50-h-3 "False positive: Exception specification is conditional"
61// parasoft-begin-suppress CERT_CPP-ERR50-g-3 "False positive: Exception specification is conditional"
62// parasoft-begin-suppress CERT_CPP-ERR51-b-3 "False positive: Exception specification is conditional"
63// parasoft-begin-suppress AUTOSAR-A15_3_2-a-2 "False positive: Exception specification is conditional"
64// parasoft-begin-suppress AUTOSAR-A15_5_3-g-2 "False positive: Exception specification is conditional"
65// parasoft-begin-suppress AUTOSAR-A15_5_3-h-2 "False positive: Exception specification is conditional"
66// parasoft-begin-suppress AUTOSAR-M15_3_4-b-2 "False positive: Exception is caught"
67// parasoft-begin-suppress AUTOSAR-A15_2_1-b-2 "False positive: Throwing constructor not invoked"
68// parasoft-begin-suppress CERT_CPP-ERR50-b-3 "False positive: Called functions are noexcept"
69// parasoft-begin-suppress AUTOSAR-A15_5_1-a-2 "False positive: Called functions are noexcept"
70// parasoft-begin-suppress AUTOSAR-A15_5_3-b-2 "False positive: Called functions are noexcept"
71// parasoft-begin-suppress CERT_CPP-DCL57-a-2 "False positive: Called functions are noexcept"
72
73namespace arene {
74namespace base {
75
76/// @brief A container similar to @c std::vector<T> that has a fixed capacity. The storage for the elements is held
77/// directly within the class. Any attempt to store more than @c Capacity elements will cause an @c ARENE_PRECONDITION
78/// violation
79/// @tparam T The type of each element
80/// @tparam Capacity The maximum number of elements that can be stored.
81template <typename T, std::size_t Capacity>
82class inline_vector;
83
84namespace inline_vector_detail {
85
86/// @brief implementation details for @c inline_vector which depend on neither the capacity nor the storage mechanism.
87template <typename T>
88class vector_base {
89 protected:
90 /// @brief Tag type used to protect construction of iterators.
91 class iterator_passkey {
92 public:
93 /// @brief The default constructor is explicit to disable construction with just @c {}
94 constexpr explicit iterator_passkey() noexcept = default;
95 };
96
97 public:
98 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False Positive: These identifiers do not hide anything"
99 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False Positive: These identifiers do not hide anything"
100 /// @brief The type used for the size of the vector.
101 using size_type = std::size_t;
102 /// @brief The type of a value stored in the vector
103 using value_type = T;
104 /// @brief The type of a reference to a value stored in the vector
105 using reference = value_type&;
106 /// @brief The type of a const reference to a value stored in the vector
107 using const_reference = value_type const&;
108 /// @brief The type of a pointer to an element stored in the container
109 using pointer = value_type*;
110 /// @brief The type of a const pointer to an element stored in the container
111 using const_pointer = value_type const*;
112 /// @brief The type of an iterator to a position in the vector
113 using iterator = ::arene::base::detail::wrapped_iterator<pointer, iterator_passkey>;
114 /// @brief The type of a const iterator to a position in the vector
115 using const_iterator = ::arene::base::detail::wrapped_iterator<const_pointer, iterator_passkey>;
116 /// @brief The type of a reverse-iterator to a position in the vector
117 using reverse_iterator = ::arene::base::reverse_iterator<iterator>;
118 /// @brief The type of a const reverse-iterator to a position in the vector
119 using const_reverse_iterator = ::arene::base::reverse_iterator<const_iterator>;
120 /// @brief The type of the difference between two iterators
121 using difference_type = typename iterator::difference_type;
122 // parasoft-end-suppress AUTOSAR-A2_10_1-e
123 // parasoft-end-suppress AUTOSAR-A2_10_1-d
124};
125
126/// @brief Type trait to check if we can construct a vector of @c T in c constexpr
127/// contexts. The result is @c true if we can, @c false otherwise.
128/// @tparam T the type being checked.
129template <typename T>
130constexpr bool allow_constexpr_vector_v =
131 std::is_trivially_default_constructible<T>::value && std::is_trivially_move_assignable<T>::value;
132
133/// @brief Base class for @c inline_vector that holds the elements when the elements aren't usable in @c constexpr
134/// contexts.
135/// @tparam T The type of the elements
136/// @tparam Capacity The capacity of the vector
137template <typename T, std::size_t Capacity, bool = std::is_trivially_destructible<T>::value>
138// NOLINTNEXTLINE(hicpp-special-member-functions)
139class inline_vector_internal_non_constexpr_storage {
140 public:
141 /// @brief Deleted copy constructor
142 inline_vector_internal_non_constexpr_storage(inline_vector_internal_non_constexpr_storage const&) = delete;
143 /// @brief Deleted move constructor
144 inline_vector_internal_non_constexpr_storage(inline_vector_internal_non_constexpr_storage&&) = delete;
145
146 /// @brief Deleted copy assignment
147 auto operator=(inline_vector_internal_non_constexpr_storage const&)
148 -> inline_vector_internal_non_constexpr_storage& = delete;
149 /// @brief Deleted move assignment
150 auto operator=(inline_vector_internal_non_constexpr_storage&&)
151 -> inline_vector_internal_non_constexpr_storage& = delete;
152
153 protected:
154 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size_type' does not hide anything"
155 /// @brief The type used to hold the size
156 using size_type = std::size_t;
157 // parasoft-end-suppress AUTOSAR-A2_10_1-d
158 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
159 /// @brief The type of the elements
160 using value_type = T;
161 // parasoft-end-suppress AUTOSAR-A2_10_1-d
162
163 /// @brief Construct the storage with no elements
164 constexpr inline_vector_internal_non_constexpr_storage() = default;
165
166 /// @brief Destroy all constructed elements.
167 // parasoft-begin-suppress AUTOSAR-A12_7_1-a "False positive: this is not the default implementation"
168 ~inline_vector_internal_non_constexpr_storage() {
169 // parasoft-begin-suppress AUTOSAR-M0_1_3-b-2 "False positive: necessary for invoking the destructors"
170 for (auto& value : values()) {
171 value.~T();
172 }
173 // parasoft-end-suppress AUTOSAR-M0_1_3-b-2
174 }
175 // parasoft-end-suppress AUTOSAR-A12_7_1-a "False positive: this is not the default implementation"
176
177 /// @brief Get a span over the current elements
178 /// @return The span
179 constexpr auto values() noexcept -> span<value_type> {
180 // We specify Capacity as a maximum valid value to eliminate the
181 // precondition in base::span constructor.
182 return {&values_.front().object, std::min(size_, Capacity)};
183 }
184
185 /// @brief Get a @c const span over the current elements
186 /// @return The span
187 constexpr auto values() const noexcept -> span<value_type const> {
188 // We specify Capacity as a maximum valid value to eliminate the
189 // precondition in base::span constructor.
190 return {&values_.front().object, std::min(size_, Capacity)};
191 }
192
193 /// @brief If the current size is more than @c new_size, reduce the size to @c new_size.
194 /// @param new_size The new size limit
195 constexpr void shrink_to(size_type new_size) noexcept {
196 if (new_size < this->size_) {
197 // parasoft-begin-suppress AUTOSAR-M0_1_3-b-2 "False positive: necessary for invoking the destructors"
198 for (auto& value : values().last(size_ - new_size)) {
199 value.~T();
200 }
201 // parasoft-end-suppress AUTOSAR-M0_1_3-b-2
202 size_ = new_size;
203 }
204 }
205
206 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "Protected member to allow access by derived class"
207 /// @brief The current size
208 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
209 size_type size_{0U};
210 // parasoft-end-suppress AUTOSAR-M11_0_1-a
211
212 /// @brief underlying element type that allows a value to exist or not exist
213 using element_storage = inline_container::detail::unsafe_element_storage<T>;
214
215 // parasoft-begin-suppress CERT_C-PRE31-c-3 "False positive: static_assert is a compile-time assert and can have no
216 // side-effects"
217 static_assert(alignof(element_storage) == alignof(T), "Alignment must be the same");
218 static_assert(sizeof(element_storage) == sizeof(T), "Size must be the same");
219 // parasoft-end-suppress CERT_C-PRE31-c-3
220
221 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "Protected member to allow access by derived class"
222 // parasoft-begin-suppress AUTOSAR-M8_5_2-b-2 "False Positive: all elements default-initialized"
223 /// @brief The storage for the elements
224 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
225 arene::base::array<element_storage, Capacity> values_{};
226 // parasoft-end-suppress AUTOSAR-M8_5_2-b-2
227 // parasoft-end-suppress AUTOSAR-M11_0_1-a
228};
229
230/// @brief Base class for @c inline_vector that holds the elements when the elements aren't usable in @c constexpr
231/// contexts.
232/// @tparam T The type of the elements
233/// @tparam Capacity The capacity of the vector
234///
235/// This specialization handles the case that the elements are trivially destructible
236template <typename T, std::size_t Capacity>
237// NOLINTNEXTLINE(hicpp-special-member-functions)
238class inline_vector_internal_non_constexpr_storage<T, Capacity, true> {
239 protected:
240 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size_type' does not hide anything"
241 /// @brief The type used to hold the size
242 using size_type = std::size_t;
243 // parasoft-end-suppress AUTOSAR-A2_10_1-d
244 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
245 /// @brief The type of the elements
246 using value_type = T;
247 // parasoft-end-suppress AUTOSAR-A2_10_1-d
248
249 /// @brief Get a span over the current elements
250 /// @return The span
251 constexpr auto values() noexcept -> span<value_type> {
252 // We specify Capacity as a maximum valid value to eliminate the
253 // precondition in base::span constructor.
254 return {&values_.front().object, std::min(size_, Capacity)};
255 }
256
257 /// @brief Get a @c const span over the current elements
258 /// @return The span
259 constexpr auto values() const noexcept -> span<value_type const> {
260 // We specify Capacity as a maximum valid value to eliminate the
261 // precondition in base::span constructor.
262 return {&values_.front().object, std::min(size_, Capacity)};
263 }
264
265 /// @brief If the current size is more than @c new_size, reduce the size to @c new_size.
266 /// @param new_size The new size limit
267 constexpr void shrink_to(size_type new_size) noexcept {
268 if (new_size < this->size_) {
269 size_ = new_size;
270 }
271 }
272
273 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "Protected member to allow access by derived class"
274 /// @brief The current size
275 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
276 size_type size_{0U};
277 // parasoft-end-suppress AUTOSAR-M11_0_1-a
278
279 /// @brief underlying element type that allows a value to exist or not exist
280 using element_storage = inline_container::detail::unsafe_element_storage<T>;
281
282 // parasoft-begin-suppress CERT_C-PRE31-c-3 "False positive: static_assert is a compile-time assert and can have no
283 // side-effects"
284 static_assert(alignof(element_storage) == alignof(T), "Alignment must be the same");
285 static_assert(sizeof(element_storage) == sizeof(T), "Size must be the same");
286 // parasoft-end-suppress CERT_C-PRE31-c-3
287
288 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "Protected member to allow access by derived class"
289 // parasoft-begin-suppress AUTOSAR-M8_5_2-b-2 "False Positive: all elements default-initialized"
290 /// @brief The storage for the elements
291 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
292 arene::base::array<element_storage, Capacity> values_{};
293 // parasoft-end-suppress AUTOSAR-M8_5_2-b-2
294 // parasoft-end-suppress AUTOSAR-M11_0_1-a
295};
296
297// parasoft-begin-suppress CERT_CPP-MEM51-c-1 "False Positive: Copy assignment is defined or deleted as appropriate"
298// parasoft-begin-suppress AUTOSAR-M14_5_3-a-2 "False Positive: Copy assignment is defined or deleted as appropriate"
299// parasoft-begin-suppress AUTOSAR-A14_5_1-a-2 "False Positive: Copy constructor is defined or deleted as appropriate"
300// parasoft-begin-suppress AUTOSAR-A1_1_1-c-2 "False Positive: Copy operations are defined or deleted as appropriate"
301// parasoft-begin-suppress AUTOSAR-A1_1_1-b-2 "False Positive: Copy operations are defined or deleted as appropriate"
302// parasoft-begin-suppress AUTOSAR-A12_0_1-a-2 "False Positive: Copy operations are defined or deleted as appropriate"
303/// @brief Base class for @c inline_vector that holds the elements.
304/// @tparam T The type of the elements
305/// @tparam Capacity The capacity of the vector
306template <typename T, std::size_t Capacity, bool = Capacity != 0 && allow_constexpr_vector_v<T>>
307// NOLINTNEXTLINE(hicpp-special-member-functions)
308class inline_vector_internal_storage : public inline_vector_internal_non_constexpr_storage<T, Capacity> {
309 /// @brief The base class with the actual storage
310 using non_constexpr_storage_base = inline_vector_internal_non_constexpr_storage<T, Capacity>;
311
312 /// @brief The type of the argument to the "copy constructor": either @c
313 /// inline_vector_internal_storage to provide a real copy constructor if @c T is
314 /// copy-constructible, or @c non_constructible_dummy otherwise.
315 using copy_constructor_arg =
316 conditional_t<std::is_copy_constructible<T>::value, inline_vector_internal_storage, non_constructible_dummy>;
317
318 /// @brief The type of the argument to the "copy assignment operator": either @c
319 /// inline_vector_internal_storage to provide a real copy assignment operator if @c T is
320 /// copy-assignable, or @c non_constructible_dummy otherwise.
321 using copy_assignment_arg = conditional_t<
323 inline_vector_internal_storage,
324 non_constructible_dummy>;
325
326 /// @brief The type of the argument to the "move constructor": either @c
327 /// inline_vector_internal_storage to provide a real move constructor if @c T is
328 /// move-constructible, or @c non_constructible_dummy otherwise.
329 using move_constructor_arg =
330 conditional_t<std::is_move_constructible<T>::value, inline_vector_internal_storage, non_constructible_dummy>;
331
332 /// @brief The type of the argument to the "move assignment operator": either @c
333 /// inline_vector_internal_storage to provide a real move assignment operator if @c T is
334 /// move-assignable, or @c non_constructible_dummy otherwise.
335 using move_assignment_arg = conditional_t<
337 inline_vector_internal_storage,
338 non_constructible_dummy>;
339
340 public:
341 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size_type' does not hide anything"
342 /// @brief The type used to hold the size
343 using size_type = typename non_constexpr_storage_base::size_type;
344 // parasoft-end-suppress AUTOSAR-A2_10_1-d
345 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
346 /// @brief The type of the elements
347 using value_type = typename non_constexpr_storage_base::value_type;
348 // parasoft-end-suppress AUTOSAR-A2_10_1-d
349
350 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
351 /// @brief Get the maximum number of elements in the vector, @c Capacity
352 static constexpr std::integral_constant<std::size_t, Capacity> capacity{};
353 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
354 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
355 /// @brief Get the maximum number of elements in the vector, @c Capacity
356 static constexpr std::integral_constant<std::size_t, Capacity> max_size{};
357 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
358
359 /// @brief Construct the storage with no elements
360 constexpr inline_vector_internal_storage() = default;
361
362 // parasoft-begin-suppress AUTOSAR-A12_8_6-a-2 "Not guaranteed to be a base class"
363 /// @brief Copy constructor if @c T is copy-constructible, useless conversion from @c
364 /// non_constructible_dummy otherwise. If copying, copies all the elements
365 /// from @c other into @c *this.
366 /// @param other The source
367 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
368 constexpr inline_vector_internal_storage(copy_constructor_arg const& other
370 : non_constexpr_storage_base{} {
371 for (auto& value : other.values()) {
372 internal_emplace_back(value);
373 }
374 }
375 // parasoft-end-suppress AUTOSAR-A12_8_6-a-2
376
377 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
378 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved"
379 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved"
380 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved"
381 /// @brief Move constructor if @c T is move-constructible, useless conversion from @c
382 /// non_constructible_dummy otherwise. If moving, move-constructs all the
383 /// elements from @c other into @c *this.
384 /// @param other The source
385 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
386 constexpr inline_vector_internal_storage(move_constructor_arg&& other
388 : non_constexpr_storage_base{} {
389 for (auto& value : other.values()) {
390 internal_emplace_back(std::move(value));
391 }
392 other.shrink_to(0U);
393 }
394 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
395 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
396 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
397 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
398
399 // parasoft-begin-suppress AUTOSAR-A12_8_6-a-2 "Not guaranteed to be a base class"
400 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved"
401 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved"
402 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved"
403 /// @brief Copy assignment operator if @c T is copy-constructible and copy
404 /// assignable, useless conversion from @c non_constructible_dummy otherwise.
405 /// If copying, copies all the elements from @c other into @c *this, assigning
406 /// over existing elements, constructing new ones, and destroying an excess
407 /// existing elements.
408 /// @param other The source
409 /// @return @c *this
410 constexpr auto operator=(copy_assignment_arg const& other
412 -> inline_vector_internal_storage& {
413 if (&other != this) {
414 auto our_values = this->values();
415 auto other_values = other.values();
416 inline_vector_internal_storage::size_type idx{0U};
417 for (; (idx < our_values.size()) && (idx < other_values.size()); ++idx) {
418 our_values[idx] = other_values[idx];
419 }
420 for (; idx < other_values.size(); ++idx) {
421 internal_emplace_back(other_values[idx]);
422 }
423 this->shrink_to(idx);
424 }
425 return *this;
426 }
427 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
428 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
429 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
430 // parasoft-end-suppress AUTOSAR-A12_8_6-a-2
431
432 // parasoft-begin-suppress AUTOSAR-A15_5_1-b-2 "False positive: Conditionally noxecept"
433 // parasoft-begin-suppress AUTOSAR-A12_8_6-a-2 "Not guaranteed to be a base class"
434 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved"
435 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved"
436 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved"
437 /// @brief Move assignment operator if @c T is move-constructible and move
438 /// assignable, useless conversion from @c non_constructible_dummy otherwise.
439 /// If moving, copies all the elements from @c other into @c *this, assigning
440 /// over existing elements, constructing new ones, and destroying an excess
441 /// existing elements.
442 /// @param other The source
443 /// @return @c *this
444 constexpr auto operator=(move_assignment_arg&& other
446 -> inline_vector_internal_storage& {
447 if (&other != this) {
448 auto our_values = this->values();
449 auto other_values = other.values();
450 inline_vector_internal_storage::size_type idx{0U};
451 for (; (idx < our_values.size()) && (idx < other_values.size()); ++idx) {
452 our_values[idx] = std::move(other_values[idx]);
453 }
454 for (; idx < other_values.size(); ++idx) {
455 internal_emplace_back(std::move(other_values[idx]));
456 }
457 this->shrink_to(idx);
458 other.shrink_to(0U);
459 }
460 return *this;
461 }
462 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
463 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
464 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
465 // parasoft-end-suppress AUTOSAR-A12_8_6-a-2
466 // parasoft-end-suppress AUTOSAR-A15_5_1-b-2
467 /// @brief Destroy all constructed elements.
468 ~inline_vector_internal_storage() = default;
469
470 /// @brief Construct a new element at the end of the existing range, from the
471 /// supplied arguments.
472 /// @tparam Args The types of the arguments
473 /// @param args The constructor arguments
474 template <typename... Args>
475 constexpr void internal_emplace_back(Args&&... args) noexcept(std::is_nothrow_constructible<T, Args...>::value) {
476 construct_at(&this->values_[this->size_].object, std::forward<Args>(args)...);
477 ++this->size_;
478 }
479};
480// parasoft-end-suppress AUTOSAR-A12_0_1-a-2
481// parasoft-end-suppress AUTOSAR-A1_1_1-c-2
482// parasoft-end-suppress AUTOSAR-A1_1_1-b-2
483// parasoft-end-suppress AUTOSAR-M14_5_3-a-2
484// parasoft-end-suppress AUTOSAR-A14_5_1-a-2
485
486/// @brief Specialization for the case that the element @c T is suitable for use in a
487/// @c constexpr container. The elements are held as a default-constructed array
488/// of @c T rather than an array of storage entries.
489/// @tparam T The type of the elements
490/// @tparam Capacity The number of elements that can be stored
491template <typename T, std::size_t Capacity>
492class inline_vector_internal_storage<T, Capacity, true> {
493 public:
494 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size_type' does not hide anything"
495 /// @brief The type used to hold the size
496 using size_type = std::size_t;
497 // parasoft-end-suppress AUTOSAR-A2_10_1-d
498 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
499 /// @brief The type of the elements
500 using value_type = T;
501 // parasoft-end-suppress AUTOSAR-A2_10_1-d
502
503 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
504 /// @brief Get the maximum number of elements in the vector, @c Capacity
505 static constexpr std::integral_constant<size_type, Capacity> capacity{};
506 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
507 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
508 /// @brief Get the maximum number of elements in the vector, @c Capacity
509 static constexpr std::integral_constant<size_type, Capacity> max_size{};
510 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
511
512 /// @brief Get a span of the current "live" values
513 /// @return The span
514 constexpr auto values() noexcept -> span<value_type> {
515 // We specify Capacity as a maximum valid value to eliminate the
516 // precondition in base::span constructor.
517 return {&values_.front(), std::min(size_, Capacity)};
518 }
519 /// @brief Get a @c const span of the current "live" values
520 /// @return The span
521 constexpr auto values() const noexcept -> span<value_type const> {
522 // We specify Capacity as a maximum valid value to eliminate the
523 // precondition in base::span constructor.
524 return {&values_.front(), std::min(size_, Capacity)};
525 }
526
527 /// @brief Construct a new element at the end of the existing range, from the
528 /// supplied arguments.
529 /// @tparam Args The types of the arguments
530 /// @param args The constructor arguments
531 template <typename... Args>
532 constexpr void internal_emplace_back(Args&&... args) noexcept(std::is_nothrow_constructible<T, Args...>::value) {
533 // parasoft-begin-suppress AUTOSAR-A5_2_2-a-2 "False positive: constructor call, not C-style cast"
534 values_[size_] = T(std::forward<Args>(args)...);
535 // parasoft-end-suppress AUTOSAR-A5_2_2-a-2
536 ++size_;
537 }
538
539 /// @brief If the current size is more than @c new_size, reduce the size to @c new_size.
540 /// @param new_size The new size limit
541 constexpr void shrink_to(size_type new_size) noexcept {
542 if (new_size < size_) {
543 size_ = new_size;
544 }
545 }
546
547 private:
548 /// @brief The current size
549 size_type size_{0U};
550
551 /// @brief The elements
552 arene::base::array<value_type, Capacity> values_{};
553};
554// parasoft-end-suppress CERT_CPP-MEM51-c-1
555
556/// @brief Specialization for the case that the @c Capacity is zero: such a vector can
557/// never hold any elements, so has a size of zero and is an empty class.
558/// @tparam T The element type
559template <typename T>
560class inline_vector_internal_storage<T, 0, false> {
561 public:
562 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size_type' does not hide anything"
563 /// @brief The type used to hold the size
564 using size_type = std::size_t;
565 // parasoft-end-suppress AUTOSAR-A2_10_1-d
566 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
567 /// @brief The type of the elements
568 using value_type = T;
569 // parasoft-end-suppress AUTOSAR-A2_10_1-d
570
571 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
572 /// @brief Get the maximum number of elements in the vector, @c Capacity
573 static constexpr std::integral_constant<size_type, 0> capacity{};
574 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
575 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property,
576 /// @brief Get the maximum number of elements in the vector, @c Capacity
577 static constexpr std::integral_constant<size_type, 0> max_size{};
578 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
579
580 /// @brief Get an empty span for the current elements
581 /// @return The span
582 static constexpr auto values() noexcept -> span<value_type> { return {}; }
583 /// @brief Do-nothing placeholder for constructing a new element
584 /// @tparam Args The types of the initializers
585 template <typename... Args>
586 static constexpr void internal_emplace_back(Args&&...) noexcept {
587 ARENE_INVARIANT_UNREACHABLE("Can never add to a zero-size container");
588 }
589 /// @brief Do-nothing placeholder for shrinking the size
590 /// @param new_size The new size to shrink to
591 static constexpr void shrink_to(size_type new_size) noexcept { ARENE_PRECONDITION(new_size == 0U); }
592};
593
594template <typename T, std::size_t Capacity, bool NonEmptyConstexpr>
595constexpr std::integral_constant<std::size_t, Capacity>
596 inline_vector_internal_storage<T, Capacity, NonEmptyConstexpr>::capacity;
597
598template <typename T, std::size_t Capacity, bool NonEmptyConstexpr>
599constexpr std::integral_constant<std::size_t, Capacity>
600 inline_vector_internal_storage<T, Capacity, NonEmptyConstexpr>::max_size;
601
602template <typename T, std::size_t Capacity>
603constexpr std::integral_constant<std::size_t, Capacity> inline_vector_internal_storage<T, Capacity, true>::capacity;
604
605template <typename T, std::size_t Capacity>
606constexpr std::integral_constant<std::size_t, Capacity> inline_vector_internal_storage<T, Capacity, true>::max_size;
607
608template <typename T>
609constexpr std::integral_constant<std::size_t, 0> inline_vector_internal_storage<T, 0, false>::capacity;
610
611template <typename T>
612constexpr std::integral_constant<std::size_t, 0> inline_vector_internal_storage<T, 0, false>::max_size;
613
614// parasoft-begin-suppress CERT_CPP-MEM51-c-1 "False Positive: Copy assignment is defined or deleted as appropriate"
615// parasoft-begin-suppress AUTOSAR-M14_5_3-a-2 "False Positive: Copy assignment is defined or deleted as appropriate"
616// parasoft-begin-suppress AUTOSAR-A14_5_1-a-2 "False Positive: Copy constructor is defined or deleted as appropriate"
617// parasoft-begin-suppress AUTOSAR-A1_1_1-c-2 "False Positive: Copy operations are defined or deleted as appropriate"
618// parasoft-begin-suppress AUTOSAR-A1_1_1-b-2 "False Positive: Copy operations are defined or deleted as appropriate"
619// parasoft-begin-suppress AUTOSAR-A12_0_1-a-2 "False Positive: Copy operations are defined or deleted as appropriate"
620// parasoft-begin-suppress AUTOSAR-A10_1_1-a-2 "False positive: 'vector_base' is an interface
621/// @brief Interface to the storage for @c inline_vector
622/// @tparam Storage The class that provides storage for holding the elements
623///
624/// Helper class to define functions necessary for defining a vector.
625///
626/// The @c Storage type is required to provide the following typedefs:
627/// * @c size_type
628/// * @c value_type
629///
630/// The @c Storage type is required to implement the following functions:
631/// * <tt> auto values() const -> span<value_type const> </tt>
632/// * <tt> auto values() -> span<value_type> </tt>
633/// * <tt> void internal_emplace_back(args&&...) </tt>
634/// * <tt> void shrink_to() </tt>
635///
636/// This interface can be constructed as:
637/// * <tt> vector_interface(vector_interface) </tt> (protected)
638/// * <tt> vector_interface() </tt>
639/// * <tt> vector_interface(std::initializer_list) </tt>
640/// * <tt> vector_interface(size_type) </tt>
641/// * <tt> vector_interface(size_type, value_type) </tt>
642/// * <tt> vector_interface(Iterator, Iterator) </tt>
643/// * <tt> vector_interface(move_construction_tag, SourceContainer) </tt>
644///
645/// This interface will provide:
646/// * <tt> auto empty() const -> bool </tt>
647/// * <tt> auto size() const -> size_type </tt>
648/// * <tt> auto back() -> reference </tt>
649/// * <tt> auto back() const -> const_reference </tt>
650/// * <tt> auto front() -> reference </tt>
651/// * <tt> auto front() const -> const_reference </tt>
652/// * <tt> void assign(Iterator, Iterator) </tt>
653/// * <tt> void assign(std::initializer_list) </tt>
654/// * <tt> void assign(size_type, value_type) </tt>
655/// * <tt> void resize(size_type) </tt>
656/// * <tt> void resize(size_type, value_type) </tt>
657/// * <tt> void push_back(value_type) </tt>
658/// * <tt> void emplace_back(Args...) </tt>
659/// * <tt> void clear() </tt>
660/// * <tt> auto data() -> pointer </tt>
661/// * <tt> auto data() const -> const_pointer </tt>
662/// * <tt> auto at(size_type) -> reference </tt>
663/// * <tt> auto at(size_type) const -> const_reference </tt>
664/// * <tt> auto operator[](size_type) -> reference </tt>
665/// * <tt> auto operator[](size_type) const -> const_reference </tt>
666/// * <tt> auto begin() -> iterator </tt>
667/// * <tt> auto begin() const -> const_iterator </tt>
668/// * <tt> auto cbegin() const -> const_iterator </tt>
669/// * <tt> auto end() -> iterator </tt>
670/// * <tt> auto end() const -> const_iterator </tt>
671/// * <tt> auto cend() const -> const_iterator </tt>
672/// * <tt> auto rbegin() -> reverse_iterator </tt>
673/// * <tt> auto rbegin() const -> const_reverse_iterator </tt>
674/// * <tt> auto crbegin() const -> const_reverse_iterator </tt>
675/// * <tt> auto rend() -> reverse_iterator </tt>
676/// * <tt> auto rend() const -> const_reverse_iterator </tt>
677/// * <tt> auto crend() const -> const_iterator </tt>
678/// * <tt> auto insert(const_iterator, value_type) -> iterator </tt>
679/// * <tt> auto insert(const_iterator, size_type, value_type) -> iterator </tt>
680/// * <tt> auto insert(const_iterator, InputIterator, InputIterator) -> iterator </tt>
681/// * <tt> auto erase(const_iterator) -> iterator </tt>
682/// * <tt> auto erase(const_iterator, const_iterator) -> iterator </tt>
683/// * <tt> void pop_back() </tt>
684template <typename Storage>
685// NOLINTNEXTLINE(hicpp-special-member-functions)
686class vector_interface
687 : public vector_base<typename Storage::value_type>
688 , public detail::mixin_at<vector_interface<Storage>, typename vector_base<typename Storage::value_type>::size_type>
689 , protected Storage {
690 /// @brief type alias for the base class with type aliases
691 using vector_base_type = vector_base<typename Storage::value_type>;
692
693 protected:
694 // Alias in typedefs from base class
695 using typename vector_base_type::const_iterator;
696 using typename vector_base_type::const_pointer;
697 using typename vector_base_type::const_reference;
698 using typename vector_base_type::const_reverse_iterator;
699 using typename vector_base_type::difference_type;
700 using typename vector_base_type::iterator;
701 using typename vector_base_type::pointer;
702 using typename vector_base_type::reference;
703 using typename vector_base_type::reverse_iterator;
704 using typename vector_base_type::size_type;
705 using typename vector_base_type::value_type;
706
707 using Storage::capacity;
708
709 /// @brief swaps all the elements between this vector and another.
710 ///
711 /// @param other the vector to swap with.
712 /// @post The elements in @c this and @c other are exchanged 1:1 up to the @c size() of the smallest vector. Relative
713 /// order is maintained. The remaining elements from the originally larger vector are move-constructed into the
714 /// originally smaller vector maintaining relative order, and the elements in the originally larger vector are
715 /// destroyed.
716 ///
717 constexpr void do_swap(vector_interface& other
718 ) noexcept(is_nothrow_swappable_v<value_type> && std::is_nothrow_move_constructible<value_type>::value) {
719 auto our_values = this->values();
720 auto other_values = other.values();
721 auto const swap_count = std::min<>(size(), other.size());
722 for (vector_interface::size_type i{0U}; i < swap_count; ++i) {
723 ::arene::base::swap(our_values[i], other_values[i]);
724 }
725 if (size() < other.size()) {
726 for (vector_interface::size_type i{swap_count}; i < other.size(); ++i) {
727 this->internal_emplace_back(std::move(other_values[i]));
728 }
729 other.shrink_to(swap_count);
730 } else {
731 for (vector_interface::size_type i{swap_count}; i < size(); ++i) {
732 other.internal_emplace_back(std::move(our_values[i]));
733 }
734 this->shrink_to(swap_count);
735 }
736 }
737
738 /// @brief passkey type for constructor to indicate move construction from a source
739 class move_construction_tag {
740 public:
741 /// @brief explicit default constructor to avoid initialization from empty braces
742 explicit move_construction_tag() = default;
743 };
744
745 /// @brief Default copy constructor
746 constexpr vector_interface(vector_interface const&) = default;
747 /// @brief Default move constructor
748 constexpr vector_interface(vector_interface&&) = default;
749
750 /// @brief Default copy assignment operator
751 constexpr auto operator=(vector_interface const&) -> vector_interface& = default;
752 /// @brief Default move assignment operator
753 constexpr auto operator=(vector_interface&&) -> vector_interface& = default;
754
755 public:
756 /// @brief Construct the storage with no elements
757 constexpr vector_interface() noexcept = default;
758
759 /// @brief Default destructor
760 ~vector_interface() = default;
761
762 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
763 // initialize the base class"
764 /// @brief Construct a vector populated with the supplied elements.
765 /// @tparam U Dummy template parameter the same as @c value_type for constraints
766 /// @param initial_values The initial initial_values
767 /// @pre @c initial_values.size()<=capacity(), else @c ARENE_PRECONDITION violation
768 template <
769 typename U = value_type,
770 constraints<
771 std::enable_if_t<std::is_same<U, value_type>::value>,
772 std::enable_if_t<std::is_copy_constructible<U>::value>> = nullptr>
773 constexpr vector_interface(std::initializer_list<value_type> initial_values
774 ) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
775 : vector_interface() {
776 ARENE_PRECONDITION(initial_values.size() <= capacity());
777 // parasoft-begin-suppress AUTOSAR-M14_6_1-a-2 "False Positive: unqualified identifier not used"
778 for (auto& value : initial_values) { // parasoft-suppress AUTOSAR-A7_1_5-a-2 "False Positive: variable is declared
779 // to have same type as initializer"
780 // parasoft-end-suppress AUTOSAR-M14_6_1-a-2
781 this->internal_emplace_back(value);
782 }
783 }
784 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
785
786 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
787 // initialize the base class"
788 /// @brief Construct a vector populated with the specified number of default-constructed elements
789 /// @tparam U Dummy template parameter the same as @c value_type for constraints
790 /// @param count The initial size
791 /// @pre @c count<=capacity(), else @c ARENE_PRECONDITION violation
792 template <
793 typename U = value_type,
795 std::enable_if_t<std::is_same<U, value_type>::value>,
796 std::enable_if_t<std::is_default_constructible<U>::value>> = nullptr>
797 constexpr explicit vector_interface(vector_interface::size_type const count
799 : vector_interface() {
800 ARENE_PRECONDITION(count <= capacity());
801 for (vector_interface::size_type i{count}; i != 0U; --i) {
802 this->internal_emplace_back();
803 }
804 }
805 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
806
807 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
808 // initialize the base class"
809 /// @brief Construct a vector populated with the specified number of
810 /// elements copy-constructed from the supplied value
811 /// @tparam U Dummy template parameter the same as @c value_type for constraints
812 /// @param count The initial size
813 /// @param source The initial value
814 /// @pre @c count<=capacity(), else @c ARENE_PRECONDITION violation
815 template <
816 typename U = value_type,
818 std::enable_if_t<std::is_same<U, value_type>::value>,
819 std::enable_if_t<std::is_copy_constructible<U>::value>> = nullptr>
820 constexpr explicit vector_interface(vector_interface::size_type const count, value_type const& source) noexcept(
822 )
823 : vector_interface() {
824 ARENE_PRECONDITION(count <= capacity());
825 for (vector_interface::size_type i{count}; i != 0U; --i) {
826 this->internal_emplace_back(source);
827 }
828 }
829 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
830
831 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
832 // initialize the base class"
833 /// @brief Construct a vector from the elements of an input iterator range
834 /// @tparam Iterator The type of the iterator
835 /// @param first The start of the range
836 /// @param last The end of the range
837 /// @pre The number of elements in the range must be less than @c Capacity, else @c ARENE_PRECONDITION violation
838 template <
839 typename Iterator,
843 vector_interface(Iterator first, Iterator last) noexcept(
844 denotes_nothrow_iterable_range_v<Iterator> &&
845 std::is_nothrow_constructible<value_type, typename std::iterator_traits<Iterator>::reference>::value
846 )
847 : vector_interface() {
848 for (auto&& elem : make_subrange(first, last)) {
849 push_back(std::forward<decltype(elem)>(elem));
850 }
851 }
852 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
853 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
854 // initialize the base class"
855 /// @brief Construct a vector from the elements of a bidrectional iterator range
856 /// @tparam Iterator The type of the iterator
857 /// @param first The start of the range
858 /// @param last The end of the range
859 /// @pre The number of elements in the range must be less than @c Capacity, else @c ARENE_PRECONDITION violation
860 template <
861 typename Iterator,
865 std::is_constructible<value_type, typename std::iterator_traits<Iterator>::reference>::value>> = nullptr>
866 constexpr vector_interface(Iterator first, Iterator last) noexcept(
867 denotes_nothrow_iterable_range_v<Iterator> &&
868 std::is_nothrow_constructible<value_type, typename std::iterator_traits<Iterator>::reference>::value
869 )
870 : vector_interface() {
871 auto const source_count = static_cast<size_type>(arene::base::distance(first, last));
872 ARENE_PRECONDITION(source_count <= capacity());
873 for (auto&& elem : make_subrange(first, last)) {
874 this->internal_emplace_back(std::forward<decltype(elem)>(elem));
875 }
876 }
877 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
878
879 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
880 // initialize the base class"
881 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved"
882 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved"
883 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved"
884 /// @brief Move construct from another vector
885 /// @tparam SoureContainer The type of the other vector
886 /// @param other The other vector
887 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation
888 template <typename SourceContainer>
889 constexpr explicit vector_interface(move_construction_tag, SourceContainer&& other) noexcept(
891 )
892 : vector_interface() {
893 ARENE_PRECONDITION(other.size() <= capacity());
894 // parasoft-begin-suppress AUTOSAR-M14_6_1-a-2 "False Positive: unqualified identifier not used"
895 for (auto& elem : other) {
896 // parasoft-end-suppress AUTOSAR-M14_6_1-a-2
897 this->internal_emplace_back(std::move(elem));
898 }
899 }
900 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
901 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
902 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
903 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
904
905 /// @brief Check if the vector is empty.
906 /// @return @c true if the vector is empty, @c false otherwise
907 constexpr auto empty() const noexcept -> bool { return size() == 0U; }
908
909 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
910 /// @brief Get the current number of live elements in the vector
911 /// @return the size
912 constexpr auto size() const noexcept -> size_type { return this->values().size(); }
913 // parasoft-end-suppress AUTOSAR-A2_10_1-d
914
915 /// @brief Get a reference to the last element.
916 /// @return A reference to the element
917 /// @pre The vector must not be empty
918 constexpr auto back() noexcept -> reference { return this->values().back(); }
919 /// @brief Get a reference to the last element.
920 /// @return A reference to the element
921 /// @pre The vector must not be empty
922 constexpr auto back() const noexcept -> const_reference { return this->values().back(); }
923
924 /// @brief Get a reference to the first element.
925 /// @return A reference to the element
926 /// @pre The vector must not be empty
927 constexpr auto front() noexcept -> reference { return this->values().front(); }
928 /// @brief Get a reference to the first element.
929 /// @return A reference to the element
930 /// @pre The vector must not be empty
931 constexpr auto front() const noexcept -> const_reference { return this->values().front(); }
932
933 // parasoft-begin-suppress AUTOSAR-M0_1_8-b "False positive: function assign is not empty"
934 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: parameters first and last are used"
935 /// @brief Assign to the vector from the elements of an input iterator range. Assigns
936 /// over existing elements, constructs additional elements, and destroys any
937 /// excess.
938 /// @tparam Iterator The type of the iterator
939 /// @param first The start of the range
940 /// @param last The end of the range
941 /// @pre The number of elements in the range must be less than @c Capacity, else @c ARENE_PRECONDITION violation
942 template <
943 typename Iterator,
947 constexpr void assign(Iterator first, Iterator last) noexcept(
948 denotes_nothrow_iterable_range_v<Iterator> &&
949 std::is_nothrow_constructible<value_type, typename std::iterator_traits<Iterator>::reference>::value &&
950 std::is_nothrow_assignable<value_type&, typename std::iterator_traits<Iterator>::reference>::value
951 ) {
952 auto our_values = this->values();
953 vector_interface::size_type idx{0U};
954 while ((idx < our_values.size()) && (first != last)) {
955 our_values[idx] = *first++;
956 ++idx;
957 }
958 while (first != last) {
959 push_back(*first++);
960 ++idx;
961 }
962 this->shrink_to(idx);
963 }
964 // parasoft-end-suppress AUTOSAR-A0_1_4-a
965 // parasoft-end-suppress AUTOSAR-M0_1_8-b
966
967 /// @brief Assign to the vector from the elements of a bidrectional iterator range.
968 /// Assigns over existing elements, constructs additional elements, and
969 /// destroys any excess.
970 /// @tparam Iterator The type of the iterator
971 /// @param first The start of the range
972 /// @param last The end of the range
973 /// @pre The number of elements in the range must be less than @c Capacity, else @c ARENE_PRECONDITION violation
974 template <typename Iterator, constraints<std::enable_if_t<arene::base::is_forward_iterator_v<Iterator>>> = nullptr>
975 constexpr void assign(Iterator const first, Iterator const last) noexcept(
976 denotes_nothrow_iterable_range_v<Iterator> &&
977 std::is_nothrow_constructible<value_type, typename std::iterator_traits<Iterator>::reference>::value &&
978 std::is_nothrow_assignable<value_type&, typename std::iterator_traits<Iterator>::reference>::value
979 ) {
980 auto const source_distance = arene::base::distance(first, last);
981 auto const source_size = static_cast<size_type>(source_distance);
982 ARENE_PRECONDITION(source_size <= this->capacity());
983
984 // parasoft-begin-suppress AUTOSAR-M14_6_1-a-2 "False Positive: unqualified identifier not used"
985 Iterator current_source{first};
986 for (auto& elem_to_overwrite : this->values()) {
987 // parasoft-end-suppress AUTOSAR-M14_6_1-a-2
988 if (current_source == last) {
989 break;
990 }
991 elem_to_overwrite = *current_source;
992 // parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "False positive: current_source is an iterator, bounded by last"
993 ++current_source;
994 // parasoft-end-suppress AUTOSAR-M5_0_15-a-2
995 }
996
997 for (auto&& source_elem : make_subrange(current_source, last)) {
998 this->internal_emplace_back(std::forward<decltype(source_elem)>(source_elem));
999 }
1000 this->shrink_to(source_size);
1001 }
1002
1003 /// @brief Assign to the vector from the elements of an initializer list. Assigns
1004 /// over existing elements, constructs additional elements, and destroys any
1005 /// excess.
1006 /// @param source_values The source values
1007 /// @pre @c source_values.size()<=Capacity, else @c ARENE_PRECONDITION violation
1008 void assign(std::initializer_list<value_type> source_values) noexcept(
1010 ) {
1011 assign(source_values.begin(), source_values.end());
1012 }
1013
1014 /// @brief Assign to the vector the specified number of copies of a given source
1015 /// element. Assigns over existing elements, constructs additional elements,
1016 /// and destroys any excess.
1017 /// @param count The number of copies to store
1018 /// @param value The source value to use
1019 /// @pre @c count<=Capacity, else @c ARENE_PRECONDITION violation
1020 void assign(size_type count, value_type const& value) noexcept(
1022 ) {
1023 ARENE_PRECONDITION(count <= this->capacity());
1024 auto our_values = this->values();
1025 for (vector_interface::size_type i{0U}; (i < our_values.size()) && (i < count); ++i) {
1026 our_values[i] = value;
1027 }
1028 resize(count, value);
1029 }
1030
1031 /// @brief Resize the vector to the specified size. Default-constructs any missing
1032 /// elements, and destroys any excess.
1033 /// @param count The desired size
1034 /// @pre @c count<=Capacity, else @c ARENE_PRECONDITION violation
1035 constexpr void resize(size_type count) noexcept(std::is_nothrow_default_constructible<value_type>::value) {
1036 ARENE_PRECONDITION(count <= this->capacity());
1037 while (size() < count) {
1038 this->internal_emplace_back();
1039 }
1040 this->shrink_to(count);
1041 }
1042
1043 /// @brief Resize the vector to the specified size using a supplied value.
1044 /// Copy-constructs any missing elements from the provided value, and destroys
1045 /// any excess.
1046 /// @param count The desired size
1047 /// @param value The source value to use for the new elements
1048 /// @pre @c count<=Capacity, else @c ARENE_PRECONDITION violation
1049 constexpr void resize(size_type count, value_type const& value) noexcept(
1051 ) {
1052 ARENE_PRECONDITION(count <= this->capacity());
1053 while (size() < count) {
1054 this->internal_emplace_back(value);
1055 }
1056 this->shrink_to(count);
1057 }
1058
1059 /// @brief Add a new element to the end of the vector as a copy of the supplied
1060 /// value.
1061 /// @param value The value to copy
1062 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1063 constexpr void push_back(value_type const& value) noexcept(std::is_nothrow_copy_constructible<value_type>::value) {
1064 ARENE_PRECONDITION(size() < this->capacity());
1065 this->internal_emplace_back(value);
1066 }
1067
1068 /// @brief Add a new element to the end of the vector by move-constructing from the
1069 /// supplied value.
1070 /// @param value The value to move from
1071 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1072 constexpr void push_back(value_type&& value) noexcept(std::is_nothrow_move_constructible<value_type>::value) {
1073 ARENE_PRECONDITION(size() < this->capacity());
1074 this->internal_emplace_back(std::move(value));
1075 }
1076
1077 /// @brief Add a new element to the end of the vector, constructed in place from the
1078 /// supplied arguments.
1079 /// @tparam Args The types of the arguments
1080 /// @param args The constructor arguments
1081 /// @return A reference to the new element
1082 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1083 template <typename... Args>
1084 constexpr auto emplace_back(Args&&... args) noexcept(std::is_nothrow_constructible<value_type, Args&&...>::value)
1085 -> reference {
1086 ARENE_PRECONDITION(size() < this->capacity());
1087 this->internal_emplace_back(std::forward<Args>(args)...);
1088 return back();
1089 }
1090
1091 /// @brief Destroy all elements and set the size to zero
1092 constexpr void clear() noexcept { this->shrink_to(size_type{}); }
1093
1094 /// @brief Obtain a pointer to the stored elements
1095 /// @return A raw pointer to the elements
1096 constexpr auto data() noexcept -> pointer { return this->values().data(); }
1097
1098 /// @brief Obtain a pointer to the stored elements
1099 /// @return A raw pointer to the elements
1100 constexpr auto data() const noexcept -> const_pointer { return this->values().data(); }
1101
1102 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False Positive: 'index' does not hide anything"
1103 /// @brief Obtain a reference to the element with the specified index
1104 /// @param index The index of the element
1105 /// @return A reference to the element
1106 /// @pre @c index must be less than @c size()
1107 constexpr auto operator[](size_type index) noexcept -> reference { return this->values()[index]; }
1108
1109 /// @brief Obtain a const reference to the element with the specified index
1110 /// @param index The index of the element
1111 /// @return A reference to the element
1112 /// @pre @c index must be less than @c size()
1113 constexpr auto operator[](size_type index) const noexcept -> const_reference { return this->values()[index]; }
1114 // parasoft-end-suppress AUTOSAR-A2_10_1-a
1115
1116 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False Positive: 'begin' and 'end' do not hide anything"
1117 /// @brief Obtain an iterator to the start of the vector.
1118 /// @return The iterator
1119 constexpr auto begin() noexcept -> iterator {
1120 return {typename vector_base_type::iterator_passkey{}, this->values().begin().base()};
1121 }
1122 /// @brief Obtain an iterator to the end of the vector.
1123 /// @return The iterator
1124 constexpr auto end() noexcept -> iterator {
1125 return {typename vector_base_type::iterator_passkey{}, this->values().end().base()};
1126 }
1127 // parasoft-end-suppress AUTOSAR-A2_10_1-d
1128
1129 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'begin' does not hide anything"
1130 /// @brief Obtain an iterator to the start of the vector.
1131 /// @return The iterator
1132 constexpr auto begin() const noexcept -> const_iterator { return cbegin(); }
1133 // parasoft-end-suppress AUTOSAR-A2_10_1-d
1134
1135 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'end' does not hide anything"
1136 /// @brief Obtain an iterator to the end of the vector.
1137 /// @return The iterator
1138 constexpr auto end() const noexcept -> const_iterator { return cend(); }
1139 // parasoft-end-suppress AUTOSAR-A2_10_1-d
1140
1141 /// @brief Obtain an iterator to the start of the vector.
1142 /// @return The iterator
1143 constexpr auto cbegin() const noexcept -> const_iterator {
1144 return {typename vector_base_type::iterator_passkey{}, this->values().cbegin().base()};
1145 }
1146 /// @brief Obtain an iterator to the end of the vector.
1147 /// @return The iterator
1148 constexpr auto cend() const noexcept -> const_iterator {
1149 return {typename vector_base_type::iterator_passkey{}, this->values().cend().base()};
1150 }
1151
1152 /// @brief Obtain an iterator to the end of the vector for iterating in reverse.
1153 /// @return The iterator
1154 constexpr auto rbegin() noexcept -> reverse_iterator { return reverse_iterator(end()); }
1155 /// @brief Obtain an iterator to the start of the vector for iterating in reverse
1156 /// @return The iterator
1157 constexpr auto rend() noexcept -> reverse_iterator { return reverse_iterator(begin()); }
1158
1159 /// @brief Obtain an iterator to the end of the vector for iterating in reverse.
1160 /// @return The iterator
1161 constexpr auto rbegin() const noexcept -> const_reverse_iterator { return crbegin(); }
1162 /// @brief Obtain an iterator to the start of the vector for iterating in reverse
1163 /// @return The iterator
1164 constexpr auto rend() const noexcept -> const_reverse_iterator { return crend(); }
1165
1166 /// @brief Obtain an iterator to the end of the vector for iterating in reverse.
1167 /// @return The iterator
1168 constexpr auto crbegin() const noexcept -> const_reverse_iterator { return const_reverse_iterator(cend()); }
1169 /// @brief Obtain an iterator to the start of the vector for iterating in reverse
1170 /// @return The iterator
1171 constexpr auto crend() const noexcept -> const_reverse_iterator { return const_reverse_iterator(cbegin()); }
1172 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False Positive: 'begin' and 'end' do not hide anything"
1173
1174 /// @brief Insert a new element at the specified position in the vector by
1175 /// move-constructing or move-assigning from the supplied value. Any existing
1176 /// elements from the specified position to the end of the vector are moved to
1177 /// make room.
1178 /// @param pos The position to insert the new element
1179 /// @param value The value to move from
1180 /// @return An iterator referring to the new element
1181 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1182 constexpr auto insert(const_iterator pos, value_type&& value) noexcept(
1184 ) -> iterator {
1185 return internal_insert(pos, 1U, std::move(value));
1186 }
1187 /// @brief Insert a new element at the specified position in the vector by
1188 /// copy-constructing or copy-assigning from the supplied value. Any existing
1189 /// elements from the specified position to the end of the vector are moved to
1190 /// make room.
1191 /// @param pos The position to insert the new element
1192 /// @param value The value to copy from
1193 /// @return An iterator referring to the new element
1194 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1195 constexpr auto insert(const_iterator pos, value_type const& value) noexcept(
1198 ) -> iterator {
1199 return internal_insert(pos, 1U, value);
1200 }
1201 /// @brief Insert a specified number of copies of a new element at the specified
1202 /// position in the vector by copy-constructing or copy-assigning from the
1203 /// supplied value. Any existing elements from the specified position to the
1204 /// end of the vector are moved to make room.
1205 /// @param pos The position to insert the new element
1206 /// @param count The number of copies to insert
1207 /// @param value The value to copy from
1208 /// @return An iterator referring to the location of the new elements
1209 /// @pre @c count<=(Capacity-size()), else @c ARENE_PRECONDITION violation
1210 constexpr auto insert(const_iterator pos, size_type count, value_type const& value) noexcept(
1213 ) -> iterator {
1214 return internal_insert(pos, count, value);
1215 }
1216
1217 /// @brief Insert new element at the specified position in the vector by
1218 /// constructing or assigning from the elements in the supplied range. Any
1219 /// existing elements from the specified position to the end of the vector are
1220 /// moved to make room.
1221 /// @param pos The position to insert the new element
1222 /// @param first The start of the range to insert
1223 /// @param last The end of the range to insert
1224 /// @return An iterator referring to the new element
1225 /// @pre The number of elements in the range must be less than or equal to @c Capacity-size(), else @c
1226 /// ARENE_PRECONDITION violation
1227 template <
1228 typename InputIterator,
1229 constraints<std::enable_if_t<arene::base::is_input_iterator_v<InputIterator>>> = nullptr>
1230 constexpr auto insert(const_iterator pos, InputIterator first, InputIterator last) noexcept(
1231 denotes_nothrow_iterable_range_v<InputIterator> && std::is_nothrow_move_constructible<value_type>::value &&
1233 std::is_nothrow_constructible<value_type, typename std::iterator_traits<InputIterator>::reference>::value
1234 ) -> iterator {
1235 return internal_insert(pos, first, last);
1236 }
1237
1238 /// @brief Insert a new element at the specified position in the vector by
1239 /// move-constructing or move-assigning from a new element constructed from
1240 /// the supplied arguments. Any existing elements from the specified position
1241 /// to the end of the vector are moved to make room.
1242 /// @tparam Args The types of the constructor arguments
1243 /// @param pos The position to insert the new element
1244 /// @param args The constructor arguments
1245 /// @return An iterator referring to the new element
1246 /// @pre @c size()<Capacity, else @c ARENE_PRECONDITION violation
1247 template <typename... Args>
1248 constexpr auto emplace(const_iterator pos, Args&&... args) noexcept(
1250 std::is_nothrow_constructible<value_type, Args&&...>::value
1251 ) -> iterator {
1252 // parasoft-begin-suppress AUTOSAR-A5_2_2-a-2 "False positive: constructor syntax not C-style cast"
1253 return internal_insert(pos, 1U, value_type(std::forward<Args>(args)...));
1254 // parasoft-end-suppress AUTOSAR-A5_2_2-a-2
1255 }
1256
1257 /// @brief Erase the element at the specified position.
1258 /// @param pos An iterator referring to the element to erase
1259 /// @return An iterator referring to the erase location
1260 /// @pre @c pos Must be a valid iterator to a live element in @c this
1261 constexpr auto erase(const_iterator pos) noexcept(std::is_nothrow_move_assignable<value_type>::value) -> iterator {
1262 return erase(pos, pos + 1);
1263 }
1264
1265 /// @brief Erase all the element in the specified range.
1266 /// @param first An iterator referring to the start of the range to erase
1267 /// @param last An iterator referring to the end of the range to erase
1268 /// @pre @c [first,last) Must be a valid iterator range in @c this
1269 /// @return An iterator referring to the erase location
1270 constexpr auto erase(const_iterator first, const_iterator last) noexcept(
1272 ) -> iterator {
1273 // parasoft-begin-suppress AUTOSAR-M14_6_1-a-2 "False Positive: unqualified identifier not used"
1274 auto count = last - first;
1275 auto ncpos = begin() + (first - begin());
1276 for (auto next = ncpos + count, endpos = end(); next != endpos; ++next) {
1277 *(next - count) = std::move(*next);
1278 }
1279 // parasoft-end-suppress AUTOSAR-M14_6_1-a-2
1280 this->shrink_to(size() - static_cast<size_type>(count));
1281 return ncpos;
1282 }
1283
1284 /// @brief Destroy the last element in the vector and decrease the size
1285 /// @pre The vector must not be empty
1286 constexpr void pop_back() noexcept {
1288 this->shrink_to(size() - size_type{1U});
1289 }
1290
1291 private:
1292 /// @brief Obtain the available free space
1293 /// @return std::size_t holding the available space before the capacity is exhausted
1294 constexpr auto free_space() const noexcept -> std::size_t { return this->capacity() - size(); }
1295
1296 /// @brief Actually do an insert at the specified position, of the specified number
1297 /// of elements from the given source. Existing elements are moved out of the
1298 /// way.
1299 /// @tparam Source The type of the source
1300 /// @param pos The position at which to insert elements
1301 /// @param count The number of elements to insert
1302 /// @param source A class representing the source of the elements
1303 /// @return An iterator to the insert position
1304 /// @pre <c>count <= (Capacity - size())</c>, else @c ARENE_PRECONDITION violation
1305 template <typename Source>
1306 constexpr auto internal_do_insert(const_iterator pos, size_type count, Source source) -> iterator {
1307 ARENE_PRECONDITION(count <= free_space());
1308
1309 vector_interface::iterator mutable_pos{arene::base::next(begin(), arene::base::distance(cbegin(), pos))};
1310 vector_interface::iterator original_end{end()};
1311
1312 // In many cases, shifting existing elements and then inserting into the target position would be more efficient,
1313 // but doing it that way can invalidate arguments that refer to elements after the target position, and there is no
1314 // reliable way to detect if this is the case. Emplace at the end + rotate is always safe.
1315
1316 for (vector_interface::size_type i{0U}; i < count; ++i) {
1317 this->internal_emplace_back(source.next());
1318 }
1319 arene::base::rotate(mutable_pos, original_end, end());
1320
1321 return mutable_pos;
1322 }
1323
1324 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: arg is moved"
1325 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: arg is moved"
1326 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: arg is moved"
1327 /// @brief Insert a number of copies of the specified value at the specified
1328 /// position. If @c Arg is an rvalue, moves rather than copies.
1329 /// @tparam Arg The type of the argument.
1330 /// @param pos The position at which to insert the elements
1331 /// @param count The number of elements to insert
1332 /// @param arg The value to insert
1333 /// @return An iterator referring to the insert location
1334 template <typename Arg>
1335 constexpr auto internal_insert(const_iterator pos, size_type count, Arg&& arg) -> iterator {
1336 /// @brief This type holds a reference to the argument, in order to avoid unnecessary copying.
1337 /// The stored reference is then used to construct the inserted value
1338 class fixed_source {
1339 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
1340 Arg& arg_;
1341
1342 public:
1343 constexpr explicit fixed_source(Arg& arg) noexcept
1344 : arg_(arg) {}
1345 constexpr auto next() const noexcept -> Arg&& { return std::forward<Arg>(arg_); }
1346 };
1347 return internal_do_insert(pos, count, fixed_source{arg});
1348 }
1349 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1350 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1351 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1352
1353 /// @brief Insert elements from a bidirectional iterator range at the specified position.
1354 /// @tparam Iterator The type of the iterator
1355 /// @param pos The position at which to insert the elements
1356 /// @param first The start of the iterator range to insert
1357 /// @param last The end of the iterator range to insert
1358 /// @return An iterator referring to the insert location
1359 template <
1360 typename Iterator,
1361 constraints<std::enable_if_t<arene::base::is_bidirectional_iterator_v<Iterator>>> = nullptr>
1362 constexpr auto internal_insert(const_iterator pos, Iterator first, Iterator last) -> iterator {
1363 auto const insert_count = static_cast<size_type>(arene::base::distance(first, last));
1364
1365 class iterator_source {
1366 Iterator current_;
1367
1368 public:
1369 constexpr explicit iterator_source(Iterator base)
1370 : current_(base) {}
1371
1372 constexpr auto next() -> decltype(*current_) { return *current_++; }
1373 };
1374 return internal_do_insert(pos, insert_count, iterator_source{first});
1375 }
1376
1377 /// @brief Insert elements from an input iterator range at the specified
1378 /// position.
1379 /// @return An iterator referring to the insert location
1380 /// @tparam Iterator The type of the iterator
1381 /// @param pos The position at which to insert the elements
1382 /// @param first The start of the iterator range to insert
1383 /// @param last The end of the iterator range to insert
1384 template <
1385 typename Iterator,
1389 constexpr auto internal_insert(const_iterator pos, Iterator first, Iterator last) -> iterator {
1390 auto ncpos = begin() + (pos - begin());
1391 for (; first != last; ++first) {
1392 internal_insert(pos++, 1, *first);
1393 }
1394 return ncpos;
1395 }
1396};
1397// parasoft-end-suppress AUTOSAR-A10_1_1-a-2
1398// parasoft-end-suppress AUTOSAR-A12_0_1-a-2
1399// parasoft-end-suppress AUTOSAR-A1_1_1-c-2
1400// parasoft-end-suppress AUTOSAR-A1_1_1-b-2
1401// parasoft-end-suppress AUTOSAR-M14_5_3-a-2
1402// parasoft-end-suppress AUTOSAR-A14_5_1-a-2
1403
1404/// @brief Constant that is @c true if a container is an instantiation of @c inline_vector of @c T with any capacity,
1405/// @c false otherwise
1406/// @tparam T The element type
1407/// @tparam Container The container type to check
1408template <typename T, typename Container>
1409constexpr bool is_inline_vector_of_t_v = false;
1410
1411/// @brief Constant that is @c true if a container is an instantiation of @c inline_vector of @c T with any capacity,
1412/// @c false otherwise
1413/// @tparam T The element type
1414/// @tparam Capacity The capacity of the @c inline_vector being checked
1415template <typename T, std::size_t Capacity>
1416constexpr bool is_inline_vector_of_t_v<T, inline_vector<T, Capacity>> = true;
1417
1418} // namespace inline_vector_detail
1419
1420// parasoft-begin-suppress AUTOSAR-A10_1_1-a-2 "False positive: the vector_interface is the only non-empty base class"
1421// parasoft-begin-suppress AUTOSAR-A12_1_5-a "False positive: No work done in constructors to delegate"
1422/// @brief A container similar to @c std::vector<T> that has a fixed capacity. The storage for the elements is held
1423/// directly within the class. Any attempt to store more than @c Capacity elements will case an @c ARENE_PRECONDITION
1424/// violation.
1425/// @tparam T The type of each element
1426/// @tparam Capacity The maximum number of elements that can be stored.
1427template <typename T, std::size_t Capacity>
1429 : public inline_vector_detail::vector_interface<inline_vector_detail::inline_vector_internal_storage<T, Capacity>>
1430 , full_ordering_operators_from_less_than_and_equals<inline_vector<T, Capacity>> {
1431 static_assert(std::is_nothrow_destructible<T>::value, "Destructors must not throw");
1432
1433 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False Positive: This identifier does not hide anything"
1434 /// @brief The type of the interface base class
1435 using interface_base =
1436 inline_vector_detail::vector_interface<inline_vector_detail::inline_vector_internal_storage<T, Capacity>>;
1437 // parasoft-end-suppress AUTOSAR-A2_10_1-e
1438
1439 public:
1440 // Alias in typedefs from base class
1441 using typename interface_base::const_iterator;
1442 using typename interface_base::const_pointer;
1443 using typename interface_base::const_reference;
1444 using typename interface_base::const_reverse_iterator;
1445 using typename interface_base::difference_type;
1446 using typename interface_base::iterator;
1447 using typename interface_base::pointer;
1448 using typename interface_base::reference;
1449 using typename interface_base::reverse_iterator;
1450 using typename interface_base::size_type;
1451 using typename interface_base::value_type;
1452
1453 using interface_base::assign;
1454 using interface_base::back;
1455 using interface_base::begin;
1456 using interface_base::capacity;
1457 using interface_base::cbegin;
1458 using interface_base::cend;
1459 using interface_base::clear;
1460 using interface_base::crbegin;
1461 using interface_base::crend;
1462 using interface_base::data;
1463 using interface_base::emplace_back;
1464 using interface_base::empty;
1465 using interface_base::end;
1466 using interface_base::erase;
1467 using interface_base::front;
1468 using interface_base::insert;
1469 using interface_base::max_size;
1470 using interface_base::push_back;
1471 using interface_base::rbegin;
1472 using interface_base::rend;
1473 using interface_base::resize;
1474 using interface_base::size;
1475 using interface_base::operator[];
1476 using interface_base::interface_base;
1477
1478 /// @brief Construct an empty vector
1479 constexpr inline_vector() = default;
1480
1481 /// @brief Default destructor
1482 ~inline_vector() = default;
1483
1484 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
1485 // initialize the base class"
1486 /// @brief Copy construct from a vector with a different capacity
1487 /// @tparam OtherCapacity The capacity of the other vector
1488 /// @tparam U Dummy template parameter the same as @c T for constraints
1489 /// @param other The other vector
1490 /// @pre @c other.size()<=capacity(), else @c ARENE_PRECONDITION violation
1491 template <
1492 size_type OtherCapacity,
1493 typename U = T,
1498 constexpr explicit inline_vector(inline_vector<T, OtherCapacity> const& other
1500 : inline_vector(other.begin(), other.end()) {}
1501 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
1502
1503 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
1504 // initialize the base class"
1505 /// @brief Move construct from a vector with a different capacity
1506 /// @tparam OtherCapacity The capacity of the other vector
1507 /// @param other The other vector
1508 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation
1509 template <size_type OtherCapacity, constraints<std::enable_if_t<OtherCapacity != Capacity>> = nullptr>
1512 : inline_vector(typename interface_base::move_construction_tag{}, std::move(other)) {}
1513 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
1514
1515 /// @brief Default copy constructor
1516 constexpr inline_vector(inline_vector const&) = default;
1517
1518 /// @brief Default move constructor
1519 constexpr inline_vector(inline_vector&&) = default;
1520
1521 /// @brief Default copy assignment
1522 constexpr auto operator=(inline_vector const&) -> inline_vector& = default;
1523
1524 /// @brief Default move assignment
1525 constexpr auto operator=(inline_vector&&) -> inline_vector& = default;
1526
1527 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False Positive: This identifier does not hide anything"
1528 /// @brief Default construct a vector
1529 /// @return optional<inline_vector> holding the default-constructed vector
1530 static constexpr auto try_construct() noexcept -> optional<inline_vector> { return {in_place}; }
1531 // parasoft-end-suppress AUTOSAR-A2_10_1-e
1532
1533 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False Positive: This identifier does not hide anything"
1534 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1535 /// @brief Construct a vector initialized with the specified parameters
1536 /// @tparam InitElement The type of the elements in the initializer list with which to initialize the vector
1537 /// @param init_list The initializer list with which to initialize the vector
1538 /// @return optional<inline_vector> holding the vector if the number of elements in the source container is less than
1539 /// or equal to the @c Capacity, otherwise returns an empty optional
1540 template <
1541 typename InitElement,
1545 typename std::initializer_list<InitElement>::const_iterator>::value>> = nullptr>
1546 static constexpr auto try_construct(std::initializer_list<InitElement> const& init_list) noexcept(
1552 if (init_list.size() > capacity()) {
1553 return {};
1554 }
1555 return {in_place, init_list.begin(), init_list.end()};
1556 }
1557 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1558
1559 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1560 /// @brief Construct a vector initialized with the specified paramters
1561 /// @tparam Container The type of the container with which to initialize the vector
1562 /// @param container The container with which to initialize the vector
1563 /// @return optional<inline_vector> holding the vector if the number of elements in the source container is less than
1564 /// or equal to the @c Capacity, otherwise returns an empty optional
1565 template <
1566 typename Container,
1570 static constexpr auto try_construct(Container const& container
1572 if (container.size() > capacity()) {
1573 return {};
1574 }
1575 return {in_place, container};
1576 }
1577 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1578
1579 /// @brief Construct a vector initialized with the specified paramters
1580 /// @tparam Container The type of the container with which to initialize the vector
1581 /// @param container The container with which to initialize the vector
1582 /// @return optional<inline_vector> holding the vector if the number of elements in the source container is less than
1583 /// or equal to the @c Capacity, otherwise returns an empty optional
1584 template <
1585 typename Container,
1589 static constexpr auto try_construct(Container&& container
1591 if (container.size() > capacity()) {
1592 return {};
1593 }
1594 return {in_place, std::forward<Container>(container)};
1595 }
1596
1597 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "Constrained via SFINAE, permitted by A13-3-1 Permit #1"
1598 /// @brief Construct a vector with the specified number of default-constructed elements
1599 /// @tparam U Dummy template parameter the same as @c T for constraints
1600 /// @param count The number of elements to construct in the vector
1601 /// @return optional<inline_vector> holding the vector if the @c count is less than or equal to the @c Capacity,
1602 /// otherwise returns an empty optional
1603 template <
1604 typename U = T,
1608 static constexpr auto try_construct(size_type count) noexcept(std::is_nothrow_default_constructible<T>::value)
1610 if (count > capacity()) {
1611 return {};
1612 }
1613 return {in_place, count};
1614 }
1615 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
1616
1617 /// @brief Construct a vector with the specified number of elements copied from the provided source
1618 /// @tparam U Dummy template parameter the same as @c T for constraints
1619 /// @param count The number of elements to construct in the vector
1620 /// @param source The element to copy
1621 /// @return optional<inline_vector> holding the vector if the @c count is less than or equal to the @c Capacity,
1622 /// otherwise returns an empty optional
1623 template <
1624 typename U = T,
1626 nullptr>
1627 static constexpr auto try_construct(size_type count, T const& source) noexcept(
1630 if (count > capacity()) {
1631 return {};
1632 }
1633 return {in_place, count, source};
1634 }
1635
1636 /// @brief Construct a vector from a bidrectional iterator range
1637 /// @tparam Iterator The type of the iterator
1638 /// @tparam U Dummy template parameter the same as @c T for constraints
1639 /// @param first The start of the range
1640 /// @param last The end of the range
1641 /// @return optional<inline_vector> holding the resulting vector if the number of elements in the range is less than
1642 /// or equal to @c Capacity, an empty optional otherwise
1643 template <
1644 typename Iterator,
1645 typename U = T,
1650 nullptr>
1651 static constexpr auto try_construct(Iterator first, Iterator last) noexcept(
1655 if (static_cast<size_type>(arene::base::distance(first, last)) > capacity()) {
1656 return {};
1657 }
1658 return {in_place, first, last};
1659 }
1660
1661 /// @brief Construct a vector from an input iterator range
1662 /// @tparam Iterator The type of the iterator
1663 /// @tparam U Dummy template parameter the same as @c T for constraints
1664 /// @param first The start of the range
1665 /// @param last The end of the range
1666 /// @return optional<inline_vector> holding the resulting vector if the number of elements in the range is less than
1667 /// or equal to @c Capacity, an empty optional otherwise
1668 template <
1669 typename Iterator,
1670 typename U = T,
1676 nullptr>
1677 static constexpr auto try_construct(Iterator first, Iterator last) noexcept(
1681 optional<inline_vector> res{in_place};
1682 for (auto& elem : make_subrange(first, last)) {
1683 if (res->size() == interface_base::capacity()) {
1684 return {};
1685 }
1686 res->internal_emplace_back(elem);
1687 }
1688 return res;
1689 }
1690 // parasoft-end-suppress AUTOSAR-A2_10_1-e
1691
1692 /// @brief Assign to the vector from the elements of an initializer list. Assigns
1693 /// over existing elements, constructs additional elements, and destroys any
1694 /// excess.
1695 /// @param source_values The source values
1696 /// @pre @c source_values.size()<=Capacity, else @c ARENE_PRECONDITION violation
1699 -> inline_vector& {
1700 this->assign(source_values);
1701 return *this;
1702 }
1703
1704 /// @brief Copy-assign to the vector from the elements of a vector with a different
1705 /// capacity. Assigns over existing elements, constructs additional elements,
1706 /// and destroys any excess.
1707 /// @param other The source vector
1708 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation
1709 template <
1710 typename U = T,
1711 size_type OtherCapacity,
1718 -> inline_vector& {
1719 this->assign(other.begin(), other.end());
1720 return *this;
1721 }
1722
1723 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Elements are moved via move_iterator"
1724 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Elements are moved via move_iterator"
1725 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Elements are moved via move_iterator"
1726 /// @brief Move-assign to the vector from the elements of a vector with a different
1727 /// capacity. Assigns over existing elements, constructs additional elements,
1728 /// and destroys any excess.
1729 /// @param other The source vector
1730 /// @pre @c other.size()<=Capacity, else @c ARENE_PRECONDITION violation
1731 template <size_type OtherCapacity, constraints<std::enable_if_t<OtherCapacity != Capacity>> = nullptr>
1734 -> inline_vector& {
1735 this->assign(std::make_move_iterator(other.begin()), std::make_move_iterator(other.end()));
1736 return *this;
1737 }
1738 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
1739 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
1740 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
1741
1742 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False Positive: 'swap' does not hide anything"
1743 /// @brief swaps all the elements between this vector and another.
1744 ///
1745 /// @tparam U the type of the elements in the array. Must satisfy @c is_swappable_v .
1746 /// @param other the vector to swap with.
1747 /// @post The elements in @c this and @c other are exchanged 1:1 up to the @c size() of the smallest vector. Relative
1748 /// order is maintained. The remaining elements from the originally larger vector are move-constructed into the
1749 /// originally smaller vector maintaining relative order, and the elements in the originally larger vector are
1750 /// destroyed.
1751 ///
1752 template <typename U = value_type, constraints<std::enable_if_t<is_swappable_v<U>>> = nullptr>
1753 constexpr void swap(inline_vector& other
1755 this->do_swap(other);
1756 }
1757 // parasoft-end-suppress AUTOSAR-A2_10_1-d
1758
1759 // parasoft-begin-suppress AUTOSAR-A2_7_2-a-2 "False positive: no commented-out code"
1760 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
1761 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Hidden friends permitted by A11-3-1 Permit #2"
1762 /// @brief swaps all the elements between two vectors.
1763 ///
1764 /// @tparam U the type of the elements in the vector. Must satisfy @c is_swappable_v .
1765 /// @param lhs the left hand vector to swap.
1766 /// @param rhs the right hand vector to swap.
1767 /// @post Equivalent to having called @c lhs.swap(rhs);
1768 /// @see inline_vector::swap.
1769 ///
1770 template <typename U = value_type, constraints<std::enable_if_t<is_swappable_v<U>>> = nullptr>
1771 friend constexpr void swap(inline_vector& lhs, inline_vector& rhs) noexcept(noexcept(lhs.swap(rhs))) {
1772 lhs.swap(rhs);
1773 }
1774 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
1775 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
1776 // parasoft-end-suppress AUTOSAR-A2_7_2-a-2
1777
1778 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
1779 // friend functions"
1780 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
1781 /// @brief Compare two vectors for equality.
1782 ///
1783 /// @tparam U dummy parameter to disable if @c value_type is three-way-comparable
1784 /// @param lhs The first vector
1785 /// @param rhs The second vector
1786 /// @return bool equivalent to @c arene::base::equal(lhs.begin(),lhs.end(),rhs.begin(),rhs.end()) .
1787 template <typename U = value_type, constraints<std::enable_if_t<is_equality_comparable_v<U>>> = nullptr>
1788 friend constexpr auto operator==(inline_vector const& lhs, inline_vector const& rhs) noexcept -> bool {
1789 return ::arene::base::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1790 }
1791 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
1792 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
1793
1794 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: It is allowed to declare comparison operators as
1795 // friend functions"
1796 // parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
1797 /// @brief Compare two vectors for lexicographical ordering.
1798 ///
1799 /// @tparam U dummy parameter to disable if @c value_type is not less-than-comparable
1800 /// @param lhs The first vector
1801 /// @param rhs The second vector
1802 /// @return bool equivalent to @c arene::base::lexicographical_compare(lhs.begin(),lhs.end(),rhs.begin(),rhs.end()) .
1803 template <typename U = value_type, constraints<std::enable_if_t<is_less_than_comparable_v<U>>> = nullptr>
1804 friend constexpr auto operator<(inline_vector const& lhs, inline_vector const& rhs) noexcept -> bool {
1805 return ::arene::base::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1806 }
1807 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
1808 // parasoft-end-suppress AUTOSAR-M3_3_2-a-2
1809};
1810// parasoft-end-suppress AUTOSAR-A10_1_1-a-2
1811// parasoft-end-suppress AUTOSAR-A12_1_5-a
1812
1813} // namespace base
1814} // namespace arene
1815
1816// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
1817
1818#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_VECTOR_HPP_
A container similar to std::vector<T> that has a fixed capacity. The storage for the elements is held...
Definition vector.hpp:1430
static constexpr auto try_construct() noexcept -> optional< inline_vector >
Default construct a vector.
Definition vector.hpp:1530
static constexpr auto try_construct(Container const &container) noexcept(std::is_nothrow_constructible< inline_vector, Container const & >::value) -> optional< inline_vector >
Construct a vector initialized with the specified paramters.
Definition vector.hpp:1570
static constexpr auto try_construct(size_type count, T const &source) noexcept(std::is_nothrow_copy_constructible< T >::value) -> optional< inline_vector >
Construct a vector with the specified number of elements copied from the provided source.
Definition vector.hpp:1627
constexpr auto operator=(inline_vector &&) -> inline_vector &=default
Default move assignment.
constexpr inline_vector(inline_vector &&)=default
Default move constructor.
constexpr inline_vector(inline_vector< T, OtherCapacity > &&other) noexcept(std::is_nothrow_move_constructible< T >::value)
Move construct from a vector with a different capacity.
Definition vector.hpp:1510
static constexpr auto try_construct(Container &&container) noexcept(std::is_nothrow_constructible< inline_vector, Container && >::value) -> optional< inline_vector >
Construct a vector initialized with the specified paramters.
Definition vector.hpp:1589
constexpr void swap(inline_vector &other) noexcept(is_nothrow_swappable_v< value_type > &&std::is_nothrow_move_constructible< value_type >::value)
swaps all the elements between this vector and another.
Definition vector.hpp:1753
constexpr inline_vector(inline_vector const &)=default
Default copy constructor.
constexpr inline_vector(inline_vector< T, OtherCapacity > const &other) noexcept(std::is_nothrow_copy_constructible< T >::value)
Copy construct from a vector with a different capacity.
Definition vector.hpp:1498
static constexpr auto try_construct(std::initializer_list< InitElement > const &init_list) noexcept(std::is_nothrow_constructible< inline_vector, typename std::initializer_list< InitElement >::const_iterator, typename std::initializer_list< InitElement >::const_iterator >::value) -> optional< inline_vector >
Construct a vector initialized with the specified parameters.
Definition vector.hpp:1546
auto operator=(inline_vector< U, OtherCapacity > const &other) noexcept(std::is_nothrow_copy_constructible< U >::value &&std::is_nothrow_copy_assignable< U >::value) -> inline_vector &
Copy-assign to the vector from the elements of a vector with a different capacity....
Definition vector.hpp:1716
friend constexpr auto operator==(inline_vector const &lhs, inline_vector const &rhs) noexcept -> bool
Compare two vectors for equality.
Definition vector.hpp:1788
constexpr inline_vector()=default
Construct an empty vector.
friend constexpr auto operator<(inline_vector const &lhs, inline_vector const &rhs) noexcept -> bool
Compare two vectors for lexicographical ordering.
Definition vector.hpp:1804
auto operator=(std::initializer_list< T > source_values) noexcept(std::is_nothrow_copy_constructible< T >::value &&std::is_nothrow_copy_assignable< T >::value) -> inline_vector &
Assign to the vector from the elements of an initializer list. Assigns over existing elements,...
Definition vector.hpp:1697
static constexpr auto try_construct(size_type count) noexcept(std::is_nothrow_default_constructible< T >::value) -> optional< inline_vector >
Construct a vector with the specified number of default-constructed elements.
Definition vector.hpp:1608
~inline_vector()=default
Default destructor.
static constexpr auto try_construct(Iterator first, Iterator last) noexcept(denotes_nothrow_iterable_range_v< Iterator > &&std::is_nothrow_constructible< T, typename std::iterator_traits< Iterator >::reference >::value) -> optional< inline_vector >
Construct a vector from a bidrectional iterator range.
Definition vector.hpp:1651
auto operator=(inline_vector< T, OtherCapacity > &&other) noexcept(std::is_nothrow_move_constructible< T >::value &&std::is_nothrow_move_assignable< T >::value) -> inline_vector &
Move-assign to the vector from the elements of a vector with a different capacity....
Definition vector.hpp:1732
friend constexpr void swap(inline_vector &lhs, inline_vector &rhs) noexcept(noexcept(lhs.swap(rhs)))
swaps all the elements between two vectors.
Definition vector.hpp:1771
constexpr auto operator=(inline_vector const &) -> inline_vector &=default
Default copy assignment.
Implementation of std::optional for pre-C++17 compilers, and which replaces defined undefined behavio...
Definition optional.hpp:122
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
iterator const_iterator
The type of the iterator.
Definition initializer_list.hpp:32
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
#define ARENE_INVARIANT_UNREACHABLE(message)
Terminate the application if this line is ever executed. The supplied message will be output in that ...
Definition contract.hpp:170
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Provides implementation of a backport of C++20's version of std::equal.
Provides backports of std::in_place_t, std::in_place_type_t, and std::in_place_index_t from C++17.
Provides an implementation of a backport of std::lexicographical_compare from C++20.
static ARENE_MAYBE_UNUSED constexpr auto const & swap
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
Definition swap.hpp:130
constexpr auto empty() -> bool
Get whether the type list is empty.
Definition size.hpp:111
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
constexpr auto distance(Iterator first, Iterator last) noexcept(noexcept(distance_impl::do_distance(first, last, typename std::iterator_traits< Iterator >::iterator_category{}))) -> typename std::iterator_traits< Iterator >::difference_type
Find the number of elements between first and last.
Definition distance.hpp:79
constexpr bool denotes_nothrow_iterable_range_v
Check if an iterator/sentinel pair form an iterable range that can be iterated without throwing.
constexpr auto make_subrange(Iterator iterator, Sentinel sentinel) noexcept(std::is_nothrow_move_constructible< Iterator >::value &&//std::is_nothrow_move_constructible< Sentinel >::value) -> make_subrange_detail::iterator_range< Iterator, Sentinel >
Combine an iterator and sentinel into a range type that can be used with range-based for loops.
Definition make_subrange.hpp:98
constexpr std::integral_constant< typename inline_map< Key, Value, Capacity, Compare >::size_type, Capacity > inline_map< Key, Value, Capacity, Compare >::capacity
Definition map.hpp:2305
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
STL namespace.
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto make_move_iterator(Iterator iter) -> std::move_iterator< Iterator >
Create a move_iterator with the specified underlying iterator.
Definition move_iterator.hpp:353
constexpr auto end(Element(&array)[Size]) noexcept -> Element *
Obtain a pointer to the one-past-the-end element of the array.
Definition end.hpp:28
constexpr auto min(initializer_list< T > list, Compare comp) noexcept(noexcept(comp(std::declval< T & >(), std::declval< T & >())) &&std::is_nothrow_copy_constructible_v< T >) -> T
Returns the smallest value in the std::initializer_list.
Definition min_initializer_list_overload.hpp:50
constexpr auto cend(Container const &cont) noexcept(noexcept(::std::end(std::declval< Container const & >()))) ->
Equivalent to invoking end(cont) on a const container.
Definition end.hpp:66
constexpr auto begin(Element(&array)[Size]) noexcept -> Element *
Obtain a pointer to the first element of the array.
Definition begin.hpp:28
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
constexpr auto cbegin(Container const &cont) noexcept(noexcept(::std::begin(std::declval< Container const & >()))) ->
Equivalent to invoking begin(cont) on a const container.
Definition begin.hpp:64
Provides a backport of the constexpr implementation of std::reverse_iterator .