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