]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/copy_n/5.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / copy_n / 5.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
e1008cd1
JW
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++11 } }
19
20#include <algorithm>
21#include <testsuite_iterators.h>
22
23void
24test01()
25{
26 // Negative sizes should be a no-op
27
28 const int from[2] = { 1, 2 };
29 __gnu_test::input_container<const int> f(from);
30 int* to = nullptr;
31 std::copy_n(f.begin(), -1, to);
32
33 std::copy_n(from, -20000, to); // random access
34
35 __gnu_test::random_access_container<const int> f2(from);
36 std::copy_n(f2.end(), -1, to);
37 std::copy_n(f2.begin(), -1, to);
38}
39
40struct Size
41{
42 operator long() const { return 2L; }
43
44 void operator++() = delete;
45 void operator--() = delete;
46 void operator++(int) = delete;
47 void operator--(int) = delete;
48
49 template<typename T> friend void operator+(Size, T) = delete;
50 template<typename T> friend void operator+(T, Size) = delete;
51 template<typename T> friend void operator-(Size, T) = delete;
52 template<typename T> friend void operator-(T, Size) = delete;
53 template<typename T> friend void operator==(Size, T) = delete;
54 template<typename T> friend void operator==(T, Size) = delete;
55 template<typename T> friend void operator!=(Size, T) = delete;
56 template<typename T> friend void operator!=(T, Size) = delete;
57 template<typename T> friend void operator<(Size, T) = delete;
58 template<typename T> friend void operator<(T, Size) = delete;
59 template<typename T> friend void operator<=(Size, T) = delete;
60 template<typename T> friend void operator<=(T, Size) = delete;
61 template<typename T> friend void operator>(Size, T) = delete;
62 template<typename T> friend void operator>(T, Size) = delete;
63 template<typename T> friend void operator>=(Size, T) = delete;
64 template<typename T> friend void operator>=(T, Size) = delete;
65};
66
67void
68test02()
69{
70 // C++20 only requires that Size is convertible to an integral type,
71 // it doesn't need to support any arithmetic or relational expressions.
72
73 const int from[3] = { 1, 2, 3 };
74 __gnu_test::input_container<const int> f(from);
75 int to[3] = { };
76 __gnu_test::output_container<int> t(to);
77 Size s;
78 std::copy_n(f.begin(), s, t.begin());
79 VERIFY( to[0] == 1 );
80 VERIFY( to[1] == 2 );
81 VERIFY( to[2] == 0 );
82
83 const int from2[3] = { 11, 22, 33 };
84 __gnu_test::random_access_container<const int> f2(from2);
85 __gnu_test::output_container<int> t2(to);
86 std::copy_n(f2.begin(), s, t2.begin());
87 VERIFY( to[0] == 11 );
88 VERIFY( to[1] == 22 );
89 VERIFY( to[2] == 0 );
90}
91
92int
93main()
94{
95 test01();
96 test02();
97}