1 // Copyright (C) 2020-2024 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 } }
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_container
;
25 using __gnu_test::test_range
;
26 using __gnu_test::input_iterator_wrapper
;
27 using __gnu_test::forward_iterator_wrapper
;
28 using __gnu_test::bidirectional_iterator_wrapper
;
30 namespace ranges
= std::ranges
;
37 constexpr X(int a
) : i(a
) { }
39 constexpr X(const X
&) = delete;
40 constexpr X
& operator=(const X
&) = delete;
42 constexpr X(X
&& other
)
44 *this = std::move(other
);
56 operator==(const X
& a
, const X
& b
)
57 { return a
.i
== b
.i
; }
64 X x
[7] = { 1, 2, 3, 4, 5, 6, 7 };
65 X y
[7] = { 2, 4, 3, 5, 8, 9, 1 };
66 X z
[7] = { 1, 2, 3, 4, 5, 6, 7 };
67 X w
[7] = { 2, 4, 3, 5, 8, 9, 1 };
68 auto [x_iter
, y_iter
] = ranges::swap_ranges(x
, y
);
69 VERIFY( ranges::equal(y
, z
) && x_iter
== x
+7 && y_iter
== y
+7 );
70 VERIFY( ranges::equal(x
, w
) );
74 int x
[3] = { 1, 2, 3 };
75 int y
[4] = { 2, 4, 6, 0 };
76 int z
[3] = { 1, 2, 3 };
77 int w
[3] = { 2, 4, 6 };
78 test_container
<int, forward_iterator_wrapper
> cx(x
);
79 test_container
<int, forward_iterator_wrapper
> cy(y
);
80 auto [x_iter
, y_iter
] = ranges::swap_ranges(cx
, cy
);
81 VERIFY( ranges::equal(y
, y
+3, z
, z
+3) );
82 VERIFY( x_iter
.ptr
== x
+3 && y_iter
.ptr
== y
+3 );
84 VERIFY( ranges::equal(x
, w
) );
88 int x
[3] = { 1, 2, 3 };
89 int y
[4] = { 2, 4, 6, 0 };
90 int z
[3] = { 1, 2, 3 };
91 int w
[3] = { 2, 4, 6 };
92 test_range
<int, input_iterator_wrapper
> cx(x
);
93 test_range
<int, input_iterator_wrapper
> cy(y
);
94 auto [y_iter
, x_iter
] = ranges::swap_ranges(cy
, cx
);
95 VERIFY( ranges::equal(y
, y
+3, z
, z
+3) );
96 VERIFY( x_iter
.ptr
== x
+3 && y_iter
.ptr
== y
+3 );
98 VERIFY( ranges::equal(x
, w
) );
106 X x
[7] = { 1, 2, 3, 4, 5, 6, 7 };
107 X y
[7] = { 2, 4, 3, 5, 8, 9, 1 };
108 X z
[7] = { 1, 2, 3, 4, 5, 6, 7 };
109 X w
[7] = { 2, 4, 3, 5, 8, 9, 1 };
110 auto [x_iter
, y_iter
] = ranges::swap_ranges(x
, y
);
111 ok
&= ranges::equal(y
, z
) && x_iter
== x
+7 && y_iter
== y
+7;
112 ok
&= ranges::equal(x
, w
);
120 static_assert(test02());