]>
Commit | Line | Data |
---|---|---|
f1355c8d JW |
1 | // Copyright (C) 2019 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-options "-std=gnu++2a" } | |
19 | // { dg-do compile { target c++2a } } | |
20 | ||
21 | #include <algorithm> | |
22 | ||
23 | constexpr bool | |
24 | test01(int i) | |
25 | { | |
26 | int a1[] = { 0, 1, 2, 3, 4, 5, 6, i, 8 }; | |
27 | long a2[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; | |
28 | ||
29 | return std::lexicographical_compare_three_way(a1, a1+0, a2, a2+0) == 0 | |
30 | && std::lexicographical_compare_three_way(a1, a1+9, a2, a2+9) == (i <=> 7) | |
31 | && std::lexicographical_compare_three_way(a1, a1+7, a2, a2+7) == 0 | |
32 | && std::lexicographical_compare_three_way(a1, a1+8, a2, a2+7) > 0 | |
33 | && std::lexicographical_compare_three_way(a1, a1+7, a2, a2+8) < 0; | |
34 | } | |
35 | ||
36 | static_assert( test01(~7) ); | |
37 | static_assert( test01(7) ); | |
38 | static_assert( test01(8) ); | |
39 | ||
40 | constexpr bool | |
41 | test02(unsigned char i) | |
42 | { | |
43 | unsigned char a1[] = { 0, 1, 2, 3, 4, 5, 6, i, 8 }; | |
44 | unsigned char a2[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; | |
45 | ||
46 | return std::lexicographical_compare_three_way(a1, a1+0, a2, a2+0) == 0 | |
47 | && std::lexicographical_compare_three_way(a1, a1+9, a2, a2+9) == (i <=> 7) | |
48 | && std::lexicographical_compare_three_way(a1, a1+7, a2, a2+7) == 0 | |
49 | && std::lexicographical_compare_three_way(a1, a1+8, a2, a2+7) > 0 | |
50 | && std::lexicographical_compare_three_way(a1, a1+7, a2, a2+8) < 0; | |
51 | } | |
52 | ||
53 | static_assert( test02(248) ); | |
54 | static_assert( test02(7) ); | |
55 | static_assert( test02(8) ); | |
56 | ||
57 | constexpr bool | |
58 | test03(unsigned char* p) | |
59 | { | |
60 | unsigned char a[2] = { 1, 2 }; | |
61 | return std::lexicographical_compare_three_way(p, p, a, a+2) < 0 | |
62 | && std::lexicographical_compare_three_way(a, a+2, p, p) > 0; | |
63 | } | |
64 | ||
65 | static_assert( test03(nullptr) ); // ensure memcmp not called with nullptr |