Skip to content

Commit fc86a84

Browse files
committed
Apply @philnik777 suggestions
1 parent 7003c10 commit fc86a84

File tree

7 files changed

+187
-184
lines changed

7 files changed

+187
-184
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: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,24 @@
1515
#include <algorithm>
1616
#include <cassert>
1717

18-
#include "common.h"
1918
#include "test_macros.h"
2019
#include "test_iterators.h"
2120
#include "type_algorithms.h"
2221

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

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

4337
template <class InIter>
4438
struct Test {
@@ -68,8 +62,20 @@ struct TestInIters {
6862

6963
TEST_CONSTEXPR_CXX20 bool test() {
7064
types::for_each(types::cpp17_input_iterator_list<const int*>(), TestInIters());
71-
test_padding();
72-
test_overlapping();
65+
{ // Make sure that padding bits aren't copied
66+
Derived src(1, 2, 3);
67+
Derived dst(4, 5, 6);
68+
std::copy(static_cast<PaddedBase*>(&src), static_cast<PaddedBase*>(&src) + 1, static_cast<PaddedBase*>(&dst));
69+
assert(dst.a_ == 1);
70+
assert(dst.b_ == 2);
71+
assert(dst.c_ == 6);
72+
}
73+
{ // Make sure that overlapping ranges can be copied
74+
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
75+
std::copy(a + 3, a + 10, a);
76+
int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
77+
assert(std::equal(a, a + 10, expected));
78+
}
7379

7480
return true;
7581
}

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,26 @@
1616
#include <algorithm>
1717
#include <cassert>
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
template <class InIter>
2640
struct TestOutIters {
2741
template <class OutIter>
@@ -39,7 +53,16 @@ struct TestOutIters {
3953
}
4054
};
4155

42-
TEST_CONSTEXPR_CXX20 void test_padding() {
56+
struct TestInIters {
57+
template <class InIter>
58+
TEST_CONSTEXPR_CXX20 void operator()() {
59+
types::for_each(types::bidirectional_iterator_list<int*>(), TestOutIters<InIter>());
60+
}
61+
};
62+
63+
TEST_CONSTEXPR_CXX20 bool test() {
64+
types::for_each(types::bidirectional_iterator_list<const int*>(), TestInIters());
65+
4366
{ // Make sure that padding bits aren't copied
4467
Derived src(1, 2, 3);
4568
Derived dst(4, 5, 6);
@@ -49,28 +72,12 @@ TEST_CONSTEXPR_CXX20 void test_padding() {
4972
assert(dst.b_ == 2);
5073
assert(dst.c_ == 6);
5174
}
52-
}
53-
54-
TEST_CONSTEXPR_CXX20 void test_overlapping() {
5575
{ // Make sure that overlapping ranges can be copied
5676
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
5777
std::copy_backward(a, a + 7, a + 10);
5878
int expected[] = {1, 2, 3, 1, 2, 3, 4, 5, 6, 7};
5979
assert(std::equal(a, a + 10, expected));
6080
}
61-
}
62-
63-
struct TestInIters {
64-
template <class InIter>
65-
TEST_CONSTEXPR_CXX20 void operator()() {
66-
types::for_each(types::bidirectional_iterator_list<int*>(), TestOutIters<InIter>());
67-
}
68-
};
69-
70-
TEST_CONSTEXPR_CXX20 bool test() {
71-
types::for_each(types::bidirectional_iterator_list<const int*>(), TestInIters());
72-
test_padding();
73-
test_overlapping();
7481

7582
return true;
7683
}

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,27 @@
1515
#include <algorithm>
1616
#include <cassert>
1717

18-
#include "common.h"
1918
#include "test_macros.h"
2019
#include "test_iterators.h"
2120
#include "type_algorithms.h"
2221
#include "user_defined_integral.h"
2322

24-
typedef UserDefinedIntegral<unsigned> UDI;
23+
class PaddedBase {
24+
public:
25+
TEST_CONSTEXPR PaddedBase(std::int16_t a, std::int8_t b) : a_(a), b_(b) {}
2526

26-
TEST_CONSTEXPR_CXX20 void test_padding() {
27-
{ // Make sure that padding bits aren't copied
28-
Derived src(1, 2, 3);
29-
Derived dst(4, 5, 6);
30-
std::copy_n(static_cast<PaddedBase*>(&src), 1, static_cast<PaddedBase*>(&dst));
31-
assert(dst.a_ == 1);
32-
assert(dst.b_ == 2);
33-
assert(dst.c_ == 6);
34-
}
35-
}
27+
std::int16_t a_;
28+
std::int8_t b_;
29+
};
3630

37-
TEST_CONSTEXPR_CXX20 void test_overlapping() {
38-
{ // Make sure that overlapping ranges can be copied
39-
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
40-
std::copy_n(a + 3, 7, a);
41-
int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
42-
assert(std::equal(a, a + 10, expected));
43-
}
44-
}
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+
};
37+
38+
typedef UserDefinedIntegral<unsigned> UDI;
4539

4640
template <class InIter>
4741
struct TestOutIters {
@@ -71,8 +65,20 @@ struct TestInIters {
7165

7266
TEST_CONSTEXPR_CXX20 bool test() {
7367
types::for_each(types::cpp17_input_iterator_list<const int*>(), TestInIters());
74-
test_padding();
75-
test_overlapping();
68+
{ // Make sure that padding bits aren't copied
69+
Derived src(1, 2, 3);
70+
Derived dst(4, 5, 6);
71+
std::copy_n(static_cast<PaddedBase*>(&src), 1, static_cast<PaddedBase*>(&dst));
72+
assert(dst.a_ == 1);
73+
assert(dst.b_ == 2);
74+
assert(dst.c_ == 6);
75+
}
76+
{ // Make sure that overlapping ranges can be copied
77+
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
78+
std::copy_n(a + 3, 7, a);
79+
int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
80+
assert(std::equal(a, a + 10, expected));
81+
}
7682

7783
return true;
7884
}

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
@@ -27,13 +27,9 @@ typedef UserDefinedIntegral<unsigned> UDI;
2727

2828
template <class Iter, class Container>
2929
TEST_CONSTEXPR_CXX20 void
30-
test(Container& in,
31-
typename Container::iterator first,
32-
size_t n,
33-
typename Container::value_type value,
34-
const Container& expected) {
35-
Iter it = std::fill_n(Iter(first), UDI(n), value);
36-
assert(base(it) == first + n);
30+
test(Container in, size_t from, size_t n, typename Container::value_type value, Container expected) {
31+
Iter it = std::fill_n(Iter(in.data() + from), UDI(n), value);
32+
assert(base(it) == in.data() + from + n);
3733
assert(in == expected);
3834
}
3935

@@ -44,22 +40,23 @@ struct Test {
4440
{
4541
std::array<T, 4> in = {1, 2, 3, 4};
4642
std::array<T, 4> expected = {5, 5, 5, 5};
47-
test<Iter>(in, in.begin(), 4, 5, expected);
43+
test<Iter>(in, 0, 4, 5, expected);
4844
}
4945
{
5046
std::array<T, 4> in = {1, 2, 3, 4};
5147
std::array<T, 4> expected = {1, 5, 5, 4};
52-
test<Iter>(in, in.begin() + 1, 2, 5, expected);
48+
test<Iter>(in, 1, 2, 5, expected);
5349
}
5450
}
5551
};
5652

57-
TEST_CONSTEXPR void test_int_array() {
53+
TEST_CONSTEXPR_CXX20 void test_int_array() {
5854
{
5955
int a[4] = {};
6056
assert(std::fill_n(a, UDI(4), static_cast<char>(1)) == a + 4);
6157
assert(a[0] == 1 && a[1] == 1 && a[2] == 1 && a[3] == 1);
6258
}
59+
#if TEST_STD_VER >= 11
6360
{
6461
const std::size_t N = 5;
6562
int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N
@@ -69,6 +66,7 @@ TEST_CONSTEXPR void test_int_array() {
6966
*it == 0 // don't overwrite the last value in the output array
7067
);
7168
}
69+
#endif
7270
}
7371

7472
struct source {
@@ -118,12 +116,12 @@ TEST_CONSTEXPR_CXX20 void test_struct_array() {
118116
assert(a[2] == A('a'));
119117
}
120118
{
121-
B test1a[4] = {};
122-
assert(std::fill_n(test1a, UDI(4), static_cast<char>(10)) == test1a + 4);
123-
assert(test1a[0].c == 11);
124-
assert(test1a[1].c == 11);
125-
assert(test1a[2].c == 11);
126-
assert(test1a[3].c == 11);
119+
B b[4] = {};
120+
assert(std::fill_n(b, UDI(4), static_cast<char>(10)) == b + 4);
121+
assert(b[0].c == 11);
122+
assert(b[1].c == 11);
123+
assert(b[2].c == 11);
124+
assert(b[3].c == 11);
127125
}
128126
{
129127
Storage foo[5];

0 commit comments

Comments
 (0)