| 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 <deque> |
| 21 |
|
| 22 |
#include <ext/new_allocator.h> |
| 23 |
#include <ext/malloc_allocator.h> |
| 24 |
|
| 25 |
#include <testsuite_hooks.h> |
| 26 |
|
| 27 |
void test01() |
| 28 |
{ |
| 29 |
using namespace std; |
| 30 |
|
| 31 |
deque<int> d; |
| 32 |
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i) |
| 33 |
d.push_back(i); |
| 34 |
|
| 35 |
const deque<int>& cd = d; |
| 36 |
|
| 37 |
VERIFY( equal(cd.begin(), cd.end(), cd.begin()) ); |
| 38 |
VERIFY( equal(cd.begin(), cd.end(), d.begin()) ); |
| 39 |
VERIFY( equal(d.begin(), d.end(), d.begin()) ); |
| 40 |
VERIFY( equal(d.begin(), d.end(), cd.begin()) ); |
| 41 |
} |
| 42 |
|
| 43 |
void test02() |
| 44 |
{ |
| 45 |
using namespace std; |
| 46 |
|
| 47 |
deque<int> d; |
| 48 |
for (int i = 0; i != 1024; ++i) |
| 49 |
d.push_back(i % 10); |
| 50 |
|
| 51 |
VERIFY( equal(d.begin(), d.begin() + 10, d.begin() + 20) ); |
| 52 |
VERIFY( equal(d.begin() + 10, d.end() - 10, d.begin()) ); |
| 53 |
|
| 54 |
const deque<int>& cd = d; |
| 55 |
|
| 56 |
VERIFY( equal(cd.begin(), cd.begin() + 10, cd.begin() + 20) ); |
| 57 |
VERIFY( equal(cd.begin() + 10, cd.end() - 10, d.begin()) ); |
| 58 |
VERIFY( equal(d.begin() + 10, d.end() - 10, cd.begin()) ); |
| 59 |
} |
| 60 |
|
| 61 |
void test03() |
| 62 |
{ |
| 63 |
using namespace std; |
| 64 |
|
| 65 |
deque<int> d1; |
| 66 |
for (int i = 0; i != 1024; ++i) |
| 67 |
d1.push_back(i % 10); |
| 68 |
|
| 69 |
deque<int> d2(d1); |
| 70 |
for (int i = 0; i != 10; ++i) |
| 71 |
d2.pop_front(); |
| 72 |
|
| 73 |
VERIFY( equal(d1.begin(), d1.begin() + 10, d2.begin()) ); |
| 74 |
VERIFY( equal(d1.begin() + 10, d1.end() - 10, d2.begin()) ); |
| 75 |
|
| 76 |
const deque<int>& cd1 = d1; |
| 77 |
const deque<int>& cd2 = d2; |
| 78 |
|
| 79 |
VERIFY( equal(cd1.begin(), cd1.begin() + 10, cd2.begin() + 20) ); |
| 80 |
VERIFY( equal(cd1.begin() + 10, cd1.end() - 10, d2.begin()) ); |
| 81 |
VERIFY( equal(cd2.begin() + 10, cd2.end() - 10, cd1.begin()) ); |
| 82 |
} |
| 83 |
|
| 84 |
void test04() |
| 85 |
{ |
| 86 |
using namespace std; |
| 87 |
|
| 88 |
deque<int> d; |
| 89 |
for (int i = 0; i != 1024; ++i) |
| 90 |
d.push_back(i); |
| 91 |
|
| 92 |
vector<int> v(d.begin(), d.end()); |
| 93 |
|
| 94 |
VERIFY( equal(d.begin(), d.end(), v.begin()) ); |
| 95 |
VERIFY( equal(v.begin(), v.end(), d.begin()) ); |
| 96 |
|
| 97 |
const deque<int>& cd = d; |
| 98 |
|
| 99 |
VERIFY( equal(cd.begin(), cd.end(), v.begin()) ); |
| 100 |
VERIFY( equal(v.begin(), v.end(), cd.begin()) ); |
| 101 |
} |
| 102 |
|
| 103 |
void test05() |
| 104 |
{ |
| 105 |
using namespace std; |
| 106 |
|
| 107 |
int a[] = { 0, 1, 2, 3, 4 }; |
| 108 |
deque<int, __gnu_cxx::new_allocator<int> > d1(a, a + 5); |
| 109 |
deque<int, __gnu_cxx::malloc_allocator<int> > d2(a, a + 5); |
| 110 |
|
| 111 |
VERIFY( equal(d1.begin(), d1.end(), d2.begin()) ); |
| 112 |
} |
| 113 |
|
| 114 |
int main() |
| 115 |
{ |
| 116 |
test01(); |
| 117 |
test02(); |
| 118 |
test03(); |
| 119 |
test04(); |
| 120 |
test05(); |
| 121 |
return 0; |
| 122 |
} |