| 1 | // { dg-options "-ltbb" } |
| 2 | // { dg-do run { target c++17 } } |
| 3 | // { dg-require-effective-target tbb_backend } |
| 4 | |
| 5 | // Bug 108236 std::exclusive_scan with execution policy does not work in-place |
| 6 | |
| 7 | #include <numeric> |
| 8 | #include <execution> |
| 9 | #include <testsuite_hooks.h> |
| 10 | |
| 11 | struct Mint |
| 12 | { |
| 13 | Mint(int i = 0) : val(i) { } |
| 14 | Mint(Mint&&) = default; |
| 15 | Mint& operator=(Mint&&) = default; |
| 16 | |
| 17 | operator int() const { return val; } |
| 18 | |
| 19 | private: |
| 20 | int val; |
| 21 | }; |
| 22 | |
| 23 | void |
| 24 | test_move_only() |
| 25 | { |
| 26 | const int input[]{10, 20, 30}; |
| 27 | int output[3]; |
| 28 | std::exclusive_scan(std::execution::seq, input, input+3, output, Mint(5), |
| 29 | std::plus<int>{}); |
| 30 | VERIFY( output[0] == 5 ); |
| 31 | VERIFY( output[1] == 15 ); |
| 32 | VERIFY( output[2] == 35 ); |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | test_pr108236() |
| 37 | { |
| 38 | int vals[]{1, 2, 3}; |
| 39 | // Output range is the same as the input range: |
| 40 | std::exclusive_scan(std::execution::seq, vals, vals+3, vals, 99); |
| 41 | VERIFY( vals[0] == 99 ); |
| 42 | VERIFY( vals[1] == 100 ); |
| 43 | VERIFY( vals[2] == 102 ); |
| 44 | } |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | test_move_only(); |
| 49 | test_pr108236(); |
| 50 | } |