17
17
#include < array>
18
18
#include < cassert>
19
19
#include < memory>
20
+ #include < type_traits>
20
21
#include < utility>
21
- #include < __type_traits/is_constant_evaluated.h>
22
22
23
23
#include " test_macros.h"
24
24
#include " test_iterators.h"
@@ -70,25 +70,39 @@ struct TestUniquePtr {
70
70
};
71
71
#endif
72
72
73
+ template <template <class > class Iter1 , template <class > class Iter2 >
73
74
TEST_CONSTEXPR_CXX20 bool test_simple_cases () {
75
+ {
76
+ int a[2 ] = {1 , 2 };
77
+ int b[2 ] = {4 , 5 };
78
+ std::swap_ranges (Iter1<int *>(a), Iter1<int *>(a + 2 ), Iter2<int *>(b));
79
+ assert (a[0 ] == 4 && a[1 ] == 5 );
80
+ assert (b[0 ] == 1 && b[1 ] == 2 );
81
+ }
74
82
{
75
83
std::array<int , 3 > a = {1 , 2 , 3 }, a0 = a;
76
84
std::array<int , 3 > b = {4 , 5 , 6 }, b0 = b;
77
- std::swap_ranges (a.begin (), a.end (), b.begin ());
85
+ using It1 = Iter1<std::array<int , 3 >::iterator>;
86
+ using It2 = Iter2<std::array<int , 3 >::iterator>;
87
+ std::swap_ranges (It1 (a.begin ()), It1 (a.end ()), It2 (b.begin ()));
78
88
assert (a == b0);
79
89
assert (b == a0);
80
90
}
81
91
{
82
92
std::array<std::array<int , 2 >, 2 > a = {{{0 , 1 }, {2 , 3 }}}, a0 = a;
83
93
std::array<std::array<int , 2 >, 2 > b = {{{9 , 8 }, {7 , 6 }}}, b0 = b;
84
- std::swap_ranges (a.begin (), a.end (), b.begin ());
94
+ using It1 = Iter1<std::array<std::array<int , 2 >, 2 >::iterator>;
95
+ using It2 = Iter2<std::array<std::array<int , 2 >, 2 >::iterator>;
96
+ std::swap_ranges (It1 (a.begin ()), It1 (a.end ()), It2 (b.begin ()));
85
97
assert (a == b0);
86
98
assert (b == a0);
87
99
}
88
100
{
89
101
std::array<std::array<int , 3 >, 3 > a = {{{0 , 1 , 2 }, {3 , 4 , 5 }, {6 , 7 , 8 }}}, a0 = a;
90
102
std::array<std::array<int , 3 >, 3 > b = {{{9 , 8 , 7 }, {6 , 5 , 4 }, {3 , 2 , 1 }}}, b0 = b;
91
- std::swap_ranges (a.begin (), a.end (), b.begin ());
103
+ using It1 = Iter1<std::array<std::array<int , 3 >, 3 >::iterator>;
104
+ using It2 = Iter2<std::array<std::array<int , 3 >, 3 >::iterator>;
105
+ std::swap_ranges (It1 (a.begin ()), It1 (a.end ()), It2 (b.begin ()));
92
106
assert (a == b0);
93
107
assert (b == a0);
94
108
}
@@ -97,18 +111,27 @@ TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
97
111
}
98
112
99
113
TEST_CONSTEXPR_CXX20 bool test () {
100
- test_simple_cases ();
114
+ test_simple_cases<forward_iterator, forward_iterator>();
115
+ test_simple_cases<forward_iterator, bidirectional_iterator>();
116
+ test_simple_cases<forward_iterator, random_access_iterator>();
117
+ test_simple_cases<bidirectional_iterator, forward_iterator>();
118
+ test_simple_cases<bidirectional_iterator, bidirectional_iterator>();
119
+ test_simple_cases<bidirectional_iterator, random_access_iterator>();
120
+ test_simple_cases<random_access_iterator, random_access_iterator>();
121
+ #if TEST_STD_VER >= 20
122
+ test_simple_cases<std::type_identity_t , std::type_identity_t >();
123
+ #endif
124
+
101
125
types::for_each (types::forward_iterator_list<int *>(), TestPtr ());
102
126
103
- if (std::__libcpp_is_constant_evaluated ()) {
104
- #if TEST_STD_VER >= 23
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 ())
105
131
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 ());
106
134
#endif
107
- } else {
108
- #if TEST_STD_VER >= 11
109
- types::for_each (types::forward_iterator_list<std::unique_ptr<int >*>(), TestUniquePtr ());
110
- #endif
111
- }
112
135
113
136
return true ;
114
137
}
0 commit comments