| 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-do run { target c++20 } } |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | using std::signed_integral; |
| 24 | |
| 25 | namespace ranges = std::ranges; |
| 26 | |
| 27 | template<signed_integral T> |
| 28 | void |
| 29 | test01() |
| 30 | { |
| 31 | T i[] = { -1 }; |
| 32 | T j[] = { 1 }; |
| 33 | |
| 34 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 35 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 36 | |
| 37 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 38 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 39 | } |
| 40 | |
| 41 | template<signed_integral T> |
| 42 | void |
| 43 | test02() |
| 44 | { |
| 45 | T i[] = { -5 }; |
| 46 | T j[] = { -5, 3 }; |
| 47 | |
| 48 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 49 | VERIFY( ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 50 | |
| 51 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 52 | VERIFY( !ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 53 | } |
| 54 | |
| 55 | template<signed_integral T> |
| 56 | void |
| 57 | test03() |
| 58 | { |
| 59 | T i[] = { -10 }; |
| 60 | T j[] = { -5, 3 }; |
| 61 | |
| 62 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 63 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 64 | |
| 65 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 66 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 67 | } |
| 68 | |
| 69 | template<signed_integral T> |
| 70 | void |
| 71 | test04() |
| 72 | { |
| 73 | T i[] = { -2 }; |
| 74 | T j[] = { -5, 3 }; |
| 75 | |
| 76 | VERIFY( !ranges::lexicographical_compare(i, j) ); |
| 77 | VERIFY( ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 78 | |
| 79 | VERIFY( ranges::lexicographical_compare(j, i) ); |
| 80 | VERIFY( !ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | test05() |
| 85 | { |
| 86 | unsigned i[] = { 1 }; |
| 87 | unsigned j[] = { 256 }; |
| 88 | |
| 89 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 90 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 91 | |
| 92 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 93 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | test06() |
| 98 | { |
| 99 | signed char i[] = { 100, 1 }; |
| 100 | unsigned char j[] = { 100 }; |
| 101 | |
| 102 | VERIFY( !ranges::lexicographical_compare(i, j) ); |
| 103 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 104 | |
| 105 | VERIFY( ranges::lexicographical_compare(j, i) ); |
| 106 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | test07() |
| 111 | { |
| 112 | char i[] = { 95, 1 }; |
| 113 | unsigned char j[] = { 100 }; |
| 114 | |
| 115 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 116 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 117 | |
| 118 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 119 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | test08() |
| 124 | { |
| 125 | signed char i[] = { 112, 1 }; |
| 126 | signed char j[] = { 87 }; |
| 127 | |
| 128 | VERIFY( !ranges::lexicographical_compare(i, j) ); |
| 129 | VERIFY( ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 130 | |
| 131 | VERIFY( ranges::lexicographical_compare(j, i) ); |
| 132 | VERIFY( !ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | test09() |
| 137 | { |
| 138 | char i[] = { 1 }; |
| 139 | unsigned char j[] = { 100 }; |
| 140 | |
| 141 | VERIFY( ranges::lexicographical_compare(i, j) ); |
| 142 | VERIFY( !ranges::lexicographical_compare(i, j, ranges::greater{}) ); |
| 143 | |
| 144 | VERIFY( !ranges::lexicographical_compare(j, i) ); |
| 145 | VERIFY( ranges::lexicographical_compare(j, i, ranges::greater{}) ); |
| 146 | } |
| 147 | |
| 148 | int |
| 149 | main() |
| 150 | { |
| 151 | test01<signed char>(); |
| 152 | test01<int>(); |
| 153 | |
| 154 | test02<signed char>(); |
| 155 | test02<int>(); |
| 156 | |
| 157 | test03<signed char>(); |
| 158 | test03<int>(); |
| 159 | |
| 160 | test04<signed char>(); |
| 161 | test04<int>(); |
| 162 | |
| 163 | test05(); |
| 164 | test06(); |
| 165 | test07(); |
| 166 | test08(); |
| 167 | test09(); |
| 168 | } |