| 1 |
// Copyright (C) 2020-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 |
// { dg-timeout-factor 2 { target debug_mode } } |
| 19 |
|
| 20 |
#include <algorithm> |
| 21 |
#include <vector> |
| 22 |
#include <deque> |
| 23 |
|
| 24 |
#include <ext/new_allocator.h> |
| 25 |
#include <ext/malloc_allocator.h> |
| 26 |
|
| 27 |
#include <testsuite_hooks.h> |
| 28 |
|
| 29 |
void test01() |
| 30 |
{ |
| 31 |
using namespace std; |
| 32 |
|
| 33 |
deque<int> d; |
| 34 |
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i) |
| 35 |
d.push_back(i); |
| 36 |
|
| 37 |
const deque<int>& cd = d; |
| 38 |
|
| 39 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), cd.begin(), cd.end()) ); |
| 40 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), d.begin(), d.end()) ); |
| 41 |
VERIFY( !lexicographical_compare(d.begin(), d.end(), d.begin(), d.end()) ); |
| 42 |
VERIFY( !lexicographical_compare(d.begin(), d.end(), cd.begin(), cd.end()) ); |
| 43 |
|
| 44 |
const deque<int>::iterator first = d.begin(), last = d.end(); |
| 45 |
VERIFY( lexicographical_compare(first, last - 1, first, last) ); |
| 46 |
VERIFY( !lexicographical_compare(first, last, first, last - 1) ); |
| 47 |
VERIFY( lexicographical_compare(first, last, first + 1, last) ); |
| 48 |
VERIFY( !lexicographical_compare(first + 1, last, first, last) ); |
| 49 |
} |
| 50 |
|
| 51 |
void test02() |
| 52 |
{ |
| 53 |
using namespace std; |
| 54 |
|
| 55 |
deque<int> d; |
| 56 |
for (int i = 0; i != 1000; ++i) |
| 57 |
d.push_back(i % 10); |
| 58 |
|
| 59 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 60 |
d.begin() + 21, d.begin() + 31) ); |
| 61 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 62 |
d.begin() + 20, d.begin() + 31) ); |
| 63 |
VERIFY( ! lexicographical_compare(d.begin() + 1, d.begin() + 10, |
| 64 |
d.begin() + 21, d.begin() + 30) ); |
| 65 |
VERIFY( !lexicographical_compare(d.begin(), d.begin() + 10, |
| 66 |
d.begin() + 20, d.begin() + 30) ); |
| 67 |
VERIFY( !lexicographical_compare(d.begin() + 1, d.begin() + 10, |
| 68 |
d.begin() + 1 + 20, d.begin() + 30) ); |
| 69 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 70 |
d.begin() + 20, d.begin() + 31) ); |
| 71 |
VERIFY( !lexicographical_compare(d.begin() + 10, d.end() - 10, |
| 72 |
d.begin(), d.end() - 20) ); |
| 73 |
|
| 74 |
const deque<int>& cd = d; |
| 75 |
|
| 76 |
VERIFY( lexicographical_compare(cd.begin(), cd.begin() + 10, |
| 77 |
cd.begin() + 21, cd.begin() + 31) ); |
| 78 |
VERIFY( lexicographical_compare(cd.begin() + 1, cd.begin() + 10, |
| 79 |
cd.begin() + 21, cd.begin() + 32) ); |
| 80 |
VERIFY( !lexicographical_compare(cd.begin(), cd.begin() + 10, |
| 81 |
cd.begin() + 20, cd.begin() + 30) ); |
| 82 |
VERIFY( !lexicographical_compare(cd.begin() + 1, cd.begin() + 10, |
| 83 |
cd.begin() + 21, cd.begin() + 30) ); |
| 84 |
VERIFY( !lexicographical_compare(cd.begin() + 10, cd.end() - 10, |
| 85 |
d.begin(), d.end() - 20) ); |
| 86 |
VERIFY( !lexicographical_compare(d.begin() + 10, d.end() - 10, |
| 87 |
cd.begin(), cd.end() - 20) ); |
| 88 |
} |
| 89 |
|
| 90 |
void test03() |
| 91 |
{ |
| 92 |
using namespace std; |
| 93 |
|
| 94 |
deque<int> d1; |
| 95 |
for (int i = 0; i != 1000; ++i) |
| 96 |
d1.push_back(i % 10); |
| 97 |
|
| 98 |
deque<int> d2(d1); |
| 99 |
for (int i = 0; i != 10; ++i) |
| 100 |
d2.pop_front(); |
| 101 |
|
| 102 |
VERIFY( !lexicographical_compare(d1.begin(), d1.begin() + 10, |
| 103 |
d2.begin(), d2.begin() + 10) ); |
| 104 |
VERIFY( !lexicographical_compare(d1.begin() + 10, d1.end() - 10, |
| 105 |
d2.begin(), d2.end() - 10) ); |
| 106 |
|
| 107 |
const deque<int>& cd1 = d1; |
| 108 |
const deque<int>& cd2 = d2; |
| 109 |
|
| 110 |
VERIFY( !lexicographical_compare(cd1.begin(), cd1.begin() + 10, |
| 111 |
cd2.begin() + 20, cd2.begin() + 30) ); |
| 112 |
VERIFY( !lexicographical_compare(cd1.begin() + 10, cd1.end() - 10, |
| 113 |
d2.begin(), d2.end() - 10) ); |
| 114 |
VERIFY( lexicographical_compare(cd2.begin() + 10, cd2.end() - 10, |
| 115 |
cd1.begin(), cd1.end() - 20) ); |
| 116 |
} |
| 117 |
|
| 118 |
void test04() |
| 119 |
{ |
| 120 |
using namespace std; |
| 121 |
|
| 122 |
deque<int> d; |
| 123 |
for (int i = 0; i != 1024; ++i) |
| 124 |
d.push_back(i); |
| 125 |
|
| 126 |
vector<int> v(d.begin(), d.end()); |
| 127 |
|
| 128 |
VERIFY( lexicographical_compare(d.begin() + 5, d.end() - 1, v.begin() + 5, v.end()) ); |
| 129 |
VERIFY( !lexicographical_compare(v.begin(), v.end(), d.begin(), d.end()) ); |
| 130 |
|
| 131 |
const deque<int>& cd = d; |
| 132 |
|
| 133 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), v.begin(), v.end()) ); |
| 134 |
VERIFY( !lexicographical_compare(v.begin(), v.end(), cd.begin(), cd.end()) ); |
| 135 |
} |
| 136 |
|
| 137 |
void test05() |
| 138 |
{ |
| 139 |
using namespace std; |
| 140 |
|
| 141 |
int a[] = { 0, 1, 2, 3, 4 }; |
| 142 |
deque<int, __gnu_cxx::new_allocator<int> > d1(a, a + 5); |
| 143 |
deque<int, __gnu_cxx::malloc_allocator<int> > d2(a, a + 5); |
| 144 |
|
| 145 |
VERIFY( !lexicographical_compare(d1.begin(), d1.end(), d2.begin(), d2.end()) ); |
| 146 |
} |
| 147 |
|
| 148 |
void |
| 149 |
test06() |
| 150 |
{ |
| 151 |
using namespace std; |
| 152 |
|
| 153 |
deque<int> d; |
| 154 |
int i = 0; |
| 155 |
VERIFY( lexicographical_compare(d.begin(), d.end(), &i, &i + 1) ); |
| 156 |
VERIFY( !lexicographical_compare(&i, &i + 1, d.begin(), d.end()) ); |
| 157 |
} |
| 158 |
|
| 159 |
void test07() |
| 160 |
{ |
| 161 |
using namespace std; |
| 162 |
|
| 163 |
deque<unsigned char> d; |
| 164 |
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i) |
| 165 |
d.push_back(i); |
| 166 |
|
| 167 |
const deque<unsigned char>& cd = d; |
| 168 |
|
| 169 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), cd.begin(), cd.end()) ); |
| 170 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), d.begin(), d.end()) ); |
| 171 |
VERIFY( !lexicographical_compare(d.begin(), d.end(), d.begin(), d.end()) ); |
| 172 |
VERIFY( !lexicographical_compare(d.begin(), d.end(), cd.begin(), cd.end()) ); |
| 173 |
|
| 174 |
const deque<unsigned char>::iterator first = d.begin(), last = d.end(); |
| 175 |
VERIFY( lexicographical_compare(first, last - 1, first, last) ); |
| 176 |
VERIFY( !lexicographical_compare(first, last, first, last - 1) ); |
| 177 |
VERIFY( lexicographical_compare(first, last, first + 1, last) ); |
| 178 |
VERIFY( !lexicographical_compare(first + 1, last, first, last) ); |
| 179 |
} |
| 180 |
|
| 181 |
void test08() |
| 182 |
{ |
| 183 |
using namespace std; |
| 184 |
|
| 185 |
deque<unsigned char> d; |
| 186 |
for (int i = 0; i != 1000; ++i) |
| 187 |
d.push_back(i % 10); |
| 188 |
|
| 189 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 190 |
d.begin() + 21, d.begin() + 31) ); |
| 191 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 192 |
d.begin() + 20, d.begin() + 31) ); |
| 193 |
VERIFY( ! lexicographical_compare(d.begin() + 1, d.begin() + 10, |
| 194 |
d.begin() + 21, d.begin() + 30) ); |
| 195 |
VERIFY( !lexicographical_compare(d.begin(), d.begin() + 10, |
| 196 |
d.begin() + 20, d.begin() + 30) ); |
| 197 |
VERIFY( !lexicographical_compare(d.begin() + 1, d.begin() + 10, |
| 198 |
d.begin() + 1 + 20, d.begin() + 30) ); |
| 199 |
VERIFY( lexicographical_compare(d.begin(), d.begin() + 10, |
| 200 |
d.begin() + 20, d.begin() + 31) ); |
| 201 |
VERIFY( !lexicographical_compare(d.begin() + 10, d.end() - 10, |
| 202 |
d.begin(), d.end() - 20) ); |
| 203 |
|
| 204 |
const deque<unsigned char>& cd = d; |
| 205 |
|
| 206 |
VERIFY( lexicographical_compare(cd.begin(), cd.begin() + 10, |
| 207 |
cd.begin() + 21, cd.begin() + 31) ); |
| 208 |
VERIFY( lexicographical_compare(cd.begin() + 1, cd.begin() + 10, |
| 209 |
cd.begin() + 21, cd.begin() + 32) ); |
| 210 |
VERIFY( !lexicographical_compare(cd.begin(), cd.begin() + 10, |
| 211 |
cd.begin() + 20, cd.begin() + 30) ); |
| 212 |
VERIFY( !lexicographical_compare(cd.begin() + 1, cd.begin() + 10, |
| 213 |
cd.begin() + 21, cd.begin() + 30) ); |
| 214 |
VERIFY( !lexicographical_compare(cd.begin() + 10, cd.end() - 10, |
| 215 |
d.begin(), d.end() - 20) ); |
| 216 |
VERIFY( !lexicographical_compare(d.begin() + 10, d.end() - 10, |
| 217 |
cd.begin(), cd.end() - 20) ); |
| 218 |
} |
| 219 |
|
| 220 |
void test09() |
| 221 |
{ |
| 222 |
using namespace std; |
| 223 |
|
| 224 |
deque<unsigned char> d1; |
| 225 |
for (int i = 0; i != 1000; ++i) |
| 226 |
d1.push_back(i % 10); |
| 227 |
|
| 228 |
deque<unsigned char> d2(d1); |
| 229 |
for (int i = 0; i != 10; ++i) |
| 230 |
d2.pop_front(); |
| 231 |
|
| 232 |
VERIFY( !lexicographical_compare(d1.begin(), d1.begin() + 10, |
| 233 |
d2.begin(), d2.begin() + 10) ); |
| 234 |
VERIFY( !lexicographical_compare(d1.begin() + 10, d1.end() - 10, |
| 235 |
d2.begin(), d2.end() - 10) ); |
| 236 |
|
| 237 |
const deque<unsigned char>& cd1 = d1; |
| 238 |
const deque<unsigned char>& cd2 = d2; |
| 239 |
|
| 240 |
VERIFY( !lexicographical_compare(cd1.begin(), cd1.begin() + 10, |
| 241 |
cd2.begin() + 20, cd2.begin() + 30) ); |
| 242 |
VERIFY( !lexicographical_compare(cd1.begin() + 10, cd1.end() - 10, |
| 243 |
d2.begin(), d2.end() - 10) ); |
| 244 |
VERIFY( lexicographical_compare(cd2.begin() + 10, cd2.end() - 10, |
| 245 |
cd1.begin(), cd1.end() - 20) ); |
| 246 |
} |
| 247 |
|
| 248 |
void test10() |
| 249 |
{ |
| 250 |
using namespace std; |
| 251 |
|
| 252 |
deque<unsigned char> d; |
| 253 |
for (int i = 0; i != 1024; ++i) |
| 254 |
d.push_back(i); |
| 255 |
|
| 256 |
vector<unsigned char> v(d.begin(), d.end()); |
| 257 |
|
| 258 |
VERIFY( lexicographical_compare(d.begin() + 5, d.end() - 1, v.begin() + 5, v.end()) ); |
| 259 |
VERIFY( !lexicographical_compare(v.begin(), v.end(), d.begin(), d.end()) ); |
| 260 |
|
| 261 |
const deque<unsigned char>& cd = d; |
| 262 |
|
| 263 |
VERIFY( !lexicographical_compare(cd.begin(), cd.end(), v.begin(), v.end()) ); |
| 264 |
VERIFY( !lexicographical_compare(v.begin(), v.end(), cd.begin(), cd.end()) ); |
| 265 |
} |
| 266 |
|
| 267 |
void test11() |
| 268 |
{ |
| 269 |
using namespace std; |
| 270 |
|
| 271 |
int a[] = { 0, 1, 2, 3, 4 }; |
| 272 |
deque<unsigned char, __gnu_cxx::new_allocator<unsigned char> > d1(a, a + 5); |
| 273 |
deque<unsigned char, __gnu_cxx::malloc_allocator<unsigned char> > d2(a, a + 5); |
| 274 |
|
| 275 |
VERIFY( !lexicographical_compare(d1.begin(), d1.end(), d2.begin(), d2.end()) ); |
| 276 |
} |
| 277 |
|
| 278 |
void |
| 279 |
test12() |
| 280 |
{ |
| 281 |
using namespace std; |
| 282 |
|
| 283 |
deque<unsigned char> d; |
| 284 |
int i = 0; |
| 285 |
VERIFY( lexicographical_compare(d.begin(), d.end(), &i, &i + 1) ); |
| 286 |
VERIFY( !lexicographical_compare(&i, &i + 1, d.begin(), d.end()) ); |
| 287 |
} |
| 288 |
|
| 289 |
int main() |
| 290 |
{ |
| 291 |
test01(); |
| 292 |
test02(); |
| 293 |
test03(); |
| 294 |
test04(); |
| 295 |
test05(); |
| 296 |
test06(); |
| 297 |
test07(); |
| 298 |
test08(); |
| 299 |
test09(); |
| 300 |
test10(); |
| 301 |
test11(); |
| 302 |
test12(); |
| 303 |
} |