]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/94013.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / lexicographical_compare / 94013.cc
CommitLineData
99dee823 1// Copyright (C) 2020-2021 Free Software Foundation, Inc.
462f6c20
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 }
19
20#include <algorithm>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26 volatile unsigned char i[] = { 0, 1, 2, 3 };
27 volatile unsigned char j[] = { 1, 2, 3 };
28 unsigned char k[] = { 2, 3, 4 };
29
30 // v = volatile, c = const, cv = const volatile, u = unqualified
31
32 VERIFY( ! std::lexicographical_compare(i+1, i+4, j, j+2) ); // v v
33 VERIFY( std::lexicographical_compare(i+2, i+4, k, k+3) ); // v u
34 VERIFY( ! std::lexicographical_compare(k, k+3, i+1, i+4) ); // u v
35
36 const volatile unsigned char* cj = j;
37 VERIFY( std::lexicographical_compare(cj, cj+2, cj+1, cj+3) ); // cv cv
38 VERIFY( ! std::lexicographical_compare(cj, cj+3, i+1, i+4) ); // cv v
39 VERIFY( std::lexicographical_compare(i, i+2, cj, cj+2) ); // v cv
40 VERIFY( std::lexicographical_compare(cj+1, cj+3, k, k+3) ); // cv u
41 VERIFY( ! std::lexicographical_compare(k, k+2, cj, cj+3) ); // u cv
42 const unsigned char* ck = k;
43 VERIFY( ! std::lexicographical_compare(ck, ck+2, i+1, i+2) ); // c v
44 VERIFY( std::lexicographical_compare(i, i+3, ck, ck+3) ); // v c
45 VERIFY( std::lexicographical_compare(cj+1, cj+3, ck, ck+3) ); // cv c
46 VERIFY( ! std::lexicographical_compare(ck, ck+1, cj, cj+2) ); // c cv
47
48#if __cplusplus > 201703L
49 using std::ranges::lexicographical_compare;
50 VERIFY( ! lexicographical_compare(i+1, i+4, j, j+2) ); // v v
51 VERIFY( lexicographical_compare(i+2, i+4, k, k+3) ); // v u
52 VERIFY( ! lexicographical_compare(k, k+3, i+1, i+4) ); // u v
53
54 VERIFY( lexicographical_compare(cj, cj+2, cj+1, cj+3) ); // cv cv
55 VERIFY( ! lexicographical_compare(cj, cj+3, i+1, i+4) ); // cv v
56 VERIFY( lexicographical_compare(i, i+2, cj, cj+2) ); // v cv
57 VERIFY( lexicographical_compare(cj+1, cj+3, k, k+3) ); // cv u
58 VERIFY( ! lexicographical_compare(k, k+2, cj, cj+3) ); // u cv
59
60 VERIFY( ! lexicographical_compare(ck, ck+2, i+1, i+2) ); // c v
61 VERIFY( lexicographical_compare(i, i+3, ck, ck+3) ); // v c
62 VERIFY( lexicographical_compare(cj+1, cj+3, ck, ck+3) ); // cv c
63 VERIFY( ! lexicographical_compare(ck, ck+1, cj, cj+2) ); // c cv
64#endif
65}
66
67int
68main()
69{
70 test01();
71}