-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++][test] Refactor tests for ranges::swap_range algorithms #121138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
415f6c8
to
21520db
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
04602db
to
094923a
Compare
@llvm/pr-subscribers-libcxx Author: Peng Liu (winner245) ChangesThis PR refactors tests for Full diff: https://github.com/llvm/llvm-project/pull/121138.diff 3 Files Affected:
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
index b3a9f5fc259ef7..72485b9d7e5eb7 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
@@ -17,28 +17,37 @@
#include <cassert>
#include "test_macros.h"
+#include "test_iterators.h"
+#include "type_algorithms.h"
-#if TEST_STD_VER > 17
-constexpr bool test_swap_constexpr()
-{
+template <class Iter1>
+struct Test {
+ template <class Iter2>
+ TEST_CONSTEXPR_CXX20 void operator()() {
int i = 1;
int j = 2;
- std::iter_swap(&i, &j);
- return i == 2 && j == 1;
+ std::iter_swap(Iter1(&i), Iter2(&j));
+ assert(i == 2 && j == 1);
+ }
+};
+
+struct TestIterators {
+ template <class Iter>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ types::for_each(types::forward_iterator_list<int*>(), Test<Iter>());
+ }
+};
+
+TEST_CONSTEXPR_CXX20 bool test() {
+ types::for_each(types::forward_iterator_list<int*>(), TestIterators());
+ return true;
}
-#endif // TEST_STD_VER > 17
-int main(int, char**)
-{
- int i = 1;
- int j = 2;
- std::iter_swap(&i, &j);
- assert(i == 2);
- assert(j == 1);
-
-#if TEST_STD_VER > 17
- static_assert(test_swap_constexpr());
-#endif // TEST_STD_VER > 17
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 20
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp
index a8d69b2832b462..aec0d6ad1c0e16 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp
@@ -25,50 +25,42 @@
#include <ranges>
#include "test_iterators.h"
+#include "type_algorithms.h"
constexpr void test_different_lengths() {
- using Expected = std::ranges::swap_ranges_result<int*, int*>;
- int i[3] = {1, 2, 3};
- int j[1] = {4};
+ using Expected = std::ranges::swap_ranges_result<int*, int*>;
+ int i[3] = {1, 2, 3};
+ int j[1] = {4};
std::same_as<Expected> auto r = std::ranges::swap_ranges(i, i + 3, j, j + 1);
assert(r.in1 == i + 1);
assert(r.in2 == j + 1);
- assert(i[0] == 4);
- assert(i[1] == 2);
- assert(i[2] == 3);
- assert(j[0] == 1);
+ assert(std::ranges::equal(i, std::array{4, 2, 3}));
+ assert(std::ranges::equal(j, std::array{1}));
std::same_as<Expected> auto r2 = std::ranges::swap_ranges(i, j);
assert(r2.in1 == i + 1);
assert(r2.in2 == j + 1);
- assert(i[0] == 1);
- assert(i[1] == 2);
- assert(i[2] == 3);
- assert(j[0] == 4);
+ assert(std::ranges::equal(i, std::array{1, 2, 3}));
+ assert(std::ranges::equal(j, std::array{4}));
std::same_as<Expected> auto r3 = std::ranges::swap_ranges(j, j + 1, i, i + 3);
assert(r3.in1 == j + 1);
assert(r3.in2 == i + 1);
- assert(i[0] == 4);
- assert(i[1] == 2);
- assert(i[2] == 3);
- assert(j[0] == 1);
+ assert(std::ranges::equal(i, std::array{4, 2, 3}));
+ assert(std::ranges::equal(j, std::array{1}));
std::same_as<Expected> auto r4 = std::ranges::swap_ranges(j, i);
assert(r4.in1 == j + 1);
assert(r4.in2 == i + 1);
- assert(i[0] == 1);
- assert(i[1] == 2);
- assert(i[2] == 3);
- assert(j[0] == 4);
+ assert(std::ranges::equal(i, std::array{1, 2, 3}));
+ assert(std::ranges::equal(j, std::array{4}));
}
constexpr void test_range() {
std::array r1 = {1, 2, 3};
std::array r2 = {4, 5, 6};
-
- std::same_as<std::ranges::in_in_result<std::array<int, 3>::iterator, std::array<int, 3>::iterator>> auto r = std::ranges::swap_ranges(r1, r2);
+ std::same_as<std::ranges::in_in_result<std::array<int, 3>::iterator, std::array<int, 3>::iterator>> auto r =
+ std::ranges::swap_ranges(r1, r2);
assert(r.in1 == r1.end());
assert(r.in2 == r2.end());
-
assert((r1 == std::array{4, 5, 6}));
assert((r2 == std::array{1, 2, 3}));
}
@@ -78,75 +70,79 @@ constexpr void test_borrowed_input_range() {
int r1[] = {1, 2, 3};
int r2[] = {4, 5, 6};
std::ranges::swap_ranges(std::views::all(r1), r2);
- assert(r1[0] == 4);
- assert(r1[1] == 5);
- assert(r1[2] == 6);
- assert(r2[0] == 1);
- assert(r2[1] == 2);
- assert(r2[2] == 3);
+ assert(std::ranges::equal(r1, std::array{4, 5, 6}));
+ assert(std::ranges::equal(r2, std::array{1, 2, 3}));
}
{
int r1[] = {1, 2, 3};
int r2[] = {4, 5, 6};
std::ranges::swap_ranges(r1, std::views::all(r2));
- assert(r1[0] == 4);
- assert(r1[1] == 5);
- assert(r1[2] == 6);
- assert(r2[0] == 1);
- assert(r2[1] == 2);
- assert(r2[2] == 3);
+ assert(std::ranges::equal(r1, std::array{4, 5, 6}));
+ assert(std::ranges::equal(r2, std::array{1, 2, 3}));
}
{
int r1[] = {1, 2, 3};
int r2[] = {4, 5, 6};
std::ranges::swap_ranges(std::views::all(r1), std::views::all(r2));
- assert(r1[0] == 4);
- assert(r1[1] == 5);
- assert(r1[2] == 6);
- assert(r2[0] == 1);
- assert(r2[1] == 2);
- assert(r2[2] == 3);
+ assert(std::ranges::equal(r1, std::array{4, 5, 6}));
+ assert(std::ranges::equal(r2, std::array{1, 2, 3}));
}
}
constexpr void test_sentinel() {
- int i[3] = {1, 2, 3};
- int j[3] = {4, 5, 6};
- using It = cpp17_input_iterator<int*>;
- using Sent = sentinel_wrapper<It>;
- using Expected = std::ranges::swap_ranges_result<It, It>;
- std::same_as<Expected> auto r =
- std::ranges::swap_ranges(It(i), Sent(It(i + 3)), It(j), Sent(It(j + 3)));
+ int i[3] = {1, 2, 3};
+ int j[3] = {4, 5, 6};
+ using It = cpp17_input_iterator<int*>;
+ using Sent = sentinel_wrapper<It>;
+ using Expected = std::ranges::swap_ranges_result<It, It>;
+ std::same_as<Expected> auto r = std::ranges::swap_ranges(It(i), Sent(It(i + 3)), It(j), Sent(It(j + 3)));
assert(base(r.in1) == i + 3);
assert(base(r.in2) == j + 3);
- assert(i[0] == 4);
- assert(i[1] == 5);
- assert(i[2] == 6);
- assert(j[0] == 1);
- assert(j[1] == 2);
- assert(j[2] == 3);
+ assert(std::ranges::equal(i, std::array{4, 5, 6}));
+ assert(std::ranges::equal(j, std::array{1, 2, 3}));
}
-template <class Iter1, class Iter2>
-constexpr void test_iterators() {
- using Expected = std::ranges::swap_ranges_result<Iter1, Iter2>;
- int i[3] = {1, 2, 3};
- int j[3] = {4, 5, 6};
- std::same_as<Expected> auto r =
- std::ranges::swap_ranges(Iter1(i), sentinel_wrapper(Iter1(i + 3)), Iter2(j), sentinel_wrapper(Iter2(j + 3)));
- assert(base(r.in1) == i + 3);
- assert(base(r.in2) == j + 3);
- assert(i[0] == 4);
- assert(i[1] == 5);
- assert(i[2] == 6);
- assert(j[0] == 1);
- assert(j[1] == 2);
- assert(j[2] == 3);
-}
+template <class Iter1>
+struct Test {
+ template <class Iter2>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ using Expected = std::ranges::swap_ranges_result<Iter1, Iter2>;
+ int a[3] = {1, 2, 3};
+ int b[3] = {4, 5, 6};
+ std::same_as<Expected> auto r =
+ std::ranges::swap_ranges(Iter1(a), sentinel_wrapper(Iter1(a + 3)), Iter2(b), sentinel_wrapper(Iter2(b + 3)));
+ assert(base(r.in1) == a + 3);
+ assert(base(r.in2) == b + 3);
+ assert(std::ranges::equal(a, std::array{4, 5, 6}));
+ assert(std::ranges::equal(b, std::array{1, 2, 3}));
+ }
+};
+
+struct TestIterators {
+ template <class Iter>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ types::for_each(types::cpp20_input_iterator_list<int*>(), Test<Iter>());
+ }
+};
+
+template <class Ptr>
+using cpp20_proxy_in_iterator_list =
+ types::type_list<Cpp20InputProxyIterator<Ptr>,
+ ForwardProxyIterator<Ptr>,
+ BidirectionalProxyIterator<Ptr>,
+ RandomAccessProxyIterator<Ptr>,
+ ContiguousProxyIterator<Ptr>>;
+
+struct TestProxyInIterators {
+ template <class Iter>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ types::for_each(cpp20_proxy_in_iterator_list<int*>(), Test<Iter>());
+ }
+};
constexpr void test_rval_range() {
{
- using Expected = std::ranges::swap_ranges_result<std::array<int, 3>::iterator, std::ranges::dangling>;
+ using Expected = std::ranges::swap_ranges_result<std::array<int, 3>::iterator, std::ranges::dangling>;
std::array<int, 3> r = {1, 2, 3};
std::same_as<Expected> auto a = std::ranges::swap_ranges(r, std::array{4, 5, 6});
assert((r == std::array{4, 5, 6}));
@@ -154,65 +150,21 @@ constexpr void test_rval_range() {
}
{
std::array<int, 3> r = {1, 2, 3};
- using Expected = std::ranges::swap_ranges_result<std::ranges::dangling, std::array<int, 3>::iterator>;
+ using Expected = std::ranges::swap_ranges_result<std::ranges::dangling, std::array<int, 3>::iterator>;
std::same_as<Expected> auto b = std::ranges::swap_ranges(std::array{4, 5, 6}, r);
assert((r == std::array{4, 5, 6}));
assert(b.in2 == r.begin() + 3);
}
}
-template <class Out>
-constexpr void test_proxy_in_iterators() {
- test_iterators<ProxyIterator<cpp20_input_iterator<int*>>, Out>();
- test_iterators<ProxyIterator<forward_iterator<int*>>, Out>();
- test_iterators<ProxyIterator<bidirectional_iterator<int*>>, Out>();
- test_iterators<ProxyIterator<random_access_iterator<int*>>, Out>();
- test_iterators<ProxyIterator<contiguous_iterator<int*>>, Out>();
-}
-
constexpr bool test() {
test_range();
-
- test_iterators<cpp20_input_iterator<int*>, cpp20_input_iterator<int*>>();
- test_iterators<cpp20_input_iterator<int*>, forward_iterator<int*>>();
- test_iterators<cpp20_input_iterator<int*>, bidirectional_iterator<int*>>();
- test_iterators<cpp20_input_iterator<int*>, random_access_iterator<int*>>();
- test_iterators<cpp20_input_iterator<int*>, int*>();
-
- test_iterators<forward_iterator<int*>, cpp20_input_iterator<int*>>();
- test_iterators<forward_iterator<int*>, forward_iterator<int*>>();
- test_iterators<forward_iterator<int*>, bidirectional_iterator<int*>>();
- test_iterators<forward_iterator<int*>, random_access_iterator<int*>>();
- test_iterators<forward_iterator<int*>, int*>();
-
- test_iterators<bidirectional_iterator<int*>, cpp20_input_iterator<int*>>();
- test_iterators<bidirectional_iterator<int*>, forward_iterator<int*>>();
- test_iterators<bidirectional_iterator<int*>, bidirectional_iterator<int*>>();
- test_iterators<bidirectional_iterator<int*>, random_access_iterator<int*>>();
- test_iterators<bidirectional_iterator<int*>, int*>();
-
- test_iterators<random_access_iterator<int*>, cpp20_input_iterator<int*>>();
- test_iterators<random_access_iterator<int*>, forward_iterator<int*>>();
- test_iterators<random_access_iterator<int*>, bidirectional_iterator<int*>>();
- test_iterators<random_access_iterator<int*>, random_access_iterator<int*>>();
- test_iterators<random_access_iterator<int*>, int*>();
-
- test_iterators<int*, cpp20_input_iterator<int*>>();
- test_iterators<int*, forward_iterator<int*>>();
- test_iterators<int*, bidirectional_iterator<int*>>();
- test_iterators<int*, random_access_iterator<int*>>();
- test_iterators<int*, int*>();
-
- test_proxy_in_iterators<ProxyIterator<cpp20_input_iterator<int*>>>();
- test_proxy_in_iterators<ProxyIterator<forward_iterator<int*>>>();
- test_proxy_in_iterators<ProxyIterator<bidirectional_iterator<int*>>>();
- test_proxy_in_iterators<ProxyIterator<random_access_iterator<int*>>>();
- test_proxy_in_iterators<ProxyIterator<contiguous_iterator<int*>>>();
-
test_sentinel();
test_different_lengths();
test_borrowed_input_range();
test_rval_range();
+ types::for_each(types::cpp20_input_iterator_list<int*>(), TestIterators());
+ types::for_each(cpp20_proxy_in_iterator_list<int*>(), TestProxyInIterators());
return true;
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
index 8bfbcd755e39f7..09374b9a64bf11 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
@@ -14,162 +14,109 @@
// swap_ranges(Iter1 first1, Iter1 last1, Iter2 first2);
#include <algorithm>
+#include <array>
#include <cassert>
#include <memory>
#include <utility>
#include "test_macros.h"
#include "test_iterators.h"
-
-template<class Iter1, class Iter2>
-void
-test()
-{
- int i[3] = {1, 2, 3};
- int j[3] = {4, 5, 6};
- Iter2 r = std::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
- assert(base(r) == j+3);
- assert(i[0] == 4);
- assert(i[1] == 5);
- assert(i[2] == 6);
- assert(j[0] == 1);
- assert(j[1] == 2);
- assert(j[2] == 3);
+#include "type_algorithms.h"
+
+template <class Iter1>
+struct Test1 {
+ template <class Iter2>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ int a[] = {1, 2, 3};
+ int b[] = {4, 5, 6};
+ Iter2 r = std::swap_ranges(Iter1(a), Iter1(a + 3), Iter2(b));
+ assert(base(r) == b + 3);
+ assert(a[0] == 4 && a[1] == 5 && a[2] == 6);
+ assert(b[0] == 1 && b[1] == 2 && b[2] == 3);
+ }
+};
+
+struct TestPtr {
+ template <class Iter>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ types::for_each(types::forward_iterator_list<int*>(), Test1<Iter>());
+ }
+};
+
+TEST_CONSTEXPR_CXX20 bool test_ptr() {
+ types::for_each(types::forward_iterator_list<int*>(), TestPtr());
+ return true;
}
#if TEST_STD_VER >= 11
-template<class Iter1, class Iter2>
-void
-test1()
-{
- std::unique_ptr<int> i[3];
+template <class Iter1>
+struct Test2 {
+ template <class Iter2>
+ TEST_CONSTEXPR_CXX23 void operator()() {
+ std::unique_ptr<int> a[3];
for (int k = 0; k < 3; ++k)
- i[k].reset(new int(k+1));
- std::unique_ptr<int> j[3];
+ a[k].reset(new int(k + 1));
+ std::unique_ptr<int> b[3];
for (int k = 0; k < 3; ++k)
- j[k].reset(new int(k+4));
- Iter2 r = std::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
- assert(base(r) == j+3);
- assert(*i[0] == 4);
- assert(*i[1] == 5);
- assert(*i[2] == 6);
- assert(*j[0] == 1);
- assert(*j[1] == 2);
- assert(*j[2] == 3);
+ b[k].reset(new int(k + 4));
+ Iter2 r = std::swap_ranges(Iter1(a), Iter1(a + 3), Iter2(b));
+ assert(base(r) == b + 3);
+ assert(*a[0] == 4 && *a[1] == 5 && *a[2] == 6);
+ assert(*b[0] == 1 && *b[1] == 2 && *b[2] == 3);
+ }
+};
+
+struct TestUnqPtr {
+ template <class Iter>
+ TEST_CONSTEXPR_CXX20 void operator()() {
+ types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), Test2<Iter>());
+ }
+};
+
+TEST_CONSTEXPR_CXX23 bool test_unq_ptr() {
+ types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUnqPtr());
+ return true;
}
-#endif // TEST_STD_VER >= 11
-
-void test2()
-{
- {
- int src[2][2] = {{0, 1}, {2, 3}};
- decltype(src) dest = {{9, 8}, {7, 6}};
-
- std::swap(src, dest);
-
- assert ( src[0][0] == 9 );
- assert ( src[0][1] == 8 );
- assert ( src[1][0] == 7 );
- assert ( src[1][1] == 6 );
-
- assert ( dest[0][0] == 0 );
- assert ( dest[0][1] == 1 );
- assert ( dest[1][0] == 2 );
- assert ( dest[1][1] == 3 );
- }
-
- {
- int src[3][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
- decltype(src) dest = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
-
- std::swap(src, dest);
-
- assert ( src[0][0] == 9 );
- assert ( src[0][1] == 8 );
- assert ( src[0][2] == 7 );
- assert ( src[1][0] == 6 );
- assert ( src[1][1] == 5 );
- assert ( src[1][2] == 4 );
- assert ( src[2][0] == 3 );
- assert ( src[2][1] == 2 );
- assert ( src[2][2] == 1 );
-
- assert ( dest[0][0] == 0 );
- assert ( dest[0][1] == 1 );
- assert ( dest[0][2] == 2 );
- assert ( dest[1][0] == 3 );
- assert ( dest[1][1] == 4 );
- assert ( dest[1][2] == 5 );
- assert ( dest[2][0] == 6 );
- assert ( dest[2][1] == 7 );
- assert ( dest[2][2] == 8 );
- }
-}
-
-#if TEST_STD_VER > 17
-constexpr bool test_swap_constexpr()
-{
- int i[3] = {1, 2, 3};
- int j[3] = {4, 5, 6};
- std::swap_ranges(i, i+3, j);
- return i[0] == 4 &&
- i[1] == 5 &&
- i[2] == 6 &&
- j[0] == 1 &&
- j[1] == 2 &&
- j[2] == 3;
+#endif
+
+TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
+ {
+ std::array<int, 3> a = {1, 2, 3}, a0 = a;
+ std::array<int, 3> b = {4, 5, 6}, b0 = b;
+ std::swap_ranges(a.begin(), a.end(), b.begin());
+ assert(a == b0);
+ assert(b == a0);
+ }
+ {
+ std::array<std::array<int, 2>, 2> a = {{{0, 1}, {2, 3}}}, a0 = a;
+ std::array<std::array<int, 2>, 2> b = {{{9, 8}, {7, 6}}}, b0 = b;
+ std::swap(a, b);
+ assert(a == b0);
+ assert(b == a0);
+ }
+ {
+ std::array<std::array<int, 3>, 3> a = {{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}}, a0 = a;
+ std::array<std::array<int, 3>, 3> b = {{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}}, b0 = b;
+ std::swap(a, b);
+ assert(a == b0);
+ assert(b == a0);
+ }
+
+ return true;
}
-#endif // TEST_STD_VER > 17
-
-int main(int, char**)
-{
- test<forward_iterator<int*>, forward_iterator<int*> >();
- test<forward_iterator<int*>, bidirectional_iterator<int*> >();
- test<forward_iterator<int*>, random_access_iterator<int*> >();
- test<forward_iterator<int*>, int*>();
-
- test<bidirectional_iterator<int*>, forward_iterator<int*> >();
- test<bidirectional_iterator<int*>, bidirectional_iterator<int*> >();
- test<bidirectional_iterator<int*>, random_access_iterator<int*> >();
- test<bidirectional_iterator<int*>, int*>();
-
- test<random_access_iterator<int*>, forward_iterator<int*> >();
- test<random_access_iterator<int*>, bidirectional_iterator<int*> >();
- test<random_access_iterator<int*>, random_access_iterator<int*> >();
- test<random_access_iterator<int*>, int*>();
-
- test<int*, forward_iterator<int*> >();
- test<int*, bidirectional_iterator<int*> >();
- test<int*, random_access_iterator<int*> >();
- test<int*, int*>();
+int main(int, char**) {
+ test_simple_cases();
+ test_ptr();
#if TEST_STD_VER >= 11
- test1<forward_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
- test1<forward_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
- test1<forward_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
- test1<forward_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
-
- test1<bidirectional_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
- test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
- test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
- test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
-
- test1<random_access_iterator<std::unique_ptr<int>*>, forward_iterator<std::unique_ptr<int>*> >();
- test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
- test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
- test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
-
- test1<std::unique_ptr<int>*, forward_iterator<std::unique_ptr<int>*> >();
- test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
- test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
- test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
-#endif // TEST_STD_VER >= 11
-
-#if TEST_STD_VER > 17
- static_assert(test_swap_constexpr());
-#endif // TEST_STD_VER > 17
-
- test2();
-
+ test_unq_ptr();
+#endif
+#if TEST_STD_VER >= 20
+ static_assert(test_simple_cases());
+ static_assert(test_ptr());
+#endif
+#if TEST_STD_VER >= 23
+ static_assert(test_unq_ptr());
+#endif
return 0;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the improvements, I do have some comments before we merge this but it generally looks really good.
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/ranges.swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
0a80cb5
to
cbea0f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor comments. Thanks a lot for the improved test coverage, that is awesome!
libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
Outdated
Show resolved
Hide resolved
877f510
to
cba43ce
Compare
cba43ce
to
2a52692
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the refactoring!
struct TestImpl { | ||
template <class Iter2> | ||
TEST_CONSTEXPR_CXX20 void operator()() { | ||
int a[] = {1, 2, 3}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine since it's a pre-existing issue, but as a simple follow-up we should add coverage for sequences of more than 3 elements.
libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
Outdated
Show resolved
Hide resolved
This patch enhances the test coverage of `{std,ranges}::swap_ranges` by adding larger test cases with 100 elements across different containers. It also inlines standalone tests for better readability, avoiding unnecessary navigation. This patch addresses a follow-up suggestion from PR #121138 to extend test coverage beyond 3 elements.
This PR refactors tests for
ranges::swap_range
,std::{swap_range, iter_swap, swap}
algorithms to eliminate redundant code.