Debian Codegraph @

libstdc++-v3/testsuite/26_numerics/exclusive_scan/2.cc

raw
1 // { dg-do run { target c++17 } }
2
3 // C++17 29.8.7 [exclusive.scan]
4
5 #include <numeric>
6 #include <testsuite_hooks.h>
7
8 struct Mint
9 {
10 Mint(int i = 0) : val(i) { }
11 Mint(Mint&&) = default;
12 Mint& operator=(Mint&&) = default;
13
14 operator int() const { return val; }
15
16 private:
17 int val;
18 };
19
20 void
21 test_move_only()
22 {
23 const int input[]{10, 20, 30};
24 int output[3];
25 std::exclusive_scan(input, input+3, output, Mint(5), std::plus<int>{});
26 VERIFY( output[0] == 5 );
27 VERIFY( output[1] == 15 );
28 VERIFY( output[2] == 35 );
29 }
30
31 void
32 test_pr108236()
33 {
34 int vals[]{1, 2, 3};
35 // Output range is the same as the input range:
36 std::exclusive_scan(vals, vals+3, vals, 99);
37 VERIFY( vals[0] == 99 );
38 VERIFY( vals[1] == 100 );
39 VERIFY( vals[2] == 102 );
40 }
41
42 int main()
43 {
44 test_move_only();
45 test_pr108236();
46 }