Skip to content

Commit 0a80cb5

Browse files
committed
Templatize test_simple_cases()
1 parent 69d709f commit 0a80cb5

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <cassert>
1919
#include <memory>
2020
#include <utility>
21-
#include <__type_traits/is_constant_evaluated.h>
21+
#include <type_traits>
2222

2323
#include "test_macros.h"
2424
#include "test_iterators.h"
@@ -70,25 +70,30 @@ struct TestUniquePtr {
7070
};
7171
#endif
7272

73+
template <template <class> class Iter1, template <class> class Iter2>
7374
TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
7475
{
7576
std::array<int, 3> a = {1, 2, 3}, a0 = a;
7677
std::array<int, 3> b = {4, 5, 6}, b0 = b;
77-
std::swap_ranges(a.begin(), a.end(), b.begin());
78+
std::swap_ranges(Iter1<int*>(a.begin()), Iter1<int*>(a.end()), Iter2<int*>(b.begin()));
7879
assert(a == b0);
7980
assert(b == a0);
8081
}
8182
{
8283
std::array<std::array<int, 2>, 2> a = {{{0, 1}, {2, 3}}}, a0 = a;
8384
std::array<std::array<int, 2>, 2> b = {{{9, 8}, {7, 6}}}, b0 = b;
84-
std::swap_ranges(a.begin(), a.end(), b.begin());
85+
using It1 = Iter1<std::array<std::array<int, 2>, 2>::iterator>;
86+
using It2 = Iter2<std::array<std::array<int, 2>, 2>::iterator>;
87+
std::swap_ranges(It1(a.begin()), It1(a.end()), It2(b.begin()));
8588
assert(a == b0);
8689
assert(b == a0);
8790
}
8891
{
8992
std::array<std::array<int, 3>, 3> a = {{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}}, a0 = a;
9093
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());
94+
using It1 = Iter1<std::array<std::array<int, 3>, 3>::iterator>;
95+
using It2 = Iter2<std::array<std::array<int, 3>, 3>::iterator>;
96+
std::swap_ranges(It1(a.begin()), It1(a.end()), It2(b.begin()));
9297
assert(a == b0);
9398
assert(b == a0);
9499
}
@@ -97,18 +102,27 @@ TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
97102
}
98103

99104
TEST_CONSTEXPR_CXX20 bool test() {
100-
test_simple_cases();
105+
test_simple_cases<forward_iterator, forward_iterator>();
106+
test_simple_cases<forward_iterator, bidirectional_iterator>();
107+
test_simple_cases<forward_iterator, random_access_iterator>();
108+
test_simple_cases<bidirectional_iterator, forward_iterator>();
109+
test_simple_cases<bidirectional_iterator, bidirectional_iterator>();
110+
test_simple_cases<bidirectional_iterator, random_access_iterator>();
111+
test_simple_cases<random_access_iterator, random_access_iterator>();
112+
#if TEST_STD_VER >= 20
113+
test_simple_cases<std::type_identity_t, std::type_identity_t>();
114+
#endif
115+
101116
types::for_each(types::forward_iterator_list<int*>(), TestPtr());
102117

103-
if (std::__libcpp_is_constant_evaluated()) {
104-
#if TEST_STD_VER >= 23
118+
#if TEST_STD_VER >= 11 && TEST_STD_VER <= 17
119+
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
120+
#elif TEST_STD_VER == 20
121+
if (!std::is_constant_evaluated())
105122
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
123+
#elif TEST_STD_VER >= 23
124+
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
106125
#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-
}
112126

113127
return true;
114128
}

0 commit comments

Comments
 (0)