]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/inner_product/lwg2055.cc
1 // Copyright (C) 2018-2023 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
; }
60 Int
operator*(Int x
, Int y
) { x
.val
*= y
.val
; return x
; }
64 Int
operator()(Int x
, Int y
) const { x
.val
+= y
.val
; return x
; }
69 Int
operator()(Int x
, Int y
) const { x
.val
*= y
.val
; return x
; }
75 Int i
[] = { 0, 1, 2, 3, 4 };
76 Int j
[] = { 5, 6, 7, 8, 9 };
77 Int res
= std::inner_product(std::begin(i
), std::end(i
), std::begin(j
),
79 VERIFY( res
.copies
== 0 );
80 VERIFY( !res
.moved_from
);
81 for (const auto& r
: i
)
82 VERIFY( !r
.moved_from
);
83 for (const auto& r
: j
)
84 VERIFY( !r
.moved_from
);
90 Int i
[] = { 0, 1, 2, 3, 4 };
91 Int j
[] = { 5, 6, 7, 8, 9 };
92 Int res
= std::inner_product(std::begin(i
), std::end(i
), std::begin(j
),
93 Int
{0}, Add
{}, Multiply
{});
94 VERIFY( res
.copies
== 0 );
95 VERIFY( !res
.moved_from
);
96 for (const auto& r
: i
)
97 VERIFY( !r
.moved_from
);
98 for (const auto& r
: j
)
99 VERIFY( !r
.moved_from
);