[libcxx-commits] [libcxx] [libc++][test] Refactor tests for ranges::swap_range algorithms (PR #121138)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 26 08:47:36 PST 2025


================
@@ -14,162 +14,130 @@
 //   swap_ranges(Iter1 first1, Iter1 last1, Iter2 first2);
 
 #include <algorithm>
+#include <array>
 #include <cassert>
 #include <memory>
+#include <type_traits>
 #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"
+
+struct TestPtr {
+  template <class Iter>
+  TEST_CONSTEXPR_CXX20 void operator()() {
+    types::for_each(types::forward_iterator_list<int*>(), TestImpl<Iter>());
+  }
+
+  template <class Iter1>
+  struct TestImpl {
+    template <class Iter2>
+    TEST_CONSTEXPR_CXX20 void operator()() {
+      int a[] = {1, 2, 3};
----------------
ldionne wrote:

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.

https://github.com/llvm/llvm-project/pull/121138


More information about the libcxx-commits mailing list