File tree Expand file tree Collapse file tree 2 files changed +20
-32
lines changed
algorithms/alg.modifying.operations/alg.swap
utilities/utility/utility.swap Expand file tree Collapse file tree 2 files changed +20
-32
lines changed Original file line number Diff line number Diff line change @@ -124,13 +124,10 @@ TEST_CONSTEXPR_CXX20 bool test() {
124
124
125
125
types::for_each (types::forward_iterator_list<int *>(), TestPtr ());
126
126
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
+ #if TEST_STD_VER >= 11
128
+ // We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
129
+ if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23 )
131
130
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
131
#endif
135
132
136
133
return true ;
Original file line number Diff line number Diff line change @@ -51,26 +51,6 @@ constexpr bool can_swap() {
51
51
}
52
52
#endif
53
53
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
-
74
54
TEST_CONSTEXPR_CXX20 bool test () {
75
55
{
76
56
int i[3 ] = {1 , 2 , 3 };
@@ -140,22 +120,33 @@ TEST_CONSTEXPR_CXX20 bool test() {
140
120
static_assert (!noexcept (std::swap (ca, ca)), " " );
141
121
static_assert (noexcept (std::swap (ma, ma)), " " );
142
122
}
123
+
124
+ // We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
125
+ if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23 ) {
126
+ std::unique_ptr<int > i[3 ];
127
+ for (int k = 0 ; k < 3 ; ++k)
128
+ i[k].reset (new int (k + 1 ));
129
+ std::unique_ptr<int > j[3 ];
130
+ for (int k = 0 ; k < 3 ; ++k)
131
+ j[k].reset (new int (k + 4 ));
132
+ std::swap (i, j);
133
+ assert (*i[0 ] == 4 );
134
+ assert (*i[1 ] == 5 );
135
+ assert (*i[2 ] == 6 );
136
+ assert (*j[0 ] == 1 );
137
+ assert (*j[1 ] == 2 );
138
+ assert (*j[2 ] == 3 );
139
+ }
143
140
#endif
144
141
145
142
return true ;
146
143
}
147
144
148
145
int main (int , char **) {
149
146
test ();
150
- #if TEST_STD_VER >= 11
151
- test_unique_ptr ();
152
- #endif
153
147
#if TEST_STD_VER >= 20
154
148
static_assert (test ());
155
149
#endif
156
- #if TEST_STD_VER >= 23
157
- static_assert (test_unique_ptr ());
158
- #endif
159
150
160
151
return 0 ;
161
152
}
You can’t perform that action at this time.
0 commit comments