File tree Expand file tree Collapse file tree 2 files changed +19
-35
lines changed
algorithms/alg.modifying.operations/alg.swap
utilities/utility/utility.swap Expand file tree Collapse file tree 2 files changed +19
-35
lines changed Original file line number Diff line number Diff line change @@ -124,14 +124,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
124124
125125 types::for_each (types::forward_iterator_list<int *>(), TestPtr ());
126126
127- #if TEST_STD_VER >= 11 && TEST_STD_VER <= 17
128- types::for_each (types::forward_iterator_list<std::unique_ptr<int >*>(), TestUniquePtr ());
129- #elif TEST_STD_VER == 20
130- if (!std::is_constant_evaluated ())
127+ // We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
128+ if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23 )
131129 types::for_each (types::forward_iterator_list<std::unique_ptr<int >*>(), TestUniquePtr ());
132- #elif TEST_STD_VER >= 23
133- types::for_each (types::forward_iterator_list<std::unique_ptr<int >*>(), TestUniquePtr ());
134- #endif
135130
136131 return true ;
137132}
Original file line number Diff line number Diff line change @@ -51,26 +51,6 @@ constexpr bool can_swap() {
5151}
5252#endif
5353
54- #if TEST_STD_VER >= 11
55- // This test is constexpr only since C++23 because constexpr std::unique_ptr is only available since C++23
56- TEST_CONSTEXPR_CXX23 bool test_unique_ptr () {
57- std::unique_ptr<int > i[3 ];
58- for (int k = 0 ; k < 3 ; ++k)
59- i[k].reset (new int (k + 1 ));
60- std::unique_ptr<int > j[3 ];
61- for (int k = 0 ; k < 3 ; ++k)
62- j[k].reset (new int (k + 4 ));
63- std::swap (i, j);
64- assert (*i[0 ] == 4 );
65- assert (*i[1 ] == 5 );
66- assert (*i[2 ] == 6 );
67- assert (*j[0 ] == 1 );
68- assert (*j[1 ] == 2 );
69- assert (*j[2 ] == 3 );
70- return true ;
71- }
72- #endif
73-
7454TEST_CONSTEXPR_CXX20 bool test () {
7555 {
7656 int i[3 ] = {1 , 2 , 3 };
@@ -142,20 +122,29 @@ TEST_CONSTEXPR_CXX20 bool test() {
142122 }
143123#endif
144124
125+ // We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
126+ if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23 ) {
127+ std::unique_ptr<int > i[3 ];
128+ for (int k = 0 ; k < 3 ; ++k)
129+ i[k].reset (new int (k + 1 ));
130+ std::unique_ptr<int > j[3 ];
131+ for (int k = 0 ; k < 3 ; ++k)
132+ j[k].reset (new int (k + 4 ));
133+ std::swap (i, j);
134+ assert (*i[0 ] == 4 );
135+ assert (*i[1 ] == 5 );
136+ assert (*i[2 ] == 6 );
137+ assert (*j[0 ] == 1 );
138+ assert (*j[1 ] == 2 );
139+ assert (*j[2 ] == 3 );
140+ }
141+
145142 return true ;
146143}
147144
148145int main (int , char **) {
149146 test ();
150- #if TEST_STD_VER >= 11
151- test_unique_ptr ();
152- #endif
153- #if TEST_STD_VER >= 20
154147 static_assert (test ());
155- #endif
156- #if TEST_STD_VER >= 23
157- static_assert (test_unique_ptr ());
158- #endif
159148
160149 return 0 ;
161150}
You can’t perform that action at this time.
0 commit comments