| 1 |
// Copyright (C) 2019-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 |
#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(d.begin(), d.end(), dest.begin()); |
| 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(cd.begin(), cd.end(), dest.begin()); |
| 52 |
|
| 53 |
VERIFY( equal(dest.begin(), dest.end(), cd.begin()) ); |
| 54 |
} |
| 55 |
|
| 56 |
void test03() |
| 57 |
{ |
| 58 |
using namespace std; |
| 59 |
|
| 60 |
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 |
vector<int> dest(d.size(), 0); |
| 68 |
|
| 69 |
copy(d.begin(), d.end(), dest.begin()); |
| 70 |
VERIFY( equal(dest.begin(), dest.end(), d.begin()) ); |
| 71 |
} |
| 72 |
|
| 73 |
void test04() |
| 74 |
{ |
| 75 |
using namespace std; |
| 76 |
|
| 77 |
vector<int> v; |
| 78 |
for (int i = 0; i != 1024; ++i) |
| 79 |
v.push_back(i); |
| 80 |
|
| 81 |
deque<int> dest(v.size() - 10, 0); |
| 82 |
|
| 83 |
std::copy(v.begin() + 5, v.end() - 5, dest.begin()); |
| 84 |
VERIFY( std::equal(dest.begin(), dest.end(), v.begin() + 5) ); |
| 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(l.begin(), l.end(), dest.begin()); |
| 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 |
} |