|
| 1 | +#include "beman/inplace_vector/inplace_vector.hpp" |
| 2 | +#include "gtest/gtest.h" |
| 3 | +#include <gtest/gtest.h> |
| 4 | +#include <type_traits> |
| 5 | + |
| 6 | +using namespace beman; |
| 7 | + |
| 8 | +// 23.3.14.1 Overview [inplace.vector.overview] |
| 9 | +// 1 An inplace_vector is a contiguous container. Its capacity is fixed and its |
| 10 | +// elements are stored within the inplace_vector object itself. |
| 11 | +// |
| 12 | +// This is not testable. |
| 13 | + |
| 14 | +// 2 An inplace_vector meets all of the requirements of a container (23.2.2.2), |
| 15 | +// of a reversible container (23.2.2.3), of a contiguous container, and of a |
| 16 | +// sequence container, including most of the optional sequence container |
| 17 | +// requirements (23.2.4). The exceptions are the push_front, prepend_range, |
| 18 | +// pop_front, and emplace_front member functions, which are not provided. |
| 19 | +// Descriptions are provided here only for operations on inplace_- vector that |
| 20 | +// are not described in one of these tables or for operations where there is |
| 21 | +// additional semantic information. |
| 22 | +// |
| 23 | +// TODO: Test container & reversible container & optional sequence container |
| 24 | +// req. |
| 25 | + |
| 26 | +// 3 For any N, inplace_vector<T, N>::iterator and inplace_vector<T, |
| 27 | +// N>::const_iterator meet the constexpr iterator requirements. |
| 28 | +// |
| 29 | +// TODO: Test this. |
| 30 | + |
| 31 | +// 4 For any N > 0, if is_trivial_v<T> is false, then no inplace_vector<T, N> |
| 32 | +// member functions are usable in constant expressions. |
| 33 | +// |
| 34 | +// This would be tested in subsequent method tests. |
| 35 | + |
| 36 | +// 5 Any member function of inplace_vector<T, N> that would cause the size to |
| 37 | +// exceed N throws an exception of type bad_alloc. |
| 38 | +// |
| 39 | +// TODO: Test this. |
| 40 | + |
| 41 | +// 6 Let IV denote a specialization of inplace_vector<T, N>. If N is zero, then |
| 42 | +// IV is both trivial and empty. Otherwise: |
| 43 | +// (6.1) — If is_trivially_copy_constructible_v<T> is true, then IV has a |
| 44 | +// trivial copy constructor |
| 45 | +// (6.2) — If is_trivially_move_constructible_v<T> is true, then IV has a |
| 46 | +// trivial move constructor. |
| 47 | +// (6.3) — If is_trivially_destructible_v<T> is true, then: |
| 48 | +// (6.3.1) — IV has a trivial destructor. |
| 49 | +// (6.3.2) — If is_trivially_copy_constructible_v<T> && |
| 50 | +// is_trivially_copy_assignable_v<T> is true, then IV has a trivial copy |
| 51 | +// assignment operator. |
| 52 | +// (6.3.3) — If is_trivially_move_constructible_v<T> && |
| 53 | +// is_trivially_move_assignable_v<T> is true, then IV has a trivial move |
| 54 | +// assignment operator. |
| 55 | + |
| 56 | +TEST(Overview, Section6) { |
| 57 | + // Let IV denote a specialization of inplace_vector<T, N>. |
| 58 | + { |
| 59 | + SCOPED_TRACE("If N is zero, then IV is both trivial and empty."); |
| 60 | + |
| 61 | + struct T { |
| 62 | + T() = delete; |
| 63 | + ~T() {} |
| 64 | + |
| 65 | + T(T &) = delete; |
| 66 | + T &operator=(T &) = delete; |
| 67 | + |
| 68 | + T(T &&) = delete; |
| 69 | + T &operator=(T &&) = delete; |
| 70 | + }; |
| 71 | + static_assert(!std::is_trivial_v<T>); |
| 72 | + using IV = inplace_vector<T, 0>; |
| 73 | + EXPECT_TRUE(std::is_trivial_v<IV> && std::is_empty_v<IV>); |
| 74 | + } |
| 75 | + { |
| 76 | + SCOPED_TRACE( |
| 77 | + "(6.1) — If is_trivially_copy_constructible_v<T> is true, then " |
| 78 | + "IV has a trivial copy constructor"); |
| 79 | + |
| 80 | + struct T { |
| 81 | + int a = 0; |
| 82 | + int b; |
| 83 | + |
| 84 | + T(T const &) = default; |
| 85 | + |
| 86 | + T() = delete; |
| 87 | + T(T &&) = delete; |
| 88 | + // TODO: This type is also trivially destructible |
| 89 | + // ~T() {} |
| 90 | + }; |
| 91 | + static_assert(std::is_trivially_copy_constructible_v<T>); |
| 92 | + using IV = inplace_vector<T, 5>; |
| 93 | + EXPECT_TRUE(std::is_trivially_copy_constructible_v<IV>); |
| 94 | + } |
| 95 | + { |
| 96 | + SCOPED_TRACE( |
| 97 | + "(6.2) — If is_trivially_move_constructible_v<T> is true, then IV " |
| 98 | + "has a trivial move constructor."); |
| 99 | + |
| 100 | + struct T { |
| 101 | + int a = 0; |
| 102 | + int b; |
| 103 | + |
| 104 | + T(T &&) = default; |
| 105 | + |
| 106 | + T() = delete; |
| 107 | + T(T const &) = default; |
| 108 | + // TODO: This type is also trivially destructible |
| 109 | + // ~T() {} |
| 110 | + }; |
| 111 | + static_assert(std::is_trivially_move_constructible_v<T>); |
| 112 | + using IV = inplace_vector<T, 5>; |
| 113 | + EXPECT_TRUE(std::is_trivially_move_constructible_v<IV>); |
| 114 | + } |
| 115 | + { |
| 116 | + SCOPED_TRACE("(6.3) — If is_trivially_destructible_v<T> is true, then:\n" |
| 117 | + "(6.3.1) — IV has a trivial destructor."); |
| 118 | + |
| 119 | + struct T { |
| 120 | + int a = 0; |
| 121 | + int b; |
| 122 | + |
| 123 | + ~T() = default; |
| 124 | + |
| 125 | + T() = delete; |
| 126 | + T(T const &) = delete; |
| 127 | + T(T &&) = delete; |
| 128 | + }; |
| 129 | + static_assert(std::is_trivially_destructible_v<T>); |
| 130 | + using IV = inplace_vector<T, 5>; |
| 131 | + EXPECT_TRUE(std::is_trivially_move_constructible_v<IV>); |
| 132 | + } |
| 133 | + { |
| 134 | + SCOPED_TRACE("(6.3) — If is_trivially_destructible_v<T> is true, then:\n" |
| 135 | + "(6.3.2) — If is_trivially_copy_constructible_v<T> && " |
| 136 | + "is_trivially_copy_assignable_v<T> is true, then IV has a " |
| 137 | + "trivial copy assignment operator."); |
| 138 | + |
| 139 | + struct T { |
| 140 | + int a = 0; |
| 141 | + int b; |
| 142 | + |
| 143 | + ~T() = default; |
| 144 | + T(T const &) = default; |
| 145 | + T &operator=(T const &) = default; |
| 146 | + |
| 147 | + T() = delete; |
| 148 | + T(T &&) = delete; |
| 149 | + }; |
| 150 | + static_assert(std::is_trivially_destructible_v<T>); |
| 151 | + static_assert(std::is_trivially_copy_constructible_v<T>); |
| 152 | + static_assert(std::is_trivially_copy_assignable_v<T>); |
| 153 | + |
| 154 | + using IV = inplace_vector<T, 5>; |
| 155 | + EXPECT_TRUE(std::is_trivially_copy_assignable_v<IV>); |
| 156 | + } |
| 157 | + { |
| 158 | + SCOPED_TRACE("(6.3) — If is_trivially_destructible_v<T> is true, then:\n" |
| 159 | + "(6.3.3) — If is_trivially_move_constructible_v<T> && " |
| 160 | + "is_trivially_move_assignable_v<T> is true, then IV has a " |
| 161 | + "trivial move assignment operator."); |
| 162 | + |
| 163 | + struct T { |
| 164 | + int a = 0; |
| 165 | + int b; |
| 166 | + |
| 167 | + ~T() = default; |
| 168 | + T(T &&) = default; |
| 169 | + T &operator=(T &&) = default; |
| 170 | + |
| 171 | + T() = delete; |
| 172 | + T(T const &) = delete; |
| 173 | + }; |
| 174 | + static_assert(std::is_trivially_destructible_v<T>); |
| 175 | + static_assert(std::is_trivially_move_constructible_v<T>); |
| 176 | + static_assert(std::is_trivially_move_assignable_v<T>); |
| 177 | + |
| 178 | + using IV = inplace_vector<T, 5>; |
| 179 | + EXPECT_TRUE(std::is_trivially_move_assignable_v<IV>); |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +// 23.3.14.2 Constructors [inplace.vector.cons] |
| 184 | + |
| 185 | +TEST(Constructors, SizedDefault) { |
| 186 | + // constexpr explicit inplace_vector(size_type n); |
| 187 | + // Preconditions: T is Cpp17DefaultInsertable into inplace_vector. |
| 188 | + // Effects: Constructs an inplace_vector with n default-inserted elements. |
| 189 | + // Complexity : Linear in n. |
| 190 | + // TODO |
| 191 | + GTEST_SKIP(); |
| 192 | +} |
| 193 | + |
| 194 | +TEST(Constructors, SizedValue) { |
| 195 | + // constexpr inplace_vector(size_type n, const T& value); |
| 196 | + // Preconditions: T is Cpp17CopyInsertable into inplace_vector. |
| 197 | + // Effects: Constructs an inplace_vector with n copies of value. |
| 198 | + // Complexity: Linear in n. |
| 199 | + // TODO |
| 200 | + GTEST_SKIP(); |
| 201 | +} |
| 202 | + |
| 203 | +TEST(Constructors, CopyIter) { |
| 204 | + // template<class InputIterator> |
| 205 | + // constexpr inplace_vector(InputIterator first, InputIterator last); |
| 206 | + // Effects: Constructs an inplace_vector equal to the range [first, last). |
| 207 | + // Complexity: Linear in distance(first, last). |
| 208 | + // TODO |
| 209 | + GTEST_SKIP(); |
| 210 | +} |
| 211 | + |
| 212 | +TEST(Constructors, CopyRanges) { |
| 213 | + // template<container-compatible-range<T> R> |
| 214 | + // constexpr inplace_vector(from_range_t, R&& rg); |
| 215 | + // Effects: Constructs an inplace_vector with the elements of the range rg. |
| 216 | + // Complexity: Linear in ranges::distance(rg). |
| 217 | + // TODO |
| 218 | + GTEST_SKIP(); |
| 219 | +} |
| 220 | + |
| 221 | +// 23.3.14.3 Size and capacity [inplace.vector.capacity] |
| 222 | +// TODO |
| 223 | + |
| 224 | +// 23.3.14.4 Data [inplace.vector.data] |
| 225 | +// TODO |
| 226 | + |
| 227 | +// 23.3.14.5 Modifiers [inplace.vector.modifiers] |
| 228 | +// TODO |
| 229 | + |
| 230 | +// 23.3.14.6 Erasure [inplace.vector.erasure] |
| 231 | +// TODO |
0 commit comments