blob: e41a006ebef0c6cb790ab46efd47680fec2d2bb1 [file] [log] [blame]
Wyatt Hepler64c165e2020-01-13 10:21:08 -08001// Copyright 2020 The Pigweed Authors
Wyatt Hepler77105652019-11-06 17:50:03 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -08004// use this file except in compliance with the License. You may obtain a copy of
5// the License at
Wyatt Hepler77105652019-11-06 17:50:03 -08006//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Wyatt Hepler1a960942019-11-26 14:13:38 -080012// License for the specific language governing permissions and limitations under
13// the License.
Wyatt Hepler77105652019-11-06 17:50:03 -080014
15// This is the base::span unit test from Chromium, with small modifications.
16// Modifications are noted with "Pigweed:" comments.
17//
18// Original file:
Wyatt Hepler64c165e2020-01-13 10:21:08 -080019// https://chromium.googlesource.com/chromium/src/+/ef71f9c29f0dc6eddae474879c4ca5232ca93a6c/base/containers/span_unittest.cc
Wyatt Hepler77105652019-11-06 17:50:03 -080020//
Wyatt Hepler64c165e2020-01-13 10:21:08 -080021// In order to minimize changes from the original, this file does NOT fully
22// adhere to Pigweed's style guide.
Wyatt Hepler77105652019-11-06 17:50:03 -080023#include "pw_span/span.h"
24
25#include <algorithm>
26#include <cstdint>
27#include <memory>
Wyatt Hepler69a51902020-06-22 10:42:53 -070028#include <span>
Wyatt Hepler77105652019-11-06 17:50:03 -080029#include <string>
30#include <type_traits>
31#include <vector>
32
33#include "gtest/gtest.h"
34
35// Pigweed: gMock matchers are not yet supported.
36#if 0
37using ::testing::ElementsAre;
38using ::testing::Eq;
39using ::testing::Pointwise;
40#endif // 0
41
Wyatt Hepler69a51902020-06-22 10:42:53 -070042namespace std {
Wyatt Hepler77105652019-11-06 17:50:03 -080043
44namespace {
45
46// constexpr implementation of std::equal's 4 argument overload.
47template <class InputIterator1, class InputIterator2>
48constexpr bool constexpr_equal(InputIterator1 first1,
49 InputIterator1 last1,
50 InputIterator2 first2,
51 InputIterator2 last2) {
52 for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
53 if (*first1 != *first2)
54 return false;
55 }
56
57 return first1 == last1 && first2 == last2;
58}
59
60} // namespace
61
Wyatt Hepler69a51902020-06-22 10:42:53 -070062// TODO(hepler): Remove these tests after eliminating pw::span.
63TEST(StdSpanCompatibility, ConstructFromPwSpanToStdSpan) {
64 char array[] = {'a', 'b', 'c', 'd', '\0'};
65
66 ::pw::span pw_span(array);
67 std::span std_span(pw_span);
68
69 std_span[0] = '!';
70 EXPECT_STREQ(std_span.data(), "!bcd");
71
72 EXPECT_EQ(pw_span.data(), std_span.data());
73 EXPECT_EQ(pw_span.size(), std_span.size());
74}
75
76TEST(StdSpanCompatibility, ConstructFromStdSpanToPwSpan) {
77 char array[] = {'a', 'b', 'c', 'd', '\0'};
78
79 std::span std_span(array);
80 ::pw::span pw_span(std_span);
81
82 pw_span[0] = '!';
83 EXPECT_STREQ(pw_span.data(), "!bcd");
84
85 EXPECT_EQ(pw_span.data(), std_span.data());
86 EXPECT_EQ(pw_span.size(), std_span.size());
87}
88
89TEST(StdSpanCompatibility, AssignFromPwSpanToStdSpan) {
90 char array[] = {'a', 'b', 'c', 'd', '\0'};
91
92 auto pw_span = ::pw::span(array);
93 std::span std_span = pw_span;
94
95 std_span[0] = '!';
96 EXPECT_STREQ(std_span.data(), "!bcd");
97
98 EXPECT_EQ(pw_span.data(), std_span.data());
99 EXPECT_EQ(pw_span.size(), std_span.size());
100}
101
102TEST(StdSpanCompatibility, AssignFromStdSpanToPwSpan) {
103 char array[] = {'a', 'b', 'c', 'd', '\0'};
104
105 auto std_span = std::span(array);
106 ::pw::span pw_span = std_span;
107
108 pw_span[0] = '!';
109 EXPECT_STREQ(pw_span.data(), "!bcd");
110
111 EXPECT_EQ(pw_span.data(), std_span.data());
112 EXPECT_EQ(pw_span.size(), std_span.size());
113}
114
Wyatt Hepler83d42482019-11-19 15:17:33 -0800115TEST(SpanTest, DeductionGuides_MutableArray) {
116 char array[] = {'a', 'b', 'c', 'd', '\0'};
117
118 auto the_span = span(array);
119 static_assert(the_span.extent == 5u);
120 static_assert(the_span.size() == 5u);
121
122 the_span[0] = '!';
123 EXPECT_STREQ(the_span.data(), "!bcd");
124}
125
126TEST(SpanTest, DeductionGuides_ConstArray) {
127 static constexpr char array[] = {'a', 'b', 'c', 'd', '\0'};
128
129 constexpr auto the_span = span(array);
130 static_assert(the_span.extent == 5u);
131 static_assert(the_span.size() == 5u);
132
133 EXPECT_STREQ(the_span.data(), "abcd");
134}
135
136TEST(SpanTest, DeductionGuides_MutableStdArray) {
137 std::array<char, 5> array{'a', 'b', 'c', 'd'};
138
139 auto the_span = span(array);
140 static_assert(the_span.extent == 5u);
141 static_assert(the_span.size() == 5u);
142
143 the_span[0] = '?';
144 EXPECT_STREQ(the_span.data(), "?bcd");
145}
146
147TEST(SpanTest, DeductionGuides_ConstStdArray) {
148 static constexpr std::array<char, 5> array{'a', 'b', 'c', 'd'};
149
150 constexpr auto the_span = span(array);
151 static_assert(the_span.extent == 5u);
152 static_assert(the_span.size() == 5u);
153
154 EXPECT_STREQ(the_span.data(), "abcd");
155}
156
Wyatt Hepler1cb06df2020-01-31 10:01:12 -0800157TEST(SpanTest, DeductionGuides_MutableContainerWithConstElements) {
158 std::string_view string("Hello");
159 auto the_span = span(string);
Wyatt Hepler83d42482019-11-19 15:17:33 -0800160 static_assert(the_span.extent == dynamic_extent);
161
162 EXPECT_STREQ("Hello", the_span.data());
163 EXPECT_EQ(5u, the_span.size());
164}
165
Wyatt Hepler1cb06df2020-01-31 10:01:12 -0800166TEST(SpanTest, DeductionGuides_MutableContainerWithMutableElements) {
167 std::string string("Hello");
168 auto the_span = span(string);
169 static_assert(the_span.extent == dynamic_extent);
170
171 EXPECT_EQ(5u, the_span.size());
172 the_span[1] = 'a';
173 EXPECT_STREQ(the_span.data(), string.data());
174 EXPECT_STREQ("Hallo", the_span.data());
175}
176
177class MutableStringView {
178 public:
179 using element_type = char;
180 using value_type = char;
181 using size_type = size_t;
182 using difference_type = ptrdiff_t;
183 using pointer = char*;
184 using reference = char&;
185 using iterator = char*;
186 using const_iterator = const char*;
187 using reverse_iterator = std::reverse_iterator<iterator>;
188 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
189
190 MutableStringView(char* str) : data_(str, std::strlen(str)) {}
191
192 char& operator[](size_type index) const { return data_[index]; }
193 pointer data() const { return data_.data(); }
194 size_type size() const { return data_.size(); }
195 iterator begin() const { return data_.begin(); }
196 iterator end() const { return data_.end(); }
197
198 private:
199 span<char> data_;
200};
201
202TEST(SpanTest, DeductionGuides_ConstContainerWithMutableElements) {
203 char data[] = "54321";
204 MutableStringView view(data);
205
206 auto the_span = span(view);
207 static_assert(the_span.extent == dynamic_extent);
208
209 EXPECT_EQ(5u, the_span.size());
210 view[2] = '?';
211 EXPECT_STREQ("54?21", the_span.data());
212 EXPECT_STREQ("54?21", data);
213}
214
215TEST(SpanTest, DeductionGuides_ConstContainerWithMutableValueType) {
216 const std::string string("Hello");
217 auto the_span = span(string);
218 static_assert(the_span.extent == dynamic_extent);
219
220 EXPECT_EQ(5u, the_span.size());
221 EXPECT_STREQ("Hello", the_span.data());
222}
223
224TEST(SpanTest, DeductionGuides_ConstContainerWithConstElements) {
225 const std::string_view string("Hello");
226 auto the_span = span(string);
227 static_assert(the_span.extent == dynamic_extent);
228
229 EXPECT_EQ(5u, the_span.size());
230 EXPECT_STREQ("Hello", the_span.data());
231}
232
233TEST(SpanTest, DeductionGuides_FromTemporary_ContainerWithConstElements) {
234 auto the_span = span(std::string_view("Hello"));
235 static_assert(the_span.extent == dynamic_extent);
236
237 EXPECT_EQ(5u, the_span.size());
238 EXPECT_STREQ("Hello", the_span.data());
239}
240
241TEST(SpanTest, DeductionGuides_FromReference) {
242 std::array<int, 5> array{1, 3, 5, 7, 9};
243 std::array<int, 5>& array_ref = array;
244
245 auto the_span = span(array_ref);
246 static_assert(the_span.extent == 5);
247
248 for (unsigned i = 0; i < array.size(); ++i) {
249 ASSERT_EQ(array[i], the_span[i]);
250 }
251}
252
253TEST(SpanTest, DeductionGuides_FromConstReference) {
254 std::string_view string = "yo!";
255 const std::string_view& string_ref = string;
256
257 auto the_span = span(string_ref);
258 static_assert(the_span.extent == dynamic_extent);
259
260 EXPECT_EQ(string, the_span.data());
261}
262
Wyatt Hepler77105652019-11-06 17:50:03 -0800263TEST(SpanTest, DefaultConstructor) {
264 span<int> dynamic_span;
265 EXPECT_EQ(nullptr, dynamic_span.data());
266 EXPECT_EQ(0u, dynamic_span.size());
267
268 constexpr span<int, 0> static_span;
269 static_assert(nullptr == static_span.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800270 static_assert(static_span.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800271}
272
273TEST(SpanTest, ConstructFromDataAndSize) {
274 constexpr span<int> empty_span(nullptr, 0);
275 EXPECT_TRUE(empty_span.empty());
276 EXPECT_EQ(nullptr, empty_span.data());
277
278 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
279
280 span<int> dynamic_span(vector.data(), vector.size());
281 EXPECT_EQ(vector.data(), dynamic_span.data());
282 EXPECT_EQ(vector.size(), dynamic_span.size());
283
284 for (size_t i = 0; i < dynamic_span.size(); ++i)
285 EXPECT_EQ(vector[i], dynamic_span[i]);
286
287 span<int, 6> static_span(vector.data(), vector.size());
288 EXPECT_EQ(vector.data(), static_span.data());
289 EXPECT_EQ(vector.size(), static_span.size());
290
291 for (size_t i = 0; i < static_span.size(); ++i)
292 EXPECT_EQ(vector[i], static_span[i]);
293}
294
295TEST(SpanTest, ConstructFromPointerPair) {
296 constexpr span<int> empty_span(nullptr, nullptr);
297 EXPECT_TRUE(empty_span.empty());
298 EXPECT_EQ(nullptr, empty_span.data());
299
300 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
301
302 span<int> dynamic_span(vector.data(), vector.data() + vector.size() / 2);
303 EXPECT_EQ(vector.data(), dynamic_span.data());
304 EXPECT_EQ(vector.size() / 2, dynamic_span.size());
305
306 for (size_t i = 0; i < dynamic_span.size(); ++i)
307 EXPECT_EQ(vector[i], dynamic_span[i]);
308
309 span<int, 3> static_span(vector.data(), vector.data() + vector.size() / 2);
310 EXPECT_EQ(vector.data(), static_span.data());
311 EXPECT_EQ(vector.size() / 2, static_span.size());
312
313 for (size_t i = 0; i < static_span.size(); ++i)
314 EXPECT_EQ(vector[i], static_span[i]);
315}
316
Wyatt Hepler3a3ec582020-03-13 10:05:12 -0700317TEST(SpanTest, AllowedConversionsFromStdArray) {
318 // In the following assertions we use std::is_convertible_v<From, To>, which
319 // for non-void types is equivalent to checking whether the following
320 // expression is well-formed:
321 //
322 // T obj = std::declval<From>();
323 //
324 // In particular we are checking whether From is implicitly convertible to To,
325 // which also implies that To is explicitly constructible from From.
326 static_assert(
327 std::is_convertible<std::array<int, 3>&, span<int>>::value,
328 "Error: l-value reference to std::array<int> should be convertible to "
329 "span<int> with dynamic extent.");
330 static_assert(
331 std::is_convertible<std::array<int, 3>&, span<int, 3>>::value,
332 "Error: l-value reference to std::array<int> should be convertible to "
333 "span<int> with the same static extent.");
334 static_assert(
335 std::is_convertible<std::array<int, 3>&, span<const int>>::value,
336 "Error: l-value reference to std::array<int> should be convertible to "
337 "span<const int> with dynamic extent.");
338 static_assert(
339 std::is_convertible<std::array<int, 3>&, span<const int, 3>>::value,
340 "Error: l-value reference to std::array<int> should be convertible to "
341 "span<const int> with the same static extent.");
342 static_assert(
343 std::is_convertible<const std::array<int, 3>&, span<const int>>::value,
344 "Error: const l-value reference to std::array<int> should be "
345 "convertible to span<const int> with dynamic extent.");
346 static_assert(
347 std::is_convertible<const std::array<int, 3>&, span<const int, 3>>::value,
348 "Error: const l-value reference to std::array<int> should be convertible "
349 "to span<const int> with the same static extent.");
350 static_assert(
351 std::is_convertible<std::array<const int, 3>&, span<const int>>::value,
352 "Error: l-value reference to std::array<const int> should be "
353 "convertible to span<const int> with dynamic extent.");
354 static_assert(
355 std::is_convertible<std::array<const int, 3>&, span<const int, 3>>::value,
356 "Error: l-value reference to std::array<const int> should be convertible "
357 "to span<const int> with the same static extent.");
358 static_assert(
359 std::is_convertible<const std::array<const int, 3>&,
360 span<const int>>::value,
361 "Error: const l-value reference to std::array<const int> should be "
362 "convertible to span<const int> with dynamic extent.");
363 static_assert(
364 std::is_convertible<const std::array<const int, 3>&,
365 span<const int, 3>>::value,
366 "Error: const l-value reference to std::array<const int> should be "
367 "convertible to span<const int> with the same static extent.");
368}
369
370TEST(SpanTest, DisallowedConstructionsFromStdArray) {
371 // In the following assertions we use !std::is_constructible_v<T, Args>, which
372 // is equivalent to checking whether the following expression is malformed:
373 //
374 // T obj(std::declval<Args>()...);
375 //
376 // In particular we are checking that T is not explicitly constructible from
377 // Args, which also implies that T is not implicitly constructible from Args
378 // as well.
379 static_assert(
380 !std::is_constructible<span<int>, const std::array<int, 3>&>::value,
381 "Error: span<int> with dynamic extent should not be constructible "
382 "from const l-value reference to std::array<int>");
383
384 static_assert(
385 !std::is_constructible<span<int>, std::array<const int, 3>&>::value,
386 "Error: span<int> with dynamic extent should not be constructible "
387 "from l-value reference to std::array<const int>");
388
389 static_assert(
390 !std::is_constructible<span<int>, const std::array<const int, 3>&>::value,
391 "Error: span<int> with dynamic extent should not be constructible "
392 "const from l-value reference to std::array<const int>");
393
394 static_assert(
395 !std::is_constructible<span<int, 2>, std::array<int, 3>&>::value,
396 "Error: span<int> with static extent should not be constructible "
397 "from l-value reference to std::array<int> with different extent");
398
399 static_assert(
400 !std::is_constructible<span<int, 4>, std::array<int, 3>&>::value,
401 "Error: span<int> with dynamic extent should not be constructible "
402 "from l-value reference to std::array<int> with different extent");
403
404 static_assert(
405 !std::is_constructible<span<int>, std::array<bool, 3>&>::value,
406 "Error: span<int> with dynamic extent should not be constructible "
407 "from l-value reference to std::array<bool>");
408}
409
Wyatt Hepler77105652019-11-06 17:50:03 -0800410TEST(SpanTest, ConstructFromConstexprArray) {
411 static constexpr int kArray[] = {5, 4, 3, 2, 1};
412
413 constexpr span<const int> dynamic_span(kArray);
414 static_assert(kArray == dynamic_span.data(), "");
415 static_assert(std::size(kArray) == dynamic_span.size(), "");
416
417 static_assert(kArray[0] == dynamic_span[0], "");
418 static_assert(kArray[1] == dynamic_span[1], "");
419 static_assert(kArray[2] == dynamic_span[2], "");
420 static_assert(kArray[3] == dynamic_span[3], "");
421 static_assert(kArray[4] == dynamic_span[4], "");
422
423 constexpr span<const int, std::size(kArray)> static_span(kArray);
424 static_assert(kArray == static_span.data(), "");
425 static_assert(std::size(kArray) == static_span.size(), "");
426
427 static_assert(kArray[0] == static_span[0], "");
428 static_assert(kArray[1] == static_span[1], "");
429 static_assert(kArray[2] == static_span[2], "");
430 static_assert(kArray[3] == static_span[3], "");
431 static_assert(kArray[4] == static_span[4], "");
432}
433
434TEST(SpanTest, ConstructFromArray) {
435 int array[] = {5, 4, 3, 2, 1};
436
437 span<const int> const_span(array);
438 EXPECT_EQ(array, const_span.data());
439 EXPECT_EQ(std::size(array), const_span.size());
440 for (size_t i = 0; i < const_span.size(); ++i)
441 EXPECT_EQ(array[i], const_span[i]);
442
443 span<int> dynamic_span(array);
444 EXPECT_EQ(array, dynamic_span.data());
445 EXPECT_EQ(std::size(array), dynamic_span.size());
446 for (size_t i = 0; i < dynamic_span.size(); ++i)
447 EXPECT_EQ(array[i], dynamic_span[i]);
448
449 span<int, std::size(array)> static_span(array);
450 EXPECT_EQ(array, static_span.data());
451 EXPECT_EQ(std::size(array), static_span.size());
452 for (size_t i = 0; i < static_span.size(); ++i)
453 EXPECT_EQ(array[i], static_span[i]);
454}
455
456TEST(SpanTest, ConstructFromStdArray) {
457 // Note: Constructing a constexpr span from a constexpr std::array does not
458 // work prior to C++17 due to non-constexpr std::array::data.
459 std::array<int, 5> array = {{5, 4, 3, 2, 1}};
460
461 span<const int> const_span(array);
462 EXPECT_EQ(array.data(), const_span.data());
463 EXPECT_EQ(array.size(), const_span.size());
464 for (size_t i = 0; i < const_span.size(); ++i)
465 EXPECT_EQ(array[i], const_span[i]);
466
467 span<int> dynamic_span(array);
468 EXPECT_EQ(array.data(), dynamic_span.data());
469 EXPECT_EQ(array.size(), dynamic_span.size());
470 for (size_t i = 0; i < dynamic_span.size(); ++i)
471 EXPECT_EQ(array[i], dynamic_span[i]);
472
473 span<int, std::size(array)> static_span(array);
474 EXPECT_EQ(array.data(), static_span.data());
475 EXPECT_EQ(array.size(), static_span.size());
476 for (size_t i = 0; i < static_span.size(); ++i)
477 EXPECT_EQ(array[i], static_span[i]);
478}
479
480TEST(SpanTest, ConstructFromInitializerList) {
481 std::initializer_list<int> il = {1, 1, 2, 3, 5, 8};
482
483 span<const int> const_span(il);
484 EXPECT_EQ(il.begin(), const_span.data());
485 EXPECT_EQ(il.size(), const_span.size());
486
487 for (size_t i = 0; i < const_span.size(); ++i)
488 EXPECT_EQ(il.begin()[i], const_span[i]);
489
490 span<const int, 6> static_span(il.begin(), il.end());
491 EXPECT_EQ(il.begin(), static_span.data());
492 EXPECT_EQ(il.size(), static_span.size());
493
494 for (size_t i = 0; i < static_span.size(); ++i)
495 EXPECT_EQ(il.begin()[i], static_span[i]);
496}
497
498TEST(SpanTest, ConstructFromStdString) {
499 std::string str = "foobar";
500
501 span<const char> const_span(str);
502 EXPECT_EQ(str.data(), const_span.data());
503 EXPECT_EQ(str.size(), const_span.size());
504
505 for (size_t i = 0; i < const_span.size(); ++i)
506 EXPECT_EQ(str[i], const_span[i]);
507
508 span<char> dynamic_span(str);
509 EXPECT_EQ(str.data(), dynamic_span.data());
510 EXPECT_EQ(str.size(), dynamic_span.size());
511
512 for (size_t i = 0; i < dynamic_span.size(); ++i)
513 EXPECT_EQ(str[i], dynamic_span[i]);
514
515 span<char, 6> static_span(data(str), str.size());
516 EXPECT_EQ(str.data(), static_span.data());
517 EXPECT_EQ(str.size(), static_span.size());
518
519 for (size_t i = 0; i < static_span.size(); ++i)
520 EXPECT_EQ(str[i], static_span[i]);
521}
522
523TEST(SpanTest, ConstructFromConstContainer) {
524 const std::vector<int> vector = {1, 1, 2, 3, 5, 8};
525
526 span<const int> const_span(vector);
527 EXPECT_EQ(vector.data(), const_span.data());
528 EXPECT_EQ(vector.size(), const_span.size());
529
530 for (size_t i = 0; i < const_span.size(); ++i)
531 EXPECT_EQ(vector[i], const_span[i]);
532
533 span<const int, 6> static_span(vector.data(), vector.size());
534 EXPECT_EQ(vector.data(), static_span.data());
535 EXPECT_EQ(vector.size(), static_span.size());
536
537 for (size_t i = 0; i < static_span.size(); ++i)
538 EXPECT_EQ(vector[i], static_span[i]);
539}
540
541TEST(SpanTest, ConstructFromContainer) {
542 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
543
544 span<const int> const_span(vector);
545 EXPECT_EQ(vector.data(), const_span.data());
546 EXPECT_EQ(vector.size(), const_span.size());
547
548 for (size_t i = 0; i < const_span.size(); ++i)
549 EXPECT_EQ(vector[i], const_span[i]);
550
551 span<int> dynamic_span(vector);
552 EXPECT_EQ(vector.data(), dynamic_span.data());
553 EXPECT_EQ(vector.size(), dynamic_span.size());
554
555 for (size_t i = 0; i < dynamic_span.size(); ++i)
556 EXPECT_EQ(vector[i], dynamic_span[i]);
557
558 span<int, 6> static_span(vector.data(), vector.size());
559 EXPECT_EQ(vector.data(), static_span.data());
560 EXPECT_EQ(vector.size(), static_span.size());
561
562 for (size_t i = 0; i < static_span.size(); ++i)
563 EXPECT_EQ(vector[i], static_span[i]);
564}
565
566#if 0
567
568// Pigweed: gMock matchers are not yet supported.
569TEST(SpanTest, ConvertNonConstIntegralToConst) {
570 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
571
572 span<int> int_span(vector.data(), vector.size());
573 span<const int> const_span(int_span);
574 EXPECT_EQ(int_span.size(), const_span.size());
575
576 EXPECT_THAT(const_span, Pointwise(Eq(), int_span));
577
578 span<int, 6> static_int_span(vector.data(), vector.size());
579 span<const int, 6> static_const_span(static_int_span);
580 EXPECT_THAT(static_const_span, Pointwise(Eq(), static_int_span));
581}
582
583// Pigweed: gMock matchers are not yet supported.
584TEST(SpanTest, ConvertNonConstPointerToConst) {
585 auto a = std::make_unique<int>(11);
586 auto b = std::make_unique<int>(22);
587 auto c = std::make_unique<int>(33);
588 std::vector<int*> vector = {a.get(), b.get(), c.get()};
589
590 span<int*> non_const_pointer_span(vector);
591 EXPECT_THAT(non_const_pointer_span, Pointwise(Eq(), vector));
592 span<int* const> const_pointer_span(non_const_pointer_span);
593 EXPECT_THAT(const_pointer_span, Pointwise(Eq(), non_const_pointer_span));
594 // Note: no test for conversion from span<int> to span<const int*>, since that
595 // would imply a conversion from int** to const int**, which is unsafe.
596 //
597 // Note: no test for conversion from span<int*> to span<const int* const>,
598 // due to CWG Defect 330:
599 // http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#330
600
601 span<int*, 3> static_non_const_pointer_span(vector.data(), vector.size());
602 EXPECT_THAT(static_non_const_pointer_span, Pointwise(Eq(), vector));
603 span<int* const, 3> static_const_pointer_span(static_non_const_pointer_span);
604 EXPECT_THAT(static_const_pointer_span,
605 Pointwise(Eq(), static_non_const_pointer_span));
606}
607
608// Pigweed: This test does not work on platforms where int32_t is long int.
609TEST(SpanTest, ConvertBetweenEquivalentTypes) {
610 std::vector<int32_t> vector = {2, 4, 8, 16, 32};
611
612 span<int32_t> int32_t_span(vector);
613 span<int> converted_span(int32_t_span);
614 EXPECT_EQ(int32_t_span.data(), converted_span.data());
615 EXPECT_EQ(int32_t_span.size(), converted_span.size());
616
617 span<int32_t, 5> static_int32_t_span(vector.data(), vector.size());
618 span<int, 5> static_converted_span(static_int32_t_span);
619 EXPECT_EQ(static_int32_t_span.data(), static_converted_span.data());
620 EXPECT_EQ(static_int32_t_span.size(), static_converted_span.size());
621}
622
623#endif // 0
624
625TEST(SpanTest, TemplatedFirst) {
626 static constexpr int array[] = {1, 2, 3};
627 constexpr span<const int, 3> span(array);
628
629 {
630 constexpr auto subspan = span.first<0>();
631 static_assert(span.data() == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800632 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800633 static_assert(0u == decltype(subspan)::extent, "");
634 }
635
636 {
637 constexpr auto subspan = span.first<1>();
638 static_assert(span.data() == subspan.data(), "");
639 static_assert(1u == subspan.size(), "");
640 static_assert(1u == decltype(subspan)::extent, "");
641 static_assert(1 == subspan[0], "");
642 }
643
644 {
645 constexpr auto subspan = span.first<2>();
646 static_assert(span.data() == subspan.data(), "");
647 static_assert(2u == subspan.size(), "");
648 static_assert(2u == decltype(subspan)::extent, "");
649 static_assert(1 == subspan[0], "");
650 static_assert(2 == subspan[1], "");
651 }
652
653 {
654 constexpr auto subspan = span.first<3>();
655 static_assert(span.data() == subspan.data(), "");
656 static_assert(3u == subspan.size(), "");
657 static_assert(3u == decltype(subspan)::extent, "");
658 static_assert(1 == subspan[0], "");
659 static_assert(2 == subspan[1], "");
660 static_assert(3 == subspan[2], "");
661 }
662}
663
664TEST(SpanTest, TemplatedLast) {
665 static constexpr int array[] = {1, 2, 3};
666 constexpr span<const int, 3> span(array);
667
668 {
669 constexpr auto subspan = span.last<0>();
670 static_assert(span.data() + 3 == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800671 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800672 static_assert(0u == decltype(subspan)::extent, "");
673 }
674
675 {
676 constexpr auto subspan = span.last<1>();
677 static_assert(span.data() + 2 == subspan.data(), "");
678 static_assert(1u == subspan.size(), "");
679 static_assert(1u == decltype(subspan)::extent, "");
680 static_assert(3 == subspan[0], "");
681 }
682
683 {
684 constexpr auto subspan = span.last<2>();
685 static_assert(span.data() + 1 == subspan.data(), "");
686 static_assert(2u == subspan.size(), "");
687 static_assert(2u == decltype(subspan)::extent, "");
688 static_assert(2 == subspan[0], "");
689 static_assert(3 == subspan[1], "");
690 }
691
692 {
693 constexpr auto subspan = span.last<3>();
694 static_assert(span.data() == subspan.data(), "");
695 static_assert(3u == subspan.size(), "");
696 static_assert(3u == decltype(subspan)::extent, "");
697 static_assert(1 == subspan[0], "");
698 static_assert(2 == subspan[1], "");
699 static_assert(3 == subspan[2], "");
700 }
701}
702
703TEST(SpanTest, TemplatedSubspan) {
704 static constexpr int array[] = {1, 2, 3};
705 constexpr span<const int, 3> span(array);
706
707 {
708 constexpr auto subspan = span.subspan<0>();
709 static_assert(span.data() == subspan.data(), "");
710 static_assert(3u == subspan.size(), "");
711 static_assert(3u == decltype(subspan)::extent, "");
712 static_assert(1 == subspan[0], "");
713 static_assert(2 == subspan[1], "");
714 static_assert(3 == subspan[2], "");
715 }
716
717 {
718 constexpr auto subspan = span.subspan<1>();
719 static_assert(span.data() + 1 == subspan.data(), "");
720 static_assert(2u == subspan.size(), "");
721 static_assert(2u == decltype(subspan)::extent, "");
722 static_assert(2 == subspan[0], "");
723 static_assert(3 == subspan[1], "");
724 }
725
726 {
727 constexpr auto subspan = span.subspan<2>();
728 static_assert(span.data() + 2 == subspan.data(), "");
729 static_assert(1u == subspan.size(), "");
730 static_assert(1u == decltype(subspan)::extent, "");
731 static_assert(3 == subspan[0], "");
732 }
733
734 {
735 constexpr auto subspan = span.subspan<3>();
736 static_assert(span.data() + 3 == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800737 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800738 static_assert(0u == decltype(subspan)::extent, "");
739 }
740
741 {
742 constexpr auto subspan = span.subspan<0, 0>();
743 static_assert(span.data() == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800744 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800745 static_assert(0u == decltype(subspan)::extent, "");
746 }
747
748 {
749 constexpr auto subspan = span.subspan<1, 0>();
750 static_assert(span.data() + 1 == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800751 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800752 static_assert(0u == decltype(subspan)::extent, "");
753 }
754
755 {
756 constexpr auto subspan = span.subspan<2, 0>();
757 static_assert(span.data() + 2 == subspan.data(), "");
Rob Mohrcd59b7e2019-11-19 09:54:45 -0800758 static_assert(subspan.empty(), "");
Wyatt Hepler77105652019-11-06 17:50:03 -0800759 static_assert(0u == decltype(subspan)::extent, "");
760 }
761
762 {
763 constexpr auto subspan = span.subspan<0, 1>();
764 static_assert(span.data() == subspan.data(), "");
765 static_assert(1u == subspan.size(), "");
766 static_assert(1u == decltype(subspan)::extent, "");
767 static_assert(1 == subspan[0], "");
768 }
769
770 {
771 constexpr auto subspan = span.subspan<1, 1>();
772 static_assert(span.data() + 1 == subspan.data(), "");
773 static_assert(1u == subspan.size(), "");
774 static_assert(1u == decltype(subspan)::extent, "");
775 static_assert(2 == subspan[0], "");
776 }
777
778 {
779 constexpr auto subspan = span.subspan<2, 1>();
780 static_assert(span.data() + 2 == subspan.data(), "");
781 static_assert(1u == subspan.size(), "");
782 static_assert(1u == decltype(subspan)::extent, "");
783 static_assert(3 == subspan[0], "");
784 }
785
786 {
787 constexpr auto subspan = span.subspan<0, 2>();
788 static_assert(span.data() == subspan.data(), "");
789 static_assert(2u == subspan.size(), "");
790 static_assert(2u == decltype(subspan)::extent, "");
791 static_assert(1 == subspan[0], "");
792 static_assert(2 == subspan[1], "");
793 }
794
795 {
796 constexpr auto subspan = span.subspan<1, 2>();
797 static_assert(span.data() + 1 == subspan.data(), "");
798 static_assert(2u == subspan.size(), "");
799 static_assert(2u == decltype(subspan)::extent, "");
800 static_assert(2 == subspan[0], "");
801 static_assert(3 == subspan[1], "");
802 }
803
804 {
805 constexpr auto subspan = span.subspan<0, 3>();
806 static_assert(span.data() == subspan.data(), "");
807 static_assert(3u == subspan.size(), "");
808 static_assert(3u == decltype(subspan)::extent, "");
809 static_assert(1 == subspan[0], "");
810 static_assert(2 == subspan[1], "");
811 static_assert(3 == subspan[2], "");
812 }
813}
814
815TEST(SpanTest, SubscriptedBeginIterator) {
816 int array[] = {1, 2, 3};
817 span<const int> const_span(array);
818 for (size_t i = 0; i < const_span.size(); ++i)
819 EXPECT_EQ(array[i], const_span.begin()[i]);
820
821 span<int> mutable_span(array);
822 for (size_t i = 0; i < mutable_span.size(); ++i)
823 EXPECT_EQ(array[i], mutable_span.begin()[i]);
824}
825
826TEST(SpanTest, TemplatedFirstOnDynamicSpan) {
827 int array[] = {1, 2, 3};
828 span<const int> span(array);
829
830 {
831 auto subspan = span.first<0>();
832 EXPECT_EQ(span.data(), subspan.data());
833 EXPECT_EQ(0u, subspan.size());
834 static_assert(0u == decltype(subspan)::extent, "");
835 }
836
837 {
838 auto subspan = span.first<1>();
839 EXPECT_EQ(span.data(), subspan.data());
840 EXPECT_EQ(1u, subspan.size());
841 static_assert(1u == decltype(subspan)::extent, "");
842 EXPECT_EQ(1, subspan[0]);
843 }
844
845 {
846 auto subspan = span.first<2>();
847 EXPECT_EQ(span.data(), subspan.data());
848 EXPECT_EQ(2u, subspan.size());
849 static_assert(2u == decltype(subspan)::extent, "");
850 EXPECT_EQ(1, subspan[0]);
851 EXPECT_EQ(2, subspan[1]);
852 }
853
854 {
855 auto subspan = span.first<3>();
856 EXPECT_EQ(span.data(), subspan.data());
857 EXPECT_EQ(3u, subspan.size());
858 static_assert(3u == decltype(subspan)::extent, "");
859 EXPECT_EQ(1, subspan[0]);
860 EXPECT_EQ(2, subspan[1]);
861 EXPECT_EQ(3, subspan[2]);
862 }
863}
864
865TEST(SpanTest, TemplatedLastOnDynamicSpan) {
866 int array[] = {1, 2, 3};
867 span<int> span(array);
868
869 {
870 auto subspan = span.last<0>();
871 EXPECT_EQ(span.data() + 3, subspan.data());
872 EXPECT_EQ(0u, subspan.size());
873 static_assert(0u == decltype(subspan)::extent, "");
874 }
875
876 {
877 auto subspan = span.last<1>();
878 EXPECT_EQ(span.data() + 2, subspan.data());
879 EXPECT_EQ(1u, subspan.size());
880 static_assert(1u == decltype(subspan)::extent, "");
881 EXPECT_EQ(3, subspan[0]);
882 }
883
884 {
885 auto subspan = span.last<2>();
886 EXPECT_EQ(span.data() + 1, subspan.data());
887 EXPECT_EQ(2u, subspan.size());
888 static_assert(2u == decltype(subspan)::extent, "");
889 EXPECT_EQ(2, subspan[0]);
890 EXPECT_EQ(3, subspan[1]);
891 }
892
893 {
894 auto subspan = span.last<3>();
895 EXPECT_EQ(span.data(), subspan.data());
896 EXPECT_EQ(3u, subspan.size());
897 static_assert(3u == decltype(subspan)::extent, "");
898 EXPECT_EQ(1, subspan[0]);
899 EXPECT_EQ(2, subspan[1]);
900 EXPECT_EQ(3, subspan[2]);
901 }
902}
903
904TEST(SpanTest, TemplatedSubspanFromDynamicSpan) {
905 int array[] = {1, 2, 3};
906 span<int, 3> span(array);
907
908 {
909 auto subspan = span.subspan<0>();
910 EXPECT_EQ(span.data(), subspan.data());
911 static_assert(3u == decltype(subspan)::extent, "");
912 EXPECT_EQ(3u, subspan.size());
913 EXPECT_EQ(1, subspan[0]);
914 EXPECT_EQ(2, subspan[1]);
915 EXPECT_EQ(3, subspan[2]);
916 }
917
918 {
919 auto subspan = span.subspan<1>();
920 EXPECT_EQ(span.data() + 1, subspan.data());
921 EXPECT_EQ(2u, subspan.size());
922 static_assert(2u == decltype(subspan)::extent, "");
923 EXPECT_EQ(2, subspan[0]);
924 EXPECT_EQ(3, subspan[1]);
925 }
926
927 {
928 auto subspan = span.subspan<2>();
929 EXPECT_EQ(span.data() + 2, subspan.data());
930 EXPECT_EQ(1u, subspan.size());
931 static_assert(1u == decltype(subspan)::extent, "");
932 EXPECT_EQ(3, subspan[0]);
933 }
934
935 {
936 auto subspan = span.subspan<3>();
937 EXPECT_EQ(span.data() + 3, subspan.data());
938 EXPECT_EQ(0u, subspan.size());
939 static_assert(0u == decltype(subspan)::extent, "");
940 }
941
942 {
943 auto subspan = span.subspan<0, 0>();
944 EXPECT_EQ(span.data(), subspan.data());
945 EXPECT_EQ(0u, subspan.size());
946 static_assert(0u == decltype(subspan)::extent, "");
947 }
948
949 {
950 auto subspan = span.subspan<1, 0>();
951 EXPECT_EQ(span.data() + 1, subspan.data());
952 EXPECT_EQ(0u, subspan.size());
953 static_assert(0u == decltype(subspan)::extent, "");
954 }
955
956 {
957 auto subspan = span.subspan<2, 0>();
958 EXPECT_EQ(span.data() + 2, subspan.data());
959 EXPECT_EQ(0u, subspan.size());
960 static_assert(0u == decltype(subspan)::extent, "");
961 }
962
963 {
964 auto subspan = span.subspan<0, 1>();
965 EXPECT_EQ(span.data(), subspan.data());
966 EXPECT_EQ(1u, subspan.size());
967 static_assert(1u == decltype(subspan)::extent, "");
968 EXPECT_EQ(1, subspan[0]);
969 }
970
971 {
972 auto subspan = span.subspan<1, 1>();
973 EXPECT_EQ(span.data() + 1, subspan.data());
974 EXPECT_EQ(1u, subspan.size());
975 static_assert(1u == decltype(subspan)::extent, "");
976 EXPECT_EQ(2, subspan[0]);
977 }
978
979 {
980 auto subspan = span.subspan<2, 1>();
981 EXPECT_EQ(span.data() + 2, subspan.data());
982 EXPECT_EQ(1u, subspan.size());
983 static_assert(1u == decltype(subspan)::extent, "");
984 EXPECT_EQ(3, subspan[0]);
985 }
986
987 {
988 auto subspan = span.subspan<0, 2>();
989 EXPECT_EQ(span.data(), subspan.data());
990 EXPECT_EQ(2u, subspan.size());
991 static_assert(2u == decltype(subspan)::extent, "");
992 EXPECT_EQ(1, subspan[0]);
993 EXPECT_EQ(2, subspan[1]);
994 }
995
996 {
997 auto subspan = span.subspan<1, 2>();
998 EXPECT_EQ(span.data() + 1, subspan.data());
999 EXPECT_EQ(2u, subspan.size());
1000 static_assert(2u == decltype(subspan)::extent, "");
1001 EXPECT_EQ(2, subspan[0]);
1002 EXPECT_EQ(3, subspan[1]);
1003 }
1004
1005 {
1006 auto subspan = span.subspan<0, 3>();
1007 EXPECT_EQ(span.data(), subspan.data());
1008 EXPECT_EQ(3u, subspan.size());
1009 static_assert(3u == decltype(subspan)::extent, "");
1010 EXPECT_EQ(1, subspan[0]);
1011 EXPECT_EQ(2, subspan[1]);
1012 EXPECT_EQ(3, subspan[2]);
1013 }
1014}
1015
1016TEST(SpanTest, First) {
1017 int array[] = {1, 2, 3};
1018 span<int> span(array);
1019
1020 {
1021 auto subspan = span.first(0);
1022 EXPECT_EQ(span.data(), subspan.data());
1023 EXPECT_EQ(0u, subspan.size());
1024 }
1025
1026 {
1027 auto subspan = span.first(1);
1028 EXPECT_EQ(span.data(), subspan.data());
1029 EXPECT_EQ(1u, subspan.size());
1030 EXPECT_EQ(1, subspan[0]);
1031 }
1032
1033 {
1034 auto subspan = span.first(2);
1035 EXPECT_EQ(span.data(), subspan.data());
1036 EXPECT_EQ(2u, subspan.size());
1037 EXPECT_EQ(1, subspan[0]);
1038 EXPECT_EQ(2, subspan[1]);
1039 }
1040
1041 {
1042 auto subspan = span.first(3);
1043 EXPECT_EQ(span.data(), subspan.data());
1044 EXPECT_EQ(3u, subspan.size());
1045 EXPECT_EQ(1, subspan[0]);
1046 EXPECT_EQ(2, subspan[1]);
1047 EXPECT_EQ(3, subspan[2]);
1048 }
1049}
1050
1051TEST(SpanTest, Last) {
1052 int array[] = {1, 2, 3};
1053 span<int> span(array);
1054
1055 {
1056 auto subspan = span.last(0);
1057 EXPECT_EQ(span.data() + 3, subspan.data());
1058 EXPECT_EQ(0u, subspan.size());
1059 }
1060
1061 {
1062 auto subspan = span.last(1);
1063 EXPECT_EQ(span.data() + 2, subspan.data());
1064 EXPECT_EQ(1u, subspan.size());
1065 EXPECT_EQ(3, subspan[0]);
1066 }
1067
1068 {
1069 auto subspan = span.last(2);
1070 EXPECT_EQ(span.data() + 1, subspan.data());
1071 EXPECT_EQ(2u, subspan.size());
1072 EXPECT_EQ(2, subspan[0]);
1073 EXPECT_EQ(3, subspan[1]);
1074 }
1075
1076 {
1077 auto subspan = span.last(3);
1078 EXPECT_EQ(span.data(), subspan.data());
1079 EXPECT_EQ(3u, subspan.size());
1080 EXPECT_EQ(1, subspan[0]);
1081 EXPECT_EQ(2, subspan[1]);
1082 EXPECT_EQ(3, subspan[2]);
1083 }
1084}
1085
1086TEST(SpanTest, Subspan) {
1087 int array[] = {1, 2, 3};
1088 span<int> span(array);
1089
1090 {
1091 auto subspan = span.subspan(0);
1092 EXPECT_EQ(span.data(), subspan.data());
1093 EXPECT_EQ(3u, subspan.size());
1094 EXPECT_EQ(1, subspan[0]);
1095 EXPECT_EQ(2, subspan[1]);
1096 EXPECT_EQ(3, subspan[2]);
1097 }
1098
1099 {
1100 auto subspan = span.subspan(1);
1101 EXPECT_EQ(span.data() + 1, subspan.data());
1102 EXPECT_EQ(2u, subspan.size());
1103 EXPECT_EQ(2, subspan[0]);
1104 EXPECT_EQ(3, subspan[1]);
1105 }
1106
1107 {
1108 auto subspan = span.subspan(2);
1109 EXPECT_EQ(span.data() + 2, subspan.data());
1110 EXPECT_EQ(1u, subspan.size());
1111 EXPECT_EQ(3, subspan[0]);
1112 }
1113
1114 {
1115 auto subspan = span.subspan(3);
1116 EXPECT_EQ(span.data() + 3, subspan.data());
1117 EXPECT_EQ(0u, subspan.size());
1118 }
1119
1120 {
1121 auto subspan = span.subspan(0, 0);
1122 EXPECT_EQ(span.data(), subspan.data());
1123 EXPECT_EQ(0u, subspan.size());
1124 }
1125
1126 {
1127 auto subspan = span.subspan(1, 0);
1128 EXPECT_EQ(span.data() + 1, subspan.data());
1129 EXPECT_EQ(0u, subspan.size());
1130 }
1131
1132 {
1133 auto subspan = span.subspan(2, 0);
1134 EXPECT_EQ(span.data() + 2, subspan.data());
1135 EXPECT_EQ(0u, subspan.size());
1136 }
1137
1138 {
1139 auto subspan = span.subspan(0, 1);
1140 EXPECT_EQ(span.data(), subspan.data());
1141 EXPECT_EQ(1u, subspan.size());
1142 EXPECT_EQ(1, subspan[0]);
1143 }
1144
1145 {
1146 auto subspan = span.subspan(1, 1);
1147 EXPECT_EQ(span.data() + 1, subspan.data());
1148 EXPECT_EQ(1u, subspan.size());
1149 EXPECT_EQ(2, subspan[0]);
1150 }
1151
1152 {
1153 auto subspan = span.subspan(2, 1);
1154 EXPECT_EQ(span.data() + 2, subspan.data());
1155 EXPECT_EQ(1u, subspan.size());
1156 EXPECT_EQ(3, subspan[0]);
1157 }
1158
1159 {
1160 auto subspan = span.subspan(0, 2);
1161 EXPECT_EQ(span.data(), subspan.data());
1162 EXPECT_EQ(2u, subspan.size());
1163 EXPECT_EQ(1, subspan[0]);
1164 EXPECT_EQ(2, subspan[1]);
1165 }
1166
1167 {
1168 auto subspan = span.subspan(1, 2);
1169 EXPECT_EQ(span.data() + 1, subspan.data());
1170 EXPECT_EQ(2u, subspan.size());
1171 EXPECT_EQ(2, subspan[0]);
1172 EXPECT_EQ(3, subspan[1]);
1173 }
1174
1175 {
1176 auto subspan = span.subspan(0, 3);
1177 EXPECT_EQ(span.data(), subspan.data());
1178 EXPECT_EQ(span.size(), subspan.size());
1179 EXPECT_EQ(1, subspan[0]);
1180 EXPECT_EQ(2, subspan[1]);
1181 EXPECT_EQ(3, subspan[2]);
1182 }
1183}
1184
1185TEST(SpanTest, Size) {
1186 {
1187 span<int> span;
1188 EXPECT_EQ(0u, span.size());
1189 }
1190
1191 {
1192 int array[] = {1, 2, 3};
1193 span<int> span(array);
1194 EXPECT_EQ(3u, span.size());
1195 }
1196}
1197
1198TEST(SpanTest, SizeBytes) {
1199 {
1200 span<int> span;
1201 EXPECT_EQ(0u, span.size_bytes());
1202 }
1203
1204 {
1205 int array[] = {1, 2, 3};
1206 span<int> span(array);
1207 EXPECT_EQ(3u * sizeof(int), span.size_bytes());
1208 }
1209}
1210
1211TEST(SpanTest, Empty) {
1212 {
1213 span<int> span;
1214 EXPECT_TRUE(span.empty());
1215 }
1216
1217 {
1218 int array[] = {1, 2, 3};
1219 span<int> span(array);
1220 EXPECT_FALSE(span.empty());
1221 }
1222}
1223
1224TEST(SpanTest, OperatorAt) {
1225 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1226 constexpr span<const int> span(kArray);
1227
1228 static_assert(&kArray[0] == &span[0],
1229 "span[0] does not refer to the same element as kArray[0]");
1230 static_assert(&kArray[1] == &span[1],
1231 "span[1] does not refer to the same element as kArray[1]");
1232 static_assert(&kArray[2] == &span[2],
1233 "span[2] does not refer to the same element as kArray[2]");
1234 static_assert(&kArray[3] == &span[3],
1235 "span[3] does not refer to the same element as kArray[3]");
1236 static_assert(&kArray[4] == &span[4],
1237 "span[4] does not refer to the same element as kArray[4]");
1238}
1239
1240TEST(SpanTest, Front) {
1241 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1242 constexpr span<const int> span(kArray);
1243 static_assert(&kArray[0] == &span.front(),
1244 "span.front() does not refer to the same element as kArray[0]");
1245}
1246
1247TEST(SpanTest, Back) {
1248 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1249 constexpr span<const int> span(kArray);
1250 static_assert(&kArray[4] == &span.back(),
1251 "span.back() does not refer to the same element as kArray[4]");
1252}
1253
Wyatt Hepler77105652019-11-06 17:50:03 -08001254// Pigweed: This test uses gMock features not yet supported in Pigweed.
1255#if 0
1256TEST(SpanTest, Iterator) {
1257 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1258 constexpr span<const int> span(kArray);
1259
1260 std::vector<int> results;
1261 for (int i : span)
1262 results.emplace_back(i);
1263 EXPECT_THAT(results, ElementsAre(1, 6, 1, 8, 0));
1264}
1265#endif // 0
1266
1267TEST(SpanTest, ConstexprIterator) {
1268 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1269 constexpr span<const int> span(kArray);
1270
Wyatt Hepler83d42482019-11-19 15:17:33 -08001271 static_assert(
1272 constexpr_equal(
1273 std::begin(kArray), std::end(kArray), span.begin(), span.end()),
1274 "");
Wyatt Hepler77105652019-11-06 17:50:03 -08001275 static_assert(1 == span.begin()[0], "");
1276 // Pigweed: These tests assume an iterator object, but Pigweed's span uses a
1277 // simple pointer.
1278#if 0
1279 static_assert(1 == *(span.begin() += 0), "");
1280 static_assert(6 == *(span.begin() += 1), "");
1281
1282 static_assert(1 == *((span.begin() + 1) -= 1), "");
1283 static_assert(6 == *((span.begin() + 1) -= 0), "");
1284#endif // 0
1285}
1286
1287TEST(SpanTest, ReverseIterator) {
1288 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1289 constexpr span<const int> span(kArray);
1290
Wyatt Hepler83d42482019-11-19 15:17:33 -08001291 EXPECT_TRUE(std::equal(
1292 std::rbegin(kArray), std::rend(kArray), span.rbegin(), span.rend()));
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001293 EXPECT_TRUE(std::equal(std::crbegin(kArray),
1294 std::crend(kArray),
1295 std::crbegin(span),
1296 std::crend(span)));
Wyatt Hepler77105652019-11-06 17:50:03 -08001297}
1298
1299// Pigweed: These are tests for make_span, which is not included in Pigweed's
1300// implementation, since class template deduction is available.
1301#if 0
1302TEST(SpanTest, AsBytes) {
1303 {
1304 constexpr int kArray[] = {2, 3, 5, 7, 11, 13};
1305 span<const uint8_t, sizeof(kArray)> bytes_span =
1306 as_bytes(make_span(kArray));
1307 EXPECT_EQ(reinterpret_cast<const uint8_t*>(kArray), bytes_span.data());
1308 EXPECT_EQ(sizeof(kArray), bytes_span.size());
1309 EXPECT_EQ(bytes_span.size(), bytes_span.size_bytes());
1310 }
1311
1312 {
1313 std::vector<int> vec = {1, 1, 2, 3, 5, 8};
1314 span<int> mutable_span(vec);
1315 span<const uint8_t> bytes_span = as_bytes(mutable_span);
1316 EXPECT_EQ(reinterpret_cast<const uint8_t*>(vec.data()), bytes_span.data());
1317 EXPECT_EQ(sizeof(int) * vec.size(), bytes_span.size());
1318 EXPECT_EQ(bytes_span.size(), bytes_span.size_bytes());
1319 }
1320}
1321
1322TEST(SpanTest, AsWritableBytes) {
1323 std::vector<int> vec = {1, 1, 2, 3, 5, 8};
1324 span<int> mutable_span(vec);
1325 span<uint8_t> writable_bytes_span = as_writable_bytes(mutable_span);
1326 EXPECT_EQ(reinterpret_cast<uint8_t*>(vec.data()), writable_bytes_span.data());
1327 EXPECT_EQ(sizeof(int) * vec.size(), writable_bytes_span.size());
1328 EXPECT_EQ(writable_bytes_span.size(), writable_bytes_span.size_bytes());
1329
1330 // Set the first entry of vec to zero while writing through the span.
1331 std::fill(writable_bytes_span.data(),
1332 writable_bytes_span.data() + sizeof(int), 0);
1333 EXPECT_EQ(0, vec[0]);
1334}
1335
1336TEST(SpanTest, MakeSpanFromDataAndSize) {
1337 int* nullint = nullptr;
1338 auto empty_span = make_span(nullint, 0);
1339 EXPECT_TRUE(empty_span.empty());
1340 EXPECT_EQ(nullptr, empty_span.data());
1341
1342 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
1343 span<int> expected_span(vector.data(), vector.size());
1344 auto made_span = make_span(vector.data(), vector.size());
1345 EXPECT_EQ(expected_span.data(), made_span.data());
1346 EXPECT_EQ(expected_span.size(), made_span.size());
1347 static_assert(decltype(made_span)::extent == dynamic_extent, "");
1348 static_assert(
1349 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1350 "the type of made_span differs from expected_span!");
1351}
1352
1353TEST(SpanTest, MakeSpanFromPointerPair) {
1354 int* nullint = nullptr;
1355 auto empty_span = make_span(nullint, nullint);
1356 EXPECT_TRUE(empty_span.empty());
1357 EXPECT_EQ(nullptr, empty_span.data());
1358
1359 std::vector<int> vector = {1, 1, 2, 3, 5, 8};
1360 span<int> expected_span(vector.data(), vector.size());
1361 auto made_span = make_span(vector.data(), vector.data() + vector.size());
1362 EXPECT_EQ(expected_span.data(), made_span.data());
1363 EXPECT_EQ(expected_span.size(), made_span.size());
1364 static_assert(decltype(made_span)::extent == dynamic_extent, "");
1365 static_assert(
1366 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1367 "the type of made_span differs from expected_span!");
1368}
1369
1370TEST(SpanTest, MakeSpanFromConstexprArray) {
1371 static constexpr int kArray[] = {1, 2, 3, 4, 5};
1372 constexpr span<const int, 5> expected_span(kArray);
1373 constexpr auto made_span = make_span(kArray);
1374 EXPECT_EQ(expected_span.data(), made_span.data());
1375 EXPECT_EQ(expected_span.size(), made_span.size());
1376 static_assert(decltype(made_span)::extent == 5, "");
1377 static_assert(
1378 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1379 "the type of made_span differs from expected_span!");
1380}
1381
1382TEST(SpanTest, MakeSpanFromStdArray) {
1383 const std::array<int, 5> kArray = {{1, 2, 3, 4, 5}};
1384 span<const int, 5> expected_span(kArray);
1385 auto made_span = make_span(kArray);
1386 EXPECT_EQ(expected_span.data(), made_span.data());
1387 EXPECT_EQ(expected_span.size(), made_span.size());
1388 static_assert(decltype(made_span)::extent == 5, "");
1389 static_assert(
1390 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1391 "the type of made_span differs from expected_span!");
1392}
1393
1394TEST(SpanTest, MakeSpanFromConstContainer) {
1395 const std::vector<int> vector = {-1, -2, -3, -4, -5};
1396 span<const int> expected_span(vector);
1397 auto made_span = make_span(vector);
1398 EXPECT_EQ(expected_span.data(), made_span.data());
1399 EXPECT_EQ(expected_span.size(), made_span.size());
1400 static_assert(decltype(made_span)::extent == dynamic_extent, "");
1401 static_assert(
1402 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1403 "the type of made_span differs from expected_span!");
1404}
1405
1406TEST(SpanTest, MakeStaticSpanFromConstContainer) {
1407 const std::vector<int> vector = {-1, -2, -3, -4, -5};
1408 span<const int, 5> expected_span(vector.data(), vector.size());
1409 auto made_span = make_span<5>(vector);
1410 EXPECT_EQ(expected_span.data(), made_span.data());
1411 EXPECT_EQ(expected_span.size(), made_span.size());
1412 static_assert(decltype(made_span)::extent == 5, "");
1413 static_assert(
1414 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1415 "the type of made_span differs from expected_span!");
1416}
1417
1418TEST(SpanTest, MakeSpanFromContainer) {
1419 std::vector<int> vector = {-1, -2, -3, -4, -5};
1420 span<int> expected_span(vector);
1421 auto made_span = make_span(vector);
1422 EXPECT_EQ(expected_span.data(), made_span.data());
1423 EXPECT_EQ(expected_span.size(), made_span.size());
1424 static_assert(decltype(made_span)::extent == dynamic_extent, "");
1425 static_assert(
1426 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1427 "the type of made_span differs from expected_span!");
1428}
1429
1430TEST(SpanTest, MakeStaticSpanFromContainer) {
1431 std::vector<int> vector = {-1, -2, -3, -4, -5};
1432 span<int, 5> expected_span(vector.data(), vector.size());
1433 auto made_span = make_span<5>(vector);
1434 EXPECT_EQ(expected_span.data(), make_span<5>(vector).data());
1435 EXPECT_EQ(expected_span.size(), make_span<5>(vector).size());
1436 static_assert(decltype(make_span<5>(vector))::extent == 5, "");
1437 static_assert(
1438 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1439 "the type of made_span differs from expected_span!");
1440}
1441
1442TEST(SpanTest, MakeStaticSpanFromConstexprContainer) {
1443 constexpr StringPiece str = "Hello, World";
1444 constexpr auto made_span = make_span<12>(str);
1445 static_assert(str.data() == made_span.data(), "Error: data() does not match");
1446 static_assert(str.size() == made_span.size(), "Error: size() does not match");
1447 static_assert(std::is_same<decltype(str)::value_type,
1448 decltype(made_span)::value_type>::value,
1449 "Error: value_type does not match");
1450 static_assert(str.size() == decltype(made_span)::extent,
1451 "Error: extent does not match");
1452}
1453
1454TEST(SpanTest, MakeSpanFromRValueContainer) {
1455 std::vector<int> vector = {-1, -2, -3, -4, -5};
1456 span<const int> expected_span(vector);
1457 // Note: While static_cast<T&&>(foo) is effectively just a fancy spelling of
1458 // std::move(foo), make_span does not actually take ownership of the passed in
1459 // container. Writing it this way makes it more obvious that we simply care
1460 // about the right behavour when passing rvalues.
1461 auto made_span = make_span(static_cast<std::vector<int>&&>(vector));
1462 EXPECT_EQ(expected_span.data(), made_span.data());
1463 EXPECT_EQ(expected_span.size(), made_span.size());
1464 static_assert(decltype(made_span)::extent == dynamic_extent, "");
1465 static_assert(
1466 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1467 "the type of made_span differs from expected_span!");
1468}
1469
1470TEST(SpanTest, MakeStaticSpanFromRValueContainer) {
1471 std::vector<int> vector = {-1, -2, -3, -4, -5};
1472 span<const int, 5> expected_span(vector.data(), vector.size());
1473 // Note: While static_cast<T&&>(foo) is effectively just a fancy spelling of
1474 // std::move(foo), make_span does not actually take ownership of the passed in
1475 // container. Writing it this way makes it more obvious that we simply care
1476 // about the right behavour when passing rvalues.
1477 auto made_span = make_span<5>(static_cast<std::vector<int>&&>(vector));
1478 EXPECT_EQ(expected_span.data(), made_span.data());
1479 EXPECT_EQ(expected_span.size(), made_span.size());
1480 static_assert(decltype(made_span)::extent == 5, "");
1481 static_assert(
1482 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1483 "the type of made_span differs from expected_span!");
1484}
1485
1486TEST(SpanTest, MakeSpanFromDynamicSpan) {
1487 static constexpr int kArray[] = {1, 2, 3, 4, 5};
1488 constexpr span<const int> expected_span(kArray);
1489 constexpr auto made_span = make_span(expected_span);
1490 static_assert(std::is_same<decltype(expected_span)::element_type,
1491 decltype(made_span)::element_type>::value,
1492 "make_span(span) should have the same element_type as span");
1493
1494 static_assert(expected_span.data() == made_span.data(),
1495 "make_span(span) should have the same data() as span");
1496
1497 static_assert(expected_span.size() == made_span.size(),
1498 "make_span(span) should have the same size() as span");
1499
1500 static_assert(decltype(made_span)::extent == decltype(expected_span)::extent,
1501 "make_span(span) should have the same extent as span");
1502
1503 static_assert(
1504 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1505 "the type of made_span differs from expected_span!");
1506}
1507
1508TEST(SpanTest, MakeSpanFromStaticSpan) {
1509 static constexpr int kArray[] = {1, 2, 3, 4, 5};
1510 constexpr span<const int, 5> expected_span(kArray);
1511 constexpr auto made_span = make_span(expected_span);
1512 static_assert(std::is_same<decltype(expected_span)::element_type,
1513 decltype(made_span)::element_type>::value,
1514 "make_span(span) should have the same element_type as span");
1515
1516 static_assert(expected_span.data() == made_span.data(),
1517 "make_span(span) should have the same data() as span");
1518
1519 static_assert(expected_span.size() == made_span.size(),
1520 "make_span(span) should have the same size() as span");
1521
1522 static_assert(decltype(made_span)::extent == decltype(expected_span)::extent,
1523 "make_span(span) should have the same extent as span");
1524
1525 static_assert(
1526 std::is_same<decltype(expected_span), decltype(made_span)>::value,
1527 "the type of made_span differs from expected_span!");
1528}
1529#endif // 0
1530
Wyatt Hepler77105652019-11-06 17:50:03 -08001531TEST(SpanTest, EnsureConstexprGoodness) {
1532 static constexpr int kArray[] = {5, 4, 3, 2, 1};
1533 constexpr span<const int> constexpr_span(kArray);
1534 const size_t size = 2;
1535
1536 const size_t start = 1;
1537 constexpr span<const int> subspan =
1538 constexpr_span.subspan(start, start + size);
1539 for (size_t i = 0; i < subspan.size(); ++i)
1540 EXPECT_EQ(kArray[start + i], subspan[i]);
1541
1542 constexpr span<const int> firsts = constexpr_span.first(size);
1543 for (size_t i = 0; i < firsts.size(); ++i)
1544 EXPECT_EQ(kArray[i], firsts[i]);
1545
1546 constexpr span<const int> lasts = constexpr_span.last(size);
1547 for (size_t i = 0; i < lasts.size(); ++i) {
1548 const size_t j = (std::size(kArray) - size) + i;
1549 EXPECT_EQ(kArray[j], lasts[i]);
1550 }
1551
1552 constexpr int item = constexpr_span[size];
1553 EXPECT_EQ(kArray[size], item);
1554}
1555
1556#if 0
1557
1558// Pigweed: Death tests are not yet supported.
1559TEST(SpanTest, OutOfBoundsDeath) {
1560 constexpr span<int, 0> kEmptySpan;
1561 ASSERT_DEATH_IF_SUPPORTED(kEmptySpan[0], "");
Wyatt Hepler77105652019-11-06 17:50:03 -08001562 ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.first(1), "");
1563 ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.last(1), "");
1564 ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.subspan(1), "");
1565
1566 constexpr span<int> kEmptyDynamicSpan;
1567 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan[0], "");
Wyatt Hepler77105652019-11-06 17:50:03 -08001568 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.front(), "");
1569 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.first(1), "");
1570 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.last(1), "");
1571 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.back(), "");
1572 ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.subspan(1), "");
1573
1574 static constexpr int kArray[] = {0, 1, 2};
1575 constexpr span<const int> kNonEmptyDynamicSpan(kArray);
1576 EXPECT_EQ(3U, kNonEmptyDynamicSpan.size());
1577 ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan[4], "");
Wyatt Hepler64c165e2020-01-13 10:21:08 -08001578 ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.subspan(10), "");
1579 ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.subspan(1, 7), "");
Wyatt Hepler77105652019-11-06 17:50:03 -08001580}
1581
1582// Pigweed: These tests use CheckedContiguousConstIterator, which isn't used in
1583// Pigweed's version.
1584TEST(SpanTest, IteratorIsRangeMoveSafe) {
1585 static constexpr int kArray[] = {1, 6, 1, 8, 0};
1586 const size_t kNumElements = 5;
1587 constexpr span<const int> span(kArray);
1588
1589 static constexpr int kOverlappingStartIndexes[] = {-4, 0, 3, 4};
1590 static constexpr int kNonOverlappingStartIndexes[] = {-7, -5, 5, 7};
1591
1592 // Overlapping ranges.
1593 for (const int dest_start_index : kOverlappingStartIndexes) {
1594 EXPECT_FALSE(CheckedContiguousIterator<const int>::IsRangeMoveSafe(
1595 span.begin(), span.end(),
1596 CheckedContiguousIterator<const int>(
1597 span.data() + dest_start_index,
1598 span.data() + dest_start_index + kNumElements)));
1599 EXPECT_FALSE(CheckedContiguousConstIterator<const int>::IsRangeMoveSafe(
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001600 std::cbegin(span), std::cend(span),
Wyatt Hepler77105652019-11-06 17:50:03 -08001601 CheckedContiguousConstIterator<const int>(
1602 span.data() + dest_start_index,
1603 span.data() + dest_start_index + kNumElements)));
1604 }
1605
1606 // Non-overlapping ranges.
1607 for (const int dest_start_index : kNonOverlappingStartIndexes) {
1608 EXPECT_TRUE(CheckedContiguousIterator<const int>::IsRangeMoveSafe(
1609 span.begin(), span.end(),
1610 CheckedContiguousIterator<const int>(
1611 span.data() + dest_start_index,
1612 span.data() + dest_start_index + kNumElements)));
1613 EXPECT_TRUE(CheckedContiguousConstIterator<const int>::IsRangeMoveSafe(
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001614 std::cbegin(span), std::cend(span),
Wyatt Hepler77105652019-11-06 17:50:03 -08001615 CheckedContiguousConstIterator<const int>(
1616 span.data() + dest_start_index,
1617 span.data() + dest_start_index + kNumElements)));
1618 }
1619
1620 // IsRangeMoveSafe is true if the length to be moved is 0.
1621 EXPECT_TRUE(CheckedContiguousIterator<const int>::IsRangeMoveSafe(
1622 span.begin(), span.begin(),
1623 CheckedContiguousIterator<const int>(span.data(), span.data())));
1624 EXPECT_TRUE(CheckedContiguousConstIterator<const int>::IsRangeMoveSafe(
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001625 std::cbegin(span), std::cbegin(span),
Wyatt Hepler77105652019-11-06 17:50:03 -08001626 CheckedContiguousConstIterator<const int>(span.data(), span.data())));
1627
1628 // IsRangeMoveSafe is false if end < begin.
1629 EXPECT_FALSE(CheckedContiguousIterator<const int>::IsRangeMoveSafe(
1630 span.end(), span.begin(),
1631 CheckedContiguousIterator<const int>(span.data(), span.data())));
1632 EXPECT_FALSE(CheckedContiguousConstIterator<const int>::IsRangeMoveSafe(
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001633 std::cend(span), std::cbegin(span),
Wyatt Hepler77105652019-11-06 17:50:03 -08001634 CheckedContiguousConstIterator<const int>(span.data(), span.data())));
1635}
1636
1637// Pigweed: gMock matchers are not yet supported.
1638TEST(SpanTest, Sort) {
1639 int array[] = {5, 4, 3, 2, 1};
1640
1641 span<int> dynamic_span = array;
1642 std::sort(dynamic_span.begin(), dynamic_span.end());
1643 EXPECT_THAT(array, ElementsAre(1, 2, 3, 4, 5));
1644 std::sort(dynamic_span.rbegin(), dynamic_span.rend());
1645 EXPECT_THAT(array, ElementsAre(5, 4, 3, 2, 1));
1646
1647 span<int, 5> static_span = array;
1648 std::sort(static_span.rbegin(), static_span.rend(), std::greater<>());
1649 EXPECT_THAT(array, ElementsAre(1, 2, 3, 4, 5));
1650 std::sort(static_span.begin(), static_span.end(), std::greater<>());
1651 EXPECT_THAT(array, ElementsAre(5, 4, 3, 2, 1));
1652}
1653#endif // 0
1654
1655TEST(SpanTest, SpanExtentConversions) {
1656 // Statically checks that various conversions between spans of dynamic and
1657 // static extent are possible or not.
1658 static_assert(
1659 !std::is_constructible<span<int, 0>, span<int>>::value,
1660 "Error: static span should not be constructible from dynamic span");
1661
1662 static_assert(!std::is_constructible<span<int, 2>, span<int, 1>>::value,
1663 "Error: static span should not be constructible from static "
1664 "span with different extent");
1665
1666 static_assert(std::is_convertible<span<int, 0>, span<int>>::value,
1667 "Error: static span should be convertible to dynamic span");
1668
1669 static_assert(std::is_convertible<span<int>, span<int>>::value,
1670 "Error: dynamic span should be convertible to dynamic span");
1671
1672 static_assert(std::is_convertible<span<int, 2>, span<int, 2>>::value,
1673 "Error: static span should be convertible to static span");
1674}
1675
1676TEST(SpanTest, IteratorConversions) {
1677 static_assert(std::is_convertible<span<int>::iterator,
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001678 span<const int>::iterator>::value,
1679 "Error: iterator should be convertible to const iterator");
Wyatt Hepler77105652019-11-06 17:50:03 -08001680
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001681 static_assert(!std::is_convertible<span<const int>::iterator,
Wyatt Hepler77105652019-11-06 17:50:03 -08001682 span<int>::iterator>::value,
Wyatt Hepler3a3ec582020-03-13 10:05:12 -07001683 "Error: const iterator should not be convertible to iterator");
Wyatt Hepler77105652019-11-06 17:50:03 -08001684}
1685
Wyatt Hepler69a51902020-06-22 10:42:53 -07001686} // namespace std