1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <algorithm>
10 
11 // template<InputIterator Iter1, InputIterator Iter2>
12 //   requires HasLess<Iter1::value_type, Iter2::value_type>
13 //         && HasLess<Iter2::value_type, Iter1::value_type>
14 //   constexpr bool             // constexpr after C++17
15 //   lexicographical_compare(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
16 
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 
23 template <class T, class Iter1>
24 struct Test {
25   template <class Iter2>
26   TEST_CONSTEXPR_CXX20 void operator()() {
27     T ia[]            = {1, 2, 3, 4};
28     const unsigned sa = sizeof(ia) / sizeof(ia[0]);
29     T ib[]            = {1, 2, 3};
30     assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia + sa), Iter2(ib), Iter2(ib + 2)));
31     assert(std::lexicographical_compare(Iter1(ib), Iter1(ib + 2), Iter2(ia), Iter2(ia + sa)));
32     assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia + sa), Iter2(ib), Iter2(ib + 3)));
33     assert(std::lexicographical_compare(Iter1(ib), Iter1(ib + 3), Iter2(ia), Iter2(ia + sa)));
34     assert(std::lexicographical_compare(Iter1(ia), Iter1(ia + sa), Iter2(ib + 1), Iter2(ib + 3)));
35     assert(!std::lexicographical_compare(Iter1(ib + 1), Iter1(ib + 3), Iter2(ia), Iter2(ia + sa)));
36   }
37 };
38 
39 template <class T>
40 struct TestIter {
41   template <class Iter1>
42   TEST_CONSTEXPR_CXX20 bool operator()() {
43     types::for_each(types::cpp17_input_iterator_list<T*>(), Test<T, Iter1>());
44 
45     return true;
46   }
47 };
48 
49 TEST_CONSTEXPR_CXX20 bool test() {
50   types::for_each(types::cpp17_input_iterator_list<const int*>(), TestIter<const int>());
51 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
52   types::for_each(types::cpp17_input_iterator_list<const wchar_t*>(), TestIter<const wchar_t>());
53 #endif
54   types::for_each(types::cpp17_input_iterator_list<const char*>(), TestIter<const char>());
55   types::for_each(types::cpp17_input_iterator_list<unsigned char*>(), TestIter<unsigned char>());
56 
57   return true;
58 }
59 
60 int main(int, char**) {
61   test();
62 
63 #if TEST_STD_VER >= 20
64   static_assert(test());
65 #endif
66 
67   return 0;
68 }
69