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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template // OutputIterator exclusive_scan(InputIterator first, InputIterator last, @@ -23,55 +24,39 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template // OutputIterator @@ -24,42 +25,25 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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 @@ 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 @@ { std::array v; std::iota(v.begin(), v.end(), static_cast(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 res; - std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>()); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template // OutputIterator inclusive_scan(InputIterator first, InputIterator last, @@ -23,42 +24,25 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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 @@ } { - // 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 v, res; - std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res)); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template // OutputIterator @@ -24,42 +25,25 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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 @@ 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 @@ } { - // 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 v, res; - std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>()); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template // OutputIterator @@ -24,42 +25,25 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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 @@ 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 @@ } { - // 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 v, res; - std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), size_t{40}); -#else std::array v, res; std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), size_t{40}); -#endif assert(res.empty()); } @@ -130,18 +104,8 @@ { std::array v; std::iota(v.begin(), v.end(), static_cast(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 res; - std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), size_t{1}); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template @@ -26,14 +27,9 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif struct add_one { template @@ -42,41 +38,28 @@ } }; -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 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(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 @@ } { - // 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 v, res; - std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{40}, std::plus<>(), add_one{}); -#else std::array 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 @@ { std::array v; std::iota(v.begin(), v.end(), static_cast(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 res; - std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{1}, std::multiplies<>(), add_one{}); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template @@ -27,49 +27,32 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif struct add_one { template - constexpr auto operator()(T x) const noexcept { - return static_cast(x + 1); + constexpr T operator()(T x) const { + return x + 1; } }; -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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(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 @@ } { - // 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 v, res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}); -#else std::array 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 --- 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 @@ // //===----------------------------------------------------------------------===// -// // UNSUPPORTED: c++03, c++11, c++14 // UNSUPPORTED: clang-8 // UNSUPPORTED: gcc-9 +// + // Became constexpr in C++20 // template @@ -27,49 +28,32 @@ #include #include #include -#include #include "test_macros.h" #include "test_iterators.h" -// FIXME Remove constexpr vector workaround introduced in D90569 -#if TEST_STD_VER > 17 -#include -#endif struct add_one { template - constexpr auto operator()(T x) const noexcept { - return static_cast(x + 1); + constexpr T operator()(T x) const { + return x + 1; } }; -template +template 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::value_type> v(size); -#else - assert((size <= 5) && "Increment the size of the array"); - typename std::iterator_traits::value_type b[5]; - std::span::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 @@ 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(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 @@ } { - // 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 v, res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}, size_t{1}); -#else std::array 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 @@ { std::array v; std::iota(v.begin(), v.end(), static_cast(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 res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), add_one{}, size_t{1}); -#else std::array 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;