PR libstdc++/78179 run long double tests separately
[official-gcc.git] / libstdc++-v3 / testsuite / 26_numerics / partial_sum / lwg2055.cc
blob871ddaf4c5eab1bc3a662f46110081c234c672d1
1 // Copyright (C) 2018 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
21 #include <numeric>
22 #include <iterator>
23 #include <testsuite_hooks.h>
25 struct Int
27 Int(int v) : val(v) { }
29 ~Int() = default;
31 Int(const Int& x) : val(x.val), copies(x.copies), moved_from(x.moved_from)
32 { ++copies; }
34 Int(Int&& x) : val(x.val), copies(x.copies), moved_from(x.moved_from)
35 { x.moved_from = true; }
37 Int& operator=(const Int& x)
39 val = x.val;
40 copies = x.copies + 1;
41 moved_from = x.moved_from;
42 return *this;
45 Int& operator=(Int&& x)
47 val = x.val;
48 copies = x.copies;
49 moved_from = x.moved_from;
50 x.moved_from = true;
51 return *this;
54 int val = 0;
55 int copies = 0;
56 bool moved_from = false;
59 Int operator+(Int x, Int y) { x.val += y.val; return x; }
61 struct Add
63 Int operator()(Int x, Int y) const { x.val += y.val; return x; }
66 void
67 test01()
69 Int i[] = { 0, 1, 2, 3, 4 };
70 std::partial_sum(std::begin(i), std::end(i), std::begin(i));
71 for (const auto& r : i)
73 VERIFY( r.copies == 2 );
74 VERIFY( !r.moved_from );
78 void
79 test02()
81 Int i[] = { 0, 1, 2, 3, 4 };
82 std::partial_sum(std::begin(i), std::end(i), std::begin(i), Add{});
83 for (const auto& r : i)
85 VERIFY( r.copies == 2 );
86 VERIFY( !r.moved_from );
90 void
91 test03()
93 Int i[] = { 0, 1, 2, 3, 4 };
94 std::partial_sum(std::make_move_iterator(std::begin(i)),
95 std::make_move_iterator(std::end(i)),
96 std::begin(i));
97 for (const auto& r : i)
99 VERIFY( r.copies == 1 );
100 VERIFY( !r.moved_from );
104 void
105 test04()
107 Int i[] = { 0, 1, 2, 3, 4 };
108 std::partial_sum(std::make_move_iterator(std::begin(i)),
109 std::make_move_iterator(std::end(i)),
110 std::begin(i), Add{});
111 for (const auto& r : i)
113 VERIFY( r.copies == 1 );
114 VERIFY( !r.moved_from );
119 main()
121 test01();
122 test02();
123 test03();
124 test04();