diff --git a/test/stdpar/tests/inclusive_scan.cpp b/test/stdpar/tests/inclusive_scan.cpp new file mode 100644 index 00000000000..85232ea040b --- /dev/null +++ b/test/stdpar/tests/inclusive_scan.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +int main() +{ + constexpr std::size_t N = 1 << 16; + + std::vector in(N); + std::vector out(N); + + std::iota(in.start(), in.end(), 1); + + // inclusive_scan with default initial value + std::inclusive_scan(std::execution::par, in.begin(), in.end(), out.begin()); + + for (std::size_t i = 0; i < N; ++i) + { + const int expected = static_cast(i + 1); + if (out[i] != expected) + { + return 1; + } + } + + // inclusive_scan with non-zero initial value + const int init = 42; + std::inclusive_scan(std::execution::par, in.begin(), in.end(), out.begin(), init); + + for (std::size_t i = 0; i < N; ++i) + { + const int expected = init + static_cast(i + 1); + if (out[i] != expected) + { + return 1; + } + } + + // inclusive_scan with only binary ops and no init value + std::inclusive_scan(std::execution::par, in.begin(), in.end(), out.begin(), [](int lhs, int rhs) { + return lhs + rhs + 1; + }); + + for (std::size_t i = 0; i < N; ++i) + { + const int expected = static_cast(2 * i + 1); + if (out[i] != expected) + { + return 1; + } + } + + return 0; +}