//
//===----------------------------------------------------------------------===//
-// <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,
#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; }
//
//===----------------------------------------------------------------------===//
-// <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
#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));
}
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]);
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
{
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;
//
//===----------------------------------------------------------------------===//
-// <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,
#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));
}
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; }
}
{
- // 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());
}
}
//
//===----------------------------------------------------------------------===//
-// <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
#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));
}
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]);
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; }
}
{
- // 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());
}
}
//
//===----------------------------------------------------------------------===//
-// <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
#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));
}
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]);
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; }
}
{
- // 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());
}
{
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;
//
//===----------------------------------------------------------------------===//
-// <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>
#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>
}
};
-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
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; }
}
{
- // 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());
}
{
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;
-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
//
//===----------------------------------------------------------------------===//
-// <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>
#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));
}
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
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; }
}
{
- // 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());
}
}
//
//===----------------------------------------------------------------------===//
-// <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>
#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));
}
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
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; }
}
{
- // 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());
}
{
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;