5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_EXTERNAL_VECTOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_TESTING_EXTERNAL_VECTOR_HPP_
10#include <initializer_list>
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
23#include "arene/base/array.hpp"
24#include "arene/base/byte.hpp"
25#include "arene/base/compiler_support/diagnostics.hpp"
26#include "arene/base/compiler_support/platform_queries.hpp"
27#include "arene/base/compiler_support/preprocessor.hpp"
28#include "arene/base/inline_container/external_vector.hpp"
29#include "arene/base/inline_container/testing/customization.hpp"
30#include "arene/base/iterator.hpp"
31#include "arene/base/optional.hpp"
32#include "arene/base/span.hpp"
33#include "arene/base/testing/gtest.hpp"
34#include "arene/base/utility/swap.hpp"
68ARENE_IGNORE_ALL(
"-Wfloat-equal",
"These tests don't perform arithmetic, so equality is OK even for floating point");
104 operator T()
const noexcept(
false) {
return ::arene::base::testing::test_value<T>(0); }
114 using reference = T&;
116 using value_type = T;
118 using pointer =
void;
140 template <
typename U,
bool OperatorsNoexcept>
147 using reference = U&;
149 using value_type = U;
151 using pointer =
void;
168 template <
typename U>
172 template <
typename U>
178 template <
typename... U>
180 return vector(std::forward<U>(params)...);
187 return ::arene::base::testing::test_value<T>(idx);
196 arene::base::span<arene::base::byte> storage,
200 return ::
arene::
base::
testing::test_external_vector<T>(storage, begin, end);
207 static constexpr auto test_external_vector(arene::base::span<arene::base::byte> storage, std::size_t size)
noexcept(
210 return test_external_vector(storage, 0, size);
218 return test_external_vector(storage, capacity);
240 EXPECT_EQ(TestFixture::construct(TestFixture::standard_storage).capacity(), TestFixture::capacity);
242 constexpr std::size_t capacity2 = 19;
243 alignas(TypeParam)
typename TestFixture::
template storage_type<capacity2> storage2{};
244 ASSERT_TRUE(external_vector<TypeParam>{storage2}.capacity() == capacity2);
249 STATIC_ASSERT_TRUE(
noexcept(TestFixture::construct().capacity()));
250 STATIC_ASSERT_TRUE(
noexcept(TestFixture::construct(TestFixture::standard_storage).capacity()));
255 ASSERT_EQ(TestFixture::construct().size(), 0);
256 ASSERT_EQ(TestFixture::construct(TestFixture::standard_storage).size(), 0);
265 (
typename TestFixture::vector{
266 TestFixture::standard_storage,
267 {TestFixture::test_value(0), TestFixture::test_value(1)}
278 typename TestFixture::vector vec{TestFixture::standard_storage};
279 vec.push_back(TestFixture::test_value(0));
280 EXPECT_EQ(vec.size(), 1);
286 typename TestFixture::vector vec{TestFixture::standard_storage};
287 TypeParam
const value = TestFixture::test_value(0);
288 vec.push_back(value);
289 EXPECT_EQ(vec.back(), value);
295 typename TestFixture::vector vec{TestFixture::standard_storage};
296 TypeParam
const value = TestFixture::test_value(0);
297 vec.push_back(value);
298 ASSERT_FALSE(vec.empty());
304 typename TestFixture::vector vec{TestFixture::standard_storage};
305 TypeParam
const value1 = TestFixture::test_value(0);
306 vec.push_back(value1);
307 TypeParam
const value2 = TestFixture::test_value(1);
308 vec.push_back(value2);
309 EXPECT_EQ(vec.size(), 2);
310 EXPECT_EQ(vec.back(), value2);
315 constexpr bool copy_noexcept = std::is_nothrow_copy_constructible<TypeParam>{};
316 constexpr bool move_noexcept = std::is_nothrow_move_constructible<TypeParam>{};
318 noexcept(TestFixture::construct(std::declval<arene::base::span<arene::base::byte>>())
319 .push_back(std::declval<TypeParam
const&>())),
323 noexcept(TestFixture::construct(std::declval<arene::base::span<arene::base::byte>>())
324 .push_back(std::declval<TypeParam&&>())),
334 ASSERT_TRUE(TestFixture::construct(TestFixture::standard_storage).empty());
343#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
344 ASSERT_THROW(TestFixture::construct().at(0), std::out_of_range);
346 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
353#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
354 auto vec = TestFixture::construct(TestFixture::standard_storage);
355 TypeParam
const value = TestFixture::test_value(0);
356 vec.push_back(value);
357 EXPECT_EQ(vec.at(0), value);
359 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
366#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
367 ::testing::StaticAssertTypeEq<
decltype(std::declval<
typename TestFixture::vector&>().at(0)), TypeParam&>();
369 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
376#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
377 ::testing::StaticAssertTypeEq<
decltype(std::declval<
typename TestFixture::vector
const&>().at(0)), TypeParam
const&>(
380 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
387#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
388 auto vec = TestFixture::construct(TestFixture::standard_storage);
389 TypeParam
const value1 = TestFixture::test_value(0);
390 vec.push_back(value1);
391 TypeParam
const value2 = TestFixture::test_value(1);
392 vec.push_back(value2);
394 EXPECT_EQ(vec.at(0), value1);
395 EXPECT_EQ(vec.at(1), value2);
397 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
404#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
405 auto vec = TestFixture::construct(TestFixture::standard_storage);
406 TypeParam
const value1 = TestFixture::test_value(0);
407 vec.push_back(value1);
408 TypeParam
const value2 = TestFixture::test_value(1);
409 vec.push_back(value2);
411 ASSERT_THROW(vec.at(vec.size()), std::out_of_range);
412 ASSERT_THROW(vec.at(vec.size() * 2), std::out_of_range);
413 ASSERT_THROW(vec.at(std::numeric_limits<std::size_t>::max()), std::out_of_range);
415 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
422#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
423 auto vec = TestFixture::construct(TestFixture::standard_storage);
424 TypeParam
const value1 = TestFixture::test_value(0);
425 vec.push_back(value1);
426 TypeParam
const value2 = TestFixture::test_value(1);
427 vec.push_back(value2);
429 auto const& const_vec = vec;
430 EXPECT_EQ(const_vec.at(0), value1);
431 EXPECT_EQ(const_vec.at(1), value2);
433 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
440#if ARENE_IS_ON(ARENE_EXCEPTIONS_ENABLED)
441 auto vec = TestFixture::construct(TestFixture::standard_storage);
442 TypeParam
const value1 = TestFixture::test_value(0);
443 vec.push_back(value1);
444 TypeParam
const value2 = TestFixture::test_value(1);
445 vec.push_back(value2);
447 auto const& const_vec = vec;
449 ASSERT_THROW(const_vec.at(vec.size()), std::out_of_range);
450 ASSERT_THROW(const_vec.at(vec.size() * 2), std::out_of_range);
451 ASSERT_THROW(const_vec.at(std::numeric_limits<std::size_t>::max()), std::out_of_range);
453 GTEST_SKIP() <<
"`at` tests are skipped when exceptions are disabled.";
459 ASSERT_EQ(TestFixture::construct(TestFixture::standard_storage).max_size(), TestFixture::capacity);
460 ASSERT_EQ(TestFixture::construct().max_size(), 0);
461 ASSERT_TRUE(
noexcept(TestFixture::construct().max_size()));
463 constexpr std::size_t capacity2 = 19;
464 alignas(TypeParam)
typename TestFixture::
template storage_type<capacity2> storage2{};
465 ASSERT_EQ(
typename TestFixture::vector{storage2}.max_size(), capacity2);
470 auto vec = TestFixture::construct(TestFixture::standard_storage);
471 for (std::size_t i = 0; i < vec.max_size(); ++i) {
472 vec.push_back(TestFixture::test_value(0));
474 ASSERT_DEATH(vec.push_back(TestFixture::test_value(0)),
"Precondition violation");
480 external_vector<TypeParam>
const zvec{};
481 external_vector<TypeParam
const>
const czvec{};
482 ASSERT_EQ(zvec.begin(), zvec.end());
483 ASSERT_EQ(czvec.begin(), czvec.end());
484 ASSERT_EQ(zvec.size(), 0);
485 ASSERT_EQ(czvec.size(), 0);
490 external_vector<TypeParam> vec{};
491 ASSERT_DEATH(vec.push_back(TestFixture::test_value(0)),
"Precondition violation");
498 auto vec = TestFixture::construct(TestFixture::standard_storage);
500 TypeParam
const value1 = TestFixture::test_value(0);
501 vec.push_back(value1);
502 TypeParam& val1 = vec.back();
504 TypeParam
const value2 = TestFixture::test_value(1);
505 vec.push_back(value2);
506 TypeParam& val2 = vec.back();
508 EXPECT_EQ(std::addressof(val1), std::addressof(vec[0]));
509 EXPECT_EQ(std::addressof(val2), std::addressof(vec[1]));
517 auto vec = TestFixture::construct(TestFixture::standard_storage);
518 auto const& const_vec = vec;
520 TypeParam
const value1 = TestFixture::test_value(0);
521 vec.push_back(value1);
522 auto& val1 = const_vec.back();
523 ::testing::StaticAssertTypeEq<
decltype(val1), TypeParam
const&>();
525 TypeParam
const value2 = TestFixture::test_value(1);
526 vec.push_back(value2);
527 auto& val2 = const_vec.back();
528 ::testing::StaticAssertTypeEq<
decltype(val2), TypeParam
const&>();
530 EXPECT_EQ(std::addressof(val1), &const_vec[0]);
531 EXPECT_EQ(std::addressof(val2), &const_vec[1]);
536 STATIC_ASSERT_TRUE(
noexcept(std::declval<
typename TestFixture::vector&>().back()));
537 STATIC_ASSERT_TRUE(
noexcept(std::declval<
typename TestFixture::vector
const&>().back()));
543 std::initializer_list<TypeParam>
const values{
544 TestFixture::test_value(0),
545 TestFixture::test_value(1),
546 TestFixture::test_value(2),
547 TestFixture::test_value(3)
550 typename TestFixture::vector
const vec{TestFixture::standard_storage, values};
552 noexcept(
typename TestFixture::vector{TestFixture::standard_storage, values}),
553 std::is_nothrow_copy_constructible<TypeParam>{}
556 EXPECT_THAT(vec, ::testing::ElementsAreArray(values));
562 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
563 EXPECT_EQ(std::addressof(vec.front()), std::addressof(vec[0]));
564 ::testing::StaticAssertTypeEq<
decltype(vec.front()), TypeParam&>();
565 STATIC_ASSERT_TRUE(
noexcept(vec.front()));
566 auto const& const_vec = vec;
567 EXPECT_EQ(&const_vec.front(), &const_vec[0]);
568 ::testing::StaticAssertTypeEq<
decltype(const_vec.front()), TypeParam
const&>();
569 STATIC_ASSERT_TRUE(
noexcept(const_vec.front()));
575 auto vec = TestFixture::construct(TestFixture::standard_storage);
576 ::testing::StaticAssertTypeEq<
decltype(vec.begin()),
typename TestFixture::vector::iterator>();
577 ::testing::StaticAssertTypeEq<
decltype(vec.end()),
typename TestFixture::vector::iterator>();
578 STATIC_ASSERT_TRUE(
noexcept(vec.begin()));
579 STATIC_ASSERT_TRUE(
noexcept(vec.end()));
580 EXPECT_EQ(vec.begin(), vec.end());
588 std::initializer_list<TypeParam>
const values{
589 TestFixture::test_value(0),
590 TestFixture::test_value(1),
591 TestFixture::test_value(2),
592 TestFixture::test_value(3)
594 typename TestFixture::vector vec{
595 TestFixture::standard_storage,
598 auto const result = std::mismatch(values.begin(), values.end(), vec.begin(), vec.end());
599 EXPECT_EQ(result.first, values.end());
600 EXPECT_EQ(result.second, vec.end());
608 std::initializer_list<TypeParam>
const values{
609 TestFixture::test_value(0),
610 TestFixture::test_value(1),
611 TestFixture::test_value(2),
612 TestFixture::test_value(3)
614 typename TestFixture::vector
const vec{TestFixture::standard_storage, values};
615 auto const result = std::mismatch(values.begin(), values.end(), vec.begin(), vec.end());
616 EXPECT_EQ(result.first, values.end());
617 EXPECT_EQ(result.second, vec.end());
622 using vec =
typename TestFixture::vector;
623 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::iterator>::value_type, TypeParam>();
624 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::iterator>::reference, TypeParam&>();
625 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::iterator>::pointer, TypeParam*>();
626 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::iterator>::difference_type, std::ptrdiff_t>(
628 ::testing::StaticAssertTypeEq<
629 typename std::iterator_traits<
typename vec::iterator>::iterator_category,
630 std::random_access_iterator_tag>();
632 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::const_iterator>::value_type, TypeParam>();
634 StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::const_iterator>::reference, TypeParam
const&>();
635 ::testing::StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::const_iterator>::pointer, TypeParam
const*>(
638 StaticAssertTypeEq<
typename std::iterator_traits<
typename vec::const_iterator>::difference_type, std::ptrdiff_t>(
640 ::testing::StaticAssertTypeEq<
641 typename std::iterator_traits<
typename vec::const_iterator>::iterator_category,
642 std::random_access_iterator_tag>();
647 using vec =
typename TestFixture::vector;
648 ::testing::StaticAssertTypeEq<
typename vec::value_type, TypeParam>();
649 ::testing::StaticAssertTypeEq<
typename vec::pointer, TypeParam*>();
650 ::testing::StaticAssertTypeEq<
typename vec::const_pointer, TypeParam
const*>();
651 ::testing::StaticAssertTypeEq<
typename vec::reference, TypeParam&>();
652 ::testing::StaticAssertTypeEq<
typename vec::const_reference, TypeParam
const&>();
653 ::testing::StaticAssertTypeEq<
typename vec::size_type, std::size_t>();
654 ::testing::StaticAssertTypeEq<
typename vec::difference_type, std::ptrdiff_t>();
656 StaticAssertTypeEq<
typename vec::reverse_iterator, ::arene::base::reverse_iterator<
typename vec::iterator>>();
657 ::testing::StaticAssertTypeEq<
658 typename vec::const_reverse_iterator,
659 ::arene::base::reverse_iterator<
typename vec::const_iterator>>();
662template <
typename Vec,
typename... Args>
664 std::initializer_list<
typename Vec::value_type>
const values{std::forward<Args>(args)...};
665 Vec vec{std::forward<Args>(args)...};
668 auto val_it = values.begin();
669 for (
auto const& vec_val : vec) {
670 if (val_it == values.end()) {
673 if (vec_val != *val_it) {
679 return val_it == values.end();
686 TypeParam
const value1 = TestFixture::test_value(0);
687 TypeParam
const value2 = TestFixture::test_value(1);
688 TypeParam
const value3 = TestFixture::test_value(2);
689 TypeParam
const value4 = TestFixture::test_value(3);
691 typename TestFixture::vector vec{TestFixture::standard_storage, {value1, value2, value3, value4}};
693 STATIC_ASSERT_TRUE(std::is_same<
694 decltype(vec.erase(std::declval<
typename TestFixture::vector::const_iterator>())),
695 typename TestFixture::vector::iterator>::value);
696 auto const pos = vec.erase(vec.begin());
697 EXPECT_EQ(pos, vec.begin());
698 EXPECT_EQ(vec.size(), 3);
699 EXPECT_EQ(vec[0], value2);
700 EXPECT_EQ(vec[1], value3);
701 EXPECT_EQ(vec[2], value4);
708 TypeParam
const value1 = TestFixture::test_value(0);
709 TypeParam
const value2 = TestFixture::test_value(1);
710 TypeParam
const value3 = TestFixture::test_value(2);
711 TypeParam
const value4 = TestFixture::test_value(3);
713 typename TestFixture::vector vec{TestFixture::standard_storage, {value1, value2, value3, value4}};
715 STATIC_ASSERT_TRUE(std::is_same<
716 decltype(vec.erase(std::declval<
typename TestFixture::vector::const_iterator>())),
717 typename TestFixture::vector::iterator>::value);
718 auto pos = vec.erase(vec.begin() + 1);
719 EXPECT_EQ(pos, vec.begin() + 1);
720 EXPECT_EQ(vec.size(), 3);
721 EXPECT_EQ(vec[0], value1);
722 EXPECT_EQ(vec[1], value3);
723 EXPECT_EQ(vec[2], value4);
730 auto vec = TestFixture::construct(TestFixture::standard_storage);
731 constexpr std::size_t count = 10;
732 constexpr std::size_t erase_start = 2;
733 constexpr std::size_t erase_end = 5;
734 std::vector<TypeParam> expected;
735 for (std::size_t idx = 0; idx < count; ++idx) {
736 vec.push_back(TestFixture::test_value(idx));
737 if (idx < erase_start || idx >= erase_end) {
738 expected.push_back(TestFixture::test_value(idx));
742 ::testing::StaticAssertTypeEq<
744 std::declval<
typename TestFixture::vector::const_iterator>(),
745 std::declval<
typename TestFixture::vector::const_iterator>()
747 typename TestFixture::vector::iterator>();
748 auto const pos = vec.erase(vec.begin() + erase_start, vec.begin() + erase_end);
749 EXPECT_EQ(pos, vec.begin() + erase_start);
750 EXPECT_THAT(vec, ::testing::ElementsAreArray(expected));
755 constexpr std::size_t count = 3;
756 auto value_vec = TestFixture::construct(TestFixture::standard_storage, count);
759 noexcept(
typename TestFixture::vector(TestFixture::standard_storage, count)),
760 std::is_nothrow_default_constructible<TypeParam>{}
762 EXPECT_EQ(value_vec.size(), count);
763 EXPECT_THAT(value_vec, ::testing::Each(::testing::Eq(TypeParam{})));
769 constexpr std::size_t count = 14;
770 TypeParam
const value = TestFixture::test_value(0);
771 auto const value_vec = TestFixture::construct(TestFixture::standard_storage, count, value);
774 noexcept(
typename TestFixture::vector(TestFixture::standard_storage, count, value)),
775 std::is_nothrow_copy_constructible<TypeParam>{}
777 EXPECT_EQ(value_vec.size(), count);
778 EXPECT_THAT(value_vec, ::testing::Each(::testing::Eq(value)));
783 auto const vec = TestFixture::test_external_vector(TestFixture::standard_storage, 6);
784 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
786 typename TestFixture::vector
const copy(storage2, vec);
788 EXPECT_THAT(copy, ::testing::ElementsAreArray(vec));
793 std::initializer_list<TypeParam>
const values = {
794 TestFixture::test_value(0),
795 TestFixture::test_value(1),
796 TestFixture::test_value(2),
797 TestFixture::test_value(3),
798 TestFixture::test_value(4)
800 typename TestFixture::vector vec(TestFixture::standard_storage, values);
802 typename TestFixture::vector
const moved(std::move(vec));
804 EXPECT_THAT(moved, ::testing::ElementsAreArray(values));
809 std::initializer_list<TypeParam>
const values = {
810 TestFixture::test_value(0),
811 TestFixture::test_value(1),
812 TestFixture::test_value(2),
813 TestFixture::test_value(3),
814 TestFixture::test_value(4)
816 typename TestFixture::vector vec(TestFixture::standard_storage, values);
818 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
820 typename TestFixture::vector
const moved(storage2, std::move(vec));
822 EXPECT_THAT(moved, ::testing::ElementsAreArray(values));
829 constexpr std::size_t count = 14;
830 constexpr std::size_t smaller_count = 10;
832 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
833 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, count);
834 auto copy = TestFixture::test_external_vector(storage2, smaller_count);
837 ASSERT_EQ(vec.size(), count);
838 ASSERT_EQ(copy.size(), count);
839 for (std::size_t i = 0; i < count; ++i) {
840 EXPECT_EQ(vec[i], copy[i]);
841 EXPECT_EQ(TestFixture::test_value(i), copy[i]);
848 constexpr std::size_t count = 14;
849 constexpr std::size_t larger_count = 18;
851 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
852 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, count);
853 auto copy = TestFixture::test_external_vector(storage2, larger_count);
856 ASSERT_EQ(vec.size(), count);
857 ASSERT_EQ(copy.size(), count);
858 for (std::size_t i = 0; i < count; ++i) {
859 EXPECT_EQ(vec[i], copy[i]);
860 EXPECT_EQ(TestFixture::test_value(i), copy[i]);
867 using vec = ::arene::base::external_vector<TypeParam>;
869 constexpr bool should_be_copyable = std::is_copy_constructible<TypeParam>{} && std::is_copy_assignable<TypeParam>{};
870 STATIC_ASSERT_FALSE(std::is_copy_constructible<vec>{});
871 STATIC_ASSERT_EQ(std::is_copy_assignable<vec>{}, should_be_copyable);
873 constexpr bool should_be_noexcept =
874 std::is_nothrow_copy_constructible<TypeParam>{} && std::is_nothrow_copy_assignable<TypeParam>{};
875 STATIC_ASSERT_FALSE(std::is_nothrow_copy_constructible<vec>{});
876 STATIC_ASSERT_EQ(std::is_nothrow_copy_assignable<vec>{}, should_be_noexcept);
883 constexpr std::size_t count = 14;
884 constexpr std::size_t smaller_count = 10;
886 auto first = TestFixture::construct(TestFixture::standard_storage);
887 std::vector<TypeParam> expected;
888 for (std::size_t idx = 0; idx < count; ++idx) {
889 first.push_back(TestFixture::test_value(idx));
890 expected.push_back(TestFixture::test_value(idx));
893 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
894 auto second = TestFixture::test_external_vector(storage2, smaller_count);
896 second = std::move(first);
898 EXPECT_EQ(second.size(), count);
899 EXPECT_THAT(second, ::testing::ElementsAreArray(expected));
905 constexpr std::size_t count = 14;
906 constexpr std::size_t larger_count = 18;
908 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
909 auto first = TestFixture::test_external_vector(TestFixture::standard_storage, count);
910 auto second = TestFixture::test_external_vector(storage2, larger_count);
911 second = std::move(first);
913 ASSERT_EQ(second.size(), count);
914 for (std::size_t i = 0; i < count; ++i) {
915 EXPECT_EQ(TestFixture::test_value(i), second[i]);
922 using vec = ::arene::base::external_vector<TypeParam>;
924 constexpr bool should_be_movable = std::is_move_assignable<TypeParam>{} && std::is_move_constructible<TypeParam>{};
925 STATIC_ASSERT_TRUE(std::is_move_constructible<vec>{});
926 STATIC_ASSERT_EQ(std::is_move_assignable<vec>{}, should_be_movable);
928 constexpr bool should_be_noexcept =
929 std::is_nothrow_move_assignable<TypeParam>{} && std::is_nothrow_move_constructible<TypeParam>{};
930 STATIC_ASSERT_TRUE(std::is_nothrow_move_constructible<vec>{});
931 STATIC_ASSERT_EQ(std::is_nothrow_move_assignable<vec>{}, should_be_noexcept);
948 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, 5);
950 vec.push_back(TestFixture::test_value(5));
953 EXPECT_THAT(vec, elements_match_function(TestFixture::test_value));
958 STATIC_ASSERT_TRUE(
noexcept(std::declval<
typename TestFixture::vector>().pop_back()));
964 auto vec = TestFixture::construct(TestFixture::standard_storage);
967 STATIC_ASSERT_TRUE(
noexcept(vec.erase(vec.begin(), vec.end())));
968 STATIC_ASSERT_TRUE(
noexcept(vec.erase(vec.begin())));
974 TypeParam
const value = TestFixture::test_value(0);
975 auto vec1 = TestFixture::construct(TestFixture::standard_storage);
976 auto const& const_vec1 = vec1;
977 auto const itr = vec1.insert(const_vec1.begin(), value);
978 EXPECT_EQ(itr, vec1.begin());
979 EXPECT_EQ(vec1.size(), 1);
980 EXPECT_EQ(vec1[0], value);
986 TypeParam
const value0 = TestFixture::test_value(0);
987 TypeParam
const value1 = TestFixture::test_value(1);
988 typename TestFixture::vector vec1{TestFixture::standard_storage, {value0}};
989 auto const& const_vec1 = vec1;
990 auto const pos = vec1.insert(const_vec1.end(), value1);
991 EXPECT_EQ(pos, vec1.begin() + 1);
992 EXPECT_EQ(vec1.size(), 2);
993 EXPECT_EQ(vec1[0], value0);
994 EXPECT_EQ(vec1[1], value1);
1001 TypeParam
const value0 = TestFixture::test_value(0);
1002 TypeParam
const value1 = TestFixture::test_value(1);
1003 TypeParam
const value2 = TestFixture::test_value(2);
1004 TypeParam
const value3 = TestFixture::test_value(3);
1005 TypeParam
const value4 = TestFixture::test_value(4);
1006 typename TestFixture::vector vec1{TestFixture::standard_storage, {value0, value1, value2, value4}};
1007 auto const& const_vec1 = vec1;
1008 auto const pos = vec1.insert(const_vec1.begin() + 1, value3);
1009 EXPECT_EQ(pos, vec1.begin() + 1);
1010 EXPECT_EQ(vec1.size(), 5);
1011 EXPECT_EQ(vec1[0], value0);
1012 EXPECT_EQ(vec1[1], value3);
1013 EXPECT_EQ(vec1[2], value1);
1014 EXPECT_EQ(vec1[3], value2);
1015 EXPECT_EQ(vec1[4], value4);
1021 TypeParam
const value1 = TestFixture::test_value(0);
1022 TypeParam
const value2 = TestFixture::test_value(1);
1023 auto vec1 = TestFixture::construct(TestFixture::standard_storage, TestFixture::capacity, value1);
1024 EXPECT_EQ(vec1.size(), TestFixture::capacity);
1025 ASSERT_DEATH(vec1.insert(vec1.end(), value2),
"Precondition violation");
1026 ASSERT_DEATH(vec1.insert(vec1.begin(), value2),
"Precondition violation");
1027 EXPECT_EQ(vec1.size(), TestFixture::capacity);
1028 for (
auto& value : vec1) {
1029 EXPECT_EQ(value, value1);
1036 ExternalVectorDeathTest,
1041 TestFixture::construct(TestFixture::standard_storage, TestFixture::capacity + 1),
1042 "Precondition violation"
1049 TypeParam
const source = TestFixture::test_value(0);
1051 TestFixture::construct(TestFixture::standard_storage, TestFixture::capacity + 1, source),
1052 "Precondition violation"
1059 constexpr std::size_t small_capacity = 4;
1060 using vec = external_vector<TypeParam>;
1061 TypeParam
const value = TestFixture::test_value(0);
1063 alignas(TypeParam)
typename TestFixture::
template storage_type<small_capacity> storage{};
1064 ASSERT_DEATH((vec{storage, {value, value, value, value, value}}),
"Precondition violation");
1067template <
typename Vec>
1079 STATIC_ASSERT_EQ(
noexcept(TestFixture::construct().resize(0)), std::is_nothrow_default_constructible<TypeParam>{});
1086 noexcept(std::declval<
typename TestFixture::vector&>().resize(0, TestFixture::test_value(0))),
1087 std::is_nothrow_copy_constructible<TypeParam>{}
1094 constexpr std::size_t initial_count = 5;
1095 TypeParam
const initial_value = TestFixture::test_value(0);
1096 typename TestFixture::vector vec(TestFixture::standard_storage, initial_count, initial_value);
1097 constexpr std::size_t count = 3;
1098 TypeParam
const value = TestFixture::test_value(1);
1099 vec.resize(count, value);
1100 ASSERT_EQ(vec.size(), count);
1102 for (std::size_t idx = 0; idx < count; ++idx) {
1103 EXPECT_EQ(vec[idx], initial_value);
1112 constexpr std::size_t initial_count = 5;
1113 TypeParam
const initial_value = TestFixture::test_value(0);
1114 typename TestFixture::vector vec(TestFixture::standard_storage, initial_count, initial_value);
1115 constexpr std::size_t count = 17;
1116 TypeParam
const value = TestFixture::test_value(1);
1117 vec.resize(count, value);
1118 ASSERT_EQ(vec.size(), count);
1120 for (std::size_t idx = 0; idx < initial_count; ++idx) {
1121 EXPECT_EQ(vec[idx], initial_value);
1123 for (std::size_t idx = initial_count; idx < count; ++idx) {
1124 EXPECT_EQ(vec[idx], value);
1131 auto const source = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
1133 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
1134 typename TestFixture::vector vec(storage2, source.begin(), source.end());
1136 EXPECT_EQ(vec.size(), source.size());
1137 for (std::size_t i = 0; i < vec.size(); ++i) {
1138 EXPECT_EQ(vec[i], source[i]);
1145 using source_it =
typename std::vector<TypeParam>::const_iterator;
1146 using source_val =
typename source_it::reference;
1148 constexpr bool it_operations_noexcept =
noexcept(++std::declval<source_it>())&&
noexcept(*std::declval<source_it>());
1149 constexpr bool element_construction_noexcept =
1150 std::is_nothrow_constructible<
typename TestFixture::vector::value_type, source_val>{};
1152 STATIC_ASSERT_TRUE((
1153 std::is_constructible<
typename TestFixture::vector, arene::base::span<arene::base::byte>, source_it, source_it>{}
1156 (std::is_nothrow_constructible<
1157 typename TestFixture::vector,
1158 arene::base::span<arene::base::byte>,
1161 it_operations_noexcept && element_construction_noexcept
1164 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
1165 using convertible_array = ::arene::base::array<throws_when_converted, TestFixture::capacity>;
1166 using throwing_bidirectional_iterator =
typename TestFixture::throwing_bidirectional_iterator_of_t;
1168 STATIC_ASSERT_TRUE(std::is_constructible<
1169 typename TestFixture::vector,
1170 arene::base::span<arene::base::byte>,
1171 typename convertible_array::const_iterator,
1172 typename convertible_array::const_iterator>::value);
1173 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1174 typename TestFixture::vector,
1175 arene::base::span<arene::base::byte>,
1176 typename convertible_array::const_iterator,
1177 typename convertible_array::const_iterator>::value);
1178 STATIC_ASSERT_TRUE(std::is_constructible<
1179 typename TestFixture::vector,
1180 arene::base::span<arene::base::byte>,
1181 throwing_bidirectional_iterator,
1182 throwing_bidirectional_iterator>::value);
1183 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1184 typename TestFixture::vector,
1185 arene::base::span<arene::base::byte>,
1186 throwing_bidirectional_iterator,
1187 throwing_bidirectional_iterator>::value);
1193 using stream_it = std::istream_iterator<TypeParam>;
1194 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
1195 using throwing_it_throwing_type =
typename TestFixture::
template throwing_input_iterator<throws_when_converted>;
1196 using throwing_it_raw_type =
typename TestFixture::
template throwing_input_iterator<TypeParam>;
1197 using nothrow_it_throwing_type =
typename TestFixture::
template non_throwing_input_iterator<throws_when_converted>;
1198 using nothrow_it_raw_type =
typename TestFixture::
template non_throwing_input_iterator<TypeParam>;
1200 constexpr bool it_operations_noexcept =
noexcept(++std::declval<stream_it>())&&
noexcept(*std::declval<stream_it>());
1201 constexpr bool element_construction_noexcept =
1202 std::is_nothrow_constructible<
typename TestFixture::vector::value_type,
typename stream_it::reference>{};
1204 STATIC_ASSERT_TRUE((
1205 std::is_constructible<
typename TestFixture::vector, arene::base::span<arene::base::byte>, stream_it, stream_it>{}
1208 (std::is_nothrow_constructible<
1209 typename TestFixture::vector,
1210 arene::base::span<arene::base::byte>,
1213 it_operations_noexcept && element_construction_noexcept
1216 STATIC_ASSERT_TRUE(std::is_constructible<
1217 typename TestFixture::vector,
1218 arene::base::span<arene::base::byte>,
1219 throwing_it_throwing_type,
1220 throwing_it_throwing_type>::value);
1221 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1222 typename TestFixture::vector,
1223 arene::base::span<arene::base::byte>,
1224 throwing_it_throwing_type,
1225 throwing_it_throwing_type>::value);
1226 STATIC_ASSERT_TRUE(std::is_constructible<
1227 typename TestFixture::vector,
1228 arene::base::span<arene::base::byte>,
1229 throwing_it_raw_type,
1230 throwing_it_raw_type>::value);
1231 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1232 typename TestFixture::vector,
1233 arene::base::span<arene::base::byte>,
1234 throwing_it_raw_type,
1235 throwing_it_raw_type>::value);
1236 STATIC_ASSERT_TRUE(std::is_constructible<
1237 typename TestFixture::vector,
1238 arene::base::span<arene::base::byte>,
1239 nothrow_it_raw_type,
1240 nothrow_it_raw_type>::value);
1242 (std::is_nothrow_constructible<
1243 typename TestFixture::vector,
1244 arene::base::span<arene::base::byte>,
1245 nothrow_it_raw_type,
1246 nothrow_it_raw_type>::value),
1247 std::is_nothrow_copy_constructible<TypeParam>::value
1249 STATIC_ASSERT_TRUE(std::is_constructible<
1250 typename TestFixture::vector,
1251 arene::base::span<arene::base::byte>,
1252 nothrow_it_throwing_type,
1253 nothrow_it_throwing_type>::value);
1254 STATIC_ASSERT_FALSE(std::is_nothrow_constructible<
1255 typename TestFixture::vector,
1256 arene::base::span<arene::base::byte>,
1257 nothrow_it_throwing_type,
1258 nothrow_it_throwing_type>::value);
1265 constexpr std::size_t smaller_count = 10;
1267 std::initializer_list<TypeParam>
const value{
1268 TestFixture::test_value(0),
1269 TestFixture::test_value(1),
1270 TestFixture::test_value(2),
1271 TestFixture::test_value(3),
1272 TestFixture::test_value(4),
1273 TestFixture::test_value(5),
1274 TestFixture::test_value(6),
1275 TestFixture::test_value(7),
1276 TestFixture::test_value(8),
1277 TestFixture::test_value(9),
1278 TestFixture::test_value(10),
1279 TestFixture::test_value(11),
1280 TestFixture::test_value(12),
1281 TestFixture::test_value(13)
1284 auto copy = TestFixture::test_external_vector(TestFixture::standard_storage, smaller_count);
1287 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1295 constexpr std::size_t larger_count = 18;
1297 std::initializer_list<TypeParam>
const value{
1298 TestFixture::test_value(0),
1299 TestFixture::test_value(1),
1300 TestFixture::test_value(2),
1301 TestFixture::test_value(3),
1302 TestFixture::test_value(4),
1303 TestFixture::test_value(5),
1304 TestFixture::test_value(6),
1305 TestFixture::test_value(7),
1306 TestFixture::test_value(8),
1307 TestFixture::test_value(9),
1308 TestFixture::test_value(10),
1309 TestFixture::test_value(11),
1310 TestFixture::test_value(12),
1311 TestFixture::test_value(13)
1314 alignas(TypeParam)
typename TestFixture::
template storage_type<larger_count> storage{};
1315 auto copy = TestFixture::test_external_vector(storage, larger_count);
1318 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1324 std::vector<TypeParam>
const source{
1325 TestFixture::test_value(3),
1326 TestFixture::test_value(4),
1327 TestFixture::test_value(5),
1328 TestFixture::test_value(6)
1331 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, 3);
1332 vec.assign(source.begin(), source.end());
1334 EXPECT_THAT(vec, ::testing::ElementsAreArray(source));
1340 using array_it =
typename array<TypeParam, TestFixture::capacity>::const_iterator;
1341 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
1342 using convertible_array_it =
typename array<throws_when_converted, TestFixture::capacity>::const_iterator;
1343 using throwing_bidirectional_iterator =
typename TestFixture::throwing_bidirectional_iterator_of_t;
1345 constexpr bool it_operations_noexcept =
noexcept(++std::declval<array_it>())&&
noexcept(*std::declval<array_it>());
1346 constexpr bool element_construction_noexcept =
1347 std::is_nothrow_constructible<
typename TestFixture::vector::value_type,
typename array_it::reference>{} &&
1348 std::is_nothrow_assignable<
typename TestFixture::vector::value_type&,
typename array_it::reference>{};
1351 noexcept(std::declval<
typename TestFixture::vector&>().assign(std::declval<array_it>(), std::declval<array_it>())
1353 it_operations_noexcept && element_construction_noexcept
1355 STATIC_ASSERT_FALSE(
noexcept(std::declval<
typename TestFixture::vector&>().assign(
1356 std::declval<convertible_array_it>(),
1357 std::declval<convertible_array_it>()
1359 STATIC_ASSERT_FALSE(
noexcept(std::declval<
typename TestFixture::vector&>().assign(
1360 std::declval<throwing_bidirectional_iterator>(),
1361 std::declval<throwing_bidirectional_iterator>()
1369 constexpr std::size_t smaller_count = 10;
1371 std::initializer_list<TypeParam>
const value{
1372 TestFixture::test_value(0),
1373 TestFixture::test_value(1),
1374 TestFixture::test_value(2),
1375 TestFixture::test_value(3),
1376 TestFixture::test_value(4),
1377 TestFixture::test_value(5),
1378 TestFixture::test_value(6),
1379 TestFixture::test_value(7),
1380 TestFixture::test_value(8),
1381 TestFixture::test_value(9),
1382 TestFixture::test_value(10),
1383 TestFixture::test_value(11),
1384 TestFixture::test_value(12),
1385 TestFixture::test_value(13)
1388 auto copy = TestFixture::test_external_vector(TestFixture::standard_storage, smaller_count);
1391 EXPECT_THAT(copy, ::testing::ElementsAreArray(value));
1397 constexpr bool is_nothrow_copyable =
1398 std::is_nothrow_copy_constructible<TypeParam>{} && std::is_nothrow_copy_assignable<TypeParam>{};
1400 std::initializer_list<TypeParam>
const values{
1401 TestFixture::test_value(0),
1402 TestFixture::test_value(1),
1403 TestFixture::test_value(2),
1404 TestFixture::test_value(3),
1405 TestFixture::test_value(4),
1406 TestFixture::test_value(5),
1407 TestFixture::test_value(6),
1408 TestFixture::test_value(7),
1409 TestFixture::test_value(8),
1410 TestFixture::test_value(9),
1411 TestFixture::test_value(10),
1412 TestFixture::test_value(11),
1413 TestFixture::test_value(12),
1414 TestFixture::test_value(13)
1416 STATIC_ASSERT_EQ(
noexcept(
typename TestFixture::vector{}.assign(values)), is_nothrow_copyable);
1423 std::vector<TypeParam>
const source{
1424 TestFixture::test_value(3),
1425 TestFixture::test_value(4),
1426 TestFixture::test_value(5),
1427 TestFixture::test_value(6)
1430 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, 3);
1431 vec.assign(source.begin(), source.end());
1433 EXPECT_THAT(vec, ::testing::ElementsAreArray(source));
1439 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
1440 using throwing_it_throwing_type =
typename TestFixture::
template throwing_input_iterator<throws_when_converted>;
1441 using throwing_it_raw_type =
typename TestFixture::
template throwing_input_iterator<TypeParam>;
1442 using nothrow_it_throwing_type =
typename TestFixture::
template non_throwing_input_iterator<throws_when_converted>;
1443 using nothrow_it_raw_type =
typename TestFixture::
template non_throwing_input_iterator<TypeParam>;
1445 STATIC_ASSERT_FALSE(
noexcept(
typename TestFixture::vector{}.assign(
1446 std::declval<std::istream_iterator<TypeParam>>(),
1447 std::declval<std::istream_iterator<TypeParam>>()
1449 STATIC_ASSERT_FALSE(
noexcept(
typename TestFixture::vector{}.assign(
1450 std::declval<throwing_it_throwing_type>(),
1451 std::declval<throwing_it_throwing_type>()
1453 STATIC_ASSERT_FALSE(
noexcept(
1454 typename TestFixture::vector{}.assign(std::declval<throwing_it_raw_type>(), std::declval<throwing_it_raw_type>())
1457 noexcept(
typename TestFixture::vector{}
1458 .assign(std::declval<nothrow_it_raw_type>(), std::declval<nothrow_it_raw_type>())),
1459 std::is_nothrow_copy_assignable<TypeParam>::value
1461 STATIC_ASSERT_FALSE(
noexcept(
typename TestFixture::vector{}.assign(
1462 std::declval<nothrow_it_throwing_type>(),
1463 std::declval<nothrow_it_throwing_type>()
1470 constexpr std::size_t count = 14;
1471 constexpr std::size_t smaller_count = 10;
1473 auto copy = TestFixture::test_external_vector(TestFixture::standard_storage, smaller_count);
1474 TypeParam
const value = TestFixture::test_value(0);
1475 copy.assign(count, value);
1477 EXPECT_EQ(copy.size(), count);
1478 for (std::size_t i = 0; i < count; ++i) {
1479 EXPECT_EQ(copy[i], value);
1486 constexpr std::size_t count = 14;
1487 TypeParam
const value = TestFixture::test_value(0);
1489 constexpr bool is_nothrow_copyable =
1490 std::is_nothrow_copy_constructible<TypeParam>{} && std::is_nothrow_copy_assignable<TypeParam>{};
1491 STATIC_ASSERT_EQ(
noexcept(
typename TestFixture::vector{}.assign(count, value)), is_nothrow_copyable);
1497 constexpr std::size_t smaller_count = 10;
1499 TypeParam
const initial_value = TestFixture::test_value(0);
1500 typename TestFixture::vector copy(TestFixture::standard_storage, smaller_count, initial_value);
1501 TypeParam
const value = TestFixture::test_value(1);
1502 ASSERT_DEATH(copy.assign(TestFixture::capacity + 1, value),
"Precondition violation");
1504 EXPECT_EQ(copy.size(), smaller_count);
1505 for (std::size_t i = 0; i < smaller_count; ++i) {
1506 EXPECT_EQ(copy[i], initial_value);
1512 ::testing::StaticAssertTypeEq<
decltype(std::declval<
typename TestFixture::vector&>()[0]), TypeParam&>();
1517 ::testing::StaticAssertTypeEq<
decltype(std::declval<
typename TestFixture::vector
const&>()[0]), TypeParam
const&>();
1523 auto vec = TestFixture::construct(TestFixture::standard_storage);
1524 auto const& const_vec = vec;
1525 TypeParam
const value1 = TestFixture::test_value(0);
1526 vec.push_back(value1);
1527 TypeParam
const value2 = TestFixture::test_value(1);
1528 vec.push_back(value2);
1530 EXPECT_EQ(vec[0], value1);
1531 EXPECT_EQ(vec[1], value2);
1533 EXPECT_EQ(&const_vec[0], std::addressof(vec[0]));
1534 EXPECT_EQ(&const_vec[1], std::addressof(vec[1]));
1539 STATIC_ASSERT_TRUE(
noexcept(std::declval<
typename TestFixture::vector&>()[0]));
1545 ASSERT_DEATH(TestFixture::construct()[0],
"index < this->size()");
1550 STATIC_ASSERT_TRUE(
noexcept(std::declval<
typename TestFixture::vector
const&>()[0]));
1555 typename TestFixture::vector vec{
1556 TestFixture::standard_storage,
1557 {TestFixture::test_value(3), TestFixture::test_value(4)}
1559 auto const& const_vec = vec;
1562 EXPECT_EQ(vec.data(), std::addressof(vec[0]));
1564 EXPECT_EQ(const_vec.data(), std::addressof(vec[0]));
1566 STATIC_ASSERT_TRUE(
noexcept(vec.data()));
1567 STATIC_ASSERT_TRUE(
noexcept(const_vec.data()));
1569 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
1570 auto const value2 = TestFixture::test_external_vector(storage2, 3);
1573 ASSERT_EQ(value2.data(), std::addressof(value2[0]));
1574 alignas(TypeParam)
typename TestFixture::standard_storage_type storage3{};
1575 ASSERT_NE(TestFixture::test_external_vector(storage3, 3).data(),
nullptr);
1580 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, 2);
1582 EXPECT_EQ(vec.size(), 2);
1583 EXPECT_FALSE(vec.empty());
1585 EXPECT_EQ(vec.size(), 0);
1586 EXPECT_TRUE(vec.empty());
1588 STATIC_ASSERT_TRUE(
noexcept(vec.clear()));
1595template <
typename Container>
1598 for (std::size_t ii = 0UL; ii + 1UL < container.size(); ++ii) {
1599 for (std::size_t jj = ii + 1UL; jj < container.size(); ++jj) {
1600 if (container[ii] == container[jj]) {
1613template <
typename Container>
1618 for (std::size_t ii = 0UL; ii + 1UL < container.size(); ++ii) {
1619 if (container[ii + 1] < container[ii]) {
1621 typename Container::value_type
const temp{container[ii]};
1622 container[ii] = container[ii + 1];
1623 container[ii + 1] = temp;
1633template <
typename T>
1673 struct with_constructor_args {
1676 TypeParam& reference;
1677 std::unique_ptr<TypeParam> pointer;
1679 with_constructor_args(TypeParam val, TypeParam& ref, std::unique_ptr<TypeParam> ptr)
1682 pointer(std::move(ptr)) {}
1685 alignas(with_constructor_args)
1686 arene::base::array<arene::base::byte,
sizeof(with_constructor_args) * TestFixture::capacity>
1688 external_vector<with_constructor_args> vec(storage);
1690 TypeParam
const value1 = TestFixture::test_value(0);
1691 TypeParam value2 = TestFixture::test_value(1);
1692 TypeParam
const value3 = TestFixture::test_value(2);
1693 auto& result = vec.emplace_back(value1, value2, std::make_unique<TypeParam>(value3));
1695 ::testing::StaticAssertTypeEq<
decltype(result), with_constructor_args&>();
1696 EXPECT_EQ(vec.size(), 1);
1697 ASSERT_FALSE(vec.empty());
1698 EXPECT_EQ(std::addressof(result), std::addressof(vec[0]));
1700 EXPECT_EQ(result.value, value1);
1701 EXPECT_EQ(std::addressof(result.reference), std::addressof(value2));
1702 ASSERT_NE(result.pointer,
nullptr);
1703 EXPECT_EQ(*result.pointer, value3);
1706template <
typename T>
1716 noexcept(TestFixture::construct().emplace_back(std::declval<TypeParam&&>())),
1717 std::is_nothrow_move_constructible<TypeParam>{}
1720 noexcept(TestFixture::construct().emplace_back(std::declval<TypeParam
const&>())),
1721 std::is_nothrow_copy_constructible<TypeParam>{}
1724 STATIC_ASSERT_FALSE(
1725 noexcept(external_vector<throws_without_nullptr<TypeParam>>{}.emplace_back(std::declval<TypeParam>()))
1728 noexcept(external_vector<throws_without_nullptr<TypeParam>>{}.emplace_back(std::declval<TypeParam>(),
nullptr))
1735 using const_it =
typename TestFixture::vector::const_iterator;
1737 constexpr bool is_nothrow_movable =
1738 std::is_nothrow_move_constructible<TypeParam>{} && std::is_nothrow_move_assignable<TypeParam>{};
1741 noexcept(TestFixture::construct().emplace(std::declval<const_it>(), std::declval<TypeParam&&>())),
1742 is_nothrow_movable && std::is_nothrow_move_constructible<TypeParam>{}
1745 noexcept(TestFixture::construct().emplace(std::declval<const_it>(), std::declval<TypeParam
const&>())),
1746 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1749 using overload_test_external_vector = external_vector<throws_without_nullptr<TypeParam>>;
1750 using overload_it =
typename overload_test_external_vector::const_iterator;
1751 STATIC_ASSERT_FALSE(
1752 noexcept(overload_test_external_vector{}.emplace(std::declval<overload_it>(), std::declval<TypeParam>()))
1755 noexcept(overload_test_external_vector{}.emplace(std::declval<overload_it>(), std::declval<TypeParam>(),
nullptr))
1767 using const_it =
typename TestFixture::vector::const_iterator;
1769 constexpr bool is_nothrow_movable =
1770 std::is_nothrow_move_constructible<TypeParam>{} && std::is_nothrow_move_assignable<TypeParam>{};
1773 noexcept(TestFixture::construct().emplace_back()),
1774 std::is_nothrow_default_constructible<TypeParam>{}
1777 noexcept(TestFixture::construct().emplace(std::declval<const_it>())),
1778 is_nothrow_movable && std::is_nothrow_default_constructible<TypeParam>{}
1785 auto vec = TestFixture::test_external_vector(TestFixture::standard_storage, TestFixture::capacity);
1787 TypeParam
const value1 = TestFixture::test_value(0);
1788 ASSERT_DEATH(vec.emplace_back(value1),
"Precondition violation");
1794 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
1795 auto const source1 = TestFixture::test_external_vector(TestFixture::standard_storage, 12);
1796 auto const source2 = TestFixture::test_external_vector(storage2, 12, 16);
1797 alignas(TypeParam)
typename TestFixture::standard_storage_type storage3{};
1798 alignas(TypeParam)
typename TestFixture::standard_storage_type storage4{};
1799 typename TestFixture::vector value1(storage3, source1);
1800 typename TestFixture::vector value2(storage4, source2);
1802 swap(value1, value2);
1804 EXPECT_EQ(value1, source2);
1805 EXPECT_EQ(value2, source1);
1810 using vec =
typename TestFixture::vector;
1811 constexpr bool element_nothrow_swappable = ::arene::base::is_nothrow_swappable_v<TypeParam>;
1813 STATIC_ASSERT_EQ(::arene::base::is_nothrow_swappable_v<vec>, element_nothrow_swappable);
1814 STATIC_ASSERT_EQ(
noexcept(std::declval<vec>().swap(std::declval<vec&>())), element_nothrow_swappable);
1820 using vec =
typename TestFixture::vector;
1821 using iterator =
typename vec::const_iterator;
1823 constexpr bool is_nothrow_movable =
1824 std::is_nothrow_move_constructible<TypeParam>{} && std::is_nothrow_move_assignable<TypeParam>{};
1826 STATIC_ASSERT_EQ(
noexcept(vec{}.insert(std::declval<iterator>(), std::declval<TypeParam&&>())), is_nothrow_movable);
1828 noexcept(vec{}.insert(std::declval<iterator>(), std::declval<TypeParam
const&>())),
1829 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1836 using vec =
typename TestFixture::vector;
1837 using iterator =
typename vec::const_iterator;
1839 constexpr bool is_nothrow_movable =
1840 std::is_nothrow_move_constructible<TypeParam>{} && std::is_nothrow_move_assignable<TypeParam>{};
1843 noexcept(vec{}.insert(std::declval<iterator>(), 0U, std::declval<TypeParam&&>())),
1844 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1847 noexcept(vec{}.insert(std::declval<iterator>(), 0U, std::declval<TypeParam
const&>())),
1848 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1855 struct with_constructor_args {
1857 TypeParam* raw_pointer;
1858 std::unique_ptr<TypeParam> unique_pointer;
1860 with_constructor_args(TypeParam val, TypeParam* rptr, std::unique_ptr<TypeParam> uptr)
1863 unique_pointer(std::move(uptr)) {}
1866 alignas(with_constructor_args)
1867 arene::base::array<arene::base::byte,
sizeof(with_constructor_args) * TestFixture::capacity>
1869 external_vector<with_constructor_args> vec(storage);
1870 auto const& const_vec1 = vec;
1871 TypeParam
const value1 = TestFixture::test_value(0);
1872 TypeParam value2 = TestFixture::test_value(1);
1873 TypeParam
const value3 = TestFixture::test_value(2);
1874 auto pos = vec.emplace(const_vec1.begin(), value1, std::addressof(value2), std::make_unique<TypeParam>(value3));
1875 EXPECT_EQ(pos, vec.begin());
1876 EXPECT_EQ(vec.size(), 1);
1877 EXPECT_EQ(&*pos, std::addressof(vec[0]));
1879 EXPECT_EQ(pos->value, value1);
1880 ASSERT_NE(pos->raw_pointer,
nullptr);
1881 EXPECT_EQ(pos->raw_pointer, std::addressof(value2));
1882 ASSERT_NE(pos->unique_pointer,
nullptr);
1883 EXPECT_EQ(*pos->unique_pointer, value3);
1889 auto value = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
1891 value.insert(value.begin(), (TestFixture::capacity + 1) - value.size(), TestFixture::test_value(5)),
1892 "Precondition violation"
1894 EXPECT_EQ(value.size(), 4);
1900 TypeParam
const value1 = TestFixture::test_value(0);
1901 TypeParam
const value2 = TestFixture::test_value(1);
1902 TypeParam
const value3 = TestFixture::test_value(2);
1903 typename TestFixture::vector vec{TestFixture::standard_storage, {value1, value2}};
1904 constexpr std::size_t count = 5;
1906 vec.insert(vec.end(), count, value3);
1907 EXPECT_EQ(vec.size(), count + 2);
1908 EXPECT_EQ(vec[0], value1);
1909 EXPECT_EQ(vec[1], value2);
1910 for (std::size_t i = 0; i < count; ++i) {
1911 EXPECT_EQ(vec[i + 2], value3);
1919 TypeParam
const value1 = TestFixture::test_value(0);
1920 TypeParam
const value2 = TestFixture::test_value(1);
1921 TypeParam
const value3 = TestFixture::test_value(2);
1922 TypeParam
const value4 = TestFixture::test_value(3);
1923 TypeParam
const value_inserted = TestFixture::test_value(4);
1924 typename TestFixture::vector vec{TestFixture::standard_storage, {value1, value2, value3, value4}};
1925 constexpr std::size_t count = 5;
1927 vec.insert(vec.begin() + 1, count, value_inserted);
1928 EXPECT_EQ(vec.size(), count + 4);
1929 EXPECT_EQ(vec[0], value1);
1930 for (std::size_t i = 0; i < count; ++i) {
1931 EXPECT_EQ(vec[i + 1], value_inserted);
1933 EXPECT_EQ(vec[count + 1], value2);
1934 EXPECT_EQ(vec[count + 2], value3);
1935 EXPECT_EQ(vec[count + 3], value4);
1942 TypeParam
const value1 = TestFixture::test_value(0);
1943 TypeParam
const value2 = TestFixture::test_value(1);
1944 TypeParam
const value3 = TestFixture::test_value(2);
1945 TypeParam
const value4 = TestFixture::test_value(3);
1946 auto vec1 = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
1947 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
1948 auto const vec2 = TestFixture::test_external_vector(storage2, 4, 11);
1950 vec1.insert(vec1.begin() + 1, vec2.begin(), vec2.end());
1951 EXPECT_EQ(vec1.size(), vec2.size() + 4);
1952 EXPECT_EQ(vec1[0], value1);
1953 for (std::size_t idx = 0; idx < vec2.size(); ++idx) {
1954 EXPECT_EQ(vec1[idx + 1], vec2[idx]);
1956 EXPECT_EQ(vec1[vec2.size() + 1], value2);
1957 EXPECT_EQ(vec1[vec2.size() + 2], value3);
1958 EXPECT_EQ(vec1[vec2.size() + 3], value4);
1964 using ivec_iter =
typename TestFixture::vector::const_iterator;
1965 using source_array = ::arene::base::array<TypeParam, TestFixture::capacity>;
1966 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
1967 using throw_conv_array = ::arene::base::array<throws_when_converted, TestFixture::capacity>;
1968 using throwing_it_throwing_type =
typename TestFixture::
template throwing_input_iterator<throws_when_converted>;
1969 using throwing_it_raw_type =
typename TestFixture::
template throwing_input_iterator<TypeParam>;
1970 using nothrow_it_throwing_type =
typename TestFixture::
template non_throwing_input_iterator<throws_when_converted>;
1971 using nothrow_it_raw_type =
typename TestFixture::
template non_throwing_input_iterator<TypeParam>;
1973 constexpr bool is_nothrow_movable =
1974 std::is_nothrow_move_constructible<TypeParam>{} && std::is_nothrow_move_assignable<TypeParam>{};
1977 noexcept(
this->construct().insert(
1978 std::declval<ivec_iter>(),
1979 std::declval<
typename source_array::const_iterator>(),
1980 std::declval<
typename source_array::const_iterator>()
1982 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1985 STATIC_ASSERT_FALSE(
noexcept(
this->construct().insert(
1986 std::declval<ivec_iter>(),
1987 std::declval<
typename throw_conv_array::const_iterator>(),
1988 std::declval<
typename throw_conv_array::const_iterator>()
1992 noexcept(
this->construct().insert(
1993 std::declval<ivec_iter>(),
1994 std::declval<nothrow_it_raw_type>(),
1995 std::declval<nothrow_it_raw_type>()
1997 is_nothrow_movable && std::is_nothrow_copy_constructible<TypeParam>{}
1999 STATIC_ASSERT_FALSE(
noexcept(
this->construct().insert(
2000 std::declval<ivec_iter>(),
2001 std::declval<std::istream_iterator<TypeParam>>(),
2002 std::declval<std::istream_iterator<TypeParam>>()
2004 STATIC_ASSERT_FALSE(
noexcept(
this->construct().insert(
2005 std::declval<ivec_iter>(),
2006 std::declval<throwing_it_throwing_type>(),
2007 std::declval<throwing_it_throwing_type>()
2009 STATIC_ASSERT_FALSE(
noexcept(
this->construct().insert(
2010 std::declval<ivec_iter>(),
2011 std::declval<throwing_it_raw_type>(),
2012 std::declval<throwing_it_raw_type>()
2014 STATIC_ASSERT_FALSE(
noexcept(
this->construct().insert(
2015 std::declval<ivec_iter>(),
2016 std::declval<nothrow_it_throwing_type>(),
2017 std::declval<nothrow_it_throwing_type>()
2023 auto const value1 = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
2025 ASSERT_EQ(value1.cbegin(), value1.begin());
2026 ASSERT_EQ(value1.cend(), value1.end());
2028 ::testing::StaticAssertTypeEq<
decltype(value1.cbegin()),
typename TestFixture::vector::const_iterator>();
2029 STATIC_ASSERT_TRUE(
noexcept(value1.cbegin()));
2030 STATIC_ASSERT_TRUE(
noexcept(value1.cend()));
2032 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2033 auto value2 = TestFixture::test_external_vector(storage2, 4);
2034 ::testing::StaticAssertTypeEq<
decltype(value2.cbegin()),
typename TestFixture::vector::const_iterator>();
2035 ::testing::StaticAssertTypeEq<
decltype(value2.cend()),
typename TestFixture::vector::const_iterator>();
2037 EXPECT_EQ(value2.begin(), value2.cbegin());
2038 EXPECT_EQ(value2.end(), value2.cend());
2045 auto const value1 = TestFixture::test_external_vector(TestFixture::standard_storage, 4);
2047 auto itr = value1.rbegin();
2048 ASSERT_NE(itr, value1.rend());
2049 EXPECT_EQ(*itr, value1[3]);
2051 ASSERT_NE(itr, value1.rend());
2052 EXPECT_EQ(*itr, value1[2]);
2054 ASSERT_NE(itr, value1.rend());
2055 EXPECT_EQ(*itr, value1[1]);
2057 ASSERT_NE(itr, value1.rend());
2058 EXPECT_EQ(*itr, value1[0]);
2060 ASSERT_EQ(itr, value1.rend());
2062 auto citr = value1.crbegin();
2063 ASSERT_NE(citr, value1.crend());
2064 EXPECT_EQ(*citr, value1[3]);
2066 ASSERT_NE(citr, value1.crend());
2067 EXPECT_EQ(*citr, value1[2]);
2069 ASSERT_NE(citr, value1.crend());
2070 EXPECT_EQ(*citr, value1[1]);
2072 ASSERT_NE(citr, value1.crend());
2073 EXPECT_EQ(*citr, value1[0]);
2075 ASSERT_EQ(citr, value1.crend());
2081 constexpr std::size_t larger_capacity = TestFixture::capacity + 2UL;
2082 alignas(TypeParam)
typename TestFixture::
template storage_type<larger_capacity> storage{};
2083 external_vector<TypeParam>
const large_vector{
2085 {TestFixture::test_value(0),
2086 TestFixture::test_value(1),
2087 TestFixture::test_value(2),
2088 TestFixture::test_value(3),
2089 TestFixture::test_value(4)}
2092 alignas(TypeParam)
typename TestFixture::
template storage_type<TestFixture::capacity> storage2{};
2093 typename TestFixture::vector small_vector(storage2, large_vector);
2094 small_vector = large_vector;
2096 EXPECT_EQ(small_vector.size(), large_vector.size());
2097 for (std::size_t i = 0; i < small_vector.size(); ++i) {
2098 EXPECT_EQ(small_vector[i], large_vector[i]);
2104 using vec =
typename TestFixture::vector;
2105 STATIC_ASSERT_TRUE(std::is_same<
decltype(vec::try_construct()), ::arene::base::optional<vec>>::value);
2106 STATIC_ASSERT_TRUE(
noexcept(vec::try_construct()));
2108 ASSERT_TRUE(vec::try_construct().has_value());
2109 ASSERT_TRUE(vec::try_construct()->empty());
2118 using vec =
typename TestFixture::vector;
2119 constexpr std::size_t size1 = 10;
2121 std::is_same<
decltype(vec::try_construct(TestFixture::standard_storage, size1)), ::arene::base::optional<vec>>::
2124 STATIC_ASSERT_TRUE(
noexcept(vec::try_construct(TestFixture::standard_storage, size1)));
2126 ASSERT_TRUE(vec::try_construct(TestFixture::standard_storage, size1).has_value());
2127 ASSERT_FALSE(vec::try_construct(TestFixture::standard_storage, size1)->empty());
2128 ASSERT_EQ(vec::try_construct(TestFixture::standard_storage, size1)->size(), size1);
2138 using vec =
typename TestFixture::vector;
2139 constexpr std::size_t size1 = TestFixture::capacity + 1;
2141 std::is_same<
decltype(vec::try_construct(TestFixture::standard_storage, size1)), ::arene::base::optional<vec>>::
2144 STATIC_ASSERT_TRUE(
noexcept(vec::try_construct(TestFixture::standard_storage, size1)));
2146 ASSERT_FALSE(vec::try_construct(TestFixture::standard_storage, size1).has_value());
2152 constexpr bool can_construct_with_size_only = ::arene::base::substitution_succeeds<
2153 TestFixture::
template try_construct_result,
2154 typename TestFixture::vector,
2155 arene::base::span<arene::base::byte>,
2157 STATIC_ASSERT_EQ(can_construct_with_size_only, std::is_default_constructible<TypeParam>{});
2164 (std::is_constructible<
typename TestFixture::vector, arene::base::span<arene::base::byte>, std::size_t>::value),
2165 std::is_default_constructible<TypeParam>{}
2172 using ivec =
typename TestFixture::vector;
2173 STATIC_ASSERT_TRUE(
noexcept(ivec::try_construct()));
2174 STATIC_ASSERT_TRUE(
noexcept(ivec{}));
2176 ASSERT_TRUE(ivec::try_construct().has_value());
2177 ASSERT_TRUE(ivec::try_construct()->empty());
2178 ASSERT_TRUE(ivec().empty());
2184 using ivec =
typename TestFixture::vector;
2185 STATIC_ASSERT_TRUE(
noexcept(ivec::try_construct(TestFixture::standard_storage)));
2186 STATIC_ASSERT_TRUE(
noexcept(ivec{TestFixture::standard_storage}));
2188 ASSERT_TRUE(ivec::try_construct(TestFixture::standard_storage).has_value());
2189 ASSERT_TRUE(ivec::try_construct(TestFixture::standard_storage)->empty());
2190 ASSERT_TRUE(ivec(TestFixture::standard_storage).empty());
2200 using ivec =
typename TestFixture::vector;
2201 constexpr std::size_t small_size = 10;
2202 STATIC_ASSERT_TRUE(std::is_same<
2203 decltype(ivec::try_construct(TestFixture::standard_storage, small_size)),
2204 ::arene::base::optional<ivec>>::value);
2206 noexcept(ivec::try_construct(TestFixture::standard_storage, small_size)),
2207 std::is_default_constructible<TypeParam>{}
2218 using ivec =
typename TestFixture::vector;
2219 constexpr std::size_t size1 = TestFixture::capacity - 1;
2221 noexcept(ivec(TestFixture::standard_storage, size1)),
2222 std::is_nothrow_default_constructible<TypeParam>{}
2229 ExternalVectorDeathTest,
2233 constexpr std::size_t size1 = TestFixture::capacity + 1;
2235 this->construct(TestFixture::standard_storage, size1),
2236 "Precondition violation"
2243 using ivec =
typename TestFixture::vector;
2244 constexpr bool copy_ok = std::is_copy_constructible<TypeParam>::value;
2246 (std::is_constructible<ivec, arene::base::span<arene::base::byte>, std::size_t, TypeParam>::value),
2250 (::arene::base::substitution_succeeds<
2251 TestFixture::
template try_construct_result,
2253 arene::base::span<arene::base::byte>,
2263 static std::initializer_list<TypeParam>
const values{
2264 TestFixture::test_value(0),
2265 TestFixture::test_value(1),
2266 TestFixture::test_value(2),
2267 TestFixture::test_value(3)
2271 noexcept(TestFixture::vector::try_construct(TestFixture::standard_storage, values)),
2272 std::is_nothrow_copy_constructible<TypeParam>{}
2274 ASSERT_TRUE(TestFixture::vector::try_construct(TestFixture::standard_storage, values).has_value());
2275 ASSERT_EQ(TestFixture::vector::try_construct(TestFixture::standard_storage, values)->size(), values.size());
2277 auto res = TestFixture::vector::try_construct(TestFixture::standard_storage, values);
2278 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2284 static std::initializer_list<TypeParam>
const values{
2285 TestFixture::test_value(0), TestFixture::test_value(1), TestFixture::test_value(2),
2286 TestFixture::test_value(3), TestFixture::test_value(4), TestFixture::test_value(5),
2287 TestFixture::test_value(6), TestFixture::test_value(7), TestFixture::test_value(8),
2288 TestFixture::test_value(9), TestFixture::test_value(10), TestFixture::test_value(11),
2289 TestFixture::test_value(12), TestFixture::test_value(13), TestFixture::test_value(14),
2290 TestFixture::test_value(15), TestFixture::test_value(16), TestFixture::test_value(17),
2291 TestFixture::test_value(18), TestFixture::test_value(19), TestFixture::test_value(20),
2292 TestFixture::test_value(21), TestFixture::test_value(22), TestFixture::test_value(23),
2293 TestFixture::test_value(24), TestFixture::test_value(25)
2296 ASSERT_GT(values.size(), TestFixture::capacity);
2297 ASSERT_FALSE(TestFixture::vector::try_construct(TestFixture::standard_storage, values).has_value());
2302 using ivec =
typename TestFixture::vector;
2303 auto const values = TestFixture::test_external_vector(TestFixture::standard_storage);
2305 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2306 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2307 TestFixture::
template try_construct_result,
2309 arene::base::span<arene::base::byte>,
2312 noexcept(ivec::try_construct(storage2, values)),
2313 std::is_nothrow_copy_constructible<TypeParam>::value
2315 auto res = ivec::try_construct(storage2, values);
2316 ASSERT_TRUE(res.has_value());
2317 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2323 auto const values = TestFixture::test_external_vector(TestFixture::standard_storage);
2325 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2327 noexcept(
typename TestFixture::vector(storage2, values)),
2328 std::is_nothrow_copy_constructible<TypeParam>{}
2330 auto res =
this->construct(storage2, values);
2331 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2337 using ivec =
typename TestFixture::vector;
2338 constexpr std::size_t smaller_capacity = TestFixture::capacity - 1;
2339 alignas(TypeParam)
alignas(arene::base::byte)
2340 arene::base::array<arene::base::byte, smaller_capacity *
sizeof(TypeParam)>
2343 external_vector<TypeParam>
const values{TestFixture::test_external_vector(storage, smaller_capacity)};
2345 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2346 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2347 TestFixture::
template try_construct_result,
2349 arene::base::span<arene::base::byte>,
2352 noexcept(ivec::try_construct(storage2, values)),
2353 std::is_nothrow_copy_constructible<TypeParam>::value
2355 auto res = ivec::try_construct(storage2, values);
2356 ASSERT_TRUE(res.has_value());
2357 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2363 constexpr std::size_t smaller_capacity = TestFixture::capacity - 1;
2364 alignas(TypeParam)
typename TestFixture::
template storage_type<smaller_capacity> storage{};
2365 static external_vector<TypeParam>
const values{TestFixture::test_external_vector(storage, smaller_capacity)};
2367 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2369 noexcept(
typename TestFixture::vector(storage2, values)),
2370 std::is_nothrow_copy_constructible<TypeParam>{}
2372 auto res =
this->construct(storage2, values);
2373 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2380 using ivec =
typename TestFixture::vector;
2381 constexpr std::size_t larger_capacity = TestFixture::capacity + 1;
2382 alignas(TypeParam)
alignas(arene::base::byte)
2383 arene::base::array<arene::base::byte, larger_capacity *
sizeof(TypeParam)>
2385 auto const values = TestFixture::test_external_vector(storage, 0, TestFixture::capacity);
2387 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2388 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2389 TestFixture::
template try_construct_result,
2391 arene::base::span<arene::base::byte>,
2394 noexcept(ivec::try_construct(storage2, values)),
2395 std::is_nothrow_copy_constructible<TypeParam>::value
2397 auto res = ivec::try_construct(storage2, values);
2398 ASSERT_TRUE(res.has_value());
2399 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2405 constexpr std::size_t larger_capacity = TestFixture::capacity + 1;
2406 alignas(TypeParam)
alignas(arene::base::byte)
2407 arene::base::array<arene::base::byte, larger_capacity *
sizeof(TypeParam)>
2409 auto const values = TestFixture::test_external_vector(storage, 0, larger_capacity);
2411 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2412 EXPECT_GT(values.size(), TestFixture::capacity);
2413 EXPECT_FALSE(TestFixture::vector::try_construct(storage2, values).has_value());
2419 constexpr std::size_t larger_capacity = TestFixture::capacity + 1;
2420 alignas(TypeParam)
typename TestFixture::
template storage_type<larger_capacity> storage{};
2421 auto const values = TestFixture::test_external_vector(storage, 0, TestFixture::capacity);
2422 constexpr bool copy_is_noexcept = std::is_nothrow_copy_constructible<TypeParam>::value;
2424 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2425 STATIC_ASSERT_EQ(
noexcept(
typename TestFixture::vector(storage2, values)), copy_is_noexcept);
2426 auto res =
this->construct(storage2, values);
2427 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2432 using ivec =
typename TestFixture::vector;
2434 STATIC_ASSERT_FALSE((std::is_constructible<ivec, ivec
const&>::value));
2435 STATIC_ASSERT_FALSE(
2436 (::arene::base::substitution_succeeds<TestFixture::
template try_construct_result, ivec, ivec
const&>)
2443 using ivec =
typename TestFixture::vector;
2444 constexpr bool copy_ok = std::is_copy_constructible<TypeParam>::value;
2446 STATIC_ASSERT_EQ((std::is_constructible<ivec, span<byte>, ivec
const&>::value), copy_ok);
2448 (::arene::base::substitution_succeeds<TestFixture::
template try_construct_result, ivec, span<byte>, ivec
const&>),
2456 auto const values = TestFixture::test_external_vector(TestFixture::standard_storage);
2457 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2458 typename TestFixture::vector values_copy(storage2, values);
2460 STATIC_ASSERT_TRUE(::arene::base::substitution_succeeds<
2461 TestFixture::
template try_construct_result,
2462 typename TestFixture::vector,
2463 typename TestFixture::vector&&>);
2465 noexcept(TestFixture::vector::try_construct(std::move(values_copy))),
2466 std::is_nothrow_move_constructible<TypeParam>::value
2468 auto res = TestFixture::vector::try_construct(std::move(values_copy));
2469 ASSERT_TRUE(res.has_value());
2470 EXPECT_THAT(*res, ::testing::ElementsAreArray(values));
2476 auto const values = TestFixture::test_external_vector(TestFixture::standard_storage);
2478 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2479 typename TestFixture::vector source(storage2, values);
2481 STATIC_ASSERT_TRUE(
noexcept(
typename TestFixture::vector(std::move(source))));
2483 auto res =
this->construct(std::move(source));
2484 EXPECT_THAT(res, ::testing::ElementsAreArray(values));
2490 constexpr std::size_t larger_capacity = TestFixture::capacity + 1;
2491 alignas(TypeParam)
alignas(arene::base::byte)
2492 arene::base::array<arene::base::byte, larger_capacity *
sizeof(TypeParam)>
2494 auto values = TestFixture::test_external_vector(storage, TestFixture::capacity + 1);
2496 ASSERT_GT(values.size(), TestFixture::capacity);
2500 TestFixture::vector::try_construct(TestFixture::standard_storage, external_vector<TypeParam>{std::move(values)})
2507 using ivec = external_vector<TypeParam>;
2508 constexpr bool move_ok = std::is_move_constructible<TypeParam>::value;
2510 STATIC_ASSERT_EQ((std::is_constructible<ivec, ivec&&>::value), move_ok);
2512 (::arene::base::substitution_succeeds<TestFixture::
template try_construct_result, ivec, ivec&&>),
2520 auto const source = TestFixture::test_external_vector(TestFixture::standard_storage, 5);
2522 alignas(TypeParam)
typename TestFixture::standard_storage_type storage2{};
2523 auto maybe_vec = TestFixture::vector::try_construct(storage2, source.begin(), source.end());
2524 ASSERT_TRUE(maybe_vec.has_value());
2526 ASSERT_EQ(maybe_vec->size(), source.size());
2527 for (std::size_t i = 0; i < maybe_vec->size(); ++i) {
2528 EXPECT_EQ((*maybe_vec)[i], source[i]);
2535 using array = ::arene::base::array<TypeParam, TestFixture::capacity>;
2536 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
2537 using convertible_array = ::arene::base::array<throws_when_converted, TestFixture::capacity>;
2538 using throwing_bidirectional_iterator =
typename TestFixture::throwing_bidirectional_iterator_of_t;
2541 noexcept(TestFixture::vector::try_construct(
2542 std::declval<arene::base::span<arene::base::byte>>(),
2543 std::declval<
typename array::const_iterator>(),
2544 std::declval<
typename array::const_iterator>()
2546 std::is_nothrow_copy_constructible<TypeParam>::value
2548 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2549 std::declval<arene::base::span<arene::base::byte>>(),
2550 std::declval<
typename convertible_array::const_iterator>(),
2551 std::declval<
typename convertible_array::const_iterator>()
2553 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2554 std::declval<arene::base::span<arene::base::byte>>(),
2555 std::declval<throwing_bidirectional_iterator>(),
2556 std::declval<throwing_bidirectional_iterator>()
2563 using throws_when_converted =
typename TestFixture::throws_when_converted_to_t;
2564 using throwing_it_throwing_type =
typename TestFixture::
template throwing_input_iterator<throws_when_converted>;
2565 using throwing_it_raw_type =
typename TestFixture::
template throwing_input_iterator<TypeParam>;
2566 using nothrow_it_throwing_type =
typename TestFixture::
template non_throwing_input_iterator<throws_when_converted>;
2567 using nothrow_it_raw_type =
typename TestFixture::
template non_throwing_input_iterator<TypeParam>;
2569 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2570 std::declval<arene::base::span<arene::base::byte>>(),
2571 std::declval<std::istream_iterator<TypeParam>>(),
2572 std::declval<std::istream_iterator<TypeParam>>()
2574 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2575 std::declval<arene::base::span<arene::base::byte>>(),
2576 std::declval<throwing_it_throwing_type>(),
2577 std::declval<throwing_it_throwing_type>()
2579 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2580 std::declval<arene::base::span<arene::base::byte>>(),
2581 std::declval<throwing_it_raw_type>(),
2582 std::declval<throwing_it_raw_type>()
2585 noexcept(TestFixture::vector::try_construct(
2586 std::declval<arene::base::span<arene::base::byte>>(),
2587 std::declval<nothrow_it_raw_type>(),
2588 std::declval<nothrow_it_raw_type>()
2590 std::is_nothrow_copy_constructible<TypeParam>::value
2592 STATIC_ASSERT_FALSE(
noexcept(TestFixture::vector::try_construct(
2593 std::declval<arene::base::span<arene::base::byte>>(),
2594 std::declval<nothrow_it_throwing_type>(),
2595 std::declval<nothrow_it_throwing_type>()
2602 ASSERT_DEATH(std::ignore = *
typename TestFixture::vector::iterator{},
"Precondition violation");
2603 ASSERT_DEATH(std::ignore = *
typename TestFixture::vector::const_iterator{},
"Precondition violation");
2609 ASSERT_DEATH(std::ignore =
typename TestFixture::vector::iterator{} + 1,
"Precondition violation");
2610 ASSERT_DEATH(std::ignore =
typename TestFixture::vector::const_iterator{} + 1,
"Precondition violation");
2744 ExternalVectorDeathTest,
The Death Tests use the same fixture as the "normal" tests. Inherits so that it will be a distinct ty...
Definition external_vector.hpp:229
Test fixture for all type-parameterized external_vector tests.
Definition external_vector.hpp:73
standard_storage_type standard_storage
An instance of the default storage type to use as backing for a default capacity vector.
Definition external_vector.hpp:88
static constexpr auto test_external_vector(arene::base::span< arene::base::byte > storage, std::size_t begin, std::size_t end) noexcept(std::is_nothrow_move_constructible< T >::value) -> vector
Return a vector containing the test values [begin,end) of T , parameterized by test suite users.
Definition external_vector.hpp:195
static constexpr auto test_external_vector(arene::base::span< arene::base::byte > storage, std::size_t size) noexcept(std::is_nothrow_move_constructible< T >::value) -> vector
Return a vector containing the test values [0,size) of T , parameterized by test suite users.
Definition external_vector.hpp:207
static constexpr auto test_value(std::size_t idx) noexcept(std::is_nothrow_move_constructible< T >::value) -> T
Return the idx 'th test value of the current T , parameterized by test suite users.
Definition external_vector.hpp:186
static constexpr auto test_external_vector(arene::base::span< arene::base::byte > storage) noexcept(std::is_nothrow_move_constructible< T >::value) -> vector
Return a vector containing the test values [0,capacity) of T , parameterized by test suite users.
Definition external_vector.hpp:216
static constexpr auto construct(U &&... params) noexcept(noexcept(vector(std::forward< U >(params)...))) -> vector
Construct a vector from the passed parameters; allows calling as this->construct, which can be shorte...
Definition external_vector.hpp:179
static constexpr std::size_t capacity
The base capacity to use for most external_vector instantiations in the parameterized tests.
Definition external_vector.hpp:76
Definition customization.hpp:36
constexpr auto constexpr_resize(Vec vec, std::size_t size) -> Vec
Definition external_vector.hpp:1068
constexpr auto constexpr_iterate(Args &&... args) -> bool
Definition external_vector.hpp:663
constexpr auto bubble_sort_helper(Container container) noexcept -> Container
Inefficiently bubble sorts the argument because std::sort is not constexpr in C++14.
Definition external_vector.hpp:1614
constexpr auto test_external_vector(arene::base::span< arene::base::byte > storage, std::size_t begin, std::size_t end) noexcept(std::is_nothrow_copy_constructible< T >::value) -> ::arene::base::external_vector< T >
Create a test external vector containing a range of test values.
Definition external_vector.hpp:51
TYPED_TEST_SUITE_P(ExternalVectorDeathTest)
constexpr auto contains_duplicates(Container const &container) noexcept -> bool
Checks whether or not the given container has any duplicates, which we need to assert for test logic.
Definition external_vector.hpp:1596
TYPED_TEST_SUITE_P(ExternalVectorTest)
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)
ARENE_IGNORE_ALL("-Wfloat-equal", "These tests don't perform arithmetic, so equality is OK even for floating point")
MATCHER_P(elements_match_function, function, "")
Definition external_vector.hpp:936
constexpr bool is_fully_comparable_v
Definition external_vector.hpp:1634
REGISTER_TYPED_TEST_SUITE_P(ExternalVectorDeathTest, AddingToInvalidIteratorIsPreconditionViolation, AssignIsPreconditionViolationIfSizeOverCapacity, ConstructWithExcessiveSizeViaNormalConstructIsAlwaysPreconditionViolation, ConstructingWithOutOfRangeSizeAndSourceIsPreconditionViolation, ConstructingWithOutOfRangeSizeIsPreconditionViolation, ConstructingWithTooManyInitializersIsPreconditionViolation, DereferencingInvalidIteratorIsPreconditionViolation, EmplaceBackIsPreconditionViolationIfFull, IndexOperatorOutOfRange, InsertNIsPreconditionViolationIfTooManyItems, InsertWhenAtCapacityIsPreconditionViolation, PushBackBeyondMaxSizeIsPreconditionViolation, PushBackOnZeroSizeVectorIsPreconditionViolation)
Definition array_exceptions_disabled.cpp:11
CONDITIONAL_TYPED_TEST_P(InlineDequeTest, PushFrontOneElement, is_double_ended< TypeParam >)
Definition deque.hpp:218
TYPED_TEST_P(InlineDequeTest, CanConstruct)
Definition deque.hpp:196
CONDITIONAL_TYPED_TEST_P(InlineDequeTest, BasicFunctionFromBack, TypeParam::capacity >=2)
Definition deque.hpp:546
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
A bidirectional iterator of T which declares that it could throw, used in some noexcept tests.
Definition external_vector.hpp:108
auto operator!=(throwing_bidirectional_iterator_of_t const &) -> bool
Inequality operator; never defined.
auto operator--() -> throwing_bidirectional_iterator_of_t &
Pre-decrement operator; never defined.
auto operator++(int) -> throwing_bidirectional_iterator_of_t
Post-increment operator; never defined.
auto operator--(int) -> throwing_bidirectional_iterator_of_t
Post-decrement operator; never defined.
auto operator==(throwing_bidirectional_iterator_of_t const &) -> bool
Equality operator; never defined.
auto operator*() -> reference
Dereference operator; never defined.
auto operator++() -> throwing_bidirectional_iterator_of_t &
Pre-increment operator; never defined.
A type with a noexcept(false) conversion operator to T (doesn't actually throw, just declares it)
Definition external_vector.hpp:100
operator T() const noexcept(false)
Implicit conversion operator to T which declares that it might throw, though it doesn't actually.
Definition external_vector.hpp:104
Definition external_vector.hpp:1707
throws_without_nullptr(T)
Definition external_vector.hpp:1708
throws_without_nullptr(T, std::nullptr_t) noexcept
Definition external_vector.hpp:1709