]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/lexicographical_compare_three_way/constexpr.cc
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do compile { target c++20 } }
25 int a1
[] = { 0, 1, 2, 3, 4, 5, 6, i
, 8 };
26 long a2
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
28 return std::lexicographical_compare_three_way(a1
, a1
+0, a2
, a2
+0) == 0
29 && std::lexicographical_compare_three_way(a1
, a1
+9, a2
, a2
+9) == (i
<=> 7)
30 && std::lexicographical_compare_three_way(a1
, a1
+7, a2
, a2
+7) == 0
31 && std::lexicographical_compare_three_way(a1
, a1
+8, a2
, a2
+7) > 0
32 && std::lexicographical_compare_three_way(a1
, a1
+7, a2
, a2
+8) < 0;
35 static_assert( test01(~7) );
36 static_assert( test01(7) );
37 static_assert( test01(8) );
40 test02(unsigned char i
)
42 unsigned char a1
[] = { 0, 1, 2, 3, 4, 5, 6, i
, 8 };
43 unsigned char a2
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
45 return std::lexicographical_compare_three_way(a1
, a1
+0, a2
, a2
+0) == 0
46 && std::lexicographical_compare_three_way(a1
, a1
+9, a2
, a2
+9) == (i
<=> 7)
47 && std::lexicographical_compare_three_way(a1
, a1
+7, a2
, a2
+7) == 0
48 && std::lexicographical_compare_three_way(a1
, a1
+8, a2
, a2
+7) > 0
49 && std::lexicographical_compare_three_way(a1
, a1
+7, a2
, a2
+8) < 0;
52 static_assert( test02(248) );
53 static_assert( test02(7) );
54 static_assert( test02(8) );
57 test03(unsigned char* p
)
59 unsigned char a
[2] = { 1, 2 };
60 return std::lexicographical_compare_three_way(p
, p
, a
, a
+2) < 0
61 && std::lexicographical_compare_three_way(a
, a
+2, p
, p
) > 0;
64 static_assert( test03(nullptr) ); // ensure memcmp not called with nullptr