@@ -26,26 +26,20 @@ TYPED_TEST(Constructors, SizedDefault) {
2626 constexpr auto mid_size = std::midpoint (0ul , IV::capacity ());
2727 IV mid (mid_size);
2828 EXPECT_EQ (mid.size (), mid_size);
29- if (std::is_same_v<T, NonTriviallyDefaultConstructible > ||
30- std::is_same_v<T, NonTrivial >) {
29+ if constexpr (std::is_scalar_v<T> || std::is_aggregate_v<T > ||
30+ ! std::is_trivially_default_constructible_v<T >) {
3131
32- IV mid_correct;
33- for (auto i = 0ul ; i < mid_size; ++i)
34- mid_correct.emplace_back ();
35-
36- EXPECT_EQ (mid, mid_correct);
32+ // all elements are value-initialized
33+ EXPECT_EQ (std::ranges::count (mid, T{}), mid.size ());
3734 }
3835
3936 IV full ((IV::capacity ()));
4037 EXPECT_EQ (full.size (), IV::capacity ());
41- if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
42- std::is_same_v<T, NonTrivial>) {
43-
44- IV full_correct;
45- for (auto i = 0ul ; i < full.size (); ++i)
46- full_correct.emplace_back ();
38+ if constexpr (std::is_scalar_v<T> || std::is_aggregate_v<T> ||
39+ !std::is_trivially_default_constructible_v<T>) {
4740
48- EXPECT_EQ (full, full_correct);
41+ // all elements are value-initialized
42+ EXPECT_EQ (std::ranges::count (full, T{}), full.size ());
4943 }
5044}
5145
@@ -66,7 +60,7 @@ TYPED_TEST(Constructors, SizedValue) {
6660 EXPECT_THROW (IV (IV::capacity () + 1 , value), std::bad_alloc);
6761 }
6862
69- if (IV::capacity () < 1 )
63+ if constexpr (IV::capacity () < 1u )
7064 return ;
7165
7266 {
@@ -79,11 +73,7 @@ TYPED_TEST(Constructors, SizedValue) {
7973 T value{8194 };
8074 IV device (IV::capacity (), value);
8175
82- IV correct;
83- for (auto i = 0ul ; i < device.size (); ++i)
84- correct.push_back (value);
85-
86- EXPECT_EQ (std::count (device.begin (), device.end (), value), IV::capacity ());
76+ EXPECT_EQ (std::ranges::count (device, value), device.size ());
8777 }
8878}
8979
@@ -94,16 +84,24 @@ TYPED_TEST(Constructors, CopyIter) {
9484 // Complexity: Linear in distance(first, last).
9585
9686 using IV = TestFixture::IV;
87+ using T = TestFixture::T;
9788 using InputIterator = TestFixture::InputIterator;
9889
99- IV a (InputIterator{0 }, InputIterator{IV::max_size () / 2 });
100- EXPECT_EQ (a.size (), IV::max_size () / 2 );
101- if (!a.empty ()) {
102- EXPECT_EQ (a.back ().value , IV::max_size () / 2 - 1 );
90+ for (std::size_t n : {std::size_t (0 ), IV::max_size () / 2u , IV::max_size ()}) {
91+ // InputIterator
92+ InputIterator::num_deref = 0u ;
93+ IV a (InputIterator{}, InputIterator{static_cast <int >(n)});
94+ EXPECT_EQ (a.size (), n);
95+ for (int i = 0 ; i < static_cast <int >(n); ++i) {
96+ EXPECT_EQ (a[i], T{i});
97+ }
98+ // Only single-pass through input range
99+ EXPECT_EQ (InputIterator::num_deref, n);
100+
101+ // RandomAccessIterator
102+ IV b (a.begin (), a.end ());
103+ EXPECT_EQ (b, a);
103104 }
104-
105- IV b (a.begin (), a.end ());
106- EXPECT_EQ (b, a);
107105}
108106
109107TYPED_TEST (Constructors, CopyRanges) {
0 commit comments