]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/adjacent_difference/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-do run { target c++20 } }
22 #include <testsuite_hooks.h>
26 Int(int v
) : val(v
) { }
30 Int(const Int
& x
) : val(x
.val
), copies(x
.copies
), moved_from(x
.moved_from
)
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
)
39 copies
= x
.copies
+ 1;
40 moved_from
= x
.moved_from
;
44 Int
& operator=(Int
&& x
)
48 moved_from
= x
.moved_from
;
55 bool moved_from
= false;
58 Int
operator-(Int x
, Int y
) { x
.val
-= y
.val
; return x
; }
62 Int
operator()(Int x
, Int y
) const { x
.val
-= y
.val
; return x
; }
68 Int i
[] = { 0, 1, 2, 3, 4 };
69 std::adjacent_difference(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
);
80 Int i
[] = { 0, 1, 2, 3, 4 };
81 std::adjacent_difference(std::begin(i
), std::end(i
), std::begin(i
),
83 for (const auto& r
: i
)
85 VERIFY( r
.copies
== 2 );
86 VERIFY( !r
.moved_from
);
93 Int i
[] = { 0, 1, 2, 3, 4 };
94 std::adjacent_difference(std::make_move_iterator(std::begin(i
)),
95 std::make_move_iterator(std::end(i
)),
97 for (const auto& r
: i
)
99 VERIFY( r
.copies
== 1 );
100 VERIFY( !r
.moved_from
);
107 Int i
[] = { 0, 1, 2, 3, 4 };
108 std::adjacent_difference(std::make_move_iterator(std::begin(i
)),
109 std::make_move_iterator(std::end(i
)),
110 std::begin(i
), Subtract
{});
111 for (const auto& r
: i
)
113 VERIFY( r
.copies
== 1 );
114 VERIFY( !r
.moved_from
);