@@ -80,119 +80,111 @@ test_sort_()
8080}
8181
8282template <int N, int M>
83- TEST_CONSTEXPR_CXX26
84- void
85- test_larger_sorts ()
86- {
87- static_assert (N != 0 , " " );
88- static_assert (M != 0 , " " );
89- // create array length N filled with M different numbers
90- std::array<int , N> array_;
91- int * array = array_.data ();
92- int x = 0 ;
93- for (int i = 0 ; i < N; ++i)
94- {
95- array[i] = x;
96- if (++x == M)
97- x = 0 ;
98- }
99- // test saw tooth pattern
100- std::stable_sort (array, array+N);
101- assert (std::is_sorted (array, array+N));
102- // test random pattern
83+ TEST_CONSTEXPR_CXX26 void test_larger_sorts () {
84+ static_assert (N != 0 , " " );
85+ static_assert (M != 0 , " " );
86+ // create array length N filled with M different numbers
87+ std::array<int , N> array_;
88+ int * array = array_.data ();
89+ int x = 0 ;
90+ for (int i = 0 ; i < N; ++i) {
91+ array[i] = x;
92+ if (++x == M)
93+ x = 0 ;
94+ }
95+ // test saw tooth pattern
96+ std::stable_sort (array, array + N);
97+ assert (std::is_sorted (array, array + N));
98+ // test random pattern
10399#if TEST_STD_VER >= 26
104- if !consteval // random-number generators not constexpr-friendly
100+ if !consteval // random-number generators not constexpr-friendly
105101#endif
106- {
107- static std::mt19937 randomness;
108- std::shuffle (array, array+ N, randomness);
109- std::stable_sort (array, array+ N);
110- assert (std::is_sorted (array, array+ N));
111- }
112- // test sorted pattern
113- std::stable_sort (array, array+ N);
114- assert (std::is_sorted (array, array+ N));
115- // test reverse sorted pattern
116- std::reverse (array, array+ N);
117- std::stable_sort (array, array+ N);
118- assert (std::is_sorted (array, array+ N));
119- // test swap ranges 2 pattern
120- std::swap_ranges (array, array+N/ 2 , array+N/ 2 );
121- std::stable_sort (array, array+ N);
122- assert (std::is_sorted (array, array+ N));
123- // test reverse swap ranges 2 pattern
124- std::reverse (array, array+ N);
125- std::swap_ranges (array, array+N/ 2 , array+N/ 2 );
126- std::stable_sort (array, array+ N);
127- assert (std::is_sorted (array, array+ N));
102+ {
103+ static std::mt19937 randomness;
104+ std::shuffle (array, array + N, randomness);
105+ std::stable_sort (array, array + N);
106+ assert (std::is_sorted (array, array + N));
107+ }
108+ // test sorted pattern
109+ std::stable_sort (array, array + N);
110+ assert (std::is_sorted (array, array + N));
111+ // test reverse sorted pattern
112+ std::reverse (array, array + N);
113+ std::stable_sort (array, array + N);
114+ assert (std::is_sorted (array, array + N));
115+ // test swap ranges 2 pattern
116+ std::swap_ranges (array, array + N / 2 , array + N / 2 );
117+ std::stable_sort (array, array + N);
118+ assert (std::is_sorted (array, array + N));
119+ // test reverse swap ranges 2 pattern
120+ std::reverse (array, array + N);
121+ std::swap_ranges (array, array + N / 2 , array + N / 2 );
122+ std::stable_sort (array, array + N);
123+ assert (std::is_sorted (array, array + N));
128124}
129125
130126template <int N>
131- TEST_CONSTEXPR_CXX26
132- void
133- test_larger_sorts ()
134- {
135- test_larger_sorts<N, 1 >();
136- test_larger_sorts<N, 2 >();
137- test_larger_sorts<N, 3 >();
138- test_larger_sorts<N, N/2 -1 >();
139- test_larger_sorts<N, N/2 >();
140- test_larger_sorts<N, N/2 +1 >();
141- test_larger_sorts<N, N-2 >();
142- test_larger_sorts<N, N-1 >();
143- test_larger_sorts<N, N>();
127+ TEST_CONSTEXPR_CXX26 void test_larger_sorts () {
128+ test_larger_sorts<N, 1 >();
129+ test_larger_sorts<N, 2 >();
130+ test_larger_sorts<N, 3 >();
131+ test_larger_sorts<N, N / 2 - 1 >();
132+ test_larger_sorts<N, N / 2 >();
133+ test_larger_sorts<N, N / 2 + 1 >();
134+ test_larger_sorts<N, N - 2 >();
135+ test_larger_sorts<N, N - 1 >();
136+ test_larger_sorts<N, N>();
144137}
145138
146- TEST_CONSTEXPR_CXX26 void test ()
147- {
148- // test null range
149- int d = 0 ;
150- std::stable_sort (&d, &d);
151-
152- // exhaustively test all possibilities up to length 8
139+ TEST_CONSTEXPR_CXX26 void test () {
140+ // test null range
141+ int d = 0 ;
142+ std::stable_sort (&d, &d);
143+
144+ // exhaustively test all possibilities up to length 8
153145#if TEST_STD_VER >= 26
154- if !consteval
146+ if !consteval
155147#endif
156- {
157- test_sort_<1 >();
158- test_sort_<2 >();
159- test_sort_<3 >();
160- test_sort_<4 >();
161- test_sort_<5 >();
162- test_sort_<6 >();
163- test_sort_<7 >();
164- test_sort_<8 >();
165- }
166-
167- test_larger_sorts<256 >();
168- test_larger_sorts<257 >();
148+ {
149+ test_sort_<1 >();
150+ test_sort_<2 >();
151+ test_sort_<3 >();
152+ test_sort_<4 >();
153+ test_sort_<5 >();
154+ test_sort_<6 >();
155+ test_sort_<7 >();
156+ test_sort_<8 >();
157+ }
158+
159+ test_larger_sorts<256 >();
160+ test_larger_sorts<257 >();
169161#if TEST_STD_VER >= 26
170- if !consteval // only runtime tests bc. error: "constexpr evaluation hit maximum step limit"
162+ if !consteval // only runtime tests bc. error: "constexpr evaluation hit maximum step limit"
171163#endif
172- {
173- test_larger_sorts<499 >();
174- test_larger_sorts<500 >();
175- test_larger_sorts<997 >();
176- test_larger_sorts<1000 >();
177- test_larger_sorts<1009 >();
178- }
164+ {
165+ test_larger_sorts<499 >();
166+ test_larger_sorts<500 >();
167+ test_larger_sorts<997 >();
168+ test_larger_sorts<1000 >();
169+ test_larger_sorts<1009 >();
170+ }
179171
180172#if !defined(TEST_HAS_NO_EXCEPTIONS)
181- #if TEST_STD_VER >= 26
182- if !consteval
183- #endif
184- { // check that the algorithm works without memory
185- std::vector<int > vec (150 , 3 );
186- getGlobalMemCounter ()->throw_after = 0 ;
187- std::stable_sort (vec.begin (), vec.end ());
188- }
173+ # if TEST_STD_VER >= 26
174+ if !consteval
175+ # endif
176+ { // check that the algorithm works without memory
177+ std::vector<int > vec (150 , 3 );
178+ getGlobalMemCounter ()->throw_after = 0 ;
179+ std::stable_sort (vec.begin (), vec.end ());
180+ }
189181#endif // !defined(TEST_HAS_NO_EXCEPTIONS)
190182}
191183
192184int main (int , char **) {
193- test ();
185+ test ();
194186#if TEST_STD_VER >= 26
195- static_assert ((test (), true ));
187+ static_assert ((test (), true ));
196188#endif
197- return 0 ;
189+ return 0 ;
198190}
0 commit comments