| 1 | // Copyright (C) 2020-2025 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. |
| 8 | |
| 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. |
| 13 | |
| 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/>. |
| 17 | |
| 18 | // { dg-do run { target c++20 } } |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <testsuite_hooks.h> |
| 22 | #include <testsuite_iterators.h> |
| 23 | |
| 24 | using __gnu_test::test_range; |
| 25 | using __gnu_test::test_container; |
| 26 | using __gnu_test::bidirectional_iterator_wrapper; |
| 27 | |
| 28 | namespace ranges = std::ranges; |
| 29 | |
| 30 | void |
| 31 | test01() |
| 32 | { |
| 33 | int x[] = { 1, 2, 3, 4 }; |
| 34 | int w[4]; |
| 35 | test_container<int, bidirectional_iterator_wrapper> cx(x), cw(w); |
| 36 | const int y[] = { 4, 3, 2, 1 }; |
| 37 | |
| 38 | auto [in,out] = ranges::reverse_copy(cx, cw.begin()); |
| 39 | VERIFY( in == ranges::end(cx) && out == cw.end() ); |
| 40 | VERIFY( ranges::equal(cw, y) ); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | test02() |
| 45 | { |
| 46 | int x[] = { 1, 2, 3, 4, 5 }; |
| 47 | int w[5]; |
| 48 | test_range<int, bidirectional_iterator_wrapper> rx(x), rw(w); |
| 49 | const int y[] = { 5, 4, 3, 2, 1 }; |
| 50 | |
| 51 | auto [in,out] = ranges::reverse_copy(rx, ranges::begin(rw)); |
| 52 | VERIFY( in == ranges::end(rx) && out == ranges::end(rw) ); |
| 53 | VERIFY( ranges::equal(rw, y) ); |
| 54 | } |
| 55 | |
| 56 | constexpr bool |
| 57 | test03() |
| 58 | { |
| 59 | const int x[] = { 1, 2, 3 }; |
| 60 | int w[2]; |
| 61 | const int y[] = { 2, 1 }; |
| 62 | ranges::reverse_copy(x, x+2, w); |
| 63 | return ranges::equal(w, y); |
| 64 | } |
| 65 | |
| 66 | int |
| 67 | main() |
| 68 | { |
| 69 | test01(); |
| 70 | test02(); |
| 71 | |
| 72 | static_assert(test03()); |
| 73 | } |