[libcxx-commits] [libcxx] e9d8761 - [libc++] [test] Remove epicyclic workarounds for vector/span; use T[] or std::array.

Arthur O'Dwyer via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 21 09:42:14 PDT 2021


Author: Arthur O'Dwyer
Date: 2021-04-21T12:41:45-04:00
New Revision: e9d876159ef3d98d635bd7f90a1c2fe28a80fd57

URL: https://github.com/llvm/llvm-project/commit/e9d876159ef3d98d635bd7f90a1c2fe28a80fd57
DIFF: https://github.com/llvm/llvm-project/commit/e9d876159ef3d98d635bd7f90a1c2fe28a80fd57.diff

LOG: [libc++] [test] Remove epicyclic workarounds for vector/span; use T[] or std::array.

Simplify the test code, and drive-by also test that these algorithms
return the right iterator as their return value.

Differential Revision: https://reviews.llvm.org/D100876

Added: 
    

Modified: 
    libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
    libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
    libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
    libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
    libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
    libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp
    libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
    libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
index 90d13ee95c5d..8d4da735a4b7 100644
--- a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T>
 //     OutputIterator exclusive_scan(InputIterator first, InputIterator last,
@@ -23,55 +24,39 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
-template <class Iter1, class T, class Iter2>
+template <class Iter1, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, T init, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, T init, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Not in place
-    std::exclusive_scan(first, last, v.begin(), init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::exclusive_scan(first, last, out, init);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  In place
-    std::copy(first, last, v.begin());
-    std::exclusive_scan(v.begin(), v.end(), v.begin(), init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::exclusive_scan(out, end, out, init);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]   = {1, 3, 5, 7,  9};
+    int ia[]         = {1, 3, 5, 7,  9};
     const int pRes[] = {0, 1, 4, 9, 16};
     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
     static_assert(sa == sizeof(pRes) / sizeof(pRes[0]));       // just to be sure
 
-    for (unsigned int i = 0; i < sa; ++i )
+    for (unsigned int i = 0; i < sa; ++i) {
         test(Iter(ia), Iter(ia + i), 0, pRes, pRes + i);
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }

diff  --git a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
index c7045d950902..6814ae2e496e 100644
--- a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
 //     OutputIterator
@@ -24,42 +25,25 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
-template <class Iter1, class T, class Op, class Iter2>
+template <class Iter1, class T, class Op>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, T init, Op op, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, T init, Op op, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Not in place
-    std::exclusive_scan(first, last, v.begin(), init, op);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::exclusive_scan(first, last, out, init, op);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  In place
-    std::copy(first, last, v.begin());
-    std::exclusive_scan(v.begin(), v.end(), v.begin(), init, op);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::exclusive_scan(out, end, out, init, op);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -67,7 +51,7 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]   = {1, 3, 5,  7,   9};
+    int ia[]         = {1, 3, 5,  7,   9};
     const int pRes[] = {0, 1, 4,  9,  16};
     const int mRes[] = {1, 1, 3, 15, 105};
     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
@@ -77,7 +61,7 @@ test()
     for (unsigned int i = 0; i < sa; ++i ) {
         test(Iter(ia), Iter(ia + i), 0, std::plus<>(),       pRes, pRes + i);
         test(Iter(ia), Iter(ia + i), 1, std::multiplies<>(), mRes, mRes + i);
-        }
+    }
 }
 
 TEST_CONSTEXPR_CXX20 bool
@@ -95,18 +79,8 @@ test()
     {
     std::array<unsigned char, 10> v;
     std::iota(v.begin(), v.end(), static_cast<unsigned char>(1));
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> res;
-    std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>());
-#else
     std::array<size_t, 10> res;
     std::exclusive_scan(v.begin(), v.end(), res.begin(), 1, std::multiplies<>());
-#endif
 
     assert(res.size() == 10);
     size_t j = 1;

diff  --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
index d529f87a7d92..e89d18f48a62 100644
--- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T>
 //     OutputIterator inclusive_scan(InputIterator first, InputIterator last,
@@ -23,42 +24,25 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
-template <class Iter1, class Iter2>
+template <class Iter1, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Not in place
-    std::inclusive_scan(first, last, v.begin());
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::inclusive_scan(first, last, out);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  In place
-    std::copy(first, last, v.begin());
-    std::inclusive_scan(v.begin(), v.end(), v.begin());
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::inclusive_scan(out, end, out);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -66,13 +50,14 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]   = {1, 3, 5, 7,  9};
+    int ia[]         = {1, 3, 5, 7,  9};
     const int pRes[] = {1, 4, 9, 16, 25};
     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
     static_assert(sa == sizeof(pRes) / sizeof(pRes[0]));       // just to be sure
 
-    for (unsigned int i = 0; i < sa; ++i )
+    for (unsigned int i = 0; i < sa; ++i ) {
         test(Iter(ia), Iter(ia + i), pRes, pRes + i);
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -106,18 +91,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res));
-#else
     std::array<size_t, 0> v, res;
     std::inclusive_scan(v.begin(), v.end(), res.begin());
-#endif
     assert(res.empty());
     }
 }

diff  --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
index 38739da50c62..bb1755c01e17 100644
--- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
 //     OutputIterator
@@ -24,42 +25,25 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
-template <class Iter1, class Op, class Iter2>
+template <class Iter1, class Op, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, Op op, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, Op op, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Not in place
-    std::inclusive_scan(first, last, v.begin(), op);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::inclusive_scan(first, last, out, op);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  In place
-    std::copy(first, last, v.begin());
-    std::inclusive_scan(v.begin(), v.end(), v.begin(), op);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::inclusive_scan(out, end, out, op);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -67,7 +51,7 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]   = {1, 3,  5,   7,   9};
+    int ia[]         = {1, 3,  5,   7,   9};
     const int pRes[] = {1, 4,  9,  16,  25};
     const int mRes[] = {1, 3, 15, 105, 945};
     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
@@ -77,7 +61,7 @@ test()
     for (unsigned int i = 0; i < sa; ++i ) {
         test(Iter(ia), Iter(ia + i), std::plus<>(),       pRes, pRes + i);
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), mRes, mRes + i);
-        }
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -111,18 +95,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>());
-#else
     std::array<size_t, 0> v, res;
     std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>());
-#endif
     assert(res.empty());
     }
 }

diff  --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
index 20b443d9ffbe..b832cb84af17 100644
--- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
 //     OutputIterator
@@ -24,42 +25,25 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
-template <class Iter1, class T, class Op, class Iter2>
+template <class Iter1, class T, class Op>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, Op op, T init, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, Op op, T init, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Not in place
-    std::inclusive_scan(first, last, v.begin(), op, init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::inclusive_scan(first, last, out, op, init);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  In place
-    std::copy(first, last, v.begin());
-    std::inclusive_scan(v.begin(), v.end(), v.begin(), op, init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::inclusive_scan(out, end, out, op, init);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -67,7 +51,7 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]   = {1, 3,  5,   7,   9};
+    int ia[]         = {1, 3,  5,   7,   9};
     const int pRes[] = {1, 4,  9,  16,  25};
     const int mRes[] = {1, 3, 15, 105, 945};
     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
@@ -77,7 +61,7 @@ test()
     for (unsigned int i = 0; i < sa; ++i ) {
         test(Iter(ia), Iter(ia + i), std::plus<>(),       0, pRes, pRes + i);
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), 1, mRes, mRes + i);
-        }
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -111,18 +95,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), size_t{40});
-#else
     std::array<size_t, 0> v, res;
     std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), size_t{40});
-#endif
     assert(res.empty());
     }
 
@@ -130,18 +104,8 @@ basic_tests()
     {
     std::array<unsigned char, 10> v;
     std::iota(v.begin(), v.end(), static_cast<unsigned char>(1));
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> res;
-    std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), size_t{1});
-#else
     std::array<size_t, 10> res;
     std::inclusive_scan(v.begin(), v.end(), res.begin(), std::multiplies<>(), size_t{1});
-#endif
 
     assert(res.size() == 10);
     size_t j = 1;

diff  --git a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp
index 837e73bcbaec..1c91de77d4f5 100644
--- a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T,
 //          class BinaryOperation, class UnaryOperation>
@@ -26,14 +27,9 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
 struct add_one {
     template <typename T>
@@ -42,41 +38,28 @@ struct add_one {
     }
 };
 
-template <class Iter1, class BOp, class UOp, class T, class Iter2>
+template <class Iter1, class BOp, class UOp, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Test not in-place
-    std::transform_exclusive_scan(first, last, v.begin(), init, bop, uop);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::transform_exclusive_scan(first, last, out, init, bop, uop);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  Test in-place
-    std::copy(first, last, v.begin());
-    std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), init, bop, uop);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::transform_exclusive_scan(out, end, out, init, bop, uop);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
-
 template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]     = { 1,  3,  5,    7,   9 };
+    int ia[]           = { 1,  3,  5,    7,   9 };
     const int pResI0[] = { 0,  2,  6,   12,  20 };        // with add_one
     const int mResI0[] = { 0,  0,  0,    0,   0 };
     const int pResN0[] = { 0, -1, -4,   -9, -16 };        // with negate
@@ -104,7 +87,7 @@ test()
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_one{},       2, mResI2, mResI2 + i);
         test(Iter(ia), Iter(ia + i), std::plus<>(),       std::negate<>(), 2, pResN2, pResN2 + i);
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 2, mResN2, mResN2 + i);
-        }
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -138,18 +121,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{40}, std::plus<>(), add_one{});
-#else
     std::array<size_t, 0> v, res;
     std::transform_exclusive_scan(v.begin(), v.end(), res.begin(), size_t{40}, std::plus<>(), add_one{});
-#endif
     assert(res.empty());
     }
 
@@ -157,18 +130,8 @@ basic_tests()
     {
     std::array<unsigned char, 10> v;
     std::iota(v.begin(), v.end(), static_cast<unsigned char>(1));
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> res;
-    std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{1}, std::multiplies<>(), add_one{});
-#else
     std::array<size_t, 10> res;
     std::transform_exclusive_scan(v.begin(), v.end(), res.begin(), size_t{1}, std::multiplies<>(), add_one{});
-#endif
 
     assert(res.size() == 10);
     size_t j = 1;

diff  --git a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
index 1307d7348168..9c70311b545c 100644
--- a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
@@ -1,4 +1,3 @@
-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T,
 //          class BinaryOperation, class UnaryOperation>
@@ -27,49 +27,32 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
 struct add_one {
     template <typename T>
-    constexpr auto operator()(T x) const noexcept {
-        return static_cast<T>(x + 1);
+    constexpr T operator()(T x) const {
+        return x + 1;
     }
 };
 
-template <class Iter1, class BOp, class UOp, class Iter2>
+template <class Iter1, class BOp, class UOp, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, BOp bop, UOp uop, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, BOp bop, UOp uop, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Test not in-place
-    std::transform_inclusive_scan(first, last, v.begin(), bop, uop);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::transform_inclusive_scan(first, last, out, bop, uop);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  Test in-place
-    std::copy(first, last, v.begin());
-    std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::transform_inclusive_scan(out, end, out, bop, uop);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -77,7 +60,7 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]     = {  1,  3,   5,   7,    9 };
+    int ia[]           = {  1,  3,   5,   7,    9 };
     const int pResI0[] = {  2,  6,  12,  20,   30 };        // with add_one
     const int mResI0[] = {  2,  8, 48,  384, 3840 };
     const int pResN0[] = { -1, -4,  -9, -16,  -25 };        // with negate
@@ -93,7 +76,7 @@ test()
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_one{},       mResI0, mResI0 + i);
         test(Iter(ia), Iter(ia + i), std::plus<>(),       std::negate<>(), pResN0, pResN0 + i);
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), mResN0, mResN0 + i);
-        }
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -127,18 +110,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{});
-#else
     std::array<size_t, 0> v, res;
     std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), add_one{});
-#endif
     assert(res.empty());
     }
 }

diff  --git a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp
index d2b494cc1d7a..3ef259f104c4 100644
--- a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp
@@ -6,11 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <numeric>
 // UNSUPPORTED: c++03, c++11, c++14
 // UNSUPPORTED: clang-8
 // UNSUPPORTED: gcc-9
 
+// <numeric>
+
 // Became constexpr in C++20
 // template<class InputIterator, class OutputIterator, class T,
 //          class BinaryOperation, class UnaryOperation>
@@ -27,49 +28,32 @@
 #include <cassert>
 #include <functional>
 #include <iterator>
-#include <vector>
 
 #include "test_macros.h"
 #include "test_iterators.h"
-// FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER > 17
-#include <span>
-#endif
 
 struct add_one {
     template <typename T>
-    constexpr auto operator()(T x) const noexcept {
-        return static_cast<T>(x + 1);
+    constexpr T operator()(T x) const {
+        return x + 1;
     }
 };
 
-template <class Iter1, class BOp, class UOp, class T, class Iter2>
+template <class Iter1, class BOp, class UOp, class T>
 TEST_CONSTEXPR_CXX20 void
-test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast)
+test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, const T *rFirst, const T *rLast)
 {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-    size_t size = std::distance(first, last);
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-
-    std::vector<typename std::iterator_traits<Iter1>::value_type> v(size);
-#else
-    assert((size <= 5) && "Increment the size of the array");
-    typename std::iterator_traits<Iter1>::value_type b[5];
-    std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
-#endif
+    assert((rLast - rFirst) <= 5);  // or else increase the size of "out"
+    T out[5];
 
-//  Test not in-place
-    std::transform_inclusive_scan(first, last, v.begin(), bop, uop, init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // Not in place
+    T *end = std::transform_inclusive_scan(first, last, out, bop, uop, init);
+    assert(std::equal(out, end, rFirst, rLast));
 
-//  Test in-place
-    std::copy(first, last, v.begin());
-    std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop, init);
-    assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+    // In place
+    std::copy(first, last, out);
+    end = std::transform_inclusive_scan(out, end, out, bop, uop, init);
+    assert(std::equal(out, end, rFirst, rLast));
 }
 
 
@@ -77,7 +61,7 @@ template <class Iter>
 TEST_CONSTEXPR_CXX20 void
 test()
 {
-          int ia[]     = {  1,  3,   5,    7,     9 };
+    int ia[]           = {  1,  3,   5,    7,     9 };
     const int pResI0[] = {  2,  6,  12,   20,    30 };        // with add_one
     const int mResI0[] = {  0,  0,   0,    0,     0 };
     const int pResN0[] = { -1, -4,  -9,  -16,   -25 };        // with negate
@@ -105,7 +89,7 @@ test()
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_one{},       2, mResI2, mResI2 + i);
         test(Iter(ia), Iter(ia + i), std::plus<>(),       std::negate<>(), 2, pResN2, pResN2 + i);
         test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 2, mResN2, mResN2 + i);
-        }
+    }
 }
 
 constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
@@ -139,18 +123,8 @@ basic_tests()
     }
 
     {
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> v, res;
-    std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}, size_t{1});
-#else
     std::array<size_t, 0> v, res;
     std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), add_one{}, size_t{1});
-#endif
     assert(res.empty());
     }
 
@@ -158,18 +132,8 @@ basic_tests()
     {
     std::array<unsigned char, 10> v;
     std::iota(v.begin(), v.end(), static_cast<unsigned char>(1));
-    // C++17 doesn't test constexpr so can use a vector.
-    // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC
-    // don't have the support yet. In these cases use a std::span for the test.
-    // FIXME Remove constexpr vector workaround introduced in D90569
-#if TEST_STD_VER < 20 || \
-    (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L)
-    std::vector<size_t> res;
-    std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), add_one{}, size_t{1});
-#else
     std::array<size_t, 10> res;
     std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::multiplies<>(), add_one{}, size_t{1});
-#endif
 
     assert(res.size() == 10);
     size_t j = 2;


        


More information about the libcxx-commits mailing list