Skip to content

Commit 338f002

Browse files
committed
Apply philnik777's suggestions
1 parent 319d569 commit 338f002

File tree

8 files changed

+161
-182
lines changed

8 files changed

+161
-182
lines changed

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/common.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,24 @@
1616
#include <cassert>
1717
#include <vector>
1818

19-
#include "common.h"
2019
#include "test_macros.h"
2120
#include "test_iterators.h"
2221
#include "type_algorithms.h"
2322

24-
TEST_CONSTEXPR_CXX20 void test_padding() {
25-
{ // Make sure that padding bits aren't copied
26-
Derived src(1, 2, 3);
27-
Derived dst(4, 5, 6);
28-
std::copy(static_cast<PaddedBase*>(&src), static_cast<PaddedBase*>(&src) + 1, static_cast<PaddedBase*>(&dst));
29-
assert(dst.a_ == 1);
30-
assert(dst.b_ == 2);
31-
assert(dst.c_ == 6);
32-
}
33-
}
23+
class PaddedBase {
24+
public:
25+
TEST_CONSTEXPR PaddedBase(std::int16_t a, std::int8_t b) : a_(a), b_(b) {}
3426

35-
TEST_CONSTEXPR_CXX20 void test_overlapping() {
36-
{ // Make sure that overlapping ranges can be copied
37-
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
38-
std::copy(a + 3, a + 10, a);
39-
int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
40-
assert(std::equal(a, a + 10, expected));
41-
}
42-
}
27+
std::int16_t a_;
28+
std::int8_t b_;
29+
};
30+
31+
class Derived : public PaddedBase {
32+
public:
33+
TEST_CONSTEXPR Derived(std::int16_t a, std::int8_t b, std::int8_t c) : PaddedBase(a, b), c_(c) {}
34+
35+
std::int8_t c_;
36+
};
4337

4438
template <class InIter>
4539
struct Test {
@@ -89,8 +83,21 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) {
8983

9084
TEST_CONSTEXPR_CXX20 bool test() {
9185
types::for_each(types::cpp17_input_iterator_list<const int*>(), TestInIters());
92-
test_padding();
93-
test_overlapping();
86+
87+
{ // Make sure that padding bits aren't copied
88+
Derived src(1, 2, 3);
89+
Derived dst(4, 5, 6);
90+
std::copy(static_cast<PaddedBase*>(&src), static_cast<PaddedBase*>(&src) + 1, static_cast<PaddedBase*>(&dst));
91+
assert(dst.a_ == 1);
92+
assert(dst.b_ == 2);
93+
assert(dst.c_ == 6);
94+
}
95+
{ // Make sure that overlapping ranges can be copied
96+
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
97+
std::copy(a + 3, a + 10, a);
98+
int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
99+
assert(std::equal(a, a + 10, expected));
100+
}
94101

95102
{ // Test vector<bool>::iterator optimization
96103
assert(test_vector_bool(8));

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <cassert>
1818
#include <vector>
1919

20-
#include "common.h"
2120
#include "test_macros.h"
2221
#include "test_iterators.h"
2322
#include "type_algorithms.h"
@@ -80,11 +79,11 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) {
8079
}
8180

8281
return true;
83-
}
82+
}
8483

8584
TEST_CONSTEXPR_CXX20 bool test() {
8685
types::for_each(types::bidirectional_iterator_list<const int*>(), TestIterators());
87-
86+
8887
{ // Make sure that padding bits aren't copied
8988
Derived src(1, 2, 3);
9089
Derived dst(4, 5, 6);
@@ -94,7 +93,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
9493
assert(dst.b_ == 2);
9594
assert(dst.c_ == 6);
9695
}
97-
96+
9897
{ // Make sure that overlapping ranges can be copied
9998
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
10099
std::copy_backward(a, a + 7, a + 10);

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,26 @@
1616
#include <cassert>
1717
#include <vector>
1818

19-
#include "common.h"
2019
#include "test_macros.h"
2120
#include "test_iterators.h"
2221
#include "type_algorithms.h"
2322
#include "user_defined_integral.h"
2423

24+
class PaddedBase {
25+
public:
26+
TEST_CONSTEXPR PaddedBase(std::int16_t a, std::int8_t b) : a_(a), b_(b) {}
27+
28+
std::int16_t a_;
29+
std::int8_t b_;
30+
};
31+
32+
class Derived : public PaddedBase {
33+
public:
34+
TEST_CONSTEXPR Derived(std::int16_t a, std::int8_t b, std::int8_t c) : PaddedBase(a, b), c_(c) {}
35+
36+
std::int8_t c_;
37+
};
38+
2539
typedef UserDefinedIntegral<unsigned> UDI;
2640

2741
class PaddedBase {
@@ -95,7 +109,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
95109
assert(dst.a_ == 1);
96110
assert(dst.b_ == 2);
97111
assert(dst.c_ == 6);
98-
}
112+
}
99113

100114
{ // Make sure that overlapping ranges can be copied
101115
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static_assert(!HasCopyNIt<int*, int*, SentinelForNotWeaklyEqualityComparableWith
4040

4141
static_assert(std::is_same_v<std::ranges::copy_result<int, long>, std::ranges::in_out_result<int, long>>);
4242

43-
template <class In, class Out, class Sent = In>
43+
template <class In, class Out>
4444
constexpr void test_iterators() {
4545
{ // simple test
4646
std::array in{1, 2, 3, 4};
@@ -61,26 +61,6 @@ constexpr void test_iterators() {
6161
}
6262
}
6363

64-
template <class Out>
65-
constexpr void test_in_iterators() {
66-
test_iterators<cpp20_input_iterator<int*>, Out, sentinel_wrapper<cpp20_input_iterator<int*>>>();
67-
test_iterators<forward_iterator<int*>, Out>();
68-
test_iterators<bidirectional_iterator<int*>, Out>();
69-
test_iterators<random_access_iterator<int*>, Out>();
70-
test_iterators<contiguous_iterator<int*>, Out>();
71-
}
72-
73-
template <class Out>
74-
constexpr void test_proxy_in_iterators() {
75-
test_iterators<ProxyIterator<cpp20_input_iterator<int*>>,
76-
Out,
77-
sentinel_wrapper<ProxyIterator<cpp20_input_iterator<int*>>>>();
78-
test_iterators<ProxyIterator<forward_iterator<int*>>, Out>();
79-
test_iterators<ProxyIterator<bidirectional_iterator<int*>>, Out>();
80-
test_iterators<ProxyIterator<random_access_iterator<int*>>, Out>();
81-
test_iterators<ProxyIterator<contiguous_iterator<int*>>, Out>();
82-
}
83-
8464
#if TEST_STD_VER >= 23
8565
constexpr bool test_vector_bool(std::size_t N) {
8666
std::vector<bool> in(N, false);
@@ -104,17 +84,12 @@ constexpr bool test_vector_bool(std::size_t N) {
10484
#endif
10585

10686
constexpr bool test() {
107-
test_in_iterators<cpp20_input_iterator<int*>>();
108-
test_in_iterators<forward_iterator<int*>>();
109-
test_in_iterators<bidirectional_iterator<int*>>();
110-
test_in_iterators<random_access_iterator<int*>>();
111-
test_in_iterators<contiguous_iterator<int*>>();
112-
113-
test_proxy_in_iterators<ProxyIterator<cpp20_input_iterator<int*>>>();
114-
test_proxy_in_iterators<ProxyIterator<forward_iterator<int*>>>();
115-
test_proxy_in_iterators<ProxyIterator<bidirectional_iterator<int*>>>();
116-
test_proxy_in_iterators<ProxyIterator<random_access_iterator<int*>>>();
117-
test_proxy_in_iterators<ProxyIterator<contiguous_iterator<int*>>>();
87+
types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Out>() {
88+
types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class In>() {
89+
test_iterators<In, Out>();
90+
test_iterators<ProxyIterator<In>, ProxyIterator<Out>>();
91+
});
92+
});
11893

11994
{ // check that every element is copied exactly once
12095
struct CopyOnce {

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ typedef UserDefinedIntegral<unsigned> UDI;
2929

3030
template <class Iter, class Container>
3131
TEST_CONSTEXPR_CXX20 void
32-
test(Container& in,
33-
typename Container::iterator first,
34-
size_t n,
35-
typename Container::value_type value,
36-
const Container& expected) {
37-
Iter it = std::fill_n(Iter(first), UDI(n), value);
38-
assert(base(it) == first + n);
32+
test(Container in, size_t from, size_t n, typename Container::value_type value, Container expected) {
33+
Iter it = std::fill_n(Iter(in.data() + from), UDI(n), value);
34+
assert(base(it) == in.data() + from + n);
3935
assert(in == expected);
4036
}
4137

@@ -46,22 +42,23 @@ struct Test {
4642
{
4743
std::array<T, 4> in = {1, 2, 3, 4};
4844
std::array<T, 4> expected = {5, 5, 5, 5};
49-
test<Iter>(in, in.begin(), 4, 5, expected);
45+
test<Iter>(in, 0, 4, 5, expected);
5046
}
5147
{
5248
std::array<T, 4> in = {1, 2, 3, 4};
5349
std::array<T, 4> expected = {1, 5, 5, 4};
54-
test<Iter>(in, in.begin() + 1, 2, 5, expected);
50+
test<Iter>(in, 1, 2, 5, expected);
5551
}
5652
}
5753
};
5854

59-
TEST_CONSTEXPR void test_int_array() {
55+
TEST_CONSTEXPR_CXX20 void test_int_array() {
6056
{
6157
int a[4] = {};
6258
assert(std::fill_n(a, UDI(4), static_cast<char>(1)) == a + 4);
6359
assert(a[0] == 1 && a[1] == 1 && a[2] == 1 && a[3] == 1);
6460
}
61+
#if TEST_STD_VER >= 11
6562
{
6663
const std::size_t N = 5;
6764
int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N
@@ -71,6 +68,7 @@ TEST_CONSTEXPR void test_int_array() {
7168
*it == 0 // don't overwrite the last value in the output array
7269
);
7370
}
71+
#endif
7472
}
7573

7674
struct source {
@@ -153,12 +151,12 @@ TEST_CONSTEXPR_CXX20 void test_struct_array() {
153151
assert(a[2] == A('a'));
154152
}
155153
{
156-
B test1a[4] = {};
157-
assert(std::fill_n(test1a, UDI(4), static_cast<char>(10)) == test1a + 4);
158-
assert(test1a[0].c == 11);
159-
assert(test1a[1].c == 11);
160-
assert(test1a[2].c == 11);
161-
assert(test1a[3].c == 11);
154+
B b[4] = {};
155+
assert(std::fill_n(b, UDI(4), static_cast<char>(10)) == b + 4);
156+
assert(b[0].c == 11);
157+
assert(b[1].c == 11);
158+
assert(b[2].c == 11);
159+
assert(b[3].c == 11);
162160
}
163161
{
164162
Storage foo[5];

0 commit comments

Comments
 (0)