1717#include < array>
1818#include < cassert>
1919#include < memory>
20+ #include < type_traits>
2021#include < utility>
21- #include < __type_traits/is_constant_evaluated.h>
2222
2323#include " test_macros.h"
2424#include " test_iterators.h"
@@ -70,25 +70,39 @@ struct TestUniquePtr {
7070};
7171#endif
7272
73+ template <template <class > class Iter1 , template <class > class Iter2 >
7374TEST_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+ }
7482 {
7583 std::array<int , 3 > a = {1 , 2 , 3 }, a0 = a;
7684 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 ()));
7888 assert (a == b0);
7989 assert (b == a0);
8090 }
8191 {
8292 std::array<std::array<int , 2 >, 2 > a = {{{0 , 1 }, {2 , 3 }}}, a0 = a;
8393 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 ()));
8597 assert (a == b0);
8698 assert (b == a0);
8799 }
88100 {
89101 std::array<std::array<int , 3 >, 3 > a = {{{0 , 1 , 2 }, {3 , 4 , 5 }, {6 , 7 , 8 }}}, a0 = a;
90102 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 ()));
92106 assert (a == b0);
93107 assert (b == a0);
94108 }
@@ -97,18 +111,27 @@ TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
97111}
98112
99113TEST_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+
101125 types::for_each (types::forward_iterator_list<int *>(), TestPtr ());
102126
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 ())
105131 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 ());
106134#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- }
112135
113136 return true ;
114137}
0 commit comments