Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1// Copyright 2026, 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_TESTING_VECTOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_VECTOR_HPP_
7
8#include <gmock/gmock.h>
9#include <gtest/gtest.h>
10
24#include "arene/base/stdlib_choice/addressof.hpp"
25#include "arene/base/stdlib_choice/cstddef.hpp"
26#include "arene/base/stdlib_choice/declval.hpp"
27#include "arene/base/stdlib_choice/forward.hpp"
28#include "arene/base/stdlib_choice/initializer_list.hpp"
29#include "arene/base/stdlib_choice/integer_sequence.hpp"
30#include "arene/base/stdlib_choice/is_assignable.hpp"
31#include "arene/base/stdlib_choice/is_constructible.hpp"
32#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
33#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
34#include "arene/base/stdlib_choice/is_default_constructible.hpp"
35#include "arene/base/stdlib_choice/is_move_assignable.hpp"
36#include "arene/base/stdlib_choice/is_move_constructible.hpp"
37#include "arene/base/stdlib_choice/is_rvalue_reference.hpp"
38#include "arene/base/stdlib_choice/is_same.hpp"
39#include "arene/base/stdlib_choice/iterator_tags.hpp"
40#include "arene/base/stdlib_choice/iterator_traits.hpp"
41#include "arene/base/stdlib_choice/move.hpp"
42#include "arene/base/stdlib_choice/move_iterator.hpp"
43#include "arene/base/stdlib_choice/numeric_limits.hpp"
44#include "arene/base/stdlib_choice/pair.hpp"
45#include "arene/base/stdlib_choice/reference_wrapper.hpp"
46#include "arene/base/stdlib_choice/stdexcept.hpp"
52#include "testlibs/utilities/iterator_types.hpp"
53
54namespace arene {
55namespace base {
56namespace testing {
57
59ARENE_IGNORE_ALL("-Wfloat-equal", "These tests don't perform arithmetic, so equality is OK even for floating point");
60
61template <class T>
63 constexpr explicit equal_to_value(T const& input)
64 : value{input} {}
65 constexpr auto operator()(T const& arg) -> bool { return arg == value; }
66
67 T const& value;
68};
69
70/// @brief Check if all element of @c range are equal to @c value
71/// @tparam Range The type of the range to check
72/// @tparam T The type of the value to compare against
73/// @param range The range to check
74/// @param value The value to compare against
75///
76/// This helper is an alternative to GTest matchers @c Each(Eq(value)), which require the value to be copy
77/// constructible.
78template <class Range, class T>
79constexpr auto all_elements_are(Range const& range, T const& value) -> bool {
80 return arene::base::all_of(range.begin(), range.end(), equal_to_value<T>{value});
81}
82
83/// @brief Check if all element of @c range are equal to the elements in @c values
84/// @tparam Range1 The type of the range to check
85/// @tparam Range2 The type of the value to compare against
86/// @param range The range to check
87/// @param values The values to compare against
88///
89/// This helper is an alternative to GTest matcher @c ElementsAreArray, which require the values to be copy
90/// constructible.
91template <class Range1, class Range2>
92constexpr auto elements_are_array(Range1 const& range, Range2 const& values) -> bool {
93 return arene::base::equal(range.begin(), range.end(), values.begin());
94}
95
96/// @brief Create a test vector containing a range of test values
97/// @tparam T The type to contain in the test vector
98/// @tparam Capacity The capacity of inline_vector to populate (note: this is not the size / number of actual entries)
99/// @param begin The first index of test value to put in the vector
100/// @param end The after-end index of test value to put in the vector
101/// @return An inline_vector<T, Capacity> containing [test_value(begin), test_value(end))
102template <typename T, std::size_t Capacity>
106 for (std::size_t ii = begin; ii < end; ++ii) {
107 vec.push_back(test_value<T>(ii));
108 }
109 return vec;
110}
111
112/// @brief Push back multiple values into a vector
113/// @tparam Vector The type of the vector
114/// @tparam Values The type of the values
115/// @param vec The vector to push back into
116/// @param values the values to push back
117template <class Vector, class... Values>
118constexpr auto vector_push_back(Vector& vec, Values&&... values) -> void {
119 arene::base::consume_values({0, (vec.push_back(std::forward<Values>(values)), 0)...});
120}
121
122/// @brief sorts the container and then returns it
123/// @tparam Container The type of a container
124/// @param container A container to be sorted
125/// @return @c container with sorted elements
126///
127/// @note @c std::sort is not constexpr in C++14
128/// @note use of @c arene::base::sort introduces coverage misses
129///
130template <typename Container>
131constexpr auto sort_helper(Container container) noexcept -> Container {
132 // TODO
133 // The use of 'arene::base::sort' introduces coverage misses due to newly
134 // introduced instatiations that aren't fully exercised.
135 bool swapped{true};
136 while (swapped) {
137 swapped = false;
138 for (std::size_t ii = 0UL; ii + 1UL < container.size(); ++ii) {
139 if (container[ii + 1] < container[ii]) {
140 arene::base::swap(container[ii], container[ii + 1]);
141 swapped = true;
142 }
143 }
144 }
145 return container;
146}
147
148/// @brief True if a type is copy constructible and copy assignable, false otherwise
149/// @param T the type to check
150template <class T>
152
153/////////////////////////
154// Parameterized tests //
155/////////////////////////
156
157/// @brief Test fixture for all type-parameterized @c inline_vector tests
158/// @tparam T The type parameter currently being used for tests; filled in by Google Test as @c TypeParam
159template <typename Vector>
160class InlineVectorTest : public ::testing::Test {
161 public:
162 using T = typename Vector::value_type;
163
164 /// @brief Whether or not the current type parameter is constexpr compatible for this test
165 static constexpr bool constexpr_compatible =
167 static_assert(
169 "Constexpr-compatible types must have constexpr specializations of test_value_array or test_value"
170 );
171
172 /// @brief The base capacity to use for most @c inline_vector instantiations in the parameterized tests
173 static constexpr std::size_t capacity = Vector::capacity;
174 static_assert(capacity > 0UL, "Parameterized capacity can not be 0 (0-capacity vectors are always tested)");
175
176 protected:
178
179 /// @brief An @c inline_vector with @c capacity using any given type; useful in tests making vectors of wrapper types
180 /// @tparam ValueType The element type of this particular vector
181 template <typename ValueType>
183 /// @brief An @c inline_vector with @c value_type=T using any given capacity; useful in tests doing assignment
184 /// @tparam OtherCapacity The capacity of this particular vector
185 template <std::size_t OtherCapacity>
187
188 /// @brief A helper template to get the type resulting from a @c try_construct call
189 /// @tparam Vec An @c inline_vector type which we will try to construct
190 /// @tparam Args The arguments with which we will try to construct @c Vec
191 template <typename Vec, typename... Args>
192 using try_construct_result = decltype(Vec::try_construct(std::declval<Args>()...));
193
194 /// @brief A type with a @c noexcept(false) conversion operator to @c T (doesn't actually throw, just declares it)
196 /// @brief Implicit conversion operator to @c T which declares that it might throw, though it doesn't actually
197 /// @return The 0th test value of @c T
198 // NOLINTNEXTLINE(hicpp-explicit-conversions)
199 operator T() const noexcept(false) { return ::arene::base::testing::test_value<T>(0); }
200 };
201
202 /// @brief A bidirectional iterator of @c T which declares that it could throw, used in some @c noexcept tests
204 /// @brief The category of this iterator
206 /// @brief The type used for differences in this iterator
208 /// @brief The type returned by dereferencing this iterator
209 using reference = T&&;
210 /// @brief The value type pointed to by this iterator
211 using value_type = T;
212 /// @brief This iterator as a pointer (disabled)
213 using pointer = void;
214
215 /// @brief Dereference operator; never defined
216 auto operator*() const -> reference;
217
218 /// @brief Pre-increment operator; never defined
220 /// @brief Post-increment operator; never defined
222 /// @brief Pre-decrement operator; never defined
224 /// @brief Post-decrement operator; never defined
226 /// @brief Equality operator; never defined
227 auto operator==(throwing_bidirectional_move_iterator_of_t const&) -> bool;
228 /// @brief Inequality operator; never defined
229 auto operator!=(throwing_bidirectional_move_iterator_of_t const&) -> bool;
230 };
231
232 /// @brief An input iterator pointing to any type whose operators have adjustable @c noexcept specifications
233 /// @tparam U The value type of the iterator
234 /// @tparam OperatorsNoexcept The @c noexcept specifications of all operators are equal to this
235 template <typename U, bool OperatorsNoexcept>
237 /// @brief The category of this iterator
239 /// @brief The type used for differences in this iterator
241 /// @brief The type returned by dereferencing this iterator
242 using reference = U&;
243 /// @brief The value type pointed to by this iterator
244 using value_type = U;
245 /// @brief This iterator as a pointer (disabled)
246 using pointer = void;
247
248 /// @brief Dereference operator; never defined
249 auto operator*() const noexcept(OperatorsNoexcept) -> reference;
250
251 /// @brief Pre-increment operator; never defined
252 auto operator++() noexcept(OperatorsNoexcept) -> input_iterator_with_configurable_noexcept&;
253 /// @brief Post-increment operator; never defined
254 auto operator++(int) noexcept(OperatorsNoexcept) -> input_iterator_with_configurable_noexcept;
255 /// @brief Equality operator; never defined
256 auto operator==(input_iterator_with_configurable_noexcept const&) noexcept(OperatorsNoexcept) -> bool;
257 /// @brief Inequality operator; never defined
258 auto operator!=(input_iterator_with_configurable_noexcept const&) noexcept(OperatorsNoexcept) -> bool;
259 };
260
261 /// @brief An input iterator pointing to any type which declares that it could throw, used in some @c noexcept tests
262 /// @tparam U The value type of the iterator
263 template <typename U>
265 /// @brief An input iterator pointing to any type which declares that it can not throw, used in some @c noexcept tests
266 /// @tparam U The value type of the iterator
267 template <typename U>
269
270 /// @brief Construct a @c Vector from the passed parameters; allows calling as this->construct, which can be shorter
271 /// @tparam U The types of the arguments to the constructor
272 /// @param params The parameters to the constructor
273 template <typename... U>
274 static constexpr auto construct(U&&... params) noexcept(noexcept(Vector(std::forward<U>(params)...))) -> Vector {
275 return Vector(std::forward<U>(params)...);
276 }
277
278 /// @brief Return the @c idx 'th test value of the current @c T , parameterized by test suite users
279 /// @param idx The index of the test value to get
280 /// @return The @c idx 'th test value of the current @c T
281 static constexpr auto test_value(std::size_t idx) noexcept(noexcept(::arene::base::testing::test_value<T>(idx)))
282 -> decltype(::arene::base::testing::test_value<T>(idx)) {
283 return ::arene::base::testing::test_value<T>(idx);
284 }
285
286 /// @brief Return the @c N 'th test value of the current @c T , parameterized by test suite users
287 /// @tparam N The index of the test value to get
288 /// @return The @c N 'th test value of the current @c T
289 /// @note This requires <tt> test_value(0), ..., test_value(N) </tt> are unique values
290 template <std::size_t N>
291#ifdef ARENE_DOC_GENERATION_RUNNING
292 // Doxygen cannot resolve the dependent return type and body, so expose only the declaration while generating docs.
293 static constexpr auto unique_test_value() noexcept;
294#else
295 static constexpr auto unique_test_value() noexcept(noexcept(::arene::base::testing::unique_test_value<T, N>()))
296 -> decltype(::arene::base::testing::unique_test_value<T, N>()) {
297 return ::arene::base::testing::unique_test_value<T, N>();
298 }
299#endif
300
301 /// @brief Return a @c Vector containing the test values @c [begin,end) of @c T , parameterized by test suite users
302 /// @param begin The index of the first test value to put into the test vector
303 /// @param end The index after that of the last test value to put into the test vector
304 /// @return A test Vector holding the test values determined by the indices
305 static constexpr auto test_vector(std::size_t begin, std::size_t end) noexcept(
307 ) -> Vector {
308 return ::arene::base::testing::test_vector<T, capacity>(begin, end);
309 }
310
311 /// @brief Return a @c Vector containing the test values @c [0,size) of @c T , parameterized by test suite users
312 /// @param size The number of test values to put into the test vector
313 /// @return A test vector holding the test values determined by the size
314 static constexpr auto test_vector(std::size_t size) noexcept(noexcept(test_vector(0, size))) -> Vector {
315 return test_vector(0, size);
316 }
317
318 /// @brief Return a @c Vector containing the test values @c [0,capacity) of @c T , parameterized by test suite users
319 /// @return A test vector holding the test values determined by the capacity
320 static constexpr auto full_test_vector() noexcept(noexcept(test_vector(capacity))) -> Vector {
321 return test_vector(capacity);
322 }
323
324 /// @brief Return a @c std::initializer_list containing user-parameterized @c test_value s
325 /// @tparam Indices A pack of indices, one for each test value in the initializer list
326 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing one test value per index
327 template <std::size_t... Indices>
329 return ::arene::base::testing::test_initializer_list<T, Indices...>();
330 }
331
332 /// @brief Return a @c std::initializer_list containing user-parameterized @c test_value s
333 /// @tparam Size The number of values in the @c std::initializer_list
334 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing one test value per index
335 template <std::size_t Size>
336 static constexpr auto test_initializer_list() noexcept -> std::initializer_list<T> {
338 }
339
340 /// @brief Return a @c std::initializer_list containing @c capacity user-parameterized @c test_value s
341 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing @c capacity entries
342 static constexpr auto full_test_initializer_list() noexcept -> std::initializer_list<T> {
344 }
345};
346
347/// @brief The Death Tests use the same fixture as the "normal" tests. Inherits so that it will be a distinct type.
348/// @tparam T The type parameter of a given test instantiation
349template <typename T>
351
352// Declare the three test suites for Google Test; test cases will all be added to one of these.
355
356/// @test A default-constructed `inline_vector` is empty
357TYPED_TEST_P(InlineVectorTest, CanConstructAnEmptyVector) { ASSERT_TRUE(TestFixture::construct().empty()); }
358
359/// @test The capacity of a default-constructed `inline_vector` is equal to the supplied template parameter
360TYPED_TEST_P(InlineVectorTest, CapacityIsAsSpecified) {
361 COND_STATIC_ASSERT_EQ(TestFixture::construct().capacity(), TypeParam::capacity);
362}
363
364/// @test The `capacity` member function of `inline_vector` is declared `noexcept`
365TYPED_TEST_P(InlineVectorTest, CapacityIsNoexcept) {
366 STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().capacity()));
367}
368
369/// @test The size of a default-constructed `inline_vector` is zero
370TYPED_TEST_P(InlineVectorTest, InitialSizeIsZero) { EXPECT_EQ(TestFixture::construct().size(), 0); }
371
372/// @test The size of an `inline_vector` initialized from a list of values is correct in a `constexpr` context
374 COND_STATIC_ASSERT_EQ(TestFixture::full_test_vector().size(), TypeParam::capacity);
375}
376
377/// @test The `size` member function of `inline_vector` is declared `noexcept`
378TYPED_TEST_P(InlineVectorTest, SizeIsNoexcept) { STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().size())); }
379
380/// @test Using `push_back` to add an item to a default-constructed `inline_vector` increases the size
381TYPED_TEST_P(InlineVectorTest, CanPushBackAValue) {
382 TypeParam vec;
383 vec.push_back(TestFixture::test_value(0));
384 EXPECT_EQ(vec.size(), 1);
385}
386
387/// @test After using `push_back` to add an item to a default-constructed `inline_vector`, that item can be retrieved
388/// via the `back` member function
389TYPED_TEST_P(InlineVectorTest, AfterPushBackCanGetLastElement) {
390 TypeParam vec;
391 vec.push_back(TestFixture::test_value(0));
392 EXPECT_EQ(vec.back(), TestFixture::test_value(0));
393}
394
395/// @test After using `push_back` to add an item to a default-constructed `inline_vector`, the vector is no longer empty
396TYPED_TEST_P(InlineVectorTest, AfterPushBackVectorIsNotEmpty) {
397 TypeParam vec;
398 vec.push_back(TestFixture::test_value(0));
399 ASSERT_FALSE(vec.empty());
400}
401
402/// @test After using `push_back` twice to add two items to a default-constructed `inline_vector`, the size is
403/// incremented to 2, and the second item can be retrieved via the `back` member function
404CONDITIONAL_TYPED_TEST_P(InlineVectorTest, SecondPushBackChangesLastValue, TypeParam::capacity >= 2) {
405 TypeParam vec;
406 vec.push_back(TestFixture::test_value(0));
407 vec.push_back(TestFixture::test_value(1));
408 EXPECT_EQ(vec.size(), 2);
409 EXPECT_EQ(vec.back(), TestFixture::test_value(1));
410}
411
412/// @test `push_back` of an rvalue is `noexcept` if and only if the value type can be constructed without throwing from
413/// an rvalue
414TYPED_TEST_P(InlineVectorTest, PushBackIsConditionallyNoexceptRvalue) {
416 STATIC_ASSERT_EQ(
417 noexcept(TestFixture::construct().push_back(std::declval<typename TypeParam::value_type&&>())),
418 move_noexcept
419 );
420}
421
422/// @test `push_back` of an lvalue is `noexcept` if and only if the value type can be constructed without throwing from
423/// an lvalue
426 PushBackIsConditionallyNoexceptLvalue,
428) {
430 STATIC_ASSERT_EQ(
431 noexcept(TestFixture::construct().push_back(std::declval<typename TypeParam::value_type const&>())),
432 copy_noexcept
433 );
434}
435
436/// @test A default-constructed `inline_vector` is empty in a constexpr context
437TYPED_TEST_P(InlineVectorTest, EmptyIsConstexpr) { COND_STATIC_ASSERT_TRUE(TestFixture::construct().empty()); }
438
439/// @test The `empty` member function of `inline_vector` is `noexcept`
440TYPED_TEST_P(InlineVectorTest, EmptyIsNoexcept) { STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().empty())); }
441
442/// @test The `at` member function throws a `std::out_of_range` exception when invoked with an index of 0 on
443/// a default-constructed `inline_vector`
444TYPED_TEST_P(InlineVectorTest, RetrievingAValueWithAtThrowsOnEmpty) {
445#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
446 ASSERT_THROW(TestFixture::construct().at(0), std::out_of_range);
447#else
448 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
449#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
450}
451
452/// @test The `at` member function returns the value stored when invoked with an index of 0 on a
453/// `inline_vector` into which one element has been stored via `push_back`
454TYPED_TEST_P(InlineVectorTest, RetrievingAValueWithAtReturnsValueAfterPushBack) {
455#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
456 auto vec = TestFixture::construct();
457 vec.push_back(TestFixture::test_value(0));
458 EXPECT_EQ(vec[0], TestFixture::test_value(0));
459#else
460 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
461#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
462}
463
464/// @test The return type of the `at` member function on a non-`const` `inline_vector` is a non-`const` reference to
465/// `value_type`
466TYPED_TEST_P(InlineVectorTest, AtReturnsReference) {
467#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
468 ::testing::StaticAssertTypeEq<decltype(std::declval<TypeParam&>().at(0)), typename TypeParam::value_type&>();
469#else
470 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
471#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
472}
473
474/// @test The return type of the `at` member function on a `const` `inline_vector` is a `const` reference to
475/// `value_type`
476TYPED_TEST_P(InlineVectorTest, AtOnConstVectorReturnsConstReference) {
477#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
478 ::testing::
479 StaticAssertTypeEq<decltype(std::declval<TypeParam const&>().at(0)), typename TypeParam::value_type const&>();
480#else
481 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
482#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
483}
484
485/// @test The `at` member function returns the corresponding value stored when invoked with an index of 0 or
486/// 1 on an `inline_vector` into which two elements have been stored via `push_back`
487CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanAccessMultipleValuesWithAt, TypeParam::capacity >= 2) {
488#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
489 auto vec = TestFixture::construct();
490 vec.push_back(TestFixture::test_value(0));
491 vec.push_back(TestFixture::test_value(1));
492
493 EXPECT_EQ(vec.at(0), TestFixture::test_value(0));
494 EXPECT_EQ(vec.at(1), TestFixture::test_value(1));
495#else
496 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
497#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
498}
499
500/// @test The `at` member function throws when invoked with an index that is equal to or larger than the size of the
501/// vector on an `inline_vector` into which two elements have been stored via `push_back`
502TYPED_TEST_P(InlineVectorTest, AtIndexSizeOrLargerThrows) {
503#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
504 auto vec = TestFixture::construct();
505 vec.push_back(TestFixture::test_value(0));
506
507 ASSERT_THROW(vec.at(vec.size()), std::out_of_range);
508 ASSERT_THROW(vec.at(vec.size() * 2), std::out_of_range);
509 ASSERT_THROW(vec.at(std::numeric_limits<std::size_t>::max()), std::out_of_range);
510#else
511 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
512#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
513}
514
515/// @test The `at` member function returns the corresponding value stored when invoked via a `const` reference to a
516/// vector with an index of 0 or 1 on an `inline_vector` into which two elements have been stored via `push_back`.
517CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanAccessMultipleValuesWithAtWithConstVec, TypeParam::capacity >= 2) {
518#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
519 auto vec = TestFixture::construct();
520 vec.push_back(TestFixture::test_value(0));
521 vec.push_back(TestFixture::test_value(1));
522
523 auto const& const_vec = vec;
524 EXPECT_EQ(const_vec.at(0), TestFixture::test_value(0));
525 EXPECT_EQ(const_vec.at(1), TestFixture::test_value(1));
526#else
527 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
528#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal
529}
530
531/// @test The `at` member function throws when invoked via a `const` reference to a vector with an index that is equal
532/// to or larger than the size of an `inline_vector` into which two elements have been stored via `push_back`
533TYPED_TEST_P(InlineVectorTest, AtIndexSizeOrLargerThrowsWithConstVec) {
534#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) // conditional removal of at() tests based on exception state.
535 auto vec = TestFixture::construct();
536 vec.push_back(TestFixture::test_value(0));
537
538 auto const& const_vec = vec;
539
540 ASSERT_THROW(const_vec.at(vec.size()), std::out_of_range);
541 ASSERT_THROW(const_vec.at(vec.size() * 2), std::out_of_range);
542 ASSERT_THROW(const_vec.at(std::numeric_limits<std::size_t>::max()), std::out_of_range);
543#else
544 GTEST_SKIP() << "`at` tests skipped because exceptions are disabled";
545#endif // ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED) conditional removal of at() tests based on exception state.
546}
547
548/// @test The `max_size` member function of `inline_vector` returns the capacity specified as a template parameter.
549TYPED_TEST_P(InlineVectorTest, MaxSizeEqualsCapacity) {
550 COND_STATIC_ASSERT_EQ(TestFixture::construct().max_size(), TypeParam::capacity);
551 COND_STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().max_size()));
552}
553
554/// @test Invoking `push_back` on a vector that is at capacity terminates the program with a precondition violation.
555TYPED_TEST_P(InlineVectorDeathTest, PushBackBeyondMaxSizeIsPreconditionViolation) {
556 auto vec = TestFixture::construct();
557 for (std::size_t i = 0; i < vec.max_size(); ++i) {
558 vec.push_back(TestFixture::test_value(0));
559 }
560 ASSERT_DEATH(vec.push_back(TestFixture::test_value(0)), "Precondition violation");
561}
562
563/// @test The size of a default-constructed vector with a capacity of zero is zero, when obtained via the
564/// `size` member function, and via comparing the iterators returned from `begin` and `end`
565TYPED_TEST_P(InlineVectorTest, ZeroSizeVectorIsEmpty) {
568 ASSERT_EQ(zvec.begin(), zvec.end());
569 ASSERT_EQ(czvec.begin(), czvec.end());
570 ASSERT_EQ(zvec.size(), 0);
571 ASSERT_EQ(czvec.size(), 0);
572}
573
574/// @test Invoking `push_back` on a zero-capacity vector terminates the program with a precondition violation
575TYPED_TEST_P(InlineVectorDeathTest, PushBackOnZeroSizeVectorIsPreconditionViolation) {
577 ASSERT_DEATH(vec.push_back(TestFixture::test_value(0)), "Precondition violation");
578}
579
580/// @test Given a default-constructed `inline_vector`, after one element has been added via `push_back`, `back` returns
581/// a reference to that element. After a second element has been added via `push_back`, `back` now returns a reference
582/// to the second element.
583TYPED_TEST_P(InlineVectorTest, BackReturnsReference) {
584 auto vec = TestFixture::construct();
585
586 vec.push_back(TestFixture::test_value(0));
587 typename TypeParam::value_type& val1 = vec.back();
588 EXPECT_EQ(std::addressof(val1), std::addressof(vec[0]));
589
590 if (TypeParam::capacity >= 2UL) {
591 vec.push_back(TestFixture::test_value(1));
592 typename TypeParam::value_type& val2 = vec.back();
593 EXPECT_EQ(std::addressof(val2), std::addressof(vec[1]));
594 }
595}
596
597/// @test Given a default-constructed `inline_vector`, after one element has been added via `push_back`, `back` called
598/// via a `const` reference to the vector returns a `const` reference to that element. After a second element has been
599/// added via `push_back`, `back` called via a `const` reference to the vector now returns a `const` reference to the
600/// second element.
601TYPED_TEST_P(InlineVectorTest, ConstBackReturnsConstReference) {
602 auto vec = TestFixture::construct();
603 auto const& const_vec = vec;
604
605 vec.push_back(TestFixture::test_value(0));
606 auto& val1 = const_vec.back();
607 ::testing::StaticAssertTypeEq<decltype(val1), typename TypeParam::value_type const&>();
608 EXPECT_EQ(std::addressof(val1), &const_vec[0]);
609
610 if (TypeParam::capacity >= 2UL) {
611 vec.push_back(TestFixture::test_value(1));
612 auto& val2 = const_vec.back();
613 ::testing::StaticAssertTypeEq<decltype(val2), typename TypeParam::value_type const&>();
614 EXPECT_EQ(std::addressof(val2), &const_vec[1]);
615 }
616}
617
618/// @test Invoking `back` cannot throw
620 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().back()));
621 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam const&>().back()));
622}
623
624/// @test In a `constexpr` context, an `inline_vector` can be default-constructed, and a new value inserted via
625/// `push_back`, such that the `size` of the container is now 1, and the value can be retrieved via `at(0)`
627 constexpr auto vec = TestFixture::test_vector(1);
628 STATIC_ASSERT_EQ(vec.size(), 1);
629 STATIC_ASSERT_EQ(vec[0], TestFixture::test_value(0));
630}
631
632/// @test An `inline_vector` can be constructed from a `std::initializer_list` without throwing exceptions, and the size
633/// and values stored in the vector are the same as the size and values of the initializer list.
636 CanConstructFromInitializerList,
638) {
639 auto const values = TestFixture::full_test_initializer_list();
640
641 TypeParam const vec{values};
642 STATIC_ASSERT_EQ(noexcept(TypeParam{values}), std::is_nothrow_copy_constructible<typename TypeParam::value_type>{});
643
644 EXPECT_THAT(vec, ::testing::ElementsAreArray(values));
645}
646
647/// @test An `inline_vector` can be constructed from a `std::initializer_list` in a `constexpr` context, and the
648/// elements are those from the initializer list
651 CanConstructFromInitializerListConstexpr,
654) {
655 constexpr auto values = TestFixture::full_test_initializer_list();
656
657 constexpr TypeParam vec{values};
658
659 EXPECT_THAT(vec, ::testing::ElementsAreArray(values));
660}
661
662template <typename Vec>
663constexpr auto constexpr_non_const_back(Vec&& vec) -> typename Vec::value_type {
664 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
665 return std::forward<Vec>(vec).back();
666}
667
668/// @test Given a `constexpr` `inline_vector` constructed by pushing back values, `back` can be used in a `constexpr`
669/// context to retrieve the last value in the vector, which must therefore equal the last value pushed back
671 constexpr auto vec = TestFixture::full_test_vector();
672 STATIC_ASSERT_EQ(vec.back(), TestFixture::test_value(TypeParam::capacity - 1UL));
673 STATIC_ASSERT_EQ(
674 constexpr_non_const_back(TestFixture::full_test_vector()),
675 TestFixture::test_value(TypeParam::capacity - 1UL)
676 );
677}
678
679/// @test Given an `inline_vector` initialized by pushing back values, the `front` member function can be used to
680/// retrieve the first value, which must be equal to the first value of the vector as retrieved via `at(0)`
682 auto vec = TestFixture::full_test_vector();
683 EXPECT_EQ(std::addressof(vec.front()), std::addressof(vec[0]));
684 ::testing::StaticAssertTypeEq<decltype(vec.front()), typename TypeParam::value_type&>();
685 STATIC_ASSERT_TRUE(noexcept(vec.front()));
686 auto const& const_vec = vec;
687 EXPECT_EQ(&const_vec.front(), &const_vec[0]);
688 ::testing::StaticAssertTypeEq<decltype(const_vec.front()), typename TypeParam::value_type const&>();
689 STATIC_ASSERT_TRUE(noexcept(const_vec.front()));
690}
691
692template <typename Vec>
693constexpr auto constexpr_non_const_front(Vec&& vec) -> typename Vec::value_type {
694 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
695 return std::forward<Vec>(vec).front();
696}
697
698/// @test Given an instance of `inline_vector` by pushing back values in a `constexpr` context, the
699/// `front` member function can be used in a `constexpr` context to retrieve the first value, which must be equal to the
700/// first value of the pushed back
702 constexpr auto vec = TestFixture::full_test_vector();
703 STATIC_ASSERT_EQ(vec.front(), TestFixture::test_value(0));
704 STATIC_ASSERT_EQ(constexpr_non_const_front(TestFixture::full_test_vector()), TestFixture::test_value(0));
705}
706
707/// @test The `begin` and `end` member functions of an `inline_vector` must return an `iterator`, and they must be equal
708/// for a default-constructed vector
710 auto vec = TestFixture::construct();
711 ::testing::StaticAssertTypeEq<decltype(vec.begin()), typename TypeParam::iterator>();
712 ::testing::StaticAssertTypeEq<decltype(vec.end()), typename TypeParam::iterator>();
713 STATIC_ASSERT_TRUE(noexcept(vec.begin()));
714 STATIC_ASSERT_TRUE(noexcept(vec.end()));
715 EXPECT_EQ(vec.begin(), vec.end());
716}
717
718/// @test Given an `inline_vector` constructed by pushing back values, the iterators returned from `begin` and `end`
719/// can be passed as an iterator pair to `arene::base::equal` to compare the values in the vector to those in the
720/// initializer list, which must return @c true, to indicate that the values are the same.
721TYPED_TEST_P(InlineVectorTest, CanIterateOverValues) {
722 auto const values = TestFixture::full_test_initializer_list();
723 auto const vec = TestFixture::full_test_vector();
724 ASSERT_TRUE(arene::base::equal(values.begin(), values.end(), vec.begin(), vec.end()));
725}
726
727/// @test Given a `const` `inline_vector` constructed by pushing back values, the iterators returned from `begin` and
728/// `end` can be passed as an iterator pair to `arene::base::equal` to compare the values in the vector to those in the
729/// initializer list, which must return @c true, to indicate that the values are the same.
730TYPED_TEST_P(InlineVectorTest, CanIterateOverConstValues) {
731 auto const values = TestFixture::full_test_initializer_list();
732 auto const vec = TestFixture::full_test_vector();
733 ASSERT_TRUE(arene::base::equal(values.begin(), values.end(), vec.begin(), vec.end()));
734}
735
736/// @test The `iterator` type of an `inline_vector` must have the required type aliases for a random-access iterator.
737TYPED_TEST_P(InlineVectorTest, IteratorTypedefs) {
738 using value_type = typename TypeParam::value_type;
739 ::testing::StaticAssertTypeEq<typename TypeParam::iterator::value_type, value_type>();
740 ::testing::StaticAssertTypeEq<typename TypeParam::iterator::reference, value_type&>();
741 ::testing::StaticAssertTypeEq<typename TypeParam::iterator::pointer, value_type*>();
742 ::testing::StaticAssertTypeEq<typename TypeParam::iterator::difference_type, std::ptrdiff_t>();
743 ::testing::StaticAssertTypeEq<typename TypeParam::iterator::iterator_category, std::random_access_iterator_tag>();
744
745 ::testing::StaticAssertTypeEq<typename TypeParam::const_iterator::value_type, value_type>();
746 ::testing::StaticAssertTypeEq<typename TypeParam::const_iterator::reference, value_type const&>();
747 ::testing::StaticAssertTypeEq<typename TypeParam::const_iterator::pointer, value_type const*>();
748 ::testing::StaticAssertTypeEq<typename TypeParam::const_iterator::difference_type, std::ptrdiff_t>();
749 ::testing::StaticAssertTypeEq<typename TypeParam::const_iterator::iterator_category, std::random_access_iterator_tag>(
750 );
751}
752
753/// @test `inline_vector` must have the required type aliases for a sequence container
755 using value_type = typename TypeParam::value_type;
756 ::testing::StaticAssertTypeEq<typename TypeParam::value_type, value_type>();
757 ::testing::StaticAssertTypeEq<typename TypeParam::pointer, value_type*>();
758 ::testing::StaticAssertTypeEq<typename TypeParam::const_pointer, value_type const*>();
759 ::testing::StaticAssertTypeEq<typename TypeParam::reference, value_type&>();
760 ::testing::StaticAssertTypeEq<typename TypeParam::const_reference, value_type const&>();
761 ::testing::StaticAssertTypeEq<typename TypeParam::size_type, std::size_t>();
762 ::testing::StaticAssertTypeEq<typename TypeParam::difference_type, std::ptrdiff_t>();
763 ::testing::StaticAssertTypeEq<
764 typename TypeParam::reverse_iterator,
766 ::testing::StaticAssertTypeEq<
767 typename TypeParam::const_reverse_iterator,
769}
770
771/// @brief Check that iteration works when taking a vector with the given type
772/// @tparam Vec The type to take the vector as; intended to be a value type either with const or without
773/// @param values The values expected to be included in the vector
774/// @param vec The vector to check
775/// @return @c true if @c values and @c vec have the same contents, @c false if not
776template <typename Vec>
777constexpr auto constexpr_iterate(std::initializer_list<typename Vec::value_type> const values, Vec vec) -> bool {
778 // This test is specifically testing a range-based for loop, so we do that even though the iteration gets weird
779 auto val_it = values.begin();
780 for (auto const& vec_val : vec) {
781 if (val_it == values.end()) {
782 return false; // The ranges are unequal if this happens while there are still values in `vec`
783 }
784 if (vec_val != *val_it) {
785 return false;
786 }
787 ++val_it;
788 }
789
790 return val_it == values.end(); // If this reached the end and all elements were equal, the ranges are equal
791}
792
793/// @test It is possible to iterate over the values in a mutable `inline_vector` using a ranged-`for` loop in a
794/// `constexpr` context.
796 STATIC_ASSERT_TRUE(
797 constexpr_iterate<TypeParam>(TestFixture::full_test_initializer_list(), TestFixture::full_test_vector())
798 );
799}
800
801/// @test It is possible to iterate over the values in a const `inline_vector` using a ranged-`for` loop in a
802/// `constexpr` context.
804 STATIC_ASSERT_TRUE(
805 constexpr_iterate<TypeParam const>(TestFixture::full_test_initializer_list(), TestFixture::full_test_vector())
806 );
807}
808
809/// @test Given a non-empty `inline_vector`, invoking `erase` with the iterator returned from `begin` removes the first
810/// element, moving the remaining elements to one lower index and decreasing the size by one, and returns an iterator to
811/// the new first element.
812TYPED_TEST_P(InlineVectorTest, CanEraseAtBeginning) {
813 auto vec = TestFixture::full_test_vector();
814
815 STATIC_ASSERT_TRUE(std::is_same<
817 typename TypeParam::iterator>::value);
818 auto const pos = vec.erase(vec.begin());
819 EXPECT_EQ(pos, vec.begin());
820 EXPECT_EQ(vec.size(), TypeParam::capacity - 1UL);
821 if (TypeParam::capacity >= 2) {
822 EXPECT_EQ(vec[0], TestFixture::test_value(1));
823 }
824 if (TypeParam::capacity >= 3) {
825 EXPECT_EQ(vec[1], TestFixture::test_value(2));
826 }
827 if (TypeParam::capacity >= 4) {
828 EXPECT_EQ(vec[2], TestFixture::test_value(3));
829 }
830}
831
832/// @test Given a non-empty `inline_vector`, invoking `erase` with an iterator referring to an element that is neither
833/// the first or last element removes that element, moves the following elements to one lower index, reduces the size by
834/// one, and returns an iterator to the element that replaced the erased element.
835CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanEraseInMiddle, TypeParam::capacity >= 2) {
836 auto vec = TestFixture::full_test_vector();
837
838 STATIC_ASSERT_TRUE(std::is_same<
840 typename TypeParam::iterator>::value);
841 auto pos = vec.erase(vec.begin() + 1);
842 EXPECT_EQ(pos, vec.begin() + 1);
843 EXPECT_EQ(vec.size(), TypeParam::capacity - 1UL);
844 EXPECT_EQ(vec[0], TestFixture::test_value(0));
845 if (TypeParam::capacity >= 3) {
846 EXPECT_EQ(vec[1], TestFixture::test_value(2));
847 }
848 if (TypeParam::capacity >= 4) {
849 EXPECT_EQ(vec[2], TestFixture::test_value(3));
850 }
851}
852
853template <typename Vec, typename... Args>
854constexpr auto constexpr_erase(std::size_t index, Args&&... args) -> Vec {
855 Vec vec{};
857 vec.erase(vec.begin() + static_cast<std::ptrdiff_t>(index));
858 return vec;
859}
860
861/// @test In a `constexpr` context, given a non-empty `inline_vector`, invoking `erase` with an iterator referring to an
862/// element that is neither the first or last element removes that element, moves the following elements to one lower
863/// index, reduces the size by one.
866 CanErase,
868) {
869 constexpr auto vec = constexpr_erase<TypeParam>(
870 2,
871 TestFixture::test_value(0),
872 TestFixture::test_value(1),
873 TestFixture::test_value(2),
874 TestFixture::test_value(3)
875 );
876 STATIC_ASSERT_EQ(vec.size(), 3);
877 STATIC_ASSERT_EQ(vec[0], TestFixture::test_value(0));
878 STATIC_ASSERT_EQ(vec[1], TestFixture::test_value(1));
879 STATIC_ASSERT_EQ(vec[2], TestFixture::test_value(3));
880}
881
882/// @test Invoking `erase` with an iterator range referring to elements in the same `inline_vector`, removes those
883/// elements, moves the following elements to take their place, and returns an iterator with the same offset from the
884/// beginning of the vector as the first erased element
885CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanEraseRange, TypeParam::capacity >= 5) {
886 auto vec = TestFixture::construct();
887 constexpr std::size_t erase_start = 2;
888 constexpr std::size_t erase_end = 5;
890 std::size_t expected_pos{0};
891 for (std::size_t idx = 0; idx < TypeParam::capacity; ++idx) {
892 vec.push_back(TestFixture::test_value(idx));
893 if (idx < erase_start || idx >= erase_end) {
894 expected[expected_pos].emplace(TestFixture::test_value(idx));
895 ++expected_pos;
896 }
897 }
898
899 ::testing::StaticAssertTypeEq<
900 decltype(vec.erase(
903 )),
904 typename TypeParam::iterator>();
905 auto const pos = vec.erase(vec.begin() + erase_start, vec.begin() + erase_end);
906 EXPECT_EQ(pos, vec.begin() + erase_start);
907 ASSERT_EQ(vec.size(), expected_pos);
908 EXPECT_TRUE(elements_are_array(vec, expected));
909}
910
911/// @test Constructing with just a size creates a vector with that many default-constructed elements
914 CanConstructWithSize,
916) {
917 auto value_vec = TestFixture::construct(TypeParam::capacity);
918
919 STATIC_ASSERT_EQ(noexcept(TypeParam(0)), std::is_nothrow_default_constructible<typename TypeParam::value_type>{});
920 EXPECT_EQ(value_vec.size(), TypeParam::capacity);
921 EXPECT_TRUE(all_elements_are(value_vec, typename TypeParam::value_type{}));
922}
923
924/// @test Constructing an `inline_vector` with a count and a value creates the specified number of elements
925/// copy-constructed from the supplied value, and sets the `size` of the vector to that count.
928 CanConstructWithSizeAndValue,
930) {
931 auto const value = TestFixture::test_value(0);
932 auto const value_vec = TestFixture::construct(TypeParam::capacity, value);
933
934 STATIC_ASSERT_EQ(
935 noexcept(TypeParam(TypeParam::capacity, value)),
937 );
938 EXPECT_EQ(value_vec.size(), TypeParam::capacity);
939 EXPECT_THAT(value_vec, ::testing::Each(::testing::Eq(value)));
940}
941
942/// @test The `inline_vector` copy constructor copies the stored elements and size from the original vector.
945 CopyingVectorCopiesElements,
947) {
948 auto const vec = TestFixture::full_test_vector();
949 // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
950 auto const copy(vec);
951
952 EXPECT_THAT(copy, ::testing::ElementsAreArray(vec));
953}
954
955/// @test The `inline_vector` move constructor moves the stored elements from the original vector
956TYPED_TEST_P(InlineVectorTest, MovingVectorMovesElements) {
957 auto const values = TestFixture::full_test_initializer_list();
958 auto vec = TestFixture::full_test_vector();
959
960 // NOLINTNEXTLINE(hicpp-move-const-arg)
961 TypeParam const moved(std::move(vec));
962 EXPECT_TRUE(elements_are_array(moved, values));
963}
964
965/// @test The `inline_vector` copy-assignment operator uses copy assignment for elements from the source where there is
966/// already a corresponding element in the destination, and copy construction for elements that do not have a
967/// corresponding element in the destination
969 constexpr std::size_t count = TypeParam::capacity;
970 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
971
972 auto vec = TestFixture::test_vector(count);
973 auto copy = TestFixture::test_vector(smaller_count);
974 copy = vec;
975
976 ASSERT_EQ(vec.size(), count);
977 ASSERT_EQ(copy.size(), count);
978 for (std::size_t i = 0; i < count; ++i) {
979 EXPECT_EQ(vec[i], copy[i]);
980 EXPECT_EQ(TestFixture::test_value(i), copy[i]);
981 }
982}
983
984/// @test The `inline_vector` copy-assignment operator destroys the excess elements in the destination when the source
985/// vector has fewer elements than the destination vector
987 constexpr std::size_t count = TypeParam::capacity - 1UL;
988 constexpr std::size_t larger_count = TypeParam::capacity;
989
990 auto vec = TestFixture::test_vector(count);
991 auto copy = TestFixture::test_vector(larger_count);
992 copy = vec;
993
994 ASSERT_EQ(vec.size(), count);
995 ASSERT_EQ(copy.size(), count);
996 for (std::size_t i = 0; i < count; ++i) {
997 EXPECT_EQ(vec[i], copy[i]);
998 EXPECT_EQ(TestFixture::test_value(i), copy[i]);
999 }
1000}
1001
1002/// @test Copy-assignment for `inline_vector` is `noexcept` if and only if the stored element type is both
1003/// nothrow-copy-constructible and nothrow-copy-assignable
1004TYPED_TEST_P(InlineVectorTest, CopyingIsConditionallyDefined) {
1005 using short_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity>;
1006 using vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity + 1UL>;
1007
1008 constexpr bool should_be_copyable = std::is_copy_constructible<typename TypeParam::value_type>{} &&
1010 STATIC_ASSERT_EQ(
1013 );
1014 STATIC_ASSERT_EQ(std::is_copy_assignable<vec>{}, should_be_copyable);
1015 STATIC_ASSERT_EQ((std::is_assignable<short_vec&, vec const&>{}), should_be_copyable);
1016 STATIC_ASSERT_EQ((std::is_assignable<vec&, short_vec const&>{}), should_be_copyable);
1017
1018 constexpr bool assign_noexcept = std::is_nothrow_copy_constructible<typename TypeParam::value_type>{} &&
1020 STATIC_ASSERT_EQ(
1023 );
1024 STATIC_ASSERT_EQ(std::is_nothrow_copy_assignable<vec>{}, assign_noexcept);
1025 STATIC_ASSERT_EQ((std::is_nothrow_assignable<short_vec&, vec const&>{}), assign_noexcept);
1026 STATIC_ASSERT_EQ((std::is_nothrow_assignable<vec&, short_vec const&>{}), assign_noexcept);
1027}
1028
1029/// @test The `inline_vector` move-assignment operator uses move assignment for elements from the source where there is
1030/// already a corresponding element in the destination, and move construction for elements that do not have a
1031/// corresponding element in the destination
1032TYPED_TEST_P(InlineVectorTest, MoveAssignOverSmallerVectorMovesElements) {
1033 constexpr std::size_t count = TypeParam::capacity;
1034 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
1035
1036 auto first = TestFixture::construct();
1038 std::size_t expected_pos{0};
1039 for (std::size_t idx = 0; idx < count; ++idx) {
1040 first.push_back(TestFixture::test_value(idx));
1041 expected[expected_pos].emplace(TestFixture::test_value(idx));
1042 ++expected_pos;
1043 }
1044
1045 auto second = TestFixture::test_vector(smaller_count);
1046 // NOLINTNEXTLINE(hicpp-move-const-arg)
1047 second = std::move(first);
1048
1049 EXPECT_EQ(second.size(), count);
1050 EXPECT_TRUE(elements_are_array(second, expected));
1051}
1052
1053/// @test The `inline_vector` move-assignment operator destroys the excess elements in the destination when the source
1054/// vector has fewer elements than the destination vector
1055TYPED_TEST_P(InlineVectorTest, MoveAssignOverLargerVectorDestroysExcess) {
1056 constexpr std::size_t count = TypeParam::capacity - 1UL;
1057 constexpr std::size_t larger_count = TypeParam::capacity;
1058
1059 auto first = TestFixture::test_vector(count);
1060 auto second = TestFixture::test_vector(larger_count);
1061 second = std::move(first);
1062
1063 ASSERT_EQ(second.size(), count);
1064 for (std::size_t i = 0; i < count; ++i) {
1065 EXPECT_EQ(TestFixture::test_value(i), second[i]);
1066 }
1067}
1068
1069/// @test Move-assignment for `inline_vector` is `noexcept` if and only if the value type is nothrow-move-constructible
1070/// and nothrow-move-assignable
1071TYPED_TEST_P(InlineVectorTest, MovingIsConditionallyDefined) {
1072 using short_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity>;
1073 using vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity + 1UL>;
1074
1075 constexpr bool should_be_movable = std::is_move_assignable<typename TypeParam::value_type>{} &&
1077 STATIC_ASSERT_EQ(std::is_move_constructible<vec>{}, should_be_movable);
1078 STATIC_ASSERT_EQ(std::is_move_assignable<vec>{}, should_be_movable);
1079 STATIC_ASSERT_EQ((std::is_assignable<short_vec&, vec>{}), should_be_movable);
1080 STATIC_ASSERT_EQ((std::is_assignable<vec&, short_vec>{}), should_be_movable);
1081
1082 constexpr bool assign_should_be_noexcept = std::is_nothrow_move_assignable<typename TypeParam::value_type>{} &&
1084 STATIC_ASSERT_EQ(
1087 );
1088 STATIC_ASSERT_EQ(std::is_nothrow_move_assignable<vec>{}, assign_should_be_noexcept);
1089 STATIC_ASSERT_EQ((std::is_nothrow_assignable<short_vec&, vec>{}), assign_should_be_noexcept);
1090 STATIC_ASSERT_EQ((std::is_nothrow_assignable<vec&, short_vec>{}), assign_should_be_noexcept);
1091}
1092
1093// A Matcher that checks if the elements in an argument (by index) match the result of calling a function with the index
1094// NOLINTNEXTLINE(modernize-use-trailing-return-type) The declaration happens in a macro and we can't control it
1095MATCHER_P(elements_match_function, function, "") {
1096 for (std::size_t ii = 0; ii < arg.size(); ++ii) {
1097 if (arg[ii] != function(ii)) {
1098 return false;
1099 }
1100 }
1101
1102 return true;
1103}
1104
1105/// @test Invoking `pop_back` on a non-empty `inline_vector` destroys the last element and reduces the size by one.
1107 auto vec = TestFixture::test_vector(TypeParam::capacity - 1UL);
1108
1109 vec.push_back(TestFixture::test_value(TypeParam::capacity - 1UL));
1110 vec.pop_back();
1111
1112 EXPECT_EQ(vec.size(), TypeParam::capacity - 1UL);
1113 EXPECT_THAT(vec, elements_match_function(TestFixture::test_value));
1114}
1115
1116/// @test `pop_back` is declared `noexcept`
1117TYPED_TEST_P(InlineVectorTest, PopBackIsNoexcept) {
1118 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam>().pop_back()));
1119}
1120
1121template <typename Vec>
1122constexpr auto constexpr_pop_back(Vec&& vec) -> Vec {
1123 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
1124 std::forward<Vec>(vec).pop_back();
1125 return std::forward<Vec>(vec);
1126}
1127
1128/// @test In a `constexpr` context, `pop_back` removes the last element of a non-empty vector
1130 constexpr auto vec = constexpr_pop_back<TypeParam>(TestFixture::full_test_vector());
1131 STATIC_ASSERT_EQ(vec.size(), TypeParam::capacity - 1UL);
1132
1133 if (TypeParam::capacity >= 2) {
1134 EXPECT_EQ(vec[0], TestFixture::test_value(0));
1135 }
1136 if (TypeParam::capacity >= 3) {
1137 EXPECT_EQ(vec[1], TestFixture::test_value(1));
1138 }
1139 if (TypeParam::capacity >= 4) {
1140 EXPECT_EQ(vec[2], TestFixture::test_value(2));
1141 }
1142}
1143
1144/// @test `erase` is `noexcept` if and only if the element type has `noexcept` move assignment
1145TYPED_TEST_P(InlineVectorTest, EraseIsNoexceptIfTypeHasNoexceptMove) {
1146 auto vec = TestFixture::construct();
1147
1148 STATIC_ASSERT_EQ(
1149 noexcept(vec.erase(vec.begin(), vec.end())),
1151 );
1152 STATIC_ASSERT_EQ(noexcept(vec.erase(vec.begin())), std::is_nothrow_move_assignable<typename TypeParam::value_type>{});
1153}
1154
1155/// @test Given an empty `inline_vector`, and the iterator returned from `begin`, `insert` can add an element to the
1156/// vector, setting the size to one.
1157TYPED_TEST_P(InlineVectorTest, CanInsertInEmptyVector) {
1158 auto vec1 = TestFixture::construct();
1159 auto const& const_vec1 = vec1;
1160 auto const itr = vec1.insert(const_vec1.begin(), TestFixture::test_value(0));
1161 EXPECT_EQ(itr, vec1.begin());
1162 EXPECT_EQ(vec1.size(), 1);
1163 EXPECT_EQ(vec1[0], TestFixture::test_value(0));
1164}
1165
1166/// @test Given an `inline_vector` with existing elements, and the iterator returned from `end`, `insert` can add an
1167/// element to the end of the vector, increasing the size by one
1168CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanInsertAtEndOfExistingVector, TypeParam::capacity >= 2) {
1169 auto vec1 = TestFixture::test_vector(1);
1170 auto const& const_vec1 = vec1;
1171 auto const pos = vec1.insert(const_vec1.end(), TestFixture::test_value(1));
1172 EXPECT_EQ(pos, vec1.begin() + 1);
1173 EXPECT_EQ(vec1.size(), 2);
1174 EXPECT_EQ(vec1[0], TestFixture::test_value(0));
1175 EXPECT_EQ(vec1[1], TestFixture::test_value(1));
1176}
1177
1178/// @test Given an `inline_vector` with existing elements, and an iterator to an existing element in the vector,
1179/// `insert` can add an element at the iterator position, increasing the vector size by one. The existing element at the
1180/// location referenced by the iterator, and the subsequent elements, are moved to make room for the new element.
1181CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanInsertInMiddleOfExistingVector, TypeParam::capacity >= 3) {
1182 auto vec1 = TestFixture::test_vector(2);
1183 auto const& const_vec1 = vec1;
1184 auto const pos = vec1.insert(const_vec1.begin() + 1, TestFixture::test_value(2));
1185 EXPECT_EQ(pos, vec1.begin() + 1);
1186 EXPECT_EQ(vec1.size(), 3);
1187 EXPECT_EQ(vec1[0], TestFixture::test_value(0));
1188 EXPECT_EQ(vec1[1], TestFixture::test_value(2));
1189 EXPECT_EQ(vec1[2], TestFixture::test_value(1));
1190}
1191
1192/// @test Invoking `insert` on an `inline_vector` with `size` equal to the capacity terminates the program with a
1193/// precondition violation
1196 InsertWhenAtCapacityIsPreconditionViolation,
1198) {
1199 auto vec1 = TestFixture::construct(TypeParam::capacity);
1200 EXPECT_EQ(vec1.size(), TypeParam::capacity);
1201 ASSERT_DEATH(vec1.insert(vec1.end(), TestFixture::test_value(0)), "Precondition violation");
1202 ASSERT_DEATH(vec1.insert(vec1.begin(), TestFixture::test_value(0)), "Precondition violation");
1203 EXPECT_EQ(vec1.size(), TypeParam::capacity);
1204 EXPECT_TRUE(all_elements_are(vec1, typename TypeParam::value_type{}));
1205}
1206
1207/// @test Invoking the `inline_vector` constructor with a count larger than the capacity terminates the program with a
1208/// precondition violation
1211 ConstructingWithOutOfRangeSizeIsPreconditionViolation,
1213) {
1214 ASSERT_DEATH(TestFixture::construct(TypeParam::capacity + 1), "Precondition violation");
1215}
1216
1217/// @test Invoking the `inline_vector` constructor with a count and value where the count is larger than the capacity
1218/// terminates the program with a precondition violation
1221 ConstructingWithOutOfRangeSizeAndSourceIsPreconditionViolation,
1223) {
1224 auto const source = TestFixture::test_value(0);
1225 ASSERT_DEATH(TestFixture::construct(TypeParam::capacity + 1, source), "Precondition violation");
1226}
1227
1228/// @test Invoking the `inline_vector` constructor with an initializer list with more elements than the capacity
1229/// terminates the program with a precondition violation
1232 ConstructingWithTooManyInitializersIsPreconditionViolation,
1234) {
1235 ASSERT_DEATH(
1236 TestFixture::construct(TestFixture::template test_initializer_list<TypeParam::capacity + 1UL>()),
1237 "Precondition violation"
1238 );
1239}
1240
1241template <typename Vec>
1242constexpr auto constexpr_resize(Vec vec, std::size_t size) -> Vec {
1243 vec.resize(size);
1244 return vec;
1245}
1246
1247/// @test In a constexpr context, invoking `resize` with a count of zero on an `inline_vector` with a capacity of zero
1248/// does nothing
1251 ResizeZeroCapacityVecToZeroIsOk,
1253) {
1254 constexpr typename TestFixture::template vector_with_capacity<0> vec{};
1255 constexpr typename TestFixture::template vector_with_capacity<0> vec2 = constexpr_resize(vec, 0);
1256 // NOLINTNEXTLINE(readability-container-size-empty)
1257 STATIC_ASSERT_EQ(vec2.size(), 0);
1258}
1259
1260/// @test In a `constexpr` context, invoking `resize` with a count of zero on an `inline_vector` with a non-zero
1261/// capacity and size sets the size to zero
1264 ResizeNonZeroCapacityVecToZeroIsOk,
1266) {
1267 constexpr auto vec = TestFixture::construct(TypeParam::capacity);
1268 constexpr auto vec2 = constexpr_resize(vec, 0);
1269 // NOLINTNEXTLINE(readability-container-size-empty)
1270 STATIC_ASSERT_EQ(vec2.size(), 0);
1271}
1272
1273/// @test In a `constexpr` context, invoking `resize` with a non-zero count on an `inline_vector` with a non-zero
1274/// capacity and different size sets the size to the specified size
1277 ResizeNonZeroCapacityVecToOtherIsOk,
1279) {
1280 constexpr std::size_t count1 = TypeParam::capacity - 1UL;
1281 constexpr std::size_t count2 = TypeParam::capacity;
1282 constexpr auto vec = TestFixture::construct(count1);
1283 STATIC_ASSERT_EQ(vec.size(), count1);
1284 constexpr auto vec2 = constexpr_resize(vec, count2);
1285 STATIC_ASSERT_EQ(vec2.size(), count2);
1286}
1287
1288/// @test `resize` is `noexcept` if and only if the default constructor of the element type is `noexcept`
1291 ResizeIsConditionallyNoexcept,
1293) {
1294 STATIC_ASSERT_EQ(
1295 noexcept(TestFixture::construct().resize(0)),
1297 );
1298}
1299
1300/// @test `resize` with a value to copy is `noexcept` if and only if the copy constructor of the element type is
1301/// `noexcept`
1312
1313/// @test Invoking the `resize` member function with a size and a value on a vector with more elements than the
1314/// specified size sets the size of the vector to the specified count and does not construct new elements
1317 ResizingFromLargeToSmallLeavesElements,
1319) {
1320 constexpr std::size_t initial_count = TypeParam::capacity;
1321 auto const initial_value = TestFixture::test_value(0);
1322 TypeParam vec(initial_count, initial_value);
1323 constexpr std::size_t count = TypeParam::capacity - 1UL;
1324 auto const value = TestFixture::test_value(1);
1325 vec.resize(count, value);
1326 ASSERT_EQ(vec.size(), count);
1327
1328 for (std::size_t idx = 0; idx < count; ++idx) {
1329 EXPECT_EQ(vec[idx], initial_value);
1330 }
1331}
1332
1333/// @test Invoking the `resize` member function with a size and a value on a vector with fewer elements than the
1334/// specified size sets the size of the vector to the specified count, and constructs a number of new elements
1335/// equal to the difference between the specified size and the previous size by copy-construction from the specified
1336/// value
1339 ResizingFromSmallToLargeConstructsElementsAsCopiesOfSpecified,
1341) {
1342 constexpr std::size_t initial_count = TypeParam::capacity - 1UL;
1343 auto const initial_value = TestFixture::test_value(0);
1344 TypeParam vec(initial_count, initial_value);
1345 constexpr std::size_t count = TypeParam::capacity;
1346 auto const value = TestFixture::test_value(1);
1347 vec.resize(count, value);
1348 ASSERT_EQ(vec.size(), count);
1349
1350 for (std::size_t idx = 0; idx < initial_count; ++idx) {
1351 EXPECT_EQ(vec[idx], initial_value);
1352 }
1353 for (std::size_t idx = initial_count; idx < count; ++idx) {
1354 EXPECT_EQ(vec[idx], value);
1355 }
1356}
1357
1358/// @test In a `constexpr` context, invoking the `inline_vector` constructor with a count and a value constructs a
1359/// vector holding the specified number of elements copied from the source value
1362 CanInitializeWithSizeAndValue,
1365) {
1366 constexpr auto source = TestFixture::test_value(0);
1367 constexpr auto vec = TestFixture::construct(TypeParam::capacity, source);
1368
1369 STATIC_ASSERT_EQ(vec.size(), TypeParam::capacity);
1370 STATIC_ASSERT_TRUE(all_elements_are(vec, source));
1371}
1372
1373template <typename Vec, typename T>
1374constexpr auto constexpr_insert(Vec&& vec, std::ptrdiff_t offset, T&& value) -> Vec {
1375 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
1376 std::forward<Vec>(vec).insert(std::forward<Vec>(vec).begin() + offset, std::forward<T>(value));
1377 return std::forward<Vec>(vec);
1378}
1379
1380/// @test In a `constexpr` context, invoking `insert` with an iterator referring to an existing element, moves the
1381/// referred to element and subsequent elements to make room for the new element, inserts the new element, and increases
1382/// the size by one.
1385 CanInsert,
1386 InlineVectorTest<TypeParam>::constexpr_compatible&& TypeParam::capacity >= 3
1387) {
1388 constexpr auto vec = constexpr_insert<TypeParam>(TestFixture::test_vector(2), 1, TestFixture::test_value(2));
1389
1390 STATIC_ASSERT_EQ(vec.size(), 3);
1391 STATIC_ASSERT_EQ(vec[0], TestFixture::test_value(0));
1392 STATIC_ASSERT_EQ(vec[1], TestFixture::test_value(2));
1393 STATIC_ASSERT_EQ(vec[2], TestFixture::test_value(1));
1394}
1395
1396/// @test An `inline_vector` can be constructed from an iterator range, creating a vector by moving the elements
1397/// from the source range, with a size equal to the number of elements in the source range
1398TYPED_TEST_P(InlineVectorTest, CanConstructFromIteratorRange) {
1399 auto const expected = TestFixture::full_test_vector();
1400 auto source = TestFixture::full_test_vector();
1401
1402 TypeParam vec(std::make_move_iterator(source.begin()), std::make_move_iterator(source.end()));
1403
1404 EXPECT_EQ(vec.size(), expected.size());
1405 EXPECT_TRUE(elements_are_array(vec, expected));
1406}
1407
1408/// @test Construction of an `inline_vector` from an iterator range is `noexcept` if operations on the iterator are
1409/// `noexcept` and the element type of the vector is nothrow-constructible from the reference type of the iterator
1410TYPED_TEST_P(InlineVectorTest, IteratorRangeConstructionIsConditionallyNoexcept) {
1411 using source_it =
1413 using source_val = typename source_it::reference;
1414
1415 constexpr bool it_operations_noexcept = noexcept(++std::declval<source_it>())&& noexcept(*std::declval<source_it>());
1416 constexpr bool element_construction_noexcept =
1418
1420 STATIC_ASSERT_EQ(
1422 it_operations_noexcept && element_construction_noexcept
1423 );
1424
1425 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
1427 using throwing_bidirectional_iterator = typename TestFixture::throwing_bidirectional_move_iterator_of_t;
1428
1429 STATIC_ASSERT_TRUE(std::is_constructible<
1430 TypeParam,
1431 typename convertible_array::const_iterator,
1432 typename convertible_array::const_iterator>::value);
1433 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1434 TypeParam,
1435 typename convertible_array::const_iterator,
1436 typename convertible_array::const_iterator>::value);
1437 STATIC_ASSERT_TRUE(
1439 );
1440 STATIC_ASSERT_FALSE(
1442 );
1443}
1444
1445/// @test Construction of an `inline_vector` from an input iterator range is `noexcept` if operations on the iterator
1446/// are `noexcept` and the element type of the vector is nothrow-constructible from the reference type of the iterator
1447TYPED_TEST_P(InlineVectorTest, InputIteratorRangeConstructionIsConditionallyNoexcept) {
1448 using input_it = ::testing::demoted_iterator<typename TypeParam::value_type*, std::input_iterator_tag>;
1449 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
1450 using throwing_it_throwing_type = typename TestFixture::template throwing_input_iterator<throws_when_converted>;
1451 using throwing_it_raw_type = typename TestFixture::template throwing_input_iterator<typename TypeParam::value_type>;
1452 using nothrow_it_throwing_type = typename TestFixture::template non_throwing_input_iterator<throws_when_converted>;
1453 using nothrow_it_raw_type =
1455
1456 constexpr bool it_operations_noexcept = noexcept(++std::declval<input_it>())&& noexcept(*std::declval<input_it>());
1457 constexpr bool element_construction_noexcept =
1459
1461 STATIC_ASSERT_EQ(
1463 it_operations_noexcept && element_construction_noexcept
1464 );
1465
1467 STATIC_ASSERT_FALSE(
1469 );
1473 STATIC_ASSERT_EQ(
1476 );
1478 STATIC_ASSERT_FALSE(
1480 );
1481}
1482
1483/// @test In a `constexpr` context, an `inline_vector` can be constructed from an iterator range, creating a vector
1484/// holding copies of the elements from the source range, with a size equal to the number of elements in the source
1485/// range
1486// Note: std::move_iterator is not constexpr in C++14, so this is limited to copy constructible types.
1489 CanConstructFromIteratorRangeConstexpr,
1492) {
1493 constexpr auto source = TestFixture::full_test_initializer_list();
1494 constexpr TypeParam vec(source.begin(), source.end());
1495
1496 STATIC_ASSERT_EQ(vec.size(), source.size());
1497 STATIC_ASSERT_TRUE(equal(vec.begin(), vec.end(), source.begin(), source.end()));
1498}
1499
1500/// @test Given an `inline_vector` holding existing elements, assigning to that vector with an initializer list holding
1501/// more elements copy assigns over the existing elements, and then copy-constructs new elements to increase the size of
1502/// the vector to that of the initializer list
1503CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CopyAssignOverSmallerVectorFromInitListCopiesElements, is_copyable_v<typename TypeParam::value_type>) {
1504 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
1505
1506 auto const value = TestFixture::full_test_initializer_list();
1507
1508 auto copy = TestFixture::test_vector(smaller_count);
1509 copy = value;
1510
1511 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1512}
1513
1514/// @test Given an `inline_vector` holding existing elements, assigning to that vector with an initializer list holding
1515/// fewer elements copy assigns over the existing elements up to the size of the initializer list, and then destroys a
1516/// number of elements equal to the difference between the old size of the vector and the size of the initializer list
1517CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CopyAssignOverLargerVectorFromInitListDestroysExcess, is_copyable_v<typename TypeParam::value_type>) {
1518 constexpr std::size_t larger_count = TypeParam::capacity;
1519
1520 auto const value = TestFixture::template test_initializer_list<TypeParam::capacity - 1UL>();
1521
1522 auto copy = TestFixture::test_vector(larger_count);
1523 copy = value;
1524
1525 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1526}
1527
1528/// @test Invoking the `assign` member function with an iterator range sets the vector to have a size equal to the
1529/// number of elements in the range, and each element to be a copy of the corresponding element in the range
1530TYPED_TEST_P(InlineVectorTest, CanAssignFromIteratorRange) {
1531 auto source = TestFixture::full_test_vector();
1532
1533 auto vec = TestFixture::test_vector(0);
1534 vec.assign(std::make_move_iterator(source.begin()), std::make_move_iterator(source.end()));
1535
1536 EXPECT_TRUE(elements_are_array(vec, TestFixture::full_test_initializer_list()));
1537}
1538
1539/// @test Assignment of an `inline_vector` from an iterator range is `noexcept` if operations on the iterator are
1540/// `noexcept` and the element type of the vector is nothrow-constructible and nothrow-assignable from the reference
1541/// type of the iterator
1542TYPED_TEST_P(InlineVectorTest, IteratorRangeAssignmentIsConditionallyNoexcept) {
1544 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
1546 using throwing_bidirectional_iterator = typename TestFixture::throwing_bidirectional_move_iterator_of_t;
1547
1548 constexpr bool it_operations_noexcept = noexcept(++std::declval<array_it>())&& noexcept(*std::declval<array_it>());
1549 constexpr bool element_construction_noexcept =
1552
1553 STATIC_ASSERT_EQ(
1554 noexcept(TypeParam{}.assign(std::declval<array_it>(), std::declval<array_it>())),
1555 it_operations_noexcept && element_construction_noexcept
1556 );
1557 STATIC_ASSERT_FALSE(
1559 );
1560 STATIC_ASSERT_FALSE(noexcept(TypeParam{}.assign(
1563 )));
1564}
1565
1566/// @test Invoking the `assign` member function with an initializer list sets the vector to have a size equal to the
1567/// number of elements in the initializer list, and each element to be a copy of the corresponding element in the
1568/// initializer list
1570 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
1571
1572 auto const value = TestFixture::full_test_initializer_list();
1573
1574 auto copy = TestFixture::test_vector(smaller_count);
1575 copy.assign(value);
1576
1577 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1578}
1579
1580/// @test Assignment of an `inline_vector` from an initializer list is `noexcept` if the element type of the vector is
1581/// nothrow-copy-constructible
1582TYPED_TEST_P(InlineVectorTest, AssignFromInitListUsingAssignFunctionIsConditionallyNoexcept) {
1583 constexpr bool is_nothrow_copyable = std::is_nothrow_copy_constructible<typename TypeParam::value_type>{} &&
1585
1587 STATIC_ASSERT_EQ(
1589 is_nothrow_copyable
1590 );
1591
1592 auto const values = TestFixture::full_test_initializer_list();
1593 STATIC_ASSERT_EQ(noexcept(TypeParam{}.assign(values)), is_nothrow_copyable);
1594}
1595
1596/// @test Invoking the `assign` member function with an iterator range specified using input iterators sets the vector
1597/// to have a size equal to the number of elements in the range, and each element to be a copy of the corresponding
1598/// element in the range
1599TYPED_TEST_P(InlineVectorTest, CanAssignFromInputIteratorRange) {
1600 auto source = TestFixture::full_test_vector();
1601
1602 auto vec = TestFixture::test_vector(0);
1603 using move_it = std::move_iterator<typename decltype(source)::iterator>;
1604 using input_it = ::testing::demoted_iterator<move_it, std::input_iterator_tag>;
1605
1606 auto begin = input_it{std::make_move_iterator(source.begin())};
1607 auto end = input_it{std::make_move_iterator(source.end())};
1608 vec.assign(begin, end);
1609
1610 EXPECT_TRUE(elements_are_array(vec, TestFixture::full_test_initializer_list()));
1611}
1612
1613/// @test Assignment of an `inline_vector` from an input iterator range is `noexcept` if operations on the iterator are
1614/// `noexcept` and the element type of the vector is nothrow-constructible from the value type of the iterator
1616 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
1617 using throwing_it_throwing_type = typename TestFixture::template throwing_input_iterator<throws_when_converted>;
1618 using throwing_it_raw_type = typename TestFixture::template throwing_input_iterator<typename TypeParam::value_type>;
1619 using nothrow_it_throwing_type = typename TestFixture::template non_throwing_input_iterator<throws_when_converted>;
1620 using nothrow_it_raw_type =
1622
1623 STATIC_ASSERT_FALSE(noexcept(TypeParam{}.assign(
1624 std::declval<::testing::demoted_iterator<throwing_it_throwing_type, std::input_iterator_tag>>(),
1625 std::declval<::testing::demoted_iterator<throwing_it_throwing_type, std::input_iterator_tag>>()
1626 )));
1627 STATIC_ASSERT_FALSE(
1629 );
1630 STATIC_ASSERT_FALSE(
1632 );
1633 STATIC_ASSERT_EQ(
1637 );
1638 STATIC_ASSERT_FALSE(
1640 );
1641}
1642
1643/// @test Invoking the `assign` member function with a count and a value sets the size of the vector to the specified
1644/// count, where each element is a copy of the supplied value
1646 constexpr std::size_t count = TypeParam::capacity;
1647 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
1648
1649 auto copy = TestFixture::test_vector(smaller_count);
1650 auto const value = TestFixture::test_value(0);
1651 copy.assign(count, value);
1652
1653 EXPECT_EQ(copy.size(), count);
1654 for (std::size_t i = 0; i < count; ++i) {
1655 EXPECT_EQ(copy[i], value);
1656 }
1657}
1658
1659/// @test The `assign` member function taking a size and a value is not `noexcept` if the value type is
1660/// not nothrow-copy-constructible
1662 constexpr bool is_nothrow_copyable = std::is_nothrow_copy_constructible<typename TypeParam::value_type>{} &&
1664 STATIC_ASSERT_EQ(noexcept(TypeParam{}.assign(0, TestFixture::test_value(0))), is_nothrow_copyable);
1665}
1666
1667/// @test Invoking the `assign` member function with a count and a value where the count is larger than the capacity of
1668/// the vector terminates the program with a precondition violation
1670 constexpr std::size_t smaller_count = TypeParam::capacity - 1UL;
1671
1672 auto const initial_value = TestFixture::test_value(0);
1673 TypeParam copy(smaller_count, initial_value);
1674 auto const value = TestFixture::test_value(1);
1675 ASSERT_DEATH(copy.assign(TypeParam::capacity + 1, value), "Precondition violation");
1676
1677 EXPECT_EQ(copy.size(), smaller_count);
1678 for (std::size_t i = 0; i < smaller_count; ++i) {
1679 EXPECT_EQ(copy[i], initial_value);
1680 }
1681}
1682
1683/// @test The index operator returns a reference to the element type of the vector
1684TYPED_TEST_P(InlineVectorTest, IndexOperatorReturnsReference) {
1685 ::testing::StaticAssertTypeEq<decltype(std::declval<TypeParam&>()[0]), typename TypeParam::value_type&>();
1686}
1687
1688/// @test The index operator for a `const` vector returns a `const` reference to the element type of the vector
1689TYPED_TEST_P(InlineVectorTest, IndexOperatorOnConstVectorReturnsConstReference) {
1690 ::testing::StaticAssertTypeEq<decltype(std::declval<TypeParam const&>()[0]), typename TypeParam::value_type const&>();
1691}
1692
1693/// @test Given an `inline_vector` with multiple elements, the index operator can be used with appropriate index values
1694/// to access each element, returning a reference to the element at that index
1695CONDITIONAL_TYPED_TEST_P(InlineVectorTest, CanAccessMultipleValuesWithIndexOperator, TypeParam::capacity >= 2) {
1696 auto vec = TestFixture::test_vector(2);
1697 auto const& const_vec = vec;
1698
1699 EXPECT_EQ(vec[0], TestFixture::test_value(0));
1700 EXPECT_EQ(vec[1], TestFixture::test_value(1));
1701 // NOLINTNEXTLINE(readability-container-data-pointer)
1702 EXPECT_EQ(&const_vec[0], std::addressof(vec[0]));
1703 EXPECT_EQ(&const_vec[1], std::addressof(vec[1]));
1704}
1705
1706/// @test The index operator is `noexcept`
1707TYPED_TEST_P(InlineVectorTest, IndexOperatorIsNoexcept) { STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>()[0])); }
1708
1709/// @test Passing an index that is equal to or larger than the size of the vector terminates the program with a
1710/// precondition violation
1711TYPED_TEST_P(InlineVectorDeathTest, IndexOperatorOutOfRange) {
1712 ASSERT_DEATH(TestFixture::construct()[0], "index < this->size()");
1713}
1714
1715/// @test The index operator is `noexcept` for a `const` vector
1716TYPED_TEST_P(InlineVectorTest, IndexOperatorOnConstVectorIsNoexcept) {
1717 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam const&>()[0]));
1718}
1719
1720/// @test The index operator can be used to access the elements of an `inline_vector` in a `constexpr` context.
1723 IndexOperator,
1724 InlineVectorTest<TypeParam>::constexpr_compatible&& TypeParam::capacity >= 2
1725) {
1726 constexpr auto vec = TestFixture::test_vector(2);
1727 STATIC_ASSERT_EQ(vec[0], TestFixture::test_value(0));
1728 STATIC_ASSERT_EQ(vec[1], TestFixture::test_value(1));
1729}
1730
1731/// @test The `data` member function is noexcept and returns a pointer to the first element of a non-empty vector
1733 auto vec = TestFixture::full_test_vector();
1734 auto const& const_vec = vec;
1735
1736 // NOLINTNEXTLINE(readability-container-data-pointer)
1737 EXPECT_EQ(vec.data(), std::addressof(vec[0]));
1738 // NOLINTNEXTLINE(readability-container-data-pointer)
1739 EXPECT_EQ(const_vec.data(), std::addressof(vec[0]));
1740
1741 STATIC_ASSERT_TRUE(noexcept(vec.data()));
1742 STATIC_ASSERT_TRUE(noexcept(const_vec.data()));
1743
1744 // This is just to check that data() works in constexpr.
1745 COND_STATIC_ASSERT_NE(TestFixture::full_test_vector().data(), nullptr);
1746}
1747
1748/// @test Given an `inline_vector` which is not empty, invoking the `clear` method makes the vector empty
1749TYPED_TEST_P(InlineVectorTest, AfterClearVectorIsEmpty) {
1750 auto vec = TestFixture::full_test_vector();
1751
1752 EXPECT_EQ(vec.size(), TypeParam::capacity);
1753 EXPECT_FALSE(vec.empty());
1754 vec.clear();
1755 EXPECT_EQ(vec.size(), 0);
1756 EXPECT_TRUE(vec.empty());
1757
1758 STATIC_ASSERT_TRUE(noexcept(vec.clear()));
1759}
1760
1761template <typename Vec>
1762constexpr auto constexpr_clear(Vec vec) -> Vec {
1763 vec.clear();
1764 return vec;
1765}
1766
1767/// @test In a `constexpr` context, given an `inline_vector` which is not empty, invoking the `clear` method makes the
1768/// vector empty
1770 constexpr auto vec = TestFixture::full_test_vector();
1771
1772 constexpr auto value2 = constexpr_clear(vec);
1773 STATIC_ASSERT_TRUE(value2.empty());
1774}
1775
1776/// @test Two instances of `inline_vector` can be compared for equality using `operator==` and `operator!=`. Two vectors
1777/// are the same if and only if they have the same size, and each element from one vector compares equal to the element
1778/// with the same index in the other vector.
1781 CanCompareForEquality,
1782 InlineVectorTest<TypeParam>::constexpr_compatible&& TypeParam::capacity >= 4
1783) {
1784 constexpr TypeParam vec{
1785 TestFixture::template unique_test_value<0>(),
1786 TestFixture::template unique_test_value<1>(),
1787 TestFixture::template unique_test_value<2>()
1788 };
1789 constexpr TypeParam different_contents{
1790 TestFixture::template unique_test_value<3>(),
1791 TestFixture::template unique_test_value<4>(),
1792 TestFixture::template unique_test_value<5>()
1793 };
1794 constexpr auto longer = TestFixture::test_vector(4);
1795 constexpr TypeParam copy{vec};
1796
1797 STATIC_ASSERT_TRUE(vec != different_contents);
1798 STATIC_ASSERT_TRUE(vec != longer);
1799 STATIC_ASSERT_FALSE(vec != copy);
1800 STATIC_ASSERT_FALSE(vec == different_contents);
1801 STATIC_ASSERT_FALSE(vec == longer);
1802 STATIC_ASSERT_TRUE(vec == copy);
1803}
1804
1805template <class Vec>
1806constexpr auto erase_front(Vec&& vec, std::size_t count) {
1807 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
1809 std::forward<Vec>(vec).erase(
1810 std::forward<Vec>(vec).begin(),
1811 std::forward<Vec>(vec).begin() + static_cast<difference_type>(count)
1812 );
1813 return std::forward<Vec>(vec);
1814}
1815
1816/// A type trait to tell if the given type parameter is fully comparable or not for the purposes of these tests
1817/// @tparam T The type to check
1818template <typename T>
1821
1822/// @test Two instances of `inline_vector` can be compared for ordering using `operator<` and `operator>`. One vector
1823/// compares less than another if the first has a smaller size than the second, and all elements are equal to the
1824/// corresponding element in the second vector with the same index or they have the same size, and there is an element
1825/// such that all elements with a lower index compare equal to the corresponding element in the second vector, and that
1826/// element compares less than the corresponding element of the second vector.
1829 CanCompareForOrdering,
1831 TypeParam::capacity >= 4
1832) {
1833 constexpr auto sorted_test_values = sort_helper(TypeParam{
1834 TestFixture::template unique_test_value<0>(),
1835 TestFixture::template unique_test_value<1>(),
1836 TestFixture::template unique_test_value<2>(),
1837 TestFixture::template unique_test_value<3>()
1838 });
1839
1840 constexpr auto low_value = TypeParam(sorted_test_values.begin(), sorted_test_values.begin() + 2UL);
1841 constexpr auto high_value = TypeParam(sorted_test_values.begin() + 2UL, sorted_test_values.begin() + 4UL);
1842 constexpr auto long_value = TypeParam(sorted_test_values.begin(), sorted_test_values.begin() + 3UL);
1843 constexpr auto low_value_copy = low_value;
1844
1845 STATIC_ASSERT_TRUE(low_value < high_value);
1846 STATIC_ASSERT_TRUE(low_value < long_value);
1847 STATIC_ASSERT_FALSE(low_value < low_value_copy);
1848 STATIC_ASSERT_FALSE(high_value < low_value);
1849 STATIC_ASSERT_TRUE(high_value > low_value);
1850 STATIC_ASSERT_TRUE(long_value > low_value);
1851 STATIC_ASSERT_FALSE(low_value_copy > low_value);
1852 STATIC_ASSERT_FALSE(low_value > high_value);
1853
1854 STATIC_ASSERT_TRUE(low_value <= high_value);
1855 STATIC_ASSERT_TRUE(low_value <= long_value);
1856 STATIC_ASSERT_TRUE(low_value <= low_value_copy);
1857 STATIC_ASSERT_FALSE(high_value <= low_value);
1858 STATIC_ASSERT_TRUE(high_value >= low_value);
1859 STATIC_ASSERT_TRUE(long_value >= low_value);
1860 STATIC_ASSERT_TRUE(low_value_copy >= low_value);
1861 STATIC_ASSERT_FALSE(low_value >= high_value);
1862}
1863
1864template <typename ValueType>
1866 using value_type = ValueType;
1867 value_type value_;
1868
1869 public:
1870 explicit move_only_wrapper(value_type value)
1871 : value_(std::move(value)) {}
1877
1878 auto get() -> value_type& { return value_; }
1879};
1880
1881/// @test The `emplace_back` member function can be used to add an element to an `inline_vector`. The new element is
1882/// constructed with the arguments supplied to `emplace_back`
1884 using value_type = typename TypeParam::value_type;
1885
1886 struct with_constructor_args {
1888 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
1889 value_type& reference;
1891
1892 with_constructor_args(value_type const& val, value_type& ref, move_only_wrapper<value_type> wrap_arg)
1893 : value(val),
1894 reference(ref),
1895 wrapper(std::move(wrap_arg)) {}
1896 };
1897
1898 typename TestFixture::template standard_capacity_vector<with_constructor_args> vec;
1899
1900 value_type const value1 = TestFixture::test_value(0);
1901 value_type value2 = TestFixture::test_value(1);
1902 auto& result = vec.emplace_back(value1, value2, move_only_wrapper<value_type>(TestFixture::test_value(2)));
1903
1904 ::testing::StaticAssertTypeEq<decltype(result), with_constructor_args&>();
1905 EXPECT_EQ(vec.size(), 1);
1906 ASSERT_FALSE(vec.empty());
1907 EXPECT_EQ(std::addressof(result), std::addressof(vec[0]));
1908
1909 EXPECT_EQ(result.value.get(), value1);
1910 EXPECT_EQ(std::addressof(result.reference), std::addressof(value2));
1911 EXPECT_EQ(result.wrapper.get(), TestFixture::test_value(2));
1912}
1913
1914template <typename Container, typename... Args>
1915constexpr auto constexpr_emplace_back(Args&&... args) -> Container {
1916 Container res;
1917 res.emplace_back(std::forward<Args>(args)...);
1918 return res;
1919}
1920
1921/// @test In a `constexpr` context, the `emplace_back` member function can be used to add an element to an
1922/// `inline_vector`. The new element is constructed with the arguments supplied to `emplace_back`
1924 using value_type = typename TypeParam::value_type;
1925 struct with_constructor_args {
1926 value_type first;
1927 value_type second;
1928 value_type third;
1929
1930 with_constructor_args() = default;
1931
1932 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
1933 constexpr with_constructor_args(value_type&& fst, value_type&& snd, value_type&& trd)
1934 : first(std::move(fst)),
1935 second(std::move(snd)),
1936 third(std::move(trd)) {}
1937 };
1938
1939 constexpr auto vec =
1941 TestFixture::test_value(0),
1942 TestFixture::test_value(1),
1943 TestFixture::test_value(2)
1944 );
1945
1946 STATIC_ASSERT_EQ(vec.size(), 1);
1947 STATIC_ASSERT_EQ(vec[0].first, TestFixture::test_value(0));
1948 STATIC_ASSERT_EQ(vec[0].second, TestFixture::test_value(1));
1949 STATIC_ASSERT_EQ(vec[0].third, TestFixture::test_value(2));
1950}
1951
1952template <typename T>
1953struct throws_without_nullptr {
1954 explicit throws_without_nullptr(T const&) {}
1956};
1957
1958/// @test `emplace_back` is `noexcept` if and only if the element type of the vector is nothrow-constructible from the
1959/// supplied arguments
1960TYPED_TEST_P(InlineVectorTest, EmplaceBackIsConditionallyNoexceptRvalue) {
1961 STATIC_ASSERT_EQ(
1962 noexcept(TestFixture::construct().emplace_back(std::declval<typename TypeParam::value_type&&>())),
1964 );
1965}
1966
1967/// @test `emplace_back` is `noexcept` if and only if the element type of the vector is nothrow-constructible from the
1968/// supplied arguments
1971 EmplaceBackIsConditionallyNoexceptLvalue,
1973) {
1974 using value_type = typename TypeParam::value_type;
1975 STATIC_ASSERT_EQ(
1976 noexcept(TestFixture::construct().emplace_back(std::declval<value_type const&>())),
1978 );
1979
1980 STATIC_ASSERT_FALSE(
1981 noexcept(typename TestFixture::template standard_capacity_vector<throws_without_nullptr<value_type>>{}
1982 .emplace_back(std::declval<value_type const&>()))
1983 );
1984 STATIC_ASSERT_TRUE(
1985 noexcept(typename TestFixture::template standard_capacity_vector<throws_without_nullptr<value_type>>{}
1986 .emplace_back(std::declval<value_type const&>(), nullptr))
1987 );
1988}
1989
1990/// @test `emplace` with a position is `noexcept` if and only if the element type of the vector is
1991/// nothrow-move-constructible, nothrow-move-assignable, and nothrow-constructible from the supplied arguments
1992TYPED_TEST_P(InlineVectorTest, EmplaceAtPositionIsConditionallyNoexceptRvalue) {
1993 using value_type = typename TypeParam::value_type;
1994 using const_it = typename TypeParam::const_iterator;
1995
1996 constexpr bool is_nothrow_movable =
1998
1999 STATIC_ASSERT_EQ(
2000 noexcept(TestFixture::construct().emplace(std::declval<const_it>(), std::declval<value_type&&>())),
2001 is_nothrow_movable
2002 );
2003
2004 using overload_test_vector =
2006 using overload_it = typename overload_test_vector::const_iterator;
2007 STATIC_ASSERT_FALSE(noexcept(overload_test_vector{}.emplace(std::declval<overload_it>(), std::declval<value_type>()))
2008 );
2009 STATIC_ASSERT_TRUE(
2010 noexcept(overload_test_vector{}.emplace(std::declval<overload_it>(), std::declval<value_type>(), nullptr))
2011 );
2012}
2013
2014/// @test Invoking `emplace` inserts a new value at the position indicated, constructing the new value with the supplied
2015/// arguments, and returning an iterator referencing the new value
2017 using value_type = typename TypeParam::value_type;
2018 struct with_constructor_args {
2020 value_type* raw_pointer;
2022
2023 with_constructor_args(value_type const& val, value_type* rptr, move_only_wrapper<value_type> wrap_arg)
2024 : value(val),
2025 raw_pointer(rptr),
2026 wrapper(std::move(wrap_arg)) {}
2027 };
2028
2029 typename TestFixture::template standard_capacity_vector<with_constructor_args> vec;
2030 auto const& const_vec1 = vec;
2031 value_type const value1 = TestFixture::test_value(0);
2032 value_type value2 = TestFixture::test_value(1);
2033 auto pos = vec.emplace(
2034 const_vec1.begin(),
2035 value1,
2036 std::addressof(value2),
2037 move_only_wrapper<value_type>(TestFixture::test_value(2))
2038 );
2039 EXPECT_EQ(pos, vec.begin());
2040 EXPECT_EQ(vec.size(), 1);
2041 EXPECT_EQ(&*pos, std::addressof(vec[0]));
2042
2043 EXPECT_EQ(pos->value.get(), value1);
2044 ASSERT_NE(pos->raw_pointer, nullptr);
2045 EXPECT_EQ(pos->raw_pointer, std::addressof(value2));
2046 EXPECT_EQ(pos->wrapper.get(), TestFixture::test_value(2));
2047}
2048
2049template <typename Vec, typename Arg>
2050constexpr auto constexpr_emplace(Vec&& vec, std::ptrdiff_t pos, Arg&& arg) -> Vec {
2051 static_assert(std::is_rvalue_reference<Vec&&>::value, "Only expected to be called with an r-value reference.");
2052 std::forward<Vec>(vec).emplace(std::forward<Vec>(vec).begin() + pos, std::forward<Arg>(arg));
2053 return std::forward<Vec>(vec);
2054}
2055
2056/// @test `emplace` can be invoked in a `constexpr` context to construct an element at a specified index.
2059 CanEmplace,
2060 InlineVectorTest<TypeParam>::constexpr_compatible&& TypeParam::capacity >= 3
2061) {
2062 constexpr auto vec1 = TestFixture::test_vector(2);
2063
2064 struct convertible_to_typeparam {
2065 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
2066 constexpr operator typename TypeParam::value_type() noexcept { return TestFixture::test_value(2); }
2067 };
2068
2069 constexpr TypeParam vec2 = constexpr_emplace(TestFixture::test_vector(2), 1, convertible_to_typeparam{});
2070
2071 STATIC_ASSERT_EQ(vec2.size(), vec1.size() + 1);
2072 STATIC_ASSERT_EQ(vec2[0], vec1[0]);
2073 STATIC_ASSERT_EQ(vec2[1], static_cast<typename TypeParam::value_type>(convertible_to_typeparam{}));
2074 STATIC_ASSERT_EQ(vec2[2], vec1[1]);
2075}
2076
2077/// @test `emplace` with a position is `noexcept` if and only if the element type of the vector is
2078/// nothrow-move-constructible, nothrow-move-assignable, and nothrow-constructible from an lvalue argument
2081 EmplaceAtPositionIsConditionallyNoexceptLvalue,
2083) {
2084 using value_type = typename TypeParam::value_type;
2085 using const_it = typename TypeParam::const_iterator;
2086
2087 constexpr bool is_nothrow_movable =
2089
2090 STATIC_ASSERT_EQ(
2091 noexcept(TestFixture::construct().emplace(std::declval<const_it>(), std::declval<value_type const&>())),
2093 );
2094}
2095
2096/// @test Emplacing using the default constructor has the right exception specification. This test is separate from the
2097/// ones above due to a bug in GCC8 which tries to instantiate the `emplace_back` and `emplace` functions before
2098/// checking their exception specifications, which fails for types that are not default-constructible.
2101 DefaultEmplaceIsConditionallyNoexcept,
2103) {
2104 using value_type = typename TypeParam::value_type;
2105 using const_it = typename TypeParam::const_iterator;
2106
2107 constexpr bool is_nothrow_movable =
2109
2110 STATIC_ASSERT_EQ(
2111 noexcept(TestFixture::construct().emplace_back()),
2113 );
2114 STATIC_ASSERT_EQ(
2115 noexcept(TestFixture::construct().emplace(std::declval<const_it>())),
2116 is_nothrow_movable && std::is_nothrow_default_constructible<value_type>{}
2117 );
2118}
2119
2120/// @test Invoking `emplace_back` on an `inline_vector<T>` which has a size equal to its capacity terminates the program
2121/// with a precondition violation
2122TYPED_TEST_P(InlineVectorDeathTest, EmplaceBackIsPreconditionViolationIfFull) {
2123 auto vec = TestFixture::test_vector(TypeParam::capacity);
2124
2125 ASSERT_DEATH(vec.emplace_back(TestFixture::test_value(0)), "Precondition violation");
2126}
2127
2128/// @test Invoking `swap` without a namespace qualification on two `inline_vector` instances exchanges the contents, so
2129/// the elements from one have been moved to the other, and vice-versa.
2130TYPED_TEST_P(InlineVectorTest, ADLSwapSwapsContentsForBasicTypes) {
2131 auto value1 = TestFixture::full_test_vector();
2132 auto value2 = TestFixture::test_vector(TypeParam::capacity, TypeParam::capacity + TypeParam::capacity / 2UL);
2133
2134 swap(value1, value2);
2135
2136 EXPECT_EQ(value1, TestFixture::test_vector(TypeParam::capacity, TypeParam::capacity + TypeParam::capacity / 2UL));
2137 EXPECT_EQ(value2, TestFixture::full_test_vector());
2138}
2139
2140template <typename Vec>
2141constexpr auto constexpr_swap(Vec lhs, Vec rhs) -> std::pair<Vec, Vec> {
2142 swap(lhs, rhs);
2143 return {lhs, rhs};
2144}
2145
2146/// @test In a `constexpr` context, two `inline_vector` instances can be swapped with an unqualified call to `swap`.
2148 constexpr auto value1 = TestFixture::full_test_vector();
2149 constexpr auto value2 =
2150 TestFixture::test_vector(TypeParam::capacity, TypeParam::capacity + TypeParam::capacity / 2UL);
2151
2152 constexpr auto vec_swapped = constexpr_swap(value1, value2);
2153 STATIC_ASSERT_EQ(vec_swapped.first, value2);
2154 STATIC_ASSERT_EQ(vec_swapped.second, value1);
2155}
2156
2157/// @test Swapping two `inline_vector`s is `noexcept` if and only if the element
2158/// type is nothrow swappable AND the element type is nothrow move constructible
2159TYPED_TEST_P(InlineVectorTest, SwapNoexceptMatchesElementType) {
2162
2163 STATIC_ASSERT_EQ(::arene::base::is_nothrow_swappable_v<TypeParam>, element_nothrow);
2164 STATIC_ASSERT_EQ(noexcept(std::declval<TypeParam>().swap(std::declval<TypeParam&>())), element_nothrow);
2165}
2166
2167/// @test `insert` of an rvalue is `noexcept` if the element type of the vector is nothrow-constructible from the
2168/// supplied value, and is nothrow-move-constructible and nothrow-move-assignable
2169TYPED_TEST_P(InlineVectorTest, InsertRvalueIsConditionallyNoexcept) {
2170 using value_type = typename TypeParam::value_type;
2171 using iterator = typename TypeParam::const_iterator;
2172
2173 constexpr bool is_nothrow_movable =
2175
2176 STATIC_ASSERT_EQ(
2177 noexcept(TypeParam{}.insert(std::declval<iterator>(), std::declval<value_type&&>())),
2178 is_nothrow_movable
2179 );
2180}
2181
2182/// @test `insert` of an lvalue is `noexcept` if the element type of the vector is nothrow-constructible from the
2183/// supplied value, and is nothrow-move-constructible and nothrow-move-assignable
2185 using value_type = typename TypeParam::value_type;
2186 using iterator = typename TypeParam::const_iterator;
2187
2188 constexpr bool is_nothrow_movable =
2190
2191 STATIC_ASSERT_EQ(
2192 noexcept(TypeParam{}.insert(std::declval<iterator>(), std::declval<value_type const&>())),
2194 );
2195}
2196
2197/// @test `insert` is `noexcept` if the element type of the vector is nothrow-copy-constructible, and is
2198/// nothrow-move-constructible and nothrow-move-assignable
2200 using value_type = typename TypeParam::value_type;
2201 using iterator = typename TypeParam::const_iterator;
2202
2203 constexpr bool is_nothrow_movable =
2205
2206 STATIC_ASSERT_EQ(
2207 noexcept(TypeParam{}.insert(std::declval<iterator>(), 0U, std::declval<value_type&&>())),
2209 );
2210 STATIC_ASSERT_EQ(
2211 noexcept(TypeParam{}.insert(std::declval<iterator>(), 0U, std::declval<value_type const&>())),
2213 );
2214}
2215
2216/// @test Invoking `insert` with a count and a value to insert more elements than there are remaining spaces in the
2217/// vector before it exceeds capacity terminates the program with a precondition violation.
2219 auto value = TestFixture::test_vector(TypeParam::capacity - 1UL);
2220 ASSERT_DEATH(value.insert(value.begin(), 2UL, TestFixture::test_value(5)), "Precondition violation");
2221}
2222
2223/// @test Invoking `insert` with the end iterator of the `inline_vector` and a count and value appends the specified
2224/// number of copies of the supplied value to the end of the vector.
2227 InsertNAtEndInsertsElements,
2228 is_copyable_v<typename TypeParam::value_type>&& TypeParam::capacity >= 7
2229) {
2230 auto const value1 = TestFixture::test_value(0);
2231 auto const value2 = TestFixture::test_value(1);
2232 auto const value3 = TestFixture::test_value(2);
2233 TypeParam vec{value1, value2};
2234 constexpr std::size_t insert_count = 5;
2235
2236 vec.insert(vec.end(), insert_count, value3);
2237 EXPECT_EQ(vec.size(), insert_count + 2);
2238 EXPECT_EQ(vec[0], value1);
2239 EXPECT_EQ(vec[1], value2);
2240 for (std::size_t i = 0; i < insert_count; ++i) {
2241 EXPECT_EQ(vec[i + 2], value3);
2242 }
2243}
2244
2245/// @test Invoking `insert` with an iterator referring to an existing element of an `inline_vector` and a count and
2246/// value moves the referred to element and subsequent elements to make room, and inserts the specified number of copies
2247/// of the supplied value prior to the existing element.
2250 InsertNInMiddleInsertsElements,
2251 is_copyable_v<typename TypeParam::value_type>&& TypeParam::capacity >= 7
2252) {
2253 auto const value1 = TestFixture::test_value(0);
2254 auto const value2 = TestFixture::test_value(1);
2255 auto const value3 = TestFixture::test_value(2);
2256 auto const value4 = TestFixture::test_value(3);
2257 auto const value_inserted = TestFixture::test_value(4);
2258 TypeParam vec{value1, value2, value3, value4};
2259 constexpr std::size_t insert_count = 3;
2260
2261 vec.insert(vec.begin() + 1, insert_count, value_inserted);
2262 EXPECT_EQ(vec.size(), insert_count + 4);
2263 EXPECT_EQ(vec[0], value1);
2264 for (std::size_t i = 0; i < insert_count; ++i) {
2265 EXPECT_EQ(vec[i + 1], value_inserted);
2266 }
2267 EXPECT_EQ(vec[insert_count + 1], value2);
2268 EXPECT_EQ(vec[insert_count + 2], value3);
2269 EXPECT_EQ(vec[insert_count + 3], value4);
2270}
2271
2272/// @test Invoking `insert` with an iterator referring to an existing element of an `inline_vector` and a source
2273/// iterator range denoted by a pair of iterators moves the referred to element and subsequent elements to make room,
2274/// and inserts the elements from the source iterator range prior to the existing element.
2275CONDITIONAL_TYPED_TEST_P(InlineVectorTest, InsertFromIteratorRangeInMiddle, TypeParam::capacity >= 11) {
2276 auto vec1 = TestFixture::test_vector(4);
2277 auto vec2 = TestFixture::test_vector(4, 11);
2278 auto const vec2_expected = TestFixture::test_vector(4, 11);
2279
2280 vec1.insert(vec1.begin() + 1, std::make_move_iterator(vec2.begin()), std::make_move_iterator(vec2.end()));
2281 EXPECT_EQ(vec1.size(), vec2.size() + 4);
2282 EXPECT_EQ(vec1[0], TestFixture::test_value(0));
2283 for (std::size_t idx = 0; idx < vec2.size(); ++idx) {
2284 EXPECT_EQ(vec1[idx + 1], vec2_expected[idx]);
2285 }
2286 EXPECT_EQ(vec1[vec2_expected.size() + 1], TestFixture::test_value(1));
2287 EXPECT_EQ(vec1[vec2_expected.size() + 2], TestFixture::test_value(2));
2288 EXPECT_EQ(vec1[vec2_expected.size() + 3], TestFixture::test_value(3));
2289}
2290
2291/// @test `insert` is `noexcept` if the element type of the vector is nothrow-constructible from the supplied iterator's
2292/// reference type, and is nothrow-move-constructible and nothrow-move-assignable
2294 using value_type = typename TypeParam::value_type;
2295 using ivec_iter = typename TypeParam::const_iterator;
2297 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
2299 using throwing_it_throwing_type = typename TestFixture::template throwing_input_iterator<throws_when_converted>;
2300 using throwing_it_raw_type = typename TestFixture::template throwing_input_iterator<value_type>;
2301 using nothrow_it_throwing_type = typename TestFixture::template non_throwing_input_iterator<throws_when_converted>;
2302 using nothrow_it_raw_type = typename TestFixture::template non_throwing_input_iterator<value_type>;
2303
2304 constexpr bool is_nothrow_movable =
2306
2307 STATIC_ASSERT_EQ(
2308 noexcept(this->construct().insert(
2312 )),
2314 );
2315
2316 STATIC_ASSERT_FALSE(noexcept(this->construct().insert(
2320 )));
2321
2322 STATIC_ASSERT_EQ(
2323 noexcept(this->construct().insert(
2327 )),
2329 );
2330 STATIC_ASSERT_FALSE(noexcept(this->construct().insert(
2332 std::declval<::testing::demoted_iterator<throwing_it_throwing_type, std::input_iterator_tag>>(),
2333 std::declval<::testing::demoted_iterator<throwing_it_throwing_type, std::input_iterator_tag>>()
2334 )));
2335 STATIC_ASSERT_FALSE(noexcept(this->construct().insert(
2339 )));
2340 STATIC_ASSERT_FALSE(noexcept(this->construct().insert(
2344 )));
2345 STATIC_ASSERT_FALSE(noexcept(this->construct().insert(
2349 )));
2350}
2351
2352/// @test `cbegin` and `cend` return `const_iterator`s to the corresponding locations of the `inline_vector`.
2353TYPED_TEST_P(InlineVectorTest, CanGetCBeginAndEnd) {
2354 auto const value1 = TestFixture::full_test_vector();
2355
2356 ASSERT_EQ(value1.cbegin(), value1.begin());
2357 ASSERT_EQ(value1.cend(), value1.end());
2358
2359 ::testing::StaticAssertTypeEq<decltype(value1.cbegin()), typename TypeParam::const_iterator>();
2360 STATIC_ASSERT_TRUE(noexcept(value1.cbegin()));
2361 STATIC_ASSERT_TRUE(noexcept(value1.cend()));
2362
2363 auto value2 = TestFixture::full_test_vector();
2364 ::testing::StaticAssertTypeEq<decltype(value2.cbegin()), typename TypeParam::const_iterator>();
2365 ::testing::StaticAssertTypeEq<decltype(value2.cend()), typename TypeParam::const_iterator>();
2366
2367 EXPECT_EQ(value2.begin(), value2.cbegin());
2368 EXPECT_EQ(value2.end(), value2.cend());
2369}
2370
2371/// @test `rbegin`, `rend`, `crbegin` and `crend` return reverse iterators to the appropriate locations in the
2372/// `inline_vector`, such that iteration _forwards_ from `rbegin` or `crbegin` iterates through the elements of the
2373/// `inline_vector` in reverse order.
2374TYPED_TEST_P(InlineVectorTest, ReverseIteration) {
2375 auto const value1 = TestFixture::full_test_vector();
2376
2377 auto itr = value1.rbegin();
2378 auto citr = value1.crbegin();
2379 for (std::size_t steps = 0UL; steps < value1.size(); ++steps) {
2380 ASSERT_NE(itr, value1.rend());
2381 ASSERT_NE(citr, value1.crend());
2382
2383 EXPECT_EQ(*itr, value1[value1.size() - steps - 1UL]);
2384 EXPECT_EQ(*citr, value1[value1.size() - steps - 1UL]);
2385
2386 ++itr;
2387 ++citr;
2388 }
2389 EXPECT_EQ(itr, value1.rend());
2390 EXPECT_EQ(citr, value1.crend());
2391}
2392
2393/// @test An `inline_vector` can be constructed from an `inline_vector` with a larger capacity, provided the number of
2394/// elements in the source vector is less than the capacity of the target vector
2397 CanConstructFromBiggerCapacityVector,
2400) {
2401 constexpr std::size_t larger_capacity = TypeParam::capacity + 2UL;
2402 constexpr typename TestFixture::template vector_with_capacity<larger_capacity> large_vector{
2403 TestFixture::template test_initializer_list<TypeParam::capacity - 1UL>()
2404 };
2405
2406 constexpr TypeParam small_vector(large_vector);
2407
2408 STATIC_ASSERT_EQ(small_vector.size(), large_vector.size());
2409 STATIC_ASSERT_TRUE(equal(small_vector.begin(), small_vector.end(), large_vector.begin(), large_vector.end()));
2410}
2411
2412/// @test An `inline_vector` can be assigned from an `inline_vector` with a larger capacity, provided the number of
2413/// elements in the source vector is less than the capacity of the target vector
2415 constexpr std::size_t larger_capacity = TypeParam::capacity + 2UL;
2416 typename TestFixture::template vector_with_capacity<larger_capacity> const large_vector{
2417 TestFixture::template test_initializer_list<TypeParam::capacity - 1UL>()
2418 };
2419
2420 TypeParam small_vector;
2421 small_vector = large_vector;
2422
2423 EXPECT_EQ(small_vector.size(), large_vector.size());
2424 for (std::size_t i = 0; i < small_vector.size(); ++i) {
2425 EXPECT_EQ(small_vector[i], large_vector[i]);
2426 }
2427}
2428
2429/// @test `try_construct` can be used to construct an empty `inline_vector`.
2430TYPED_TEST_P(InlineVectorTest, CanDefaultConstructViaTryConstruct) {
2431 STATIC_ASSERT_TRUE(std::is_same<decltype(TypeParam::try_construct()), ::arene::base::optional<TypeParam>>::value);
2432 STATIC_ASSERT_TRUE(noexcept(TypeParam::try_construct()));
2433
2434 COND_STATIC_ASSERT_TRUE(TypeParam::try_construct().has_value());
2435 COND_STATIC_ASSERT_TRUE(TypeParam::try_construct()->empty());
2436}
2437
2438/// @test `try_construct` can be used to construct an `inline_vector` with a specified number of elements
2441 CanConstructWithSizeViaTryConstruct,
2443) {
2444 STATIC_ASSERT_TRUE(std::is_same<decltype(TypeParam::try_construct(0)), ::arene::base::optional<TypeParam>>::value);
2445 STATIC_ASSERT_EQ(
2446 noexcept(TypeParam::try_construct(0)),
2448 );
2449
2450 COND_STATIC_ASSERT_TRUE(TypeParam::try_construct(TypeParam::capacity).has_value());
2451 COND_STATIC_ASSERT_FALSE(TypeParam::try_construct(TypeParam::capacity)->empty());
2452 COND_STATIC_ASSERT_EQ(TypeParam::try_construct(TypeParam::capacity)->size(), TypeParam::capacity);
2453}
2454
2455/// @test `try_construct` can be used to attempt to construct an `inline_vector` with a specified number of elements
2456/// that exceeds the capacity of the vector, in which case the result is an empty `optional`.
2459 ConstructWithExcessiveSizeViaTryConstructFails,
2461) {
2462 constexpr std::size_t size1 = TypeParam::capacity + 1UL;
2463 STATIC_ASSERT_TRUE(std::is_same<decltype(TypeParam::try_construct(size1)), ::arene::base::optional<TypeParam>>::value
2464 );
2465 STATIC_ASSERT_EQ(
2466 noexcept(TypeParam::try_construct(size1)),
2468 );
2469
2470 COND_STATIC_ASSERT_FALSE(TypeParam::try_construct(size1).has_value());
2471}
2472
2473/// @test `try_construct` with a number of elements is not considered for overload resolution if the element type of the
2474/// `inline_vector<T>` is not default-constructible.
2475TYPED_TEST_P(InlineVectorTest, CannotTryConstructWithSizeForANonDefaultConstructibleType) {
2476 constexpr bool can_construct_with_size_only =
2478 STATIC_ASSERT_EQ(can_construct_with_size_only, std::is_default_constructible<typename TypeParam::value_type>{});
2479}
2480
2481/// @test The `inline_vector` constructor with a number of elements is not considered for overload resolution if the
2482/// element type of the `inline_vector<T>` is not default-constructible.
2483TYPED_TEST_P(InlineVectorTest, CannotConstructWithSizeForANonDefaultConstructibleType) {
2484 STATIC_ASSERT_EQ(
2487 );
2488}
2489
2490/// @test The default constructor and corresponding `try_construct` function of `inline_vector<T>` is always `noexcept`,
2491/// even if the stored element type's default constructor can throw
2492TYPED_TEST_P(InlineVectorTest, DefaultTryConstructNoexceptEvenIfDefaultConstructorNotNoexcept) {
2493 STATIC_ASSERT_TRUE(noexcept(TypeParam::try_construct()));
2494 STATIC_ASSERT_TRUE(noexcept(TypeParam{}));
2495
2496 COND_STATIC_ASSERT_TRUE(TypeParam::try_construct().has_value());
2497 COND_STATIC_ASSERT_TRUE(TypeParam::try_construct()->empty());
2498 COND_STATIC_ASSERT_TRUE(TypeParam().empty());
2499}
2500
2501/// @test The `try_construct` function of `inline_vector` that takes a number of elements is not `noexcept` if the
2502/// default constructor of the stored element type is not `noexcept`
2505 ConstructWithSizeViaTryConstructNotNoexceptIfDefaultConstructorNotNoexcept,
2507) {
2508 STATIC_ASSERT_TRUE(std::is_same<decltype(TypeParam::try_construct(0)), ::arene::base::optional<TypeParam>>::value);
2509 STATIC_ASSERT_EQ(
2510 noexcept(TypeParam::try_construct(0)),
2512 );
2513}
2514
2515/// @test The constructor of `inline_vector` that takes a number of elements is not `noexcept` if the default
2516/// constructor of the stored element type is not `noexcept`
2519 ConstructWithSizeViaNormalConstructWithDefaultConstructorNotNoexceptIsNotNoexcept,
2521) {
2522 STATIC_ASSERT_EQ(noexcept(TypeParam(0)), std::is_nothrow_default_constructible<typename TypeParam::value_type>{});
2523}
2524
2525/// @test Specifying a number of elements larger than the capacity of an `inline_vector` when invoking the
2526/// constructor terminates the program with a precondition violation
2529 ConstructWithExcessiveSizeViaNormalConstructIsAlwaysPreconditionViolation,
2531) {
2532 constexpr std::size_t size1 = TypeParam::capacity + 1UL;
2533 ASSERT_DEATH(this->construct(size1), "Precondition violation"); // dies regardless of exception behavior
2534}
2535
2536/// @test The overload of `try_construct` that takes a size and source value is not considered for overload resolution
2537/// if the element type of the `inline_vector<T>` is not copy-constructible.
2538TYPED_TEST_P(InlineVectorTest, NotConstructibleWithSizeAndSourceIfDataNotCopyable) {
2539 using value_type = typename TypeParam::value_type;
2540 constexpr bool copy_ok = std::is_copy_constructible<value_type>::value;
2542 STATIC_ASSERT_EQ(
2543 (::arene::base::
2545 copy_ok
2546 );
2547}
2548
2549/// @test The overload of `try_construct` that takes an initializer list is not considered for overload resolution if
2550/// the element type of the `inline_vector` is not copy-constructible.
2551TYPED_TEST_P(InlineVectorTest, NotConstructibleFromInitializerListIfDataTypeNotCopyConstructible) {
2552 STATIC_ASSERT_EQ(
2555 );
2556 STATIC_ASSERT_EQ(
2558 TestFixture::template try_construct_result,
2559 TypeParam,
2562 );
2563}
2564
2565/// @test Invoking `try_construct` with an initializer list constructs an `inline_vector` holding copies of the elements
2566/// from the initializer list
2569 CanTryConstructFromInitializerList,
2571) {
2572 auto const values = TestFixture::full_test_initializer_list();
2573
2574 STATIC_ASSERT_EQ(
2575 noexcept(TypeParam::try_construct(values)),
2577 );
2578 ASSERT_TRUE(TypeParam::try_construct(values).has_value());
2579 ASSERT_EQ(TypeParam::try_construct(values)->size(), values.size());
2580
2581 auto res = TypeParam::try_construct(values);
2582 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2583}
2584
2585/// @test Invoking `try_construct` with an initializer list holding more elements than the capacity of the
2586/// `inline_vector` returns an empty `optional`
2589 TryConstructFromTooLargeInitializerListReturnsEmpty,
2591) {
2592 auto const values = TestFixture::template test_initializer_list<TypeParam::capacity + 1UL>();
2593
2594 ASSERT_FALSE(TypeParam::try_construct(values).has_value());
2595}
2596
2597/// @test Invoking `try_construct` with an existing `inline_vector` returns a copy of that source vector
2600 CanCopyViaTryConstruct,
2602) {
2603 using value_type = typename TypeParam::value_type;
2604 auto const values = TestFixture::full_test_vector();
2605
2606 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2607 TestFixture::template try_construct_result,
2608 TypeParam,
2609 TypeParam const&>);
2610 STATIC_ASSERT_EQ(noexcept(TypeParam::try_construct(values)), std::is_nothrow_copy_constructible<value_type>::value);
2611 auto res = TypeParam::try_construct(values);
2612 ASSERT_TRUE(res.has_value());
2613 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2614}
2615
2616/// @test Constructing an `inline_vector` with an existing `inline_vector` copies the elements from the source vector
2619 CanCopyViaConstruct,
2621) {
2622 auto const values = TestFixture::full_test_vector();
2623
2624 STATIC_ASSERT_EQ(noexcept(TypeParam(values)), std::is_nothrow_copy_constructible<typename TypeParam::value_type>{});
2625 auto res = this->construct(values);
2626 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2627}
2628
2629/// @test Invoking `try_construct` with an existing `inline_vector` with a smaller capacity returns an `inline_vector`
2630/// with the same elements as the source vector
2633 CanCopyViaTryConstructFromSmaller,
2635) {
2636 // typename TestFixture::template vector_with_capacity<TypeParam::capacity - 1> const values{
2637 // TestFixture::test_vector(TypeParam::capacity - 1)
2638 // };
2639
2640 auto const values = ::arene::base::testing::test_vector<typename TypeParam::value_type, TypeParam::capacity - 1>(
2641 0,
2642 TypeParam::capacity - 1
2643 );
2644
2645 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2646 TestFixture::template try_construct_result,
2647 TypeParam,
2648 TypeParam const&>);
2649 STATIC_ASSERT_EQ(
2650 noexcept(TypeParam::try_construct(values)),
2652 );
2655 "-Wmaybe-uninitialized",
2656 "GCC issues false positive here when compiling with -fno-exceptions and using GCC's stdlib"
2657 );
2658 auto res = TypeParam::try_construct(values);
2660 ASSERT_TRUE(res.has_value());
2661 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2662}
2663
2664/// @test Constructing an `inline_vector` from an existing `inline_vector` with a smaller capacity returns an
2665/// `inline_vector` with the same elements as the source vector
2668 CanCopyViaConstructFromSmaller,
2670) {
2671 static typename TestFixture::template vector_with_capacity<TypeParam::capacity - 1> const values{
2672 TestFixture::test_vector(TypeParam::capacity - 1)
2673 };
2674
2675 STATIC_ASSERT_EQ(noexcept(TypeParam(values)), std::is_nothrow_copy_constructible<typename TypeParam::value_type>{});
2676 auto res = this->construct(values);
2677 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2678}
2679
2680/// @test Invoking `try_construct` with an existing `inline_vector` with a larger capacity but a size that is less than
2681/// or equal to the capacity of the destination type returns an `inline_vector` with the same elements as the source
2682/// vector
2685 CanCopyViaTryConstructFromLargerWithFewerElements,
2687) {
2689 0,
2690 TypeParam::capacity
2691 );
2692
2693 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2694 TestFixture::template try_construct_result,
2695 TypeParam,
2696 TypeParam const&>);
2697 STATIC_ASSERT_EQ(
2698 noexcept(TypeParam::try_construct(values)),
2700 );
2701 auto res = TypeParam::try_construct(values);
2702 ASSERT_TRUE(res.has_value());
2703 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2704}
2705
2706/// @test Invoking `try_construct` with an existing `inline_vector` with a larger capacity and a size that is larger
2707/// than the capacity of the destination type returns an empty `optional`
2710 FailToCopyViaTryConstructFromLargerWithMoreElements,
2712) {
2714 0,
2715 TypeParam::capacity + 1
2716 );
2717
2718 ASSERT_GT(values.size(), TypeParam::capacity);
2719 ASSERT_FALSE(TypeParam::try_construct(values).has_value());
2720}
2721
2722/// @test Constructing an `inline_vector` from an existing `inline_vector` with a larger capacity but a size that is
2723/// less than or equal to the capacity of the destination type copies elements from the source vector
2726 CanCopyViaConstructFromLargerWithFewerElements,
2728) {
2730 0,
2731 TypeParam::capacity
2732 );
2734
2735 STATIC_ASSERT_EQ(noexcept(TypeParam(values)), copy_is_noexcept);
2736 auto res = this->construct(values);
2737 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2738}
2739
2740/// @test `inline_vector` is not copy-constructible if the data type is not copy-constructible
2741TYPED_TEST_P(InlineVectorTest, NotCopyConstructibleIfDataTypeNotCopyConstructible) {
2742 using smaller_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity - 1>;
2743 using larger_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity + 1>;
2745
2747 STATIC_ASSERT_EQ(
2749 copy_ok
2750 );
2752 STATIC_ASSERT_EQ(
2754 copy_ok
2755 );
2757 STATIC_ASSERT_EQ(
2759 copy_ok
2760 );
2761}
2762
2763/// @test Invoking `try_construct` with an rvalue `inline_vector` constructs a new `inline_vector`, and move-constructs
2764/// the elements from the source to the new vector.
2765TYPED_TEST_P(InlineVectorTest, CanMoveViaTryConstruct) {
2766 auto const values = TestFixture::full_test_vector();
2767 auto values_copy = TestFixture::full_test_vector();
2768
2769 STATIC_ASSERT_TRUE(::arene::base::
2771 STATIC_ASSERT_EQ(
2772 noexcept(TypeParam::try_construct(std::move(values_copy))),
2774 );
2775 auto res = TypeParam::try_construct(std::move(values_copy));
2776 ASSERT_TRUE(res.has_value());
2777 EXPECT_TRUE(elements_are_array(*res, values));
2778}
2779
2780/// @test Constructing an `inline_vector` from an rvalue `inline_vector` move-constructs the elements from the source to
2781/// the new vector.
2782TYPED_TEST_P(InlineVectorTest, CanMoveViaConstruct) {
2783 auto const values = TestFixture::full_test_vector();
2784 auto source = TestFixture::full_test_vector();
2785
2786 // NOLINTNEXTLINE(hicpp-move-const-arg)
2787 STATIC_ASSERT_EQ(
2788 noexcept(TypeParam(std::move(source))),
2790 );
2791 // NOLINTNEXTLINE(hicpp-move-const-arg)
2792 auto res = this->construct(std::move(source));
2793 EXPECT_TRUE(elements_are_array(res, values));
2794}
2795
2796/// @test Invoking `try_construct` with an rvalue `inline_vector` with a larger capacity and a size that is larger
2797/// than the capacity of the destination type returns an empty `optional`
2798TYPED_TEST_P(InlineVectorTest, FailToMoveViaTryConstructFromLargerWithMoreElements) {
2800 0,
2801 TypeParam::capacity + 1
2802 );
2803
2804 ASSERT_GT(values.size(), TypeParam::capacity);
2805
2806 ASSERT_FALSE(TypeParam::try_construct(std::move(values)).has_value());
2807}
2808
2809/// @test `inline_vector` is not move constructible if the element type is not move constructible
2810TYPED_TEST_P(InlineVectorTest, NotMoveConstructibleIfDataTypeNotMoveConstructible) {
2811 using ivec = typename TestFixture::template vector_with_capacity<TypeParam::capacity>;
2812 using smaller_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity - 1>;
2813 using larger_vec = typename TestFixture::template vector_with_capacity<TypeParam::capacity + 1>;
2815
2816 STATIC_ASSERT_EQ((std::is_constructible<ivec, ivec&&>::value), move_ok);
2817 STATIC_ASSERT_EQ(
2819 move_ok
2820 );
2821 STATIC_ASSERT_EQ((std::is_constructible<ivec, smaller_vec&&>::value), move_ok);
2822 STATIC_ASSERT_EQ(
2824 move_ok
2825 );
2826 STATIC_ASSERT_EQ((std::is_constructible<ivec, larger_vec&&>::value), move_ok);
2827 STATIC_ASSERT_EQ(
2829 move_ok
2830 );
2831}
2832
2833/// @test Invoking `try_construct` with an iterator range returns an `inline_vector` with the same elements as the
2834/// source range
2835TYPED_TEST_P(InlineVectorTest, CanTryConstructFromIteratorRange) {
2836 auto const expected = TestFixture::full_test_vector();
2837 auto source = TestFixture::full_test_vector();
2838
2839 auto maybe_vec =
2840 TypeParam::try_construct(std::make_move_iterator(source.begin()), std::make_move_iterator(source.end()));
2841 ASSERT_TRUE(maybe_vec.has_value());
2842
2843 ASSERT_EQ(maybe_vec->size(), source.size());
2844 ASSERT_TRUE(elements_are_array(*maybe_vec, expected));
2845}
2846
2847/// @test `try_construct` from an iterator range is `noexcept` if the element type of the vector is
2848/// nothrow-constructible from the iterator's reference type
2849// Note: std::move_iterator is not marked noexcept, so this test requires the type to be copy constructible.
2852 IteratorRangeTryConstructionIsConditionallyNoexcept,
2854) {
2856 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
2858 using throwing_bidirectional_iterator = typename TestFixture::throwing_bidirectional_move_iterator_of_t;
2859
2860 STATIC_ASSERT_EQ(
2861 noexcept(TypeParam::try_construct(
2864 )),
2866 );
2867 STATIC_ASSERT_FALSE(noexcept(TypeParam::try_construct(
2870 )));
2871 STATIC_ASSERT_FALSE(noexcept(TypeParam::try_construct(
2874 )));
2875}
2876
2877/// @test `try_construct` from an input iterator range is `noexcept` if the element type of the vector is
2878/// nothrow-constructible from the iterator's reference type
2881 InputIteratorRangeTryConstructionIsConditionallyNoexcept,
2883) {
2884 using value_type = typename TypeParam::value_type;
2885 using throws_when_converted = typename TestFixture::throws_when_converted_to_t;
2886 using throwing_it_throwing_type = typename TestFixture::template throwing_input_iterator<throws_when_converted>;
2887 using throwing_it_raw_type = typename TestFixture::template throwing_input_iterator<value_type>;
2888 using nothrow_it_throwing_type = typename TestFixture::template non_throwing_input_iterator<throws_when_converted>;
2889 using nothrow_it_raw_type = typename TestFixture::template non_throwing_input_iterator<value_type>;
2890
2891 STATIC_ASSERT_EQ(
2892 noexcept(TypeParam::try_construct(
2893 std::declval<::testing::demoted_iterator<value_type*, std::input_iterator_tag>>(),
2894 std::declval<::testing::demoted_iterator<value_type*, std::input_iterator_tag>>()
2895 )),
2897 );
2898 STATIC_ASSERT_FALSE(noexcept(
2900 ));
2901 STATIC_ASSERT_FALSE(
2902 noexcept(TypeParam::try_construct(std::declval<throwing_it_raw_type>(), std::declval<throwing_it_raw_type>()))
2903 );
2904 STATIC_ASSERT_EQ(
2905 noexcept(TypeParam::try_construct(std::declval<nothrow_it_raw_type>(), std::declval<nothrow_it_raw_type>())),
2907 );
2908 STATIC_ASSERT_FALSE(noexcept(
2910 ));
2911}
2912
2913/// @test Dereferencing a default-constructed `inline_vector` iterator terminates the program with a precondition
2914/// violation
2915TYPED_TEST_P(InlineVectorDeathTest, DereferencingInvalidIteratorIsPreconditionViolation) {
2916 ASSERT_DEATH(*typename TypeParam::iterator{}, "Precondition violation");
2917 ASSERT_DEATH(*typename TypeParam::const_iterator{}, "Precondition violation");
2918}
2919
2920/// @test Iterator arithmetic on a default-constructed `inline_vector` iterator terminates the program with a
2921/// precondition violation
2922TYPED_TEST_P(InlineVectorDeathTest, AddingToInvalidIteratorIsPreconditionViolation) {
2923 ASSERT_DEATH(typename TypeParam::iterator{} + 1, "Precondition violation");
2924 ASSERT_DEATH(typename TypeParam::const_iterator{} + 1, "Precondition violation");
2925}
2926
2928
2931 CanConstructAnEmptyVector,
2932 CapacityIsAsSpecified,
2933 CapacityIsNoexcept,
2934 InitialSizeIsZero,
2935 SizeIsConstexpr,
2936 SizeIsNoexcept,
2937 CanPushBackAValue,
2938 AfterPushBackCanGetLastElement,
2939 AfterPushBackVectorIsNotEmpty,
2940 SecondPushBackChangesLastValue,
2941 PushBackIsConditionallyNoexceptRvalue,
2942 PushBackIsConditionallyNoexceptLvalue,
2943 EmptyIsConstexpr,
2944 EmptyIsNoexcept,
2945 RetrievingAValueWithAtThrowsOnEmpty,
2946 RetrievingAValueWithAtReturnsValueAfterPushBack,
2947 AtReturnsReference,
2948 AtOnConstVectorReturnsConstReference,
2949 CanAccessMultipleValuesWithAt,
2950 AtIndexSizeOrLargerThrows,
2951 CanAccessMultipleValuesWithAtWithConstVec,
2952 AtIndexSizeOrLargerThrowsWithConstVec,
2953 MaxSizeEqualsCapacity,
2954 ZeroSizeVectorIsEmpty,
2955 BackReturnsReference,
2956 ConstBackReturnsConstReference,
2957 BackIsNoexcept,
2958 CanPushBack,
2959 CanConstructFromInitializerList,
2960 CanConstructFromInitializerListConstexpr,
2961 CanUseBack,
2962 CanGetFront,
2963 Front,
2964 CanGetIterator,
2965 CanIterateOverValues,
2966 CanIterateOverConstValues,
2967 IteratorTypedefs,
2968 Typedefs,
2969 Iteration,
2970 ConstIteration,
2971 CanEraseAtBeginning,
2972 CanEraseInMiddle,
2973 CanErase,
2974 CanEraseRange,
2975 CanConstructWithSize,
2976 CanConstructWithSizeAndValue,
2977 CopyingVectorCopiesElements,
2978 MovingVectorMovesElements,
2979 CopyAssignOverSmallerVectorCopiesElements,
2980 CopyAssignOverLargerVectorDestroysExcess,
2981 CopyingIsConditionallyDefined,
2982 MoveAssignOverSmallerVectorMovesElements,
2983 MoveAssignOverLargerVectorDestroysExcess,
2984 MovingIsConditionallyDefined,
2985 CanPopBack,
2986 PopBackIsNoexcept,
2987 PopBackIsUsable,
2988 EraseIsNoexceptIfTypeHasNoexceptMove,
2989 CanInsertInEmptyVector,
2990 CanInsertAtEndOfExistingVector,
2991 CanInsertInMiddleOfExistingVector,
2992 ResizeZeroCapacityVecToZeroIsOk,
2993 ResizeNonZeroCapacityVecToZeroIsOk,
2994 ResizeNonZeroCapacityVecToOtherIsOk,
2995 ResizeIsConditionallyNoexcept,
2996 ResizeWithValueIsConditionallyNoexcept,
2997 ResizingFromLargeToSmallLeavesElements,
2998 ResizingFromSmallToLargeConstructsElementsAsCopiesOfSpecified,
2999 CanInitializeWithSizeAndValue,
3000 CanInsert,
3001 CanConstructFromIteratorRange,
3002 IteratorRangeConstructionIsConditionallyNoexcept,
3003 InputIteratorRangeConstructionIsConditionallyNoexcept,
3004 CanConstructFromIteratorRangeConstexpr,
3005 CopyAssignOverSmallerVectorFromInitListCopiesElements,
3006 CopyAssignOverLargerVectorFromInitListDestroysExcess,
3007 CanAssignFromIteratorRange,
3008 IteratorRangeAssignmentIsConditionallyNoexcept,
3009 CanAssignFromInputIteratorRange,
3010 InputIteratorRangeAssignmentIsConditionallyNoexcept,
3011 CanAssignFromInitListUsingAssignFunction,
3012 AssignFromInitListUsingAssignFunctionIsConditionallyNoexcept,
3013 CanAssignFromSizeAndValue,
3014 AssignFromSizeAndValueIsConditionallyNoexcept,
3015 IndexOperatorReturnsReference,
3016 IndexOperatorOnConstVectorReturnsConstReference,
3017 CanAccessMultipleValuesWithIndexOperator,
3018 IndexOperatorIsNoexcept,
3019 IndexOperatorOnConstVectorIsNoexcept,
3020 IndexOperator,
3021 Data,
3022 AfterClearVectorIsEmpty,
3023 ClearWorks,
3024 CanCompareForEquality,
3025 CanCompareForOrdering,
3026 CanEmplaceBack,
3027 CanEmplaceBackConstexpr,
3028 EmplaceBackIsConditionallyNoexceptRvalue,
3029 EmplaceBackIsConditionallyNoexceptLvalue,
3030 EmplaceInsert,
3031 CanEmplace,
3032 EmplaceAtPositionIsConditionallyNoexceptRvalue,
3033 EmplaceAtPositionIsConditionallyNoexceptLvalue,
3034 DefaultEmplaceIsConditionallyNoexcept,
3035 ADLSwapSwapsContentsForBasicTypes,
3036 CanSwap,
3037 SwapNoexceptMatchesElementType,
3038 InsertRvalueIsConditionallyNoexcept,
3039 InsertLvalueIsConditionallyNoexcept,
3040 InsertWithCountIsConditionallyNoexcept,
3041 InsertNAtEndInsertsElements,
3042 InsertNInMiddleInsertsElements,
3043 InsertFromIteratorRangeInMiddle,
3044 InsertFromIteratorRangeIsConditionallyNoexcept,
3045 CanGetCBeginAndEnd,
3046 ReverseIteration,
3047 CanConstructFromBiggerCapacityVector,
3048 CanAssignFromBiggerCapacityVector,
3049 CanDefaultConstructViaTryConstruct,
3050 CanConstructWithSizeViaTryConstruct,
3051 ConstructWithExcessiveSizeViaTryConstructFails,
3052 CannotTryConstructWithSizeForANonDefaultConstructibleType,
3053 CannotConstructWithSizeForANonDefaultConstructibleType,
3054 DefaultTryConstructNoexceptEvenIfDefaultConstructorNotNoexcept,
3055 ConstructWithSizeViaTryConstructNotNoexceptIfDefaultConstructorNotNoexcept,
3056 ConstructWithSizeViaNormalConstructWithDefaultConstructorNotNoexceptIsNotNoexcept,
3057 NotConstructibleWithSizeAndSourceIfDataNotCopyable,
3058 NotConstructibleFromInitializerListIfDataTypeNotCopyConstructible,
3059 CanTryConstructFromInitializerList,
3060 TryConstructFromTooLargeInitializerListReturnsEmpty,
3061 CanCopyViaTryConstruct,
3062 CanCopyViaConstruct,
3063 CanCopyViaTryConstructFromSmaller,
3064 CanCopyViaConstructFromSmaller,
3065 CanCopyViaTryConstructFromLargerWithFewerElements,
3066 FailToCopyViaTryConstructFromLargerWithMoreElements,
3067 CanCopyViaConstructFromLargerWithFewerElements,
3068 NotCopyConstructibleIfDataTypeNotCopyConstructible,
3069 CanMoveViaTryConstruct,
3070 CanMoveViaConstruct,
3071 FailToMoveViaTryConstructFromLargerWithMoreElements,
3072 NotMoveConstructibleIfDataTypeNotMoveConstructible,
3073 CanTryConstructFromIteratorRange,
3074 IteratorRangeTryConstructionIsConditionallyNoexcept,
3075 InputIteratorRangeTryConstructionIsConditionallyNoexcept
3076);
3077
3080 PushBackBeyondMaxSizeIsPreconditionViolation,
3081 PushBackOnZeroSizeVectorIsPreconditionViolation,
3082 InsertWhenAtCapacityIsPreconditionViolation,
3083 ConstructingWithOutOfRangeSizeIsPreconditionViolation,
3084 ConstructingWithOutOfRangeSizeAndSourceIsPreconditionViolation,
3085 ConstructingWithTooManyInitializersIsPreconditionViolation,
3086 AssignIsPreconditionViolationIfSizeOverCapacity,
3087 IndexOperatorOutOfRange,
3088 EmplaceBackIsPreconditionViolationIfFull,
3089 InsertNIsPreconditionViolationIfTooManyItems,
3090 ConstructWithExcessiveSizeViaNormalConstructIsAlwaysPreconditionViolation,
3091 DereferencingInvalidIteratorIsPreconditionViolation,
3092 AddingToInvalidIteratorIsPreconditionViolation
3093);
3094
3095} // namespace testing
3096} // namespace base
3097} // namespace arene
3098
3099#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_VECTOR_HPP_
A fixed-size array of T objects.
Definition array.hpp:77
A container similar to std::vector<T> that has a fixed capacity. The storage for the elements is held...
Definition vector.hpp:1430
Implementation of std::optional for pre-C++17 compilers, and which replaces defined undefined behavio...
Definition optional.hpp:122
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
ARENE_NODISCARD constexpr auto value() &noexcept -> value_type &
Accesses a reference to the content of the value channel.
Definition result.hpp:319
A backport of the constexpr std::reverse_iterator from C++17.
Definition reverse_iterator.hpp:188
The Death Tests use the same fixture as the "normal" tests. Inherits so that it will be a distinct ty...
Definition vector.hpp:350
Test fixture for all type-parameterized inline_vector tests.
Definition vector.hpp:160
typename Vector::value_type T
Definition vector.hpp:162
static constexpr auto test_vector(std::size_t begin, std::size_t end) noexcept(noexcept(::arene::base::testing::test_vector< T, capacity >(begin, end))) -> Vector
Return a Vector containing the test values [begin,end) of T , parameterized by test suite users.
Definition vector.hpp:305
static constexpr bool constexpr_compatible
Whether or not the current type parameter is constexpr compatible for this test.
Definition vector.hpp:165
static constexpr std::size_t capacity
The base capacity to use for most inline_vector instantiations in the parameterized tests.
Definition vector.hpp:173
static constexpr auto full_test_initializer_list() noexcept -> std::initializer_list< T >
Return a std::initializer_list containing capacity user-parameterized test_value s.
Definition vector.hpp:342
static void SetUpTestSuite()
Definition vector.hpp:177
static constexpr auto test_initializer_list(std::index_sequence< Indices... >) noexcept -> std::initializer_list< T >
Return a std::initializer_list containing user-parameterized test_value s.
Definition vector.hpp:328
inline_vector< ValueType, capacity > standard_capacity_vector
An inline_vector with capacity using any given type; useful in tests making vectors of wrapper types.
Definition vector.hpp:182
input_iterator_with_configurable_noexcept< U, true > non_throwing_input_iterator
An input iterator pointing to any type which declares that it can not throw, used in some noexcept te...
Definition vector.hpp:268
typedef try_construct_result
A helper template to get the type resulting from a try_construct call.
Definition vector.hpp:192
input_iterator_with_configurable_noexcept< U, false > throwing_input_iterator
An input iterator pointing to any type which declares that it could throw, used in some noexcept test...
Definition vector.hpp:264
static constexpr auto unique_test_value() noexcept
Return the N 'th test value of the current T , parameterized by test suite users.
static constexpr auto full_test_vector() noexcept(noexcept(test_vector(capacity))) -> Vector
Return a Vector containing the test values [0,capacity) of T , parameterized by test suite users.
Definition vector.hpp:320
static constexpr auto test_initializer_list() noexcept -> std::initializer_list< T >
Return a std::initializer_list containing user-parameterized test_value s.
Definition vector.hpp:336
static constexpr auto test_value(std::size_t idx) noexcept(noexcept(::arene::base::testing::test_value< T >(idx))) ->
Return the idx 'th test value of the current T , parameterized by test suite users.
Definition vector.hpp:281
static constexpr auto test_vector(std::size_t size) noexcept(noexcept(test_vector(0, size))) -> Vector
Return a Vector containing the test values [0,size) of T , parameterized by test suite users.
Definition vector.hpp:314
static constexpr auto construct(U &&... params) noexcept(noexcept(Vector(std::forward< U >(params)...))) -> Vector
Construct a Vector from the passed parameters; allows calling as this->construct, which can be shorte...
Definition vector.hpp:274
inline_vector< T, OtherCapacity > vector_with_capacity
An inline_vector with value_type=T using any given capacity; useful in tests doing assignment.
Definition vector.hpp:186
Definition vector.hpp:1865
auto operator=(move_only_wrapper &&) -> move_only_wrapper &=default
move_only_wrapper(value_type value)
Definition vector.hpp:1870
move_only_wrapper(move_only_wrapper &&)=default
auto get() -> value_type &
Definition vector.hpp:1878
move_only_wrapper(move_only_wrapper const &)=delete
auto operator=(move_only_wrapper const &) -> move_only_wrapper &=delete
An empty tag type corresponding to a bidirectional iterator.
Definition iterator_tags.hpp:25
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
An empty tag type corresponding to an input iterator.
Definition iterator_tags.hpp:16
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if an instance of To is assignable to from arguments of From.
Definition is_assignable.hpp:47
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 an instance of T is copy assignable.
Definition is_copy_assignable.hpp:59
Type trait to detect if an instance of T is copy constructible.
Definition is_copy_constructible.hpp:60
Type trait to detect if an instance of T is default constructible.
Definition is_default_constructible.hpp:26
Type trait to detect if an instance of T is move assignable.
Definition is_move_assignable.hpp:60
Type trait to detect if an instance of T is move constructible.
Definition is_move_constructible.hpp:59
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
Definition is_assignable.hpp:78
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
Type trait to detect if an instance of T is copy assignable without throwing.
Definition is_copy_assignable.hpp:69
Type trait to detect if an instance of T is copy constructible without throwing.
Definition is_copy_constructible.hpp:71
Type trait to detect if an instance of T is default constructible without throwing.
Definition is_default_constructible.hpp:36
Type trait to detect if an instance of T is move assignable without throwing.
Definition is_move_assignable.hpp:70
Type trait to detect if an instance of T is move constructible without throwing.
Definition is_move_constructible.hpp:70
Trait to detect if the two template parameters are the same or not. The value member is true if the t...
Definition is_same.hpp:35
provides a uniform interface to the properties of an iterator
Definition iterator_traits.hpp:90
An iterator adaptor that wraps another iterator such that dereferencing the wrapped iterator yields a...
Definition move_iterator.hpp:35
static constexpr auto max() noexcept -> T
The maximum finite value.
Definition numeric_limits.hpp:230
wraps a reference in a copyable and assignable object
Definition reference_wrapper.hpp:178
#define COND_STATIC_ASSERT_NE(left_arg, right_arg)
Call Google Test ASSERT_NE at runtime, and also statically if TypeParam is compatible.
Definition conditional_assertions.hpp:74
#define COND_STATIC_ASSERT_EQ(left_arg, right_arg)
Call Google Test ASSERT_EQ at runtime, and also statically if TypeParam is compatible.
Definition conditional_assertions.hpp:68
#define COND_STATIC_ASSERT_TRUE(...)
Call Google Test ASSERT_TRUE at runtime, and also statically if TypeParam is compatible.
Definition conditional_assertions.hpp:46
#define COND_STATIC_ASSERT_FALSE(...)
Call Google Test ASSERT_FALSE at runtime, and also statically if TypeParam is compatible.
Definition conditional_assertions.hpp:51
Provides macros used to disable and enable compiler specific diagnostics using the _Pragma operator.
#define ARENE_IGNORE_END()
Ends a region of a suppressed diagnostic.
Definition diagnostics.hpp:136
#define ARENE_IGNORE_START()
Begins a region of a suppressed diagnostic.
Definition diagnostics.hpp:131
#define ARENE_IGNORE_GCC(s, comment)
Pushes an ignore for a diagnostic into the compiler for gcc only (which includes qcc).
Definition diagnostics.hpp:113
#define ARENE_IGNORE_ALL(s, comment)
Pushes an ignore for a diagnostic into the compiler for any compiler.
Definition diagnostics.hpp:122
Provides implementation of a backport of C++20's version of std::equal.
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
Definition customization.hpp:31
constexpr auto sort_helper(Container container) noexcept -> Container
sorts the container and then returns it
Definition vector.hpp:131
constexpr auto constexpr_resize(Vec vec, std::size_t size) -> Vec
Definition external_vector.hpp:1068
constexpr auto constexpr_emplace_back(Args &&... args) -> Container
Definition vector.hpp:1915
constexpr auto vector_push_back(Vector &vec, Values &&... values) -> void
Push back multiple values into a vector.
Definition vector.hpp:118
constexpr bool has_constexpr_test_value
Check whether or not a given type's test_value function works in constexpr contexts.
Definition customization.hpp:116
constexpr auto constexpr_iterate(Args &&... args) -> bool
Definition external_vector.hpp:663
constexpr auto elements_are_array(Range1 const &range, Range2 const &values) -> bool
Check if all element of range are equal to the elements in values.
Definition vector.hpp:92
constexpr auto all_elements_are(Range const &range, T const &value) -> bool
Check if all element of range are equal to value.
Definition vector.hpp:79
constexpr auto assert_default_constructible_properties() -> void
Assert default constructible types have the expected properties.
Definition default_constructible_properties.hpp:139
constexpr auto constexpr_non_const_front(Vec &&vec) -> typename Vec::value_type
Definition vector.hpp:693
constexpr auto constexpr_pop_back(Vec &&vec) -> Vec
Definition vector.hpp:1122
constexpr customization_detail::init_list_holder< T, has_constexpr_test_value< T >, Indices... > test_initializer_list
A function object returning a std::initializer_list of one test_value per index in the given pack.
constexpr auto constexpr_insert(Vec &&vec, std::ptrdiff_t offset, T &&value) -> Vec
Definition vector.hpp:1374
constexpr auto constexpr_non_const_back(Vec &&vec) -> typename Vec::value_type
Definition vector.hpp:663
constexpr auto test_value(std::size_t idx) noexcept(noexcept(customization_detail::test_value_generator< T >::test_value(idx))) -> T
Get the idx 'th test value of type T.
Definition customization.hpp:108
constexpr auto constexpr_erase(std::size_t index, Args &&... args) -> Vec
Definition vector.hpp:854
constexpr auto test_vector(std::size_t begin, std::size_t end) noexcept(std::is_nothrow_copy_constructible< T >::value) -> ::arene::base::inline_vector< T, Capacity >
Create a test vector containing a range of test values.
Definition vector.hpp:103
TYPED_TEST_SUITE_P(ExternalVectorTest)
TYPED_TEST_P(ExternalVectorTest, CanConstructAnEmptyVector)
Definition external_vector.hpp:236
constexpr auto constexpr_emplace(Vec &&vec, std::ptrdiff_t pos, Arg &&arg) -> Vec
Definition vector.hpp:2050
constexpr auto erase_front(Vec &&vec, std::size_t count)
Definition vector.hpp:1806
REGISTER_TYPED_TEST_SUITE_P(ExternalVectorTest, ADLSwapSwapsContentsForBasicTypes, AfterClearVectorIsEmpty, AfterPushBackCanGetLastElement, AfterPushBackVectorIsNotEmpty, AssignFromInitListUsingAssignFunctionIsConditionallyNoexcept, AssignFromSizeAndValueIsConditionallyNoexcept, AtIndexSizeOrLargerThrows, AtIndexSizeOrLargerThrowsWithConstVec, AtOnConstVectorReturnsConstReference, AtReturnsReference, BackIsNoexcept, BackReturnsReference, CanAccessMultipleValuesWithAt, CanAccessMultipleValuesWithAtWithConstVec, CanAccessMultipleValuesWithIndexOperator, CanAssignFromBiggerCapacityVector, CanAssignFromInitListUsingAssignFunction, CanAssignFromInputIteratorRange, CanAssignFromIteratorRange, CanAssignFromSizeAndValue, CanCompareForOrdering, CanConstructAnEmptyVector, CanConstructFromInitializerList, CanConstructFromIteratorRange, CanConstructWithSize, CanConstructWithSizeAndValue, CanConstructWithSizeViaTryConstruct, CanCopyViaConstruct, CanCopyViaConstructFromLargerWithFewerElements, CanCopyViaConstructFromSmaller, CanCopyViaTryConstruct, CanCopyViaTryConstructFromLargerWithFewerElements, CanCopyViaTryConstructFromSmaller, CanDefaultConstructViaTryConstruct, CanEmplaceBack, CanEraseAtBeginning, CanEraseInMiddle, CanEraseRange, CanGetCBeginAndEnd, CanGetFront, CanGetIterator, CanInsertAtEndOfExistingVector, CanInsertInEmptyVector, CanInsertInMiddleOfExistingVector, CanIterateOverConstValues, CanIterateOverValues, CanMoveViaConstruct, CanMoveViaTryConstruct, CanPopBack, CanPushBackAValue, CanTryConstructFromInitializerList, CanTryConstructFromIteratorRange, CannotConstructWithSizeForANonDefaultConstructibleType, CannotTryConstructWithSizeForANonDefaultConstructibleType, CapacityIsAsSpecified, CapacityIsNoexcept, ConstBackReturnsConstReference, ConstructWithExcessiveSizeViaTryConstructFails, ConstructWithSizeViaNormalConstructWithDefaultConstructorNotNoexceptIsNotNoexcept, ConstructWithSizeViaTryConstructNotNoexceptIfDefaultConstructorNotNoexcept, CopyAssignOverLargerVectorDestroysExcess, CopyAssignOverLargerVectorFromInitListDestroysExcess, CopyAssignOverSmallerVectorCopiesElements, CopyAssignOverSmallerVectorFromInitListCopiesElements, CopyAssignmentIsConditionallyNoexcept, CopyingVectorCopiesElements, Data, DefaultEmplaceIsConditionallyNoexcept, DefaultTryConstructNoexceptEvenIfDefaultConstructorNotNoexcept, EmplaceAtPositionIsConditionallyNoexcept, EmplaceBackIsConditionallyNoexcept, EmplaceInsert, EmptyIfJustStorage, EmptyIsNoexcept, EmptybyDefault, EraseIsNoexceptIfTypeHasNoexceptMove, FailToCopyViaTryConstructFromLargerWithMoreElements, FailToMoveViaTryConstructFromLargerWithMoreElements, IndexOperatorIsNoexcept, IndexOperatorOnConstVectorIsNoexcept, IndexOperatorOnConstVectorReturnsConstReference, IndexOperatorReturnsReference, InitialSizeIsZero, InputIteratorRangeAssignmentIsConditionallyNoexcept, InputIteratorRangeConstructionIsConditionallyNoexcept, InputIteratorRangeTryConstructionIsConditionallyNoexcept, InsertFromIteratorRangeInMiddle, InsertFromIteratorRangeIsConditionallyNoexcept, InsertIsConditionallyNoexcept, InsertNAtEndInsertsElements, InsertNInMiddleInsertsElements, InsertWithCountIsConditionallyNoexcept, IteratorRangeAssignmentIsConditionallyNoexcept, IteratorRangeConstructionIsConditionallyNoexcept, IteratorRangeTryConstructionIsConditionallyNoexcept, IteratorTypedefs, MaxSizeEqualsCapacity, MoveAssignOverLargerVectorDestroysExcess, MoveAssignOverSmallerVectorMovesElements, MoveAssignmentIsConditionallyNoexcept, MovingVectorMovesElements, MovingVectorWithNewStorageMovesElements, NoStorageDataIsNull, NotConstructibleWithSizeAndSourceIfDataNotCopyable, NotCopyConstructible, NotCopyConstructibleIfDataTypeNotCopyConstructible, NotMoveConstructibleIfDataTypeNotMoveConstructible, PopBackIsNoexcept, PushBackIsConditionallyNoexcept, ResizeIsConditionallyNoexcept, ResizeWithValueIsConditionallyNoexcept, ResizingFromLargeToSmallLeavesElements, ResizingFromSmallToLargeConstructsElementsAsCopiesOfSpecified, RetrievingAValueWithAtReturnsValueAfterPushBack, RetrievingAValueWithAtThrowsOnEmpty, ReverseIteration, SecondPushBackChangesLastValue, SizeIsCorrect, SizeIsNoexcept, StorageOnlyTryConstructNoexceptEvenIfDefaultConstructorNotNoexcept, SwapNoexceptMatchesElementType, TryConstructFromTooLargeInitializerListReturnsEmpty, Typedefs, ZeroSizeVectorIsEmpty)
MATCHER_P(elements_match_function, function, "")
Definition external_vector.hpp:936
constexpr auto is_copyable_v
True if a type is copy constructible and copy assignable, false otherwise.
Definition vector.hpp:151
constexpr auto constexpr_clear(Vec vec) -> Vec
Definition vector.hpp:1762
constexpr bool is_fully_comparable_v
Definition external_vector.hpp:1634
constexpr auto constexpr_swap(Vec lhs, Vec rhs) -> std::pair< Vec, Vec >
Definition vector.hpp:2141
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr std::integral_constant< std::size_t, N > array< T, N >::size
Definition array.hpp:534
constexpr std::integral_constant< bool, false > array< T, N >::empty
Definition array.hpp:540
constexpr std::integral_constant< std::size_t, N > array< T, N >::max_size
Definition array.hpp:537
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
constexpr bool is_greater_than_or_equal_comparable_v
constexpr void consume_values(std::initializer_list< consume_values_detail::anything > const &) noexcept
Consume a list of values and discard them. Must be called with an extra pair of braces around the exp...
Definition consume_values.hpp:73
constexpr bool substitution_succeeds
Determines if a template can be instantiated successfully, similar to C++20's requires clause.
constexpr auto copy(InputIterator first, InputIterator last, OutputIterator output) noexcept(noexcept(*(++output)) &&noexcept(*(++first)) &&noexcept(first !=last) &&std::is_nothrow_assignable<, typename std::iterator_traits< InputIterator >::reference >::value) -> OutputIterator
Copies the elements in the range, defined by [first, last), to another range beginning at output.
Definition copy.hpp:40
constexpr bool is_less_than_comparable_v
constexpr bool is_less_than_or_equal_comparable_v
constexpr bool is_greater_than_comparable_v
Definition accumulate.hpp:36
STL namespace.
typedef nullptr_t
The type of nullptr.
Definition cstddef.hpp:33
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
make_integer_sequence< size_t, Size > make_index_sequence
A helper alias template for make_integer_sequence<size_t, Size>
Definition integer_sequence.hpp:224
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
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 addressof(T &value) noexcept -> T *
Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
Definition addressof.hpp:24
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
Provides a backport of the constexpr implementation of std::reverse_iterator .
An input iterator pointing to any type whose operators have adjustable noexcept specifications.
Definition vector.hpp:236
auto operator*() const noexcept(OperatorsNoexcept) -> reference
Dereference operator; never defined.
U value_type
The value type pointed to by this iterator.
Definition vector.hpp:244
std::ptrdiff_t difference_type
The type used for differences in this iterator.
Definition vector.hpp:240
U & reference
The type returned by dereferencing this iterator.
Definition vector.hpp:242
void pointer
This iterator as a pointer (disabled)
Definition vector.hpp:246
std::input_iterator_tag iterator_category
The category of this iterator.
Definition vector.hpp:238
A bidirectional iterator of T which declares that it could throw, used in some noexcept tests.
Definition vector.hpp:203
T value_type
The value type pointed to by this iterator.
Definition vector.hpp:211
std::ptrdiff_t difference_type
The type used for differences in this iterator.
Definition vector.hpp:207
auto operator*() const -> reference
Dereference operator; never defined.
void pointer
This iterator as a pointer (disabled)
Definition vector.hpp:213
T && reference
The type returned by dereferencing this iterator.
Definition vector.hpp:209
std::bidirectional_iterator_tag iterator_category
The category of this iterator.
Definition vector.hpp:205
A type with a noexcept(false) conversion operator to T (doesn't actually throw, just declares it)
Definition vector.hpp:195
Definition vector.hpp:62
constexpr auto operator()(T const &arg) -> bool
Definition vector.hpp:65
T const & value
Definition vector.hpp:67
constexpr equal_to_value(T const &input)
Definition vector.hpp:63
Definition external_vector.hpp:1707
throws_without_nullptr(T const &)
Definition vector.hpp:1954
throws_without_nullptr(T const &, std::nullptr_t) noexcept
Definition vector.hpp:1955
#define CONDITIONAL_TYPED_TEST_P(SuiteName, TestName,...)
Adds a type-parameterized test to a Google Test suite which is conditionally run based on the third p...
Definition conditional_tests.hpp:33