| 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 <vector> |
| 22 | #include <testsuite_hooks.h> |
| 23 | #include <testsuite_iterators.h> |
| 24 | |
| 25 | using __gnu_test::test_container; |
| 26 | using __gnu_test::test_range; |
| 27 | using __gnu_test::input_iterator_wrapper; |
| 28 | using __gnu_test::output_iterator_wrapper; |
| 29 | using __gnu_test::random_access_iterator_wrapper; |
| 30 | |
| 31 | namespace ranges = std::ranges; |
| 32 | |
| 33 | template<template<typename> typename in_wrapper, |
| 34 | template<typename> typename out_wrapper> |
| 35 | void |
| 36 | test01() |
| 37 | { |
| 38 | int x[] = {1,2,3,4,5,6,7}; |
| 39 | for (int i = -1; i <= 7; i++) |
| 40 | { |
| 41 | test_range<int, in_wrapper> rx(x); |
| 42 | int w[7]; |
| 43 | test_range<int, out_wrapper> rw(w); |
| 44 | ranges::copy_n(rx.begin(), i, rw.begin()); |
| 45 | if (i >= 0) |
| 46 | VERIFY( ranges::equal(x, x+i, w, w+i) ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | constexpr bool |
| 51 | test02() |
| 52 | { |
| 53 | int x[] = {1,2,3}; |
| 54 | int y[2]; |
| 55 | auto [in,out] = ranges::copy_n(x, 2, y); |
| 56 | return (in == x+2 |
| 57 | && out == y+2 |
| 58 | && ranges::equal(x, x+2, y, y+2)); |
| 59 | } |
| 60 | |
| 61 | int |
| 62 | main() |
| 63 | { |
| 64 | test01<input_iterator_wrapper, |
| 65 | output_iterator_wrapper>(); |
| 66 | test01<random_access_iterator_wrapper, |
| 67 | output_iterator_wrapper>(); |
| 68 | test01<random_access_iterator_wrapper, |
| 69 | random_access_iterator_wrapper>(); |
| 70 | static_assert(test02()); |
| 71 | } |