Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
deque.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_DEQUE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_DEQUE_HPP_
7
8#include <gtest/gtest.h>
9
18#include "arene/base/stdlib_choice/addressof.hpp"
19#include "arene/base/stdlib_choice/conditional.hpp"
20#include "arene/base/stdlib_choice/cstddef.hpp"
21#include "arene/base/stdlib_choice/declval.hpp"
22#include "arene/base/stdlib_choice/forward.hpp"
23#include "arene/base/stdlib_choice/ignore.hpp"
24#include "arene/base/stdlib_choice/initializer_list.hpp"
25#include "arene/base/stdlib_choice/integer_sequence.hpp"
26#include "arene/base/stdlib_choice/is_assignable.hpp"
27#include "arene/base/stdlib_choice/is_constructible.hpp"
28#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
29#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
30#include "arene/base/stdlib_choice/is_default_constructible.hpp"
31#include "arene/base/stdlib_choice/is_move_assignable.hpp"
32#include "arene/base/stdlib_choice/is_move_constructible.hpp"
33#include "arene/base/stdlib_choice/is_trivially_copyable.hpp"
34#include "arene/base/stdlib_choice/iterator_tags.hpp"
35#include "arene/base/stdlib_choice/move.hpp"
36#include "arene/base/stdlib_choice/numeric_limits.hpp"
43#include "testlibs/utilities/iterator_types.hpp"
44
45namespace arene {
46namespace base {
47namespace testing {
48
50ARENE_IGNORE_ALL("-Wfloat-equal", "These tests don't perform arithmetic, so equality is OK even for floating point");
51
52/// @brief Create a test deque containing a range of test values
53/// @tparam T The deque type to create an instance of
54/// @param begin The first index of test value to put in the deque
55/// @param end The after-end index of test value to put in the deque
56/// @return An inline_deque<T, Capacity> containing [test_value(begin), test_value(end))
57template <typename T>
58constexpr auto test_deque(std::size_t begin, std::size_t end) noexcept(
60) -> T {
61 T deque;
62 for (std::size_t i = begin; i < end; i++) {
63 deque.push_back(test_value<typename T::value_type>(i));
64 }
65 return deque;
66}
67
68/// @brief A type trait to check if a type is list-initializable using a brace-enclosed list of values with a given type
69/// @tparam T Type to check
70/// @tparam ElementType Type to use for the elements of the brace-enclosed initializer list
71/// @{
72template <typename T, typename ElementType, typename = constraints<>>
73constexpr bool is_list_initializable_v{false};
74
75template <typename T, typename ElementType>
76constexpr bool is_list_initializable_v<
77 T,
78 ElementType,
80
81/////////////////////////
82// Parameterized tests //
83/////////////////////////
84
85/// @brief Test fixture for all type-parameterized @c inline_deque tests
86/// @tparam Deque The type parameter currently being used for tests; filled in by Google Test as @c TypeParam
87template <typename Deque>
88class InlineDequeTest : public ::testing::Test {
89 using T = typename Deque::value_type;
90
91 public:
92 /// @brief Whether the type parameter is constexpr compatible for this test
93 static constexpr bool constexpr_compatible =
95 static_assert(
96 !constexpr_compatible || has_constexpr_test_value<T>,
97 "Constexpr-compatible types must have constexpr specializations of test_value_array or test_value"
98 );
99
100 protected:
101 /// @brief Return the @c idx 'th test value of the current @c T , parameterized by test suite users
102 /// @param idx The index of the test value to get
103 /// @return The @c idx 'th test value of the current @c T
104 static constexpr auto test_value(std::size_t idx) noexcept(noexcept(::arene::base::testing::test_value<T>(idx)))
105 -> decltype(::arene::base::testing::test_value<T>(idx)) {
106 return ::arene::base::testing::test_value<T>(idx);
107 }
108
109 /// @brief Return an empty @c Deque, allowing to call as this->construct,
110 /// which becomes useful with the ...STATIC_ASSERT... macros
111 static constexpr auto construct() noexcept(noexcept(Deque())) -> Deque { return Deque(); }
112
113 /// @brief Return a @c Deque containing the test values @c [begin,end) of @c T
114 /// @param begin The index of the first test value to put into the test deque
115 /// @param end The index after that of the last test value to put into the test deque
116 /// @return A test deque holding the test values determined by the indices
117 static constexpr auto test_deque(std::size_t begin, std::size_t end) noexcept(
119 ) -> Deque {
120 return ::arene::base::testing::test_deque<Deque>(begin, end);
121 }
122
123 /// @brief Return a @c Deque containing the test values @c [0,size) of @c T
124 /// @param size The number of test values to put into the test deque
125 /// @return A test deque holding the test values determined by the size
126 static constexpr auto test_deque(std::size_t size) noexcept(noexcept(test_deque(0, size))) -> Deque {
127 return test_deque(0, size);
128 }
129
130 /// @brief Return a @c Deque containing the test values @c [0,capacity/2) of @c T
131 /// @return A test deque holding the test values determined by the capacity
132 static constexpr auto half_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque {
133 return test_deque(Deque::capacity / 2U);
134 }
135
136 /// @brief Return a @c Deque containing the test values @c [0,capacity) of @c T
137 /// @return A test deque holding the test values determined by the capacity
138 static constexpr auto full_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque {
139 return test_deque(Deque::capacity);
140 }
141
142 /// @brief Return a @c Deque containing the test values <c>[capacity/2, 3*capacity/2)</c> of @c T
143 /// @return A test deque holding the test values, wrapped around so they start in the middle
144 /// @note This is useful for testing that functions aren't accidentally assuming the data starts at buffer index 0
145 static constexpr auto wrapped_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque {
146 Deque deque = test_deque(Deque::capacity);
147 for (std::size_t i{}; i < Deque::capacity / 2U; ++i) {
148 deque.pop_front();
149 deque.push_back(::arene::base::testing::test_value<T>(Deque::capacity + i));
150 }
151 return deque;
152 }
153
154 /// @brief Return a @c std::initializer_list containing user-parameterized <c>test_value</c>s
155 /// @tparam Indices A pack of indices, one for each test value in the initializer list
156 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing one test value per index
157 template <std::size_t... Indices>
159 return ::arene::base::testing::test_initializer_list<T, Indices...>();
160 }
161
162 /// @brief Return a @c std::initializer_list containing user-parameterized <c>test_value</c>s
163 /// @tparam Size The number of values in the @c std::initializer_list
164 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing one test value per index
165 template <std::size_t Size>
166 static constexpr auto test_initializer_list() noexcept -> std::initializer_list<T> {
168 }
169
170 /// @brief Return a @c std::initializer_list containing @c Deque::capacity user-parameterized <c>test_value</c>s
171 /// @return A copy of a statically-allocated @c std::initializer_list<T> containing @c Deque::capacity entries
172 static constexpr auto full_test_initializer_list() noexcept -> std::initializer_list<T> {
174 }
175};
176
177/// @brief The death tests use the same fixture as the non-death tests, but as a distinct type to improve log output
178/// @tparam Deque The @c inline_deque type to test
179template <typename Deque>
180class InlineDequeDeathTest : public InlineDequeTest<Deque> {};
181
182/// @brief Type trait to see if a particular @c TypeParam is double-ended or not; used to exclude some tests
183/// @tparam TypeParam The queue/deque type to check
184/// @note This implementation works kind of by coincidence, because currently the only queue with wrapping allowed
185/// happens to be single-ended. There's no inherent relationship between wrapping being allowed and being double-ended.
186template <typename TypeParam>
187constexpr bool is_double_ended = !TypeParam::wrapping_allowed;
188
189// Declare the test suite(s) where test cases will be added.
192
193/// @test A default-constructed `inline_deque` has size equal to zero
195 TypeParam const deque;
196 EXPECT_EQ(deque.size(), 0);
197
198 auto maybe_deque = TypeParam::try_construct();
199 ASSERT_TRUE(maybe_deque.has_value());
200 EXPECT_EQ(maybe_deque->size(), 0);
201}
202
203/// @test The capacity of a default-constructed `inline_deque` is equal to the supplied template parameter
204TYPED_TEST_P(InlineDequeTest, CapacityIsAsSpecified) {
205 COND_STATIC_ASSERT_EQ(TestFixture::construct().capacity(), TypeParam::capacity);
206}
207
208/// @test The `capacity` member function of `inline_deque` is declared `noexcept`
209TYPED_TEST_P(InlineDequeTest, CapacityIsNoexcept) { STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().capacity())); }
210
211/// @test The `size` member function of `inline_deque` is declared `noexcept`
212TYPED_TEST_P(InlineDequeTest, SizeIsNoexcept) { STATIC_ASSERT_TRUE(noexcept(TestFixture::construct().size())); }
213
214/// @test Given a default-constructed `inline_deque` with plenty of capacity,
215/// an element can be inserted via `push_front`, which causes a size increase
217 TypeParam deque;
218 deque.push_front(TestFixture::test_value(0));
219 EXPECT_EQ(deque.size(), 1);
220}
221
222/// @test Given a default-constructed `inline_deque` with plenty of capacity,
223/// an element can be inserted via `push_back`, which causes a size increase
224TYPED_TEST_P(InlineDequeTest, PushBackOneElement) {
225 TypeParam deque;
226 deque.push_back(TestFixture::test_value(0));
227 EXPECT_EQ(deque.size(), 1);
228}
229
230/// @test Emplacing an element into the front of an `inline_deque` returns a reference to the emplaced element
232 TypeParam deque;
233 auto& front_ref = deque.emplace_front(TestFixture::test_value(0));
234 EXPECT_EQ(std::addressof(front_ref), std::addressof(deque.front()));
235}
236
237/// @test Emplacing an element into the back of an `inline_deque` returns a reference to the emplaced element
238TYPED_TEST_P(InlineDequeTest, EmplaceBackReturnsReference) {
239 TypeParam deque;
240 auto& back_ref = deque.emplace_back(TestFixture::test_value(0));
241 EXPECT_EQ(std::addressof(back_ref), std::addressof(deque.back()));
242}
243
244/// @test Given a default-constructed `inline_deque` with plenty of capacity,
245/// an element can be inserted via `push_front` and then inspected
247 TypeParam deque;
248 deque.push_front(TestFixture::test_value(0));
249 ASSERT_EQ(deque.size(), 1);
250 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
251 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
252
253 TypeParam const& as_const(deque);
254 EXPECT_EQ(as_const.front(), TestFixture::test_value(0));
255 EXPECT_EQ(as_const.back(), TestFixture::test_value(0));
256}
257
258/// @test Given a default-constructed `inline_deque` with plenty of capacity,
259/// an element can be inserted via `push_back` and then inspected
260TYPED_TEST_P(InlineDequeTest, BackPushedElementIsCorrect) {
261 TypeParam deque;
262 deque.push_back(TestFixture::test_value(0));
263 ASSERT_EQ(deque.size(), 1);
264 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
265 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
266
267 TypeParam const& as_const(deque);
268 EXPECT_EQ(as_const.back(), TestFixture::test_value(0));
269 EXPECT_EQ(as_const.front(), TestFixture::test_value(0));
270}
271
272/// @test Given a default-constructed `inline_deque`, elements can be inserted
273/// via `push_front` within its capacity, making the size be equal to capacity
275 TypeParam deque;
276 for (typename TypeParam::size_type i = 0; i < TypeParam::capacity(); i++) {
277 deque.push_front(TestFixture::test_value(i));
278 }
279 EXPECT_EQ(deque.size(), TypeParam::capacity());
280}
281
282/// @test Given a default-constructed `inline_deque`, elements can be inserted
283/// via `push_back` within its capacity, making the size be equal to capacity
284TYPED_TEST_P(InlineDequeTest, PushBackWithinCapacity) {
285 TypeParam deque;
286 for (typename TypeParam::size_type i = 0; i < TypeParam::capacity(); i++) {
287 deque.push_back(TestFixture::test_value(i));
288 }
289 EXPECT_EQ(deque.size(), TypeParam::capacity());
290}
291
292/// @test Inserting any element beyond an `inline_deque`'s capacity terminates
293/// the application with a precondition violation or wraps, depending on its parameters
295 TypeParam deque;
296 for (typename TypeParam::size_type i = 0; i < TypeParam::capacity(); i++) {
297 deque.push_front(TestFixture::test_value(i));
298 }
299
300 ASSERT_DEATH(deque.push_front(TestFixture::test_value(TypeParam::capacity())), "Precondition violation");
301}
302
303/// @test For deques with a single-ended public interface, the unexposed functions in the other direction still work.
304/// This test is needed for coverage purposes.
306 using deque_impl = arene::base::inline_deque_detail::inline_deque_impl< //
307 typename TypeParam::value_type, //
308 TypeParam::capacity(), //
309 TypeParam::wrapping_allowed //
310 >;
311
312 deque_impl deque;
313 for (typename TypeParam::size_type i = 0; i < TypeParam::capacity(); i++) {
314 deque.push_front(TestFixture::test_value(i));
315 }
316
317 if (deque.wrapping_allowed()) {
318 EXPECT_EQ(deque.front(), TestFixture::test_value(TypeParam::capacity() - 1U));
319 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
320 deque.push_front(TestFixture::test_value(TypeParam::capacity()));
321 EXPECT_EQ(deque.front(), TestFixture::test_value(TypeParam::capacity()));
322 EXPECT_EQ(deque.back(), TestFixture::test_value(1));
323 } else {
324 ASSERT_DEATH(deque.push_front(TestFixture::test_value(TypeParam::capacity())), "Precondition violation");
325 }
326}
327
328/// @test Inserting any element beyond an `inline_deque`'s capacity terminates
329/// the application with a precondition violation or wraps, depending on its parameters
330TYPED_TEST_P(InlineDequeDeathTest, PushBackMoreThanCapacity) {
331 TypeParam deque;
332 for (typename TypeParam::size_type i = 0; i < TypeParam::capacity(); i++) {
333 deque.push_back(TestFixture::test_value(i));
334 }
335
336 if (deque.wrapping_allowed()) {
337 EXPECT_EQ(deque.back(), TestFixture::test_value(TypeParam::capacity() - 1U));
338 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
339 deque.push_back(TestFixture::test_value(TypeParam::capacity()));
340 EXPECT_EQ(deque.back(), TestFixture::test_value(TypeParam::capacity()));
341 EXPECT_EQ(deque.front(), TestFixture::test_value(1));
342 } else {
343 ASSERT_DEATH(deque.push_back(TestFixture::test_value(TypeParam::capacity())), "Precondition violation");
344 }
345}
346
347/// @test The constraints and exception specifications for the `insert` functions are correct
348CONDITIONAL_TYPED_TEST_P(InlineDequeTest, InsertConstraints, !TypeParam::wrapping_allowed) {
349 using value_type = typename TypeParam::value_type;
350
351 auto inserter = [](auto& deque,
352 auto&& value) noexcept(noexcept(deque.insert(deque.begin(), std::forward<decltype(value)>(value)))
353 ) -> decltype(deque.insert(deque.begin(), std::forward<decltype(value)>(value))) { return {}; };
354
356 constexpr bool copy_insert_ok = shift_ok && std::is_copy_assignable<value_type>::value;
357 constexpr bool move_insert_ok = shift_ok;
358
359 STATIC_ASSERT_EQ((arene::base::is_invocable_v<decltype(inserter), TypeParam&, value_type const&>), copy_insert_ok);
360 STATIC_ASSERT_EQ((arene::base::is_invocable_v<decltype(inserter), TypeParam&, value_type&&>), move_insert_ok);
361
362 constexpr bool shift_noexcept =
364 constexpr bool copy_insert_noexcept =
365 copy_insert_ok && shift_noexcept && std::is_nothrow_copy_constructible<value_type>::value;
366 constexpr bool move_insert_noexcept = move_insert_ok && shift_noexcept;
367
368 STATIC_ASSERT_EQ(
369 (arene::base::is_nothrow_invocable_v<decltype(inserter), TypeParam&, value_type const&>),
370 copy_insert_noexcept
371 );
372 STATIC_ASSERT_EQ(
373 (arene::base::is_nothrow_invocable_v<decltype(inserter), TypeParam&, value_type&&>),
374 move_insert_noexcept
375 );
376}
377
378/// @test The copy-based one-element version of `insert` inserts a copy of the value at the requested position
381 CopyInsertOne,
384) {
385 using index_type = typename TypeParam::iterator::difference_type;
386
387 TypeParam deque = TestFixture::half_test_deque();
388 for (typename TypeParam::size_type i = 0U; i < TypeParam::capacity() / 2U; ++i) {
389 // We need a new iterator every time because insert() invalidates all iterators. Each prior index has two entries.
390 auto const pos = next(deque.cbegin(), static_cast<index_type>(2U * i));
391
392 typename TypeParam::value_type const new_value = TestFixture::test_value((TypeParam::capacity() / 2U) + i);
393 auto new_iter = deque.insert(pos, new_value);
394
395 // The new iterator should have the same distance from `begin()` as `pos`, even though `pos` is now invalid.
396 EXPECT_EQ(distance(deque.begin(), new_iter), static_cast<index_type>(2U * i));
397 }
398
399 for (typename TypeParam::size_type i = 0U; i < TypeParam::capacity() / 2U; ++i) {
400 EXPECT_EQ(deque[static_cast<index_type>(2U * i)], TestFixture::test_value(TypeParam::capacity() / 2U + i));
401 EXPECT_EQ(deque[static_cast<index_type>((2U * i) + 1U)], TestFixture::test_value(i));
402 }
403}
404
405/// @test The move-based one-element version of `insert` inserts the value at the requested position
408 MoveInsertOne,
411) {
412 using index_type = typename TypeParam::iterator::difference_type;
413
414 TypeParam deque = TestFixture::half_test_deque();
415 for (typename TypeParam::size_type i = 0U; i < TypeParam::capacity() / 2U; ++i) {
416 // We need a new iterator every time because insert() invalidates all iterators. Each prior index has two entries.
417 auto const pos = next(deque.cbegin(), static_cast<index_type>(2U * i));
418
419 deque.insert(pos, TestFixture::test_value((TypeParam::capacity() / 2U) + i));
420 }
421
422 for (typename TypeParam::size_type i = 0U; i < TypeParam::capacity() / 2U; ++i) {
423 EXPECT_EQ(deque[static_cast<index_type>(2U * i)], TestFixture::test_value(TypeParam::capacity() / 2U + i));
424 EXPECT_EQ(deque[static_cast<index_type>((2U * i) + 1U)], TestFixture::test_value(i));
425 }
426}
427
428/// @test The copy-based one-element version of `insert` can insert a value at the end
431 CopyInsertOneAtEnd,
434) {
435 typename TypeParam::value_type const value = TestFixture::test_value(TypeParam::capacity() / 2U);
436
437 TypeParam deque = TestFixture::half_test_deque();
438 typename TypeParam::size_type expected_size = deque.size();
439
440 if (deque.size() == deque.capacity()) {
441 deque.pop_front();
442 } else {
443 ++expected_size;
444 }
445 deque.insert(deque.cend(), value);
446 EXPECT_EQ(deque.size(), expected_size);
447 EXPECT_EQ(deque.back(), value);
448}
449
450/// @test The move-based one-element version of `insert` can insert a value at the end
453 MoveInsertOneAtEnd,
456) {
457 typename TypeParam::value_type const value = TestFixture::test_value(TypeParam::capacity() / 2U);
458 typename TypeParam::value_type value_again = TestFixture::test_value(TypeParam::capacity() / 2U);
459
460 TypeParam deque = TestFixture::half_test_deque();
461 typename TypeParam::size_type expected_size = deque.size();
462
463 if (deque.size() == deque.capacity()) {
464 deque.pop_front();
465 } else {
466 ++expected_size;
467 }
468 deque.insert(deque.cend(), std::move(value_again));
469 EXPECT_EQ(deque.size(), expected_size);
470 EXPECT_EQ(deque.back(), value);
471}
472
473/// @test Calling the one-element version of `insert` when a non-wrapping deque is full terminates the application
476 NonWrappingInsertOneWhenFull,
479) {
480 TypeParam deque = TestFixture::full_test_deque();
481
482 auto pos = next(deque.begin());
483 for (typename TypeParam::size_type i{0U}; i <= deque.capacity(); ++i) {
484 ASSERT_DEATH(deque.insert(pos, TestFixture::test_value(TypeParam::capacity() + i)), "Precondition violation");
485 ++pos;
486 }
487}
488
489/// @test `inline_deque` has circular or ring-buffer behavior, such that when
490/// previously inserted elements via `push_front` are removed via `pop_back`,
491/// then space in the fixed-capacity storage of the deque is made available
492/// for new elements to be inserted
494 TypeParam deque;
495 for (std::size_t i = 0; i < 2 * TypeParam::capacity(); i++) {
496 deque.push_front(TestFixture::test_value(i));
497 EXPECT_EQ(deque.back(), TestFixture::test_value(i));
498 deque.pop_back();
499 }
500}
501
502/// @test `inline_deque` has circular or ring-buffer behavior, such that when
503/// previously inserted elements via `push_back` are removed via `pop_front`,
504/// then space in the fixed-capacity storage of the deque is made available
505/// for new elements to be inserted
506TYPED_TEST_P(InlineDequeTest, GoCircularFromBack) {
507 TypeParam deque;
508 for (std::size_t i = 0; i < 2 * TypeParam::capacity(); i++) {
509 deque.push_back(TestFixture::test_value(i));
510 EXPECT_EQ(deque.front(), TestFixture::test_value(i));
511 deque.pop_front();
512 }
513}
514
515/// @test basic `inline_deque` functionality, inserting elements via
516/// `push_front` observing them with `back`, verifying that it doesn't remove
517/// elements, removing with `pop_back`, and checking the correct dequeing order
518/// (namely, FIFO) is preserved with the operations
521 BasicFunctionFromFront,
522 is_double_ended<TypeParam>&& TypeParam::capacity >= 2
523) {
524 TypeParam deque;
525 // Push an element and check it.
526 deque.push_front(TestFixture::test_value(0));
527 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
528 // Check that the element is still there after observing it.
529 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
530 // Push a second element.
531 deque.push_front(TestFixture::test_value(1));
532 EXPECT_EQ(deque.size(), 2);
533 // Check that the first pushed element is still "at the back".
534 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
535 deque.pop_back();
536 EXPECT_EQ(deque.back(), TestFixture::test_value(1));
537 EXPECT_EQ(deque.size(), 1);
538}
539
540/// @test basic `inline_deque` functionality, inserting elements via
541/// `push_back` observing them with `front`, verifying that it doesn't remove
542/// elements, removing with `pop_front`, and checking the correct dequeing order
543/// (namely, FIFO) is preserved with the operations
544CONDITIONAL_TYPED_TEST_P(InlineDequeTest, BasicFunctionFromBack, TypeParam::capacity >= 2) {
545 TypeParam deque;
546 // Push an element and check it.
547 deque.push_back(TestFixture::test_value(0));
548 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
549 // Check that the element is still there after observing it.
550 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
551 // Push a second element.
552 deque.push_back(TestFixture::test_value(1));
553 EXPECT_EQ(deque.size(), 2);
554 // Check that the first pushed element is still "at the back".
555 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
556 deque.pop_front();
557 EXPECT_EQ(deque.front(), TestFixture::test_value(1));
558 EXPECT_EQ(deque.size(), 1);
559}
560
561/// @test `inline_deque`'s `back` can also be used to modify the least-recently
562/// inserted element inplace
565 CanObserveAndModifyFromFront,
566 is_double_ended<TypeParam>&& TypeParam::capacity >= 2
567) {
568 TypeParam deque;
569 deque.push_front(TestFixture::test_value(0));
570 deque.push_front(TestFixture::test_value(1));
571 EXPECT_EQ(deque.back(), TestFixture::test_value(0));
572 deque.back() = TestFixture::test_value(2);
573 EXPECT_EQ(deque.back(), TestFixture::test_value(2));
574 EXPECT_EQ(deque.size(), 2);
575 deque.pop_back();
576 EXPECT_EQ(deque.back(), TestFixture::test_value(1));
577}
578
579/// @test `inline_deque`'s `front` can also be used to modify the least-recently
580/// inserted element inplace
581CONDITIONAL_TYPED_TEST_P(InlineDequeTest, CanObserveAndModifyFromBack, TypeParam::capacity >= 2) {
582 TypeParam deque;
583 deque.push_back(TestFixture::test_value(0));
584 deque.push_back(TestFixture::test_value(1));
585 EXPECT_EQ(deque.front(), TestFixture::test_value(0));
586 deque.front() = TestFixture::test_value(2);
587 EXPECT_EQ(deque.front(), TestFixture::test_value(2));
588 EXPECT_EQ(deque.size(), 2);
589 deque.pop_front();
590 EXPECT_EQ(deque.front(), TestFixture::test_value(1));
591}
592
593/// @test Pushing lvalue data onto the front of an `inline_deque` copies it
596 PushFrontCopiesLvalues,
598) {
599 auto deque = TestFixture::construct();
600 auto const value = TestFixture::test_value(0);
601 deque.push_front(value);
602 EXPECT_EQ(deque.front(), value);
603 EXPECT_NE(std::addressof(deque.front()), std::addressof(value));
604}
605
606/// @test Pushing lvalue data onto the back of an `inline_deque` copies it
608 auto deque = TestFixture::construct();
609 auto const value = TestFixture::test_value(0);
610 deque.push_back(value);
611 EXPECT_EQ(deque.back(), value);
612 EXPECT_NE(std::addressof(deque.back()), std::addressof(value));
613}
614
615/// @test when the `inline_deque` is empty, `back` terminates the application with a precondition violation
617 TypeParam deque;
618 ASSERT_DEATH(deque.back(), "Precondition violation");
619}
620
621/// @test when the `inline_deque` is empty, the `const` overload of `back` terminates the application with
622/// a precondition violation
623TYPED_TEST_P(InlineDequeDeathTest, ConstBackWhenEmpty) {
624 TypeParam const deque;
625 ASSERT_DEATH(deque.back(), "Precondition violation");
626}
627
628/// @test when the `inline_deque` is empty, `pop_front` terminates the application with a precondition violation
630 TypeParam deque;
631 ASSERT_DEATH(deque.pop_front(), "Precondition violation");
632}
633
634/// @test when the `inline_deque` is empty, `pop_back` terminates the application with a precondition violation
636 TypeParam deque;
637 ASSERT_DEATH(deque.pop_back(), "Precondition violation");
638}
639
640/// @test when the `inline_deque` is empty, `front` terminates the application with a precondition violation
642 TypeParam deque;
643 ASSERT_DEATH(deque.front(), "Precondition violation");
644}
645
646/// @test when the `inline_deque` is empty, the `const` overload of `front` terminates the application with
647/// a precondition violation
648TYPED_TEST_P(InlineDequeDeathTest, ConstFrontWhenEmpty) {
649 TypeParam const deque;
650 ASSERT_DEATH(deque.front(), "Precondition violation");
651}
652
653/// @test `inline_deque` is not copy-constructible if the data type is not copy-constructible
654TYPED_TEST_P(InlineDequeTest, NotCopyConstructibleIfDataTypeNotCopyConstructible) {
656 static_assert(
658 "inline_deque<T> should be copy-constructible if and only if T is"
659 );
660}
661
662/// @test `inline_deque` is not move-constructible if the data type is not move-constructible
663TYPED_TEST_P(InlineDequeTest, NotMoveConstructibleIfDataTypeNotMoveConstructible) {
665 static_assert(
667 "inline_deque<T> should be move-constructible if and only if T is"
668 );
669}
670
671/// @test `inline_deque` is not copy-assignable if the data type is not copy-constructible
672TYPED_TEST_P(InlineDequeTest, NotCopyAssignableIfDataTypeNotCopyConstructibleAndCopyAssignable) {
673 static_assert(
675 "inline_deque<T> should be copy-assignable if and only if T is copy-constructible and -assignable"
676 );
677}
678
679/// @test `inline_deque` is not move-assignable if the data type is not move-constructible
680TYPED_TEST_P(InlineDequeTest, NotMoveAssignableIfDataTypeNotMoveConstructibleAndMoveAssignable) {
681 static_assert(
683 "inline_deque<T> should be move-assignable if and only if T is move-constructible and -assignable"
684 );
685}
686
687/// @test `inline_deque` can be used at compile-time, asserting properties statically
689 constexpr auto deque = TestFixture::full_test_deque();
690 STATIC_ASSERT_EQ(deque.size(), deque.capacity());
691 STATIC_ASSERT_EQ(deque.front(), TestFixture::test_value(0));
692 STATIC_ASSERT_EQ(deque.back(), TestFixture::test_value(deque.size() - 1U));
693}
694
695/// @test `inline_deque` range construction is enabled or disabled appropriately based on the arguments
696TYPED_TEST_P(InlineDequeTest, RangeConstructionSfinae) {
697 using random_access_it = typename TypeParam::value_type const*;
698 using bidirectional_it = ::testing::demoted_iterator<random_access_it, std::bidirectional_iterator_tag>;
699 using forward_it = ::testing::demoted_iterator<random_access_it, std::forward_iterator_tag>;
700 using input_it = ::testing::demoted_iterator<random_access_it, std::input_iterator_tag>;
701
702 STATIC_ASSERT_EQ(
705 );
706 STATIC_ASSERT_EQ(
709 );
710 STATIC_ASSERT_EQ(
713 );
715}
716
717/// @test `inline_deque` range construction has the correct noexcept specification
718TYPED_TEST_P(InlineDequeTest, RangeConstructionNoexcept) {
719 using ::testing::throws_on;
720 using value_type = typename TypeParam::value_type;
721
722 using normal_it = ::testing::noexcept_configurable_random_access_iterator<throws_on::nothing, value_type>;
723 using rvalue_it = testing::rvalue_iterator<value_type>;
724 using throwing_it = ::testing::noexcept_configurable_random_access_iterator<throws_on::minus_self, value_type>;
725
726 STATIC_ASSERT_EQ(
729 );
730 STATIC_ASSERT_EQ(
733 );
735}
736
737/// @test `inline_deque` can be constructed from a range of `T` using iterators
739 auto const init_list = TestFixture::full_test_initializer_list();
740 TypeParam const deque(init_list.begin(), init_list.end());
741
742 ASSERT_EQ(deque.size(), init_list.size());
743 EXPECT_TRUE(::arene::base::equal(deque.begin(), deque.end(), init_list.begin()));
744
745 auto const try_deque = TypeParam::try_construct(init_list.begin(), init_list.end());
746 ASSERT_TRUE(try_deque.has_value());
747 EXPECT_TRUE(::arene::base::equal(try_deque->begin(), try_deque->end(), init_list.begin()));
748}
749
750/// @test `inline_deque` can be constructed from a range of `T` using iterators
751TYPED_TEST_P(InlineDequeTest, MoveConstructFromRange) {
752 TypeParam const deque(
755 );
756
757 // Make an initializer list here just to make it easier to compare the contents
758 auto const init_list = TestFixture::full_test_initializer_list();
759 ASSERT_EQ(deque.size(), init_list.size());
760 EXPECT_TRUE(::arene::base::equal(deque.begin(), deque.end(), init_list.begin()));
761
762 auto const try_deque = TypeParam::try_construct(
765 );
766 ASSERT_TRUE(try_deque.has_value());
767 EXPECT_TRUE(::arene::base::equal(try_deque->begin(), try_deque->end(), init_list.begin()));
768}
769
770/// @test `inline_deque` initializer list construction is enabled or disabled appropriately based on the value type
782
783/// @test `inline_deque` initializer list construction has the correct noexcept specification
790
791/// @test `inline_deque` can be constructed from an initializer list of `T`
793 auto const init_list = TestFixture::full_test_initializer_list();
794 TypeParam const deque(init_list);
795
796 ASSERT_EQ(deque.size(), init_list.size());
797 EXPECT_TRUE(::arene::base::equal(deque.begin(), deque.end(), init_list.begin()));
798
799 auto const try_deque = TypeParam::try_construct(init_list);
800 ASSERT_TRUE(try_deque.has_value());
801 EXPECT_TRUE(::arene::base::equal(try_deque->begin(), try_deque->end(), init_list.begin()));
802}
803
804/// @test `inline_deque` can be constructed from an empty initializer list
806 auto const init_list = TestFixture::template test_initializer_list<0U>();
807
808 TypeParam const deque_from_ilist(init_list);
809 EXPECT_EQ(deque_from_ilist.size(), 0U);
810
811 TypeParam const deque_from_range(init_list.begin(), init_list.end());
812 EXPECT_EQ(deque_from_range.size(), 0U);
813
814 auto const try_deque_from_ilist = TypeParam::try_construct(init_list);
815 ASSERT_TRUE(try_deque_from_ilist.has_value());
816 EXPECT_EQ(try_deque_from_ilist->size(), 0U);
817
818 auto const try_deque_from_range = TypeParam::try_construct(init_list.begin(), init_list.end());
819 ASSERT_TRUE(try_deque_from_range.has_value());
820 EXPECT_EQ(try_deque_from_range->size(), 0U);
821}
822
823/// @test `inline_deque` crashes when copy constructed from a random-access range in the wrong order
826 CopyConstructFromBackwardRange,
828) {
829 auto const init_list = TestFixture::full_test_initializer_list();
830 ASSERT_DEATH(TypeParam(init_list.end(), init_list.begin()), "Precondition");
831}
832
833/// @test `try_construct` returns empty when copy constructing from a random-access range in the wrong order
836 TryCopyConstructFromBackwardRange,
838) {
839 auto const init_list = TestFixture::full_test_initializer_list();
840 EXPECT_FALSE(TypeParam::try_construct(init_list.end(), init_list.begin()).has_value());
841}
842
843/// @test `inline_deque` crashes when copy constructed from a range that's too large to fit within the capacity
846 CopyConstructFromOversizedRange,
848) {
849 auto const init_list = TestFixture::template test_initializer_list<TypeParam::capacity() + 1U>();
850 ASSERT_DEATH(TypeParam(init_list.begin(), init_list.end()), "Precondition");
851}
852
853/// @test `try_construct` returns empty when copy constructing from a range that's too large to fit within the capacity
856 TryCopyConstructFromOversizedRange,
858) {
859 auto const init_list = TestFixture::template test_initializer_list<TypeParam::capacity() + 1U>();
860 EXPECT_FALSE(TypeParam::try_construct(init_list.begin(), init_list.end()).has_value());
861}
862
863/// @test `inline_deque` crashes when move constructed from a range with the iterators in the wrong order
864TYPED_TEST_P(InlineDequeDeathTest, MoveConstructFromBackwardRange) {
865 ASSERT_DEATH(
866 TypeParam(
869 ),
870 "Precondition"
871 );
872}
873
874/// @test `try_construct` returns empty when move constructing from a range with the iterators in the wrong order
875TYPED_TEST_P(InlineDequeTest, TryMoveConstructFromBackwardRange) {
876 EXPECT_FALSE(TypeParam::try_construct(
879 )
880 .has_value());
881}
882
883/// @test `inline_deque` crashes when move constructed from a range that's too large to fit within the capacity
884TYPED_TEST_P(InlineDequeDeathTest, MoveConstructFromOversizedRange) {
885 ASSERT_DEATH(
886 TypeParam(
889 ),
890 "Precondition"
891 );
892}
893
894/// @test `try_construct` returns empty when move constructing from a range that's too large to fit within the capacity
895TYPED_TEST_P(InlineDequeTest, TryMoveConstructFromOversizedRange) {
896 EXPECT_FALSE(TypeParam::try_construct(
899 )
900 .has_value());
901}
902
903/// @test `inline_deque` crashes when copy constructed from an initializer list that's too large to fit in the capacity
906 ConstructFromOversizedInitializerList,
908) {
909 auto const init_list = TestFixture::template test_initializer_list<TypeParam::capacity() + 1U>();
910 ASSERT_DEATH(static_cast<void>(TypeParam(init_list)), "Precondition");
911}
912
913/// @test `try_construct` returns empty when constructing from an initializer list that's too large for the capacity
916 TryConstructFromOversizedInitializerList,
918) {
919 auto const init_list = TestFixture::template test_initializer_list<TypeParam::capacity() + 1U>();
920 EXPECT_FALSE(TypeParam::try_construct(init_list).has_value());
921}
922
923/// @test `inline_deque` copy-construction works as expected
925 auto org = TestFixture::full_test_deque();
926 auto dst(org);
927 EXPECT_EQ(org.size(), org.capacity());
928 EXPECT_EQ(org.size(), dst.size());
929 for (std::size_t i = 0; i < org.capacity(); i++) {
930 EXPECT_EQ(TestFixture::test_value(i), dst.front());
931 EXPECT_EQ(org.front(), dst.front());
932 org.pop_front();
933 dst.pop_front();
934 }
935 EXPECT_TRUE(org.empty());
936 EXPECT_TRUE(dst.empty());
937}
938
939/// @test `inline_deque` copy-construction works as expected when invoked via `try_construct`
941 auto org = TestFixture::full_test_deque();
942 auto dst = TypeParam::try_construct(org);
943
944 ASSERT_TRUE(dst.has_value());
945 EXPECT_TRUE(::arene::base::equal(org.begin(), org.end(), dst->begin()));
946}
947
948/// @test `inline_deque` move-construction works as expected
949TYPED_TEST_P(InlineDequeTest, CanMoveConstruct) {
950 auto org = TestFixture::full_test_deque();
951 EXPECT_EQ(org.size(), org.capacity());
952 TypeParam dst(std::move(org));
953 EXPECT_EQ(dst.size(), dst.capacity());
954 for (std::size_t i = 0; i < dst.capacity(); i++) {
955 EXPECT_EQ(TestFixture::test_value(i), dst.front());
956 dst.pop_front();
957 }
958 EXPECT_TRUE(dst.empty());
959}
960
961/// @test `inline_deque` move-construction works as expected when invoked via `try_construct`
962TYPED_TEST_P(InlineDequeTest, CanMoveTryConstruct) {
963 auto org = TestFixture::full_test_deque();
964 auto tmp = TestFixture::full_test_deque();
965 auto dst = TypeParam::try_construct(std::move(tmp));
966
967 ASSERT_TRUE(dst.has_value());
968 EXPECT_TRUE(::arene::base::equal(org.begin(), org.end(), dst->begin()));
969}
970
971/// @test `inline_deque` copy-assignment works as expected
973 auto org = TestFixture::full_test_deque();
974 TypeParam dst;
975 EXPECT_EQ(org.size(), org.capacity());
976 EXPECT_EQ(dst.size(), 0);
977 dst = org;
978 EXPECT_EQ(org.size(), org.capacity());
979 EXPECT_EQ(dst.size(), org.capacity());
980 for (std::size_t i = 0; i < org.capacity(); i++) {
981 EXPECT_EQ(TestFixture::test_value(i), dst.front());
982 EXPECT_EQ(org.front(), dst.front());
983 org.pop_front();
984 dst.pop_front();
985 }
986 EXPECT_TRUE(org.empty());
987 EXPECT_TRUE(dst.empty());
988}
989
990/// @test `inline_deque` self copy-assignment does nothing
992 TypeParam deque = TestFixture::full_test_deque();
993
995 ARENE_IGNORE_CLANG("-Wself-assign-overloaded", "We're specifically testing self assignment");
996 // NOLINTNEXTLINE(misc-redundant-expression)
997 deque = deque;
998 ASSERT_EQ(deque.size(), deque.capacity());
1000
1001 for (std::size_t i = 0; i < deque.size(); ++i) {
1002 EXPECT_EQ(deque.front(), TestFixture::test_value(i));
1003 deque.pop_front();
1004 }
1005}
1006
1007/// @test `inline_deque` move-assignment works as expected
1009 auto org = TestFixture::full_test_deque();
1010 TypeParam dst;
1011 ASSERT_EQ(org.size(), org.capacity());
1012 ASSERT_EQ(dst.size(), 0);
1013
1014 dst = std::move(org);
1015 ASSERT_EQ(dst.size(), org.capacity());
1016 for (std::size_t i = 0; i < org.capacity(); i++) {
1017 EXPECT_EQ(TestFixture::test_value(i), dst.front());
1018 dst.pop_front();
1019 }
1020 EXPECT_TRUE(dst.empty());
1021}
1022
1023/// @test `inline_deque` self move-assignment does nothing
1025 TypeParam deque = TestFixture::full_test_deque();
1026
1027 deque = std::move(deque);
1028 ASSERT_EQ(deque.size(), deque.capacity());
1029
1030 for (std::size_t i = 0; i < deque.size(); ++i) {
1031 EXPECT_EQ(deque.front(), TestFixture::test_value(i));
1032 deque.pop_front();
1033 }
1034}
1035
1036/// @test Copy assignment works into a partially full target
1038 auto org = TestFixture::full_test_deque();
1039 auto dst = TestFixture::full_test_deque();
1040
1041 // Remove half of the elements of dst
1042 while (dst.size() > dst.capacity() / 2U) {
1043 dst.pop_front();
1044 }
1045
1046 dst = org;
1047 ASSERT_EQ(dst.size(), org.capacity());
1048 for (std::size_t i = 0; i < org.capacity(); i++) {
1049 EXPECT_EQ(TestFixture::test_value(i), dst.front());
1050 dst.pop_front();
1051 }
1052}
1053
1054/// @test Copy assignment works from a partially full input
1056 auto org = TestFixture::full_test_deque();
1057 auto dst = TestFixture::full_test_deque();
1058
1059 // Remove half of the elements of org
1060 std::size_t removed_count{};
1061 while (org.size() > org.capacity() / 2U) {
1062 org.pop_front();
1063 ++removed_count;
1064 }
1065
1066 dst = org;
1067 ASSERT_EQ(dst.size(), org.capacity() / 2U);
1068 for (std::size_t i = 0; i < org.capacity() / 2U; i++) {
1069 EXPECT_EQ(TestFixture::test_value(i + removed_count), dst.front());
1070 dst.pop_front();
1071 }
1072}
1073
1074/// @test Move assignment works into a partially full target
1075TYPED_TEST_P(InlineDequeTest, MoveAssignIntoPartiallyFull) {
1076 auto org = TestFixture::full_test_deque();
1077 auto dst = TestFixture::full_test_deque();
1078
1079 // Remove half of the elements of dst
1080 while (dst.size() > dst.capacity() / 2U) {
1081 dst.pop_front();
1082 }
1083
1084 dst = std::move(org);
1085 ASSERT_EQ(dst.size(), org.capacity());
1086 for (std::size_t i = 0; i < org.capacity(); i++) {
1087 EXPECT_EQ(TestFixture::test_value(i), dst.front());
1088 dst.pop_front();
1089 }
1090}
1091
1092/// @test Move assignment works from a partially full input
1093TYPED_TEST_P(InlineDequeTest, MoveAssignFromPartiallyFull) {
1094 auto org = TestFixture::full_test_deque();
1095 auto dst = TestFixture::full_test_deque();
1096
1097 // Remove half of the elements of org
1098 std::size_t removed_count{};
1099 while (org.size() > org.capacity() / 2U) {
1100 org.pop_front();
1101 ++removed_count;
1102 }
1103
1104 dst = std::move(org);
1105 ASSERT_EQ(dst.size(), org.capacity() / 2U);
1106 for (std::size_t i = 0; i < org.capacity() / 2U; i++) {
1107 EXPECT_EQ(TestFixture::test_value(i + removed_count), dst.front());
1108 dst.pop_front();
1109 }
1110}
1111
1112/// @test Both const and non-const iterator types for a deque are random access, and creating them is noexcept
1113TYPED_TEST_P(InlineDequeTest, IteratorsAreRandomAccessAndNoexcept) {
1116 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().begin()));
1117 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().cbegin()));
1118 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().rbegin()));
1119 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().crbegin()));
1120 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().end()));
1121 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().cend()));
1122 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().rend()));
1123 STATIC_ASSERT_TRUE(noexcept(std::declval<TypeParam&>().crend()));
1124}
1125
1126/// @test Non-const iterators are implicitly convertible to the corresponding const iterator, but not vice versa
1127TYPED_TEST_P(InlineDequeTest, NonConstIteratorsImplicitlyConvertibleToConst) {
1128 using iterator = typename TypeParam::iterator;
1129 using const_iterator = typename TypeParam::const_iterator;
1130
1133
1134 TypeParam deque = TestFixture::full_test_deque();
1135 EXPECT_EQ(std::addressof(*deque.begin()), std::addressof(*deque.cbegin()));
1136 EXPECT_EQ(deque.begin(), deque.cbegin());
1137}
1138
1139/// @test Inspecting a deque using its iterators yields the elements from front to back
1140TYPED_TEST_P(InlineDequeTest, InspectWithIterators) {
1141 TypeParam const deque = TestFixture::full_test_deque();
1142
1143 std::size_t value_idx{0U};
1144 for (auto const& element : deque) {
1145 EXPECT_EQ(element, TestFixture::test_value(value_idx));
1146 ++value_idx;
1147 }
1148}
1149
1150/// @test Inspecting a deque using its iterators yields the elements from front to back, even when wrapping around
1151TYPED_TEST_P(InlineDequeTest, IteratorsWrapAround) {
1152 TypeParam const deque = TestFixture::wrapped_test_deque();
1153
1154 // The wrapped deque contains the elements [capacity/2, 3*capacity/2).
1155 std::size_t value_idx{(deque.capacity() / 2U)};
1156 for (auto const& element : deque) {
1157 EXPECT_EQ(element, TestFixture::test_value(value_idx));
1158 ++value_idx;
1159 }
1160}
1161
1162/// @test The elements of a deque can be changed using its mutable iterators
1163TYPED_TEST_P(InlineDequeTest, MutableIteratorsWork) {
1164 // As confirmed in the above test, this contains the elements [capacity/2, 3*capacity/2), arranged backwards.
1165 TypeParam deque = TestFixture::wrapped_test_deque();
1166
1167 // Use the mutable iterators to change the elements to [0, capacity), arranged forwards
1168 std::size_t value_idx{};
1169 for (auto& element : deque) {
1170 element = TestFixture::test_value(value_idx);
1171 ++value_idx;
1172 }
1173
1174 // Use the constant iterators to inspect that the entries have the right values in the same order
1175 value_idx = {};
1176 for (auto itr = deque.cbegin(); itr != deque.cend(); ++itr) {
1177 EXPECT_EQ(*itr, TestFixture::test_value(value_idx));
1178 ++value_idx;
1179 }
1180}
1181
1182/// @test Inspecting a deque using its reverse iterators yields the elements from back to front
1183TYPED_TEST_P(InlineDequeTest, InspectWithReverseIterators) {
1184 TypeParam const deque = TestFixture::wrapped_test_deque();
1185
1186 // The wrapped deque contains the elements [capacity/2, 3*capacity/2).
1187 std::size_t idx{deque.capacity() + (deque.capacity() / 2U) - 1U};
1188 for (auto itr = deque.crbegin(); itr != deque.crend(); ++itr) {
1189 EXPECT_EQ(*itr, TestFixture::test_value(idx));
1190 --idx;
1191 }
1192}
1193
1194/// @test The elements of a deque can be changed using its mutable reverse iterators
1195TYPED_TEST_P(InlineDequeTest, MutableReverseIteratorsWork) {
1196 // As confirmed in the above test, this contains the elements [capacity/2, 3*capacity/2), arranged backwards.
1197 TypeParam deque = TestFixture::wrapped_test_deque();
1198
1199 // Use the mutable reverse iterators to change the elements to [0, capacity), in reverse
1200 std::size_t value_idx{};
1201 for (auto itr = deque.rbegin(); itr != deque.rend(); ++itr) {
1202 *itr = TestFixture::test_value(value_idx);
1203 ++value_idx;
1204 }
1205
1206 // Use the forward iterators to inspect that the entries have the right values in the opposite order
1207 for (auto const& element : deque) {
1208 --value_idx;
1209 EXPECT_EQ(element, TestFixture::test_value(value_idx));
1210 }
1211}
1212
1213/// @test Using `pop_front()` only invalidates iterators and references to the first element
1214CONDITIONAL_TYPED_TEST_P(InlineDequeTest, IteratorsNotInvalidatedByPopFront, TypeParam::capacity() >= 2U) {
1215 // The normal TestFixture::test_deque is populated front-to-back, but we want back-to-front for this test.
1216 TypeParam deque = TestFixture::test_deque(2U);
1217
1218 auto itr = deque.cbegin();
1219 for (std::size_t value_idx{}; value_idx / 3U < TypeParam::capacity(); ++value_idx) {
1220 EXPECT_EQ(*itr, TestFixture::test_value(value_idx));
1221 ++itr;
1222 deque.pop_front(); // remove the element that was just inspected
1223 deque.push_back(TestFixture::test_value(value_idx + 2U)); // add the element we'll inspect 2 iterations from now
1224 }
1225}
1226
1227/// @test Using `pop_back()` only invalidates iterators and references to the last element and `end()`
1230 IteratorsNotInvalidatedByPopBack,
1231 is_double_ended<TypeParam>&& TypeParam::capacity() >= 3U
1232) {
1233 // This test requires capacity 3 or more because a reverse iterator is invalidated by removing the element it points
1234 // to *or* the one after (reverse-before) it. To prevent this we need to advance the iterator twice before popping.
1235 //
1236 // The above test using a forward iterator and pop_front()/push_back() works with only 2 elements in the queue,
1237 // because the forward iterator is only invalidated if the element it points to is.
1238
1239 TypeParam deque = TestFixture::construct();
1240 deque.push_front(TestFixture::test_value(0U));
1241 deque.push_front(TestFixture::test_value(1U));
1242 deque.push_front(TestFixture::test_value(2U));
1243
1244 auto itr = deque.crbegin();
1245 ++itr; // advance the iterator to ensure the element being popped is *two* elements behind the iterator
1246 for (std::size_t value_idx{1U}; value_idx / 3U < TypeParam::capacity(); ++value_idx) {
1247 EXPECT_EQ(*itr, TestFixture::test_value(value_idx));
1248 ++itr;
1249 deque.pop_back(); // remove the element that was just inspected
1250 deque.push_front(TestFixture::test_value(value_idx + 2U)); // add the element we'll inspect 2 iterations from now
1251 }
1252}
1253
1254/// @test Using binary `operator+` on an iterator gives the same result as using `operator+=` on a copy of it
1255TYPED_TEST_P(InlineDequeTest, BinaryPlusEquivalentToPlusEquals) {
1256 using difference_type = typename TypeParam::iterator::difference_type;
1257
1258 TypeParam deque = TestFixture::full_test_deque();
1259
1260 // Taking this difference out to size() so we can test the cases where the iterator falls off the edge as well
1261 for (difference_type diff{}; diff <= static_cast<difference_type>(deque.size()); ++diff) {
1262 auto begin_copy = deque.begin();
1263 begin_copy += diff;
1264 EXPECT_EQ(begin_copy, deque.begin() + diff);
1265 EXPECT_EQ(begin_copy, diff + deque.begin());
1266
1267 auto cbegin_copy = deque.cbegin();
1268 cbegin_copy += diff;
1269 EXPECT_EQ(cbegin_copy, deque.cbegin() + diff);
1270 EXPECT_EQ(cbegin_copy, diff + deque.cbegin());
1271 }
1272}
1273
1274/// @test Using binary `operator-` on an iterator and a difference gives the same result as using `operator-=` on them
1275TYPED_TEST_P(InlineDequeTest, BinaryMinusEquivalentToMinusEquals) {
1276 using difference_type = typename TypeParam::iterator::difference_type;
1277
1278 TypeParam deque = TestFixture::full_test_deque();
1279
1280 // Taking this difference out to size() so we can test the cases where the iterator falls off the edge as well
1281 for (difference_type diff{}; diff <= static_cast<difference_type>(deque.size()); ++diff) {
1282 auto end_copy = deque.end();
1283 end_copy -= diff;
1284 EXPECT_EQ(end_copy, deque.end() - diff);
1285
1286 auto cend_copy = deque.cend();
1287 cend_copy -= diff;
1288 EXPECT_EQ(cend_copy, deque.cend() - diff);
1289 }
1290}
1291
1292/// @test Using `operator[]` on an iterator gives the same result as using binary `operator+` and unary `operator*`
1293TYPED_TEST_P(InlineDequeTest, IteratorBracketOperatorEquivalentToBinaryPlus) {
1294 using difference_type = typename TypeParam::iterator::difference_type;
1295
1296 TypeParam deque = TestFixture::full_test_deque();
1297
1298 for (difference_type diff{}; diff < static_cast<difference_type>(deque.size()); ++diff) {
1299 EXPECT_EQ(std::addressof(deque.begin()[diff]), std::addressof(*(deque.begin() + diff)));
1300 EXPECT_EQ(std::addressof(deque.cbegin()[diff]), std::addressof(*(deque.cbegin() + diff)));
1301
1302 EXPECT_EQ(std::addressof(deque.rbegin()[diff]), std::addressof(*(deque.rbegin() + diff)));
1303 EXPECT_EQ(std::addressof(deque.crbegin()[diff]), std::addressof(*(deque.crbegin() + diff)));
1304 }
1305}
1306
1307/// @test Using `operator[]` on the deque gives the same result as using `operator[]` on `begin()`
1308TYPED_TEST_P(InlineDequeTest, ContainerBracketOperatorEquivalentToIteratorBracketOperator) {
1309 using difference_type = typename TypeParam::iterator::difference_type;
1310
1311 TypeParam deque = TestFixture::full_test_deque();
1312 TypeParam const& const_deque = deque;
1313
1314 for (difference_type diff{}; diff < static_cast<difference_type>(deque.size()); ++diff) {
1315 EXPECT_EQ(std::addressof(deque[diff]), std::addressof(deque.begin()[diff]));
1316 EXPECT_EQ(std::addressof(const_deque[diff]), std::addressof(deque.cbegin()[diff]));
1317 }
1318}
1319
1320/// @test Binary `operator-` between any two iterators returns the distance between them
1321TYPED_TEST_P(InlineDequeTest, AnyIteratorDifferenceReturnsDistance) {
1322 using difference_type = typename TypeParam::iterator::difference_type;
1323
1324 // If it's possible to construct a deque that's neither full nor empty, test both the full one and the partially full
1325 // one; if not, then just test the full one.
1326 using deque_array = std::
1327 conditional_t<TypeParam::capacity() >= 2U, arene::base::array<TypeParam, 2U>, arene::base::array<TypeParam, 1U>>;
1328 deque_array deques;
1329 deques[0U] = TestFixture::full_test_deque();
1330 if (deques.size() >= 2U) {
1331 deques[1U] = TestFixture::half_test_deque();
1332 }
1333
1334 for (auto& deque : deques) {
1335 auto const signed_size = static_cast<difference_type>(deque.size());
1336
1337 auto current = deque.begin();
1338 auto const_current = deque.cbegin();
1339 for (difference_type current_pos{}; current_pos <= signed_size; ++current_pos) {
1340 // Check that every iterator from beginning to end has the expected difference from the current position
1341
1342 auto test_iter = deque.begin();
1343 auto const_test_iter = deque.cbegin();
1344 for (difference_type diff{-current_pos}; diff < (signed_size - current_pos); ++diff) {
1345 EXPECT_EQ(test_iter - current, diff);
1346 EXPECT_EQ(const_test_iter - const_current, diff);
1347
1348 ++test_iter;
1349 ++const_test_iter;
1350 }
1351
1352 ++current;
1353 ++const_current;
1354 }
1355 }
1356}
1357
1358/// @test Incrementing an iterator all at once is the same as repeatedly incrementing it one step
1359TYPED_TEST_P(InlineDequeTest, IteratorForwardMovementIsTheSameAsRepeatedIncrementing) {
1360 using difference_type = typename TypeParam::iterator::difference_type;
1361
1362 TypeParam deque = TestFixture::full_test_deque();
1363 auto curr = deque.begin();
1364 auto const_curr = deque.cbegin();
1365 for (difference_type diff{}; diff <= static_cast<difference_type>(deque.size()); ++diff) {
1366 EXPECT_EQ(deque.begin() + diff, curr);
1367 ++curr;
1368
1369 EXPECT_EQ(deque.cbegin() + diff, const_curr);
1370 ++const_curr;
1371 }
1372}
1373
1374/// @test Decrementing an iterator all at once is the same as repeatedly decrementing it one step
1375TYPED_TEST_P(InlineDequeTest, IteratorBackwardMovementIsTheSameAsRepeatedDecrementing) {
1376 using difference_type = typename TypeParam::iterator::difference_type;
1377
1378 TypeParam deque = TestFixture::full_test_deque();
1379 auto curr = deque.end();
1380 auto const_curr = deque.cend();
1381 for (difference_type diff{}; diff <= static_cast<difference_type>(deque.size()); ++diff) {
1382 EXPECT_EQ(deque.end() - diff, curr);
1383 --curr;
1384
1385 EXPECT_EQ(deque.cend() - diff, const_curr);
1386 --const_curr;
1387 }
1388}
1389
1390/// @test Incrementing an iterator by exactly enough to go out of bounds causes it to become the end iterator
1391TYPED_TEST_P(InlineDequeTest, IteratorsIncrementedOutOfBoundsBecomeEnd) {
1392 using difference_type = typename TypeParam::iterator::difference_type;
1393
1394 TypeParam deque = TestFixture::full_test_deque();
1395 auto start = deque.begin();
1396 auto const_start = deque.cbegin();
1397 for (auto diff = static_cast<difference_type>(deque.size()); diff >= 0; --diff) {
1398 EXPECT_EQ(start + diff, deque.end());
1399 EXPECT_EQ(const_start + diff, deque.cend());
1400 ++start;
1401 ++const_start;
1402 }
1403}
1404
1405/// @test When created on an empty deque, the begin and end pair of each iterator type equal each other
1406TYPED_TEST_P(InlineDequeTest, EmptyDequeBeginEqualsEnd) {
1407 TypeParam deque = TestFixture::construct();
1408 EXPECT_EQ(deque.begin(), deque.end());
1409 EXPECT_EQ(deque.cbegin(), deque.cend());
1410 EXPECT_EQ(deque.rbegin(), deque.rend());
1411 EXPECT_EQ(deque.crbegin(), deque.crend());
1412}
1413
1414/// @brief Check that the first value is ordered strictly before the second
1415template <typename T>
1416auto check_ordering(T const& first, T const& second) noexcept -> void {
1417 EXPECT_TRUE(first < second);
1418 EXPECT_TRUE(first <= second);
1419 EXPECT_FALSE(first > second);
1420 EXPECT_FALSE(first >= second);
1421
1422 EXPECT_FALSE(second < first);
1423 EXPECT_FALSE(second <= first);
1424 EXPECT_TRUE(second > first);
1425 EXPECT_TRUE(second >= first);
1426}
1427
1428/// @test Iterators to the same deque are ordered with respect to each other in the way they're supposed to be
1429TYPED_TEST_P(InlineDequeTest, IteratorsAreOrdered) {
1430 TypeParam deque = TestFixture::full_test_deque();
1431
1432 auto curr = deque.begin();
1433 auto const_curr = deque.cbegin();
1434 for (std::size_t i{}; i + 1U < deque.size(); ++i) {
1435 ++curr;
1436 ++const_curr;
1437
1438 check_ordering(deque.begin(), curr);
1439 check_ordering(deque.cbegin(), const_curr);
1440 check_ordering(curr, deque.end());
1441 check_ordering(const_curr, deque.cend());
1442 }
1443}
1444
1445/// @test Dereferencing the end iterator of any iterator type causes a crash
1446TYPED_TEST_P(InlineDequeDeathTest, DereferencingEndIteratorIsPreconditionViolation) {
1447 TypeParam deque = TestFixture::full_test_deque();
1448 ASSERT_DEATH(*deque.end(), "Precondition");
1449 ASSERT_DEATH(*deque.cend(), "Precondition");
1450 ASSERT_DEATH(static_cast<void>(*deque.rend()), "Precondition");
1451 ASSERT_DEATH(static_cast<void>(*deque.crend()), "Precondition");
1452}
1453
1454/// @test When created on an empty deque, dereferencing the begin iterator of any iterator type causes a crash
1455TYPED_TEST_P(InlineDequeDeathTest, DereferencingBeginOfEmptyDequeIsPreconditionViolation) {
1456 TypeParam deque = TestFixture::construct();
1457 ASSERT_DEATH(*deque.begin(), "Precondition");
1458 ASSERT_DEATH(*deque.cbegin(), "Precondition");
1459 ASSERT_DEATH(static_cast<void>(*deque.rbegin()), "Precondition");
1460 ASSERT_DEATH(static_cast<void>(*deque.crbegin()), "Precondition");
1461}
1462
1463/// @test Default-constructed instances of any deque's iterators cause crashes when incremented or dereferenced
1464TYPED_TEST_P(InlineDequeDeathTest, DefaultConstructedIteratorCantBeUsed) {
1465 TypeParam deque = TestFixture::full_test_deque();
1466
1467 typename TypeParam::iterator default_it;
1468 EXPECT_NE(default_it, deque.begin());
1469 EXPECT_NE(default_it, deque.end());
1470 ASSERT_DEATH(*default_it, "Precondition");
1471 ASSERT_DEATH(default_it += 0, "Precondition");
1472}
1473
1474/// @test Default-constructed instances of any deque's const iterators cause crashes when incremented or dereferenced
1475TYPED_TEST_P(InlineDequeDeathTest, DefaultConstructedConstIteratorCantBeUsed) {
1476 TypeParam deque = TestFixture::full_test_deque();
1477
1478 typename TypeParam::const_iterator default_it;
1479 EXPECT_NE(default_it, deque.cbegin());
1480 EXPECT_NE(default_it, deque.cend());
1481 ASSERT_DEATH(*default_it, "Precondition");
1482 ASSERT_DEATH(default_it += 0, "Precondition");
1483}
1484
1485/// @test Trying to compare iterators for ordering when they come from two different deques causes a crash
1486TYPED_TEST_P(InlineDequeDeathTest, IteratorOrderingFromDifferentDequesIsPreconditionViolation) {
1487 TypeParam deque1 = TestFixture::full_test_deque();
1488 TypeParam deque2 = TestFixture::full_test_deque();
1489
1490 ASSERT_DEATH(std::ignore = (deque1.begin() < deque2.begin()), "Precondition");
1491 ASSERT_DEATH(std::ignore = (deque1.begin() <= deque2.begin()), "Precondition");
1492 ASSERT_DEATH(std::ignore = (deque1.begin() > deque2.begin()), "Precondition");
1493 ASSERT_DEATH(std::ignore = (deque1.begin() >= deque2.begin()), "Precondition");
1494}
1495
1496/// @test Trying to subtract the most negative possible difference from an iterator causes a precondition violation
1497TYPED_TEST_P(InlineDequeDeathTest, SubtractingIteratorByMinimumValueIsPreconditionViolation) {
1498 TypeParam deque = TestFixture::full_test_deque();
1499
1500 // This value can not be negated, so trying to subtract by it causes a precondition violation.
1502
1503 ASSERT_DEATH(std::ignore = (deque.begin() - minimum_value), "Precondition");
1504 ASSERT_DEATH(std::ignore = (deque.cbegin() - minimum_value), "Precondition");
1505}
1506
1508
1511 CanConstruct,
1512 CapacityIsAsSpecified,
1513 CapacityIsNoexcept,
1514 SizeIsNoexcept,
1515 PushFrontOneElement,
1516 PushBackOneElement,
1517 EmplaceFrontReturnsReference,
1518 EmplaceBackReturnsReference,
1519 FrontPushedElementIsCorrect,
1520 BackPushedElementIsCorrect,
1521 PushFrontWithinCapacity,
1522 PushBackWithinCapacity,
1523 PushFrontDetailCoverage,
1524 InsertConstraints,
1525 CopyInsertOne,
1526 MoveInsertOne,
1527 CopyInsertOneAtEnd,
1528 MoveInsertOneAtEnd,
1529 GoCircularFromFront,
1530 GoCircularFromBack,
1531 BasicFunctionFromFront,
1532 BasicFunctionFromBack,
1533 CanObserveAndModifyFromFront,
1534 CanObserveAndModifyFromBack,
1535 PushFrontCopiesLvalues,
1536 PushBackCopiesLvalues,
1537 NotCopyConstructibleIfDataTypeNotCopyConstructible,
1538 NotMoveConstructibleIfDataTypeNotMoveConstructible,
1539 NotCopyAssignableIfDataTypeNotCopyConstructibleAndCopyAssignable,
1540 NotMoveAssignableIfDataTypeNotMoveConstructibleAndMoveAssignable,
1541 CanConstructAtCompileTime,
1542 RangeConstructionSfinae,
1543 RangeConstructionNoexcept,
1544 CopyConstructFromRange,
1545 MoveConstructFromRange,
1546 InitializerListConstructionSfinae,
1547 InitializerListConstructionNoexcept,
1548 ConstructFromInitializerList,
1549 ConstructFromEmptyList,
1550 TryCopyConstructFromBackwardRange,
1551 TryCopyConstructFromOversizedRange,
1552 TryMoveConstructFromBackwardRange,
1553 TryMoveConstructFromOversizedRange,
1554 TryConstructFromOversizedInitializerList,
1555 CanCopyConstruct,
1556 CanCopyTryConstruct,
1557 CanMoveConstruct,
1558 CanMoveTryConstruct,
1559 CanCopyAssign,
1560 SelfCopyAssign,
1561 CanMoveAssign,
1562 SelfMoveAssign,
1563 CopyAssignIntoPartiallyFull,
1564 CopyAssignFromPartiallyFull,
1565 MoveAssignIntoPartiallyFull,
1566 MoveAssignFromPartiallyFull,
1567 IteratorsAreRandomAccessAndNoexcept,
1568 NonConstIteratorsImplicitlyConvertibleToConst,
1569 InspectWithIterators,
1570 IteratorsWrapAround,
1571 MutableIteratorsWork,
1572 InspectWithReverseIterators,
1573 MutableReverseIteratorsWork,
1574 IteratorsNotInvalidatedByPopFront,
1575 IteratorsNotInvalidatedByPopBack,
1576 BinaryPlusEquivalentToPlusEquals,
1577 BinaryMinusEquivalentToMinusEquals,
1578 IteratorBracketOperatorEquivalentToBinaryPlus,
1579 ContainerBracketOperatorEquivalentToIteratorBracketOperator,
1580 AnyIteratorDifferenceReturnsDistance,
1581 IteratorForwardMovementIsTheSameAsRepeatedIncrementing,
1582 IteratorBackwardMovementIsTheSameAsRepeatedDecrementing,
1583 IteratorsIncrementedOutOfBoundsBecomeEnd,
1584 EmptyDequeBeginEqualsEnd,
1585 IteratorsAreOrdered
1586);
1587
1590 PushFrontMoreThanCapacity,
1591 PushBackMoreThanCapacity,
1592 NonWrappingInsertOneWhenFull,
1593 BackWhenEmpty,
1594 ConstBackWhenEmpty,
1595 PopFrontWhenEmpty,
1596 PopBackWhenEmpty,
1597 FrontWhenEmpty,
1598 ConstFrontWhenEmpty,
1599 CopyConstructFromBackwardRange,
1600 CopyConstructFromOversizedRange,
1601 MoveConstructFromBackwardRange,
1602 MoveConstructFromOversizedRange,
1603 ConstructFromOversizedInitializerList,
1604 DereferencingEndIteratorIsPreconditionViolation,
1605 DereferencingBeginOfEmptyDequeIsPreconditionViolation,
1606 DefaultConstructedIteratorCantBeUsed,
1607 DefaultConstructedConstIteratorCantBeUsed,
1608 IteratorOrderingFromDifferentDequesIsPreconditionViolation,
1609 SubtractingIteratorByMinimumValueIsPreconditionViolation
1610);
1611
1612} // namespace testing
1613} // namespace base
1614} // namespace arene
1615
1616#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_DEQUE_HPP_
The death tests use the same fixture as the non-death tests, but as a distinct type to improve log ou...
Definition deque.hpp:180
Test fixture for all type-parameterized inline_deque tests.
Definition deque.hpp:88
static constexpr auto construct() noexcept(noexcept(Deque())) -> Deque
Return an empty Deque, allowing to call as this->construct, which becomes useful with the ....
Definition deque.hpp:111
static constexpr auto test_deque(std::size_t size) noexcept(noexcept(test_deque(0, size))) -> Deque
Return a Deque containing the test values [0,size) of T.
Definition deque.hpp:126
static constexpr auto test_deque(std::size_t begin, std::size_t end) noexcept(noexcept(::arene::base::testing::test_deque< Deque >(begin, end))) -> Deque
Return a Deque containing the test values [begin,end) of T.
Definition deque.hpp:117
static constexpr auto wrapped_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque
Return a Deque containing the test values [capacity/2, 3*capacity/2) of T.
Definition deque.hpp:145
static constexpr auto test_initializer_list() noexcept -> std::initializer_list< T >
Return a std::initializer_list containing user-parameterized test_values.
Definition deque.hpp:166
static constexpr auto half_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque
Return a Deque containing the test values [0,capacity/2) of T.
Definition deque.hpp:132
static constexpr bool constexpr_compatible
Whether the type parameter is constexpr compatible for this test.
Definition deque.hpp:93
static constexpr auto full_test_initializer_list() noexcept -> std::initializer_list< T >
Return a std::initializer_list containing Deque::capacity user-parameterized test_values.
Definition deque.hpp:172
static constexpr auto full_test_deque() noexcept(noexcept(test_deque(Deque::capacity))) -> Deque
Return a Deque containing the test values [0,capacity) of T.
Definition deque.hpp:138
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 deque.hpp:104
static constexpr auto test_initializer_list(std::index_sequence< Indices... >) noexcept -> std::initializer_list< T >
Return a std::initializer_list containing user-parameterized test_values.
Definition deque.hpp:158
A fixed-size array of T objects.
Definition array.hpp:77
An iterator whose i'th position yields an rvalue reference to test_value(i) of the given type.
Definition customization.hpp:174
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
static constexpr value_type value
Definition integral_constant.hpp:34
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
static constexpr auto lowest() noexcept -> T
The minimum finite value such that there is no finite value y such that y<lowest()
Definition numeric_limits.hpp:238
#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
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_CLANG(s, comment)
Pushes an ignore for a diagnostic into the compiler for clang only.
Definition diagnostics.hpp:116
#define ARENE_IGNORE_START()
Begins a region of a suppressed diagnostic.
Definition diagnostics.hpp:131
#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.
Definition customization.hpp:31
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 test_deque(std::size_t begin, std::size_t end) noexcept(std::is_nothrow_copy_constructible< typename T::value_type >::value) -> T
Create a test deque containing a range of test values.
Definition deque.hpp:58
constexpr bool is_list_initializable_v
A type trait to check if a type is list-initializable using a brace-enclosed list of values with a gi...
Definition deque.hpp:73
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 std::size_t ExternalVectorTest< T >::capacity
Definition external_vector.hpp:224
TYPED_TEST_SUITE_P(ExternalVectorTest)
TYPED_TEST_P(ExternalVectorTest, CanConstructAnEmptyVector)
Definition external_vector.hpp:236
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)
Definition accumulate.hpp:37
constexpr std::integral_constant< std::size_t, N > array< T, N >::size
Definition array.hpp:534
constexpr auto as_const(T &obj) noexcept -> std::add_const_t< T > &
Obtain an lvalue-reference to a const object of type T.
Definition as_const.hpp:29
constexpr bool is_invocable_v
Determine if a functor type is invocable with the specified argument types.
constexpr bool is_random_access_iterator_v
Definition iterator_category_traits.hpp:332
constexpr bool is_movable_v
Backport for the C++20 movable concept.
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
auto check_ordering(T const &first, T const &second) noexcept -> void
Check that the first value is ordered strictly before the second.
Definition deque.hpp:1416
constexpr bool is_double_ended
Type trait to see if a particular TypeParam is double-ended or not; used to exclude some tests.
Definition deque.hpp:187
constexpr auto distance(Iterator first, Iterator last) noexcept(noexcept(distance_impl::do_distance(first, last, typename std::iterator_traits< Iterator >::iterator_category{}))) -> typename std::iterator_traits< Iterator >::difference_type
Find the number of elements between first and last.
Definition distance.hpp:79
constexpr bool is_copyable_v
Backport for the C++20 copyable concept.
constexpr std::integral_constant< typename inline_map< Key, Value, Capacity, Compare >::size_type, Capacity > inline_map< Key, Value, Capacity, Compare >::capacity
Definition map.hpp:2305
constexpr bool is_nothrow_invocable_v
Determine if a functor type is no-throw invocable with the specified argument types.
constexpr bool is_implicitly_constructible_v
Type trait to detect if a type is implicitly constructible from arguments of the specified types.
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
STL namespace.
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
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,...
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
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
#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