]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/accumulate/lwg2055.cc
d9fa5b38a4be98d67d0357766f33f11ef8335e8e
1 // Copyright (C) 2018-2019 Free Software Foundation, Inc.
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)
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 } }
23 #include <testsuite_hooks.h>
27 Int(int v
) : val(v
) { }
31 Int(const Int
& x
) : val(x
.val
), copies(x
.copies
), moved_from(x
.moved_from
)
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
)
40 copies
= x
.copies
+ 1;
41 moved_from
= x
.moved_from
;
45 Int
& operator=(Int
&& x
)
49 moved_from
= x
.moved_from
;
56 bool moved_from
= false;
59 Int
operator+(Int x
, Int y
) { x
.val
+= y
.val
; return x
; }
63 Int
operator()(Int x
, Int y
) const { x
.val
+= y
.val
; return x
; }
69 Int i
[] = { 0, 1, 2, 3, 4 };
70 Int res
= std::accumulate(std::begin(i
), std::end(i
), Int
{0});
71 VERIFY( res
.copies
== 0 );
72 VERIFY( !res
.moved_from
);
73 for (const auto& r
: i
)
74 VERIFY( !r
.moved_from
);
80 Int i
[] = { 0, 1, 2, 3, 4 };
81 Int res
= std::accumulate(std::begin(i
), std::end(i
), Int
{0}, Add
{});
82 VERIFY( res
.copies
== 0 );
83 VERIFY( !res
.moved_from
);
84 for (const auto& r
: i
)
85 VERIFY( !r
.moved_from
);