xfail all scan-tree-dump-times checks on hppa*64*-*-* in sra-17.c and sra-18.c
[official-gcc.git] / libstdc++-v3 / testsuite / 26_numerics / partial_sum / lwg2055.cc
blobba880589f203f418ab7d1815a319e0042398d00e
1 // Copyright (C) 2018-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++20 } }
20 #include <numeric>
21 #include <iterator>
22 #include <testsuite_hooks.h>
24 struct Int
26 Int(int v) : val(v) { }
28 ~Int() = default;
30 Int(const Int& x) : val(x.val), copies(x.copies), moved_from(x.moved_from)
31 { ++copies; }
33 Int(Int&& x) : val(x.val), copies(x.copies), moved_from(x.moved_from)
34 { x.moved_from = true; }
36 Int& operator=(const Int& x)
38 val = x.val;
39 copies = x.copies + 1;
40 moved_from = x.moved_from;
41 return *this;
44 Int& operator=(Int&& x)
46 val = x.val;
47 copies = x.copies;
48 moved_from = x.moved_from;
49 x.moved_from = true;
50 return *this;
53 int val = 0;
54 int copies = 0;
55 bool moved_from = false;
58 Int operator+(Int x, Int y) { x.val += y.val; return x; }
60 struct Add
62 Int operator()(Int x, Int y) const { x.val += y.val; return x; }
65 void
66 test01()
68 Int i[] = { 0, 1, 2, 3, 4 };
69 std::partial_sum(std::begin(i), std::end(i), std::begin(i));
70 for (const auto& r : i)
72 VERIFY( r.copies == 2 );
73 VERIFY( !r.moved_from );
77 void
78 test02()
80 Int i[] = { 0, 1, 2, 3, 4 };
81 std::partial_sum(std::begin(i), std::end(i), std::begin(i), Add{});
82 for (const auto& r : i)
84 VERIFY( r.copies == 2 );
85 VERIFY( !r.moved_from );
89 void
90 test03()
92 Int i[] = { 0, 1, 2, 3, 4 };
93 std::partial_sum(std::make_move_iterator(std::begin(i)),
94 std::make_move_iterator(std::end(i)),
95 std::begin(i));
96 for (const auto& r : i)
98 VERIFY( r.copies == 1 );
99 VERIFY( !r.moved_from );
103 void
104 test04()
106 Int i[] = { 0, 1, 2, 3, 4 };
107 std::partial_sum(std::make_move_iterator(std::begin(i)),
108 std::make_move_iterator(std::end(i)),
109 std::begin(i), Add{});
110 for (const auto& r : i)
112 VERIFY( r.copies == 1 );
113 VERIFY( !r.moved_from );
118 main()
120 test01();
121 test02();
122 test03();
123 test04();