]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/copy_backward/deque_iterators/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / copy_backward / deque_iterators / 2.cc
1 // Copyright (C) 2019-2024 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 #include <algorithm>
19 #include <vector>
20 #include <list>
21 #include <deque>
22
23 #include <testsuite_hooks.h>
24
25 void test01()
26 {
27 using namespace std;
28
29 deque<int> d;
30 for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
31 d.push_back(i);
32
33 deque<int> dest(d.size(), 0);
34
35 copy_backward(d.begin(), d.end(), dest.end());
36
37 VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
38 }
39
40 void test02()
41 {
42 using namespace std;
43
44 deque<int> d;
45 for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
46 d.push_back(i);
47
48 deque<int> dest(d.size(), 0);
49
50 const deque<int>& cd = d;
51 copy_backward(cd.begin(), cd.end(), dest.end());
52
53 VERIFY( equal(dest.begin(), dest.end(), cd.begin()) );
54 }
55
56 void test03()
57 {
58 using namespace std;
59
60 std::deque<int> d;
61 for (int i = 0; i != 1024; ++i)
62 d.push_back(i);
63
64 d.pop_front();
65 d.pop_back();
66
67 std::vector<int> dest(d.size(), 0);
68
69 std::copy_backward(d.begin(), d.end(), dest.end());
70 VERIFY( std::equal(dest.begin(), dest.end(), d.begin()) );
71 }
72
73 void test04()
74 {
75 using namespace std;
76
77 std::vector<int> v;
78 for (int i = 0; i != 1024; ++i)
79 v.push_back(i);
80
81 std::deque<int> dest(v.size() - 10, 0);
82
83 std::copy_backward(v.begin() + 5, v.end() - 5, dest.end());
84 VERIFY( std::equal(v.begin() + 5, v.end() - 5, dest.begin()) );
85 }
86
87 void test05()
88 {
89 using namespace std;
90
91 std::list<int> l;
92 for (int i = 0; i != 1024; ++i)
93 l.push_back(i);
94
95 std::deque<int> dest(l.size(), 0);
96
97 std::copy_backward(l.begin(), l.end(), dest.end());
98 VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) );
99 }
100
101 int main()
102 {
103 test01();
104 test02();
105 test03();
106 test04();
107 test05();
108 return 0;
109 }