|
23 | 23 |
|
24 | 24 | #if TEST_STD_VER >= 11
|
25 | 25 | struct S {
|
26 |
| - TEST_CONSTEXPR_CXX26 S() : i_(0) {} |
27 |
| - TEST_CONSTEXPR_CXX26 S(int i) : i_(i) {} |
| 26 | + TEST_CONSTEXPR_CXX26 S() : i_(0) {} |
| 27 | + TEST_CONSTEXPR_CXX26 S(int i) : i_(i) {} |
28 | 28 |
|
29 |
| - TEST_CONSTEXPR_CXX26 S(const S& rhs) : i_(rhs.i_) {} |
30 |
| - TEST_CONSTEXPR_CXX26 S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } |
| 29 | + TEST_CONSTEXPR_CXX26 S(const S& rhs) : i_(rhs.i_) {} |
| 30 | + TEST_CONSTEXPR_CXX26 S(S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } |
31 | 31 |
|
32 |
| - TEST_CONSTEXPR_CXX26 S& operator =(const S& rhs) { i_ = rhs.i_; return *this; } |
33 |
| - TEST_CONSTEXPR_CXX26 S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; } |
34 |
| - TEST_CONSTEXPR_CXX26 S& operator =(int i) { i_ = i; return *this; } |
| 32 | + TEST_CONSTEXPR_CXX26 S& operator=(const S& rhs) { |
| 33 | + i_ = rhs.i_; |
| 34 | + return *this; |
| 35 | + } |
| 36 | + TEST_CONSTEXPR_CXX26 S& operator=(S&& rhs) { |
| 37 | + i_ = rhs.i_; |
| 38 | + rhs.i_ = -2; |
| 39 | + assert(this != &rhs); |
| 40 | + return *this; |
| 41 | + } |
| 42 | + TEST_CONSTEXPR_CXX26 S& operator=(int i) { |
| 43 | + i_ = i; |
| 44 | + return *this; |
| 45 | + } |
35 | 46 |
|
36 |
| - TEST_CONSTEXPR_CXX26 bool operator <(const S& rhs) const { return i_ < rhs.i_; } |
37 |
| - TEST_CONSTEXPR_CXX26 bool operator ==(const S& rhs) const { return i_ == rhs.i_; } |
38 |
| - TEST_CONSTEXPR_CXX26 bool operator ==(int i) const { return i_ == i; } |
| 47 | + TEST_CONSTEXPR_CXX26 bool operator<(const S& rhs) const { return i_ < rhs.i_; } |
| 48 | + TEST_CONSTEXPR_CXX26 bool operator==(const S& rhs) const { return i_ == rhs.i_; } |
| 49 | + TEST_CONSTEXPR_CXX26 bool operator==(int i) const { return i_ == i; } |
39 | 50 |
|
40 |
| - TEST_CONSTEXPR_CXX26 void set(int i) { i_ = i; } |
| 51 | + TEST_CONSTEXPR_CXX26 void set(int i) { i_ = i; } |
41 | 52 |
|
42 |
| - int i_; |
43 |
| - }; |
| 53 | + int i_; |
| 54 | +}; |
44 | 55 | #endif
|
45 | 56 |
|
46 | 57 | std::mt19937 randomness;
|
47 | 58 |
|
48 | 59 | template <class Iter>
|
49 |
| -void |
50 |
| -test_one_randomized(unsigned N, unsigned M) |
51 |
| -{ |
52 |
| - typedef typename std::iterator_traits<Iter>::value_type value_type; |
53 |
| - value_type* ia = new value_type[N]; |
54 |
| - for (unsigned i = 0; i < N; ++i) |
55 |
| - ia[i] = i; |
56 |
| - std::shuffle(ia, ia+N, randomness); |
57 |
| - std::sort(ia, ia+M); |
58 |
| - std::sort(ia+M, ia+N); |
59 |
| - std::inplace_merge(Iter(ia), Iter(ia+M), Iter(ia+N)); |
60 |
| - if(N > 0) |
61 |
| - { |
62 |
| - assert(ia[0] == 0); |
63 |
| - assert(ia[N-1] == static_cast<value_type>(N-1)); |
64 |
| - assert(std::is_sorted(ia, ia+N)); |
65 |
| - } |
66 |
| - delete [] ia; |
| 60 | +void test_one_randomized(unsigned N, unsigned M) { |
| 61 | + typedef typename std::iterator_traits<Iter>::value_type value_type; |
| 62 | + value_type* ia = new value_type[N]; |
| 63 | + for (unsigned i = 0; i < N; ++i) |
| 64 | + ia[i] = i; |
| 65 | + std::shuffle(ia, ia + N, randomness); |
| 66 | + std::sort(ia, ia + M); |
| 67 | + std::sort(ia + M, ia + N); |
| 68 | + std::inplace_merge(Iter(ia), Iter(ia + M), Iter(ia + N)); |
| 69 | + if (N > 0) { |
| 70 | + assert(ia[0] == 0); |
| 71 | + assert(ia[N - 1] == static_cast<value_type>(N - 1)); |
| 72 | + assert(std::is_sorted(ia, ia + N)); |
| 73 | + } |
| 74 | + delete[] ia; |
67 | 75 | }
|
68 | 76 |
|
69 | 77 | template <class Iter>
|
@@ -96,71 +104,65 @@ TEST_CONSTEXPR_CXX26 void test_one(unsigned N, unsigned M) {
|
96 | 104 | }
|
97 | 105 |
|
98 | 106 | template <class Iter>
|
99 |
| -TEST_CONSTEXPR_CXX26 void |
100 |
| -test(unsigned N) |
101 |
| -{ |
102 |
| - test_one<Iter>(N, 0); |
103 |
| - test_one<Iter>(N, N/4); |
104 |
| - test_one<Iter>(N, N/2); |
105 |
| - test_one<Iter>(N, 3*N/4); |
106 |
| - test_one<Iter>(N, N); |
| 107 | +TEST_CONSTEXPR_CXX26 void test(unsigned N) { |
| 108 | + test_one<Iter>(N, 0); |
| 109 | + test_one<Iter>(N, N / 4); |
| 110 | + test_one<Iter>(N, N / 2); |
| 111 | + test_one<Iter>(N, 3 * N / 4); |
| 112 | + test_one<Iter>(N, N); |
107 | 113 | }
|
108 | 114 |
|
109 | 115 | template <class Iter>
|
110 |
| -TEST_CONSTEXPR_CXX26 void |
111 |
| -test() |
112 |
| -{ |
113 |
| - test_one<Iter>(0, 0); |
114 |
| - test_one<Iter>(1, 0); |
115 |
| - test_one<Iter>(1, 1); |
116 |
| - test_one<Iter>(2, 0); |
117 |
| - test_one<Iter>(2, 1); |
118 |
| - test_one<Iter>(2, 2); |
119 |
| - test_one<Iter>(3, 0); |
120 |
| - test_one<Iter>(3, 1); |
121 |
| - test_one<Iter>(3, 2); |
122 |
| - test_one<Iter>(3, 3); |
123 |
| - test<Iter>(4); |
| 116 | +TEST_CONSTEXPR_CXX26 void test() { |
| 117 | + test_one<Iter>(0, 0); |
| 118 | + test_one<Iter>(1, 0); |
| 119 | + test_one<Iter>(1, 1); |
| 120 | + test_one<Iter>(2, 0); |
| 121 | + test_one<Iter>(2, 1); |
| 122 | + test_one<Iter>(2, 2); |
| 123 | + test_one<Iter>(3, 0); |
| 124 | + test_one<Iter>(3, 1); |
| 125 | + test_one<Iter>(3, 2); |
| 126 | + test_one<Iter>(3, 3); |
| 127 | + test<Iter>(4); |
124 | 128 | #if defined(_LIBCPP_HARDENING_MODE)
|
125 |
| - if (!TEST_IS_CONSTANT_EVALUATED) // avoid blowing past constant evaluation limit |
| 129 | + if (!TEST_IS_CONSTANT_EVALUATED) // avoid blowing past constant evaluation limit |
126 | 130 | #endif
|
127 |
| - { |
128 |
| - test<Iter>(100); |
129 |
| - } |
130 |
| - if (!TEST_IS_CONSTANT_EVALUATED) { // avoid blowing past constant evaluation limit |
131 |
| - test<Iter>(1000); |
132 |
| - } |
| 131 | + { |
| 132 | + test<Iter>(100); |
| 133 | + } |
| 134 | + if (!TEST_IS_CONSTANT_EVALUATED) { // avoid blowing past constant evaluation limit |
| 135 | + test<Iter>(1000); |
| 136 | + } |
133 | 137 | }
|
134 | 138 |
|
135 |
| -TEST_CONSTEXPR_CXX26 bool |
136 |
| -test() |
137 |
| -{ |
138 |
| - test<bidirectional_iterator<int*> >(); |
139 |
| - test<random_access_iterator<int*> >(); |
140 |
| - test<int*>(); |
| 139 | +TEST_CONSTEXPR_CXX26 bool test() { |
| 140 | + test<bidirectional_iterator<int*> >(); |
| 141 | + test<random_access_iterator<int*> >(); |
| 142 | + test<int*>(); |
141 | 143 |
|
142 | 144 | #if TEST_STD_VER >= 11
|
143 |
| - test<bidirectional_iterator<S*> >(); |
144 |
| - test<random_access_iterator<S*> >(); |
145 |
| - test<S*>(); |
| 145 | + test<bidirectional_iterator<S*> >(); |
| 146 | + test<random_access_iterator<S*> >(); |
| 147 | + test<S*>(); |
146 | 148 | #endif
|
147 | 149 |
|
148 |
| - return true; |
| 150 | + return true; |
149 | 151 | }
|
150 | 152 |
|
151 | 153 | int main(int, char**) {
|
152 |
| - test(); |
| 154 | + test(); |
153 | 155 | #if TEST_STD_VER >= 26
|
154 |
| - static_assert(test()); |
| 156 | + static_assert(test()); |
155 | 157 | #endif // TEST_STD_VER >= 26
|
156 | 158 |
|
157 | 159 | #if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS)
|
158 |
| - if (!TEST_IS_CONSTANT_EVALUATED) { |
159 |
| - std::vector<int> vec(150, 3); |
160 |
| - getGlobalMemCounter()->throw_after = 0; |
161 |
| - std::inplace_merge(vec.begin(), vec.begin() + 100, vec.end()); |
162 |
| - assert(std::all_of(vec.begin(), vec.end(), [](int i) { return i == 3; })); |
163 |
| - } |
| 160 | + if (!TEST_IS_CONSTANT_EVALUATED) { |
| 161 | + std::vector<int> vec(150, 3); |
| 162 | + getGlobalMemCounter()->throw_after = 0; |
| 163 | + std::inplace_merge(vec.begin(), vec.begin() + 100, vec.end()); |
| 164 | + assert(std::all_of(vec.begin(), vec.end(), [](int i) { return i == 3; })); |
| 165 | + } |
164 | 166 | #endif // TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS)
|
165 | 167 |
|
166 | 168 | return 0;
|
|
0 commit comments