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 | #if TEST_STD_VER > 17 |
24 | TEST_CONSTEXPR bool test_constexpr() { |
25 | int ia[] = {1, 2, 3}; |
26 | int ib[] = {1, 3, 5, 2, 4, 6}; |
27 | |
28 | return std::lexicographical_compare(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib)) |
29 | && !std::lexicographical_compare(std::begin(ib), std::end(ib), std::begin(ia), std::end(ia)) |
30 | ; |
31 | } |
32 | #endif |
33 | |
34 | template <class Iter1, class Iter2> |
35 | void |
36 | test() |
37 | { |
38 | int ia[] = {1, 2, 3, 4}; |
39 | const unsigned sa = sizeof(ia)/sizeof(ia[0]); |
40 | int ib[] = {1, 2, 3}; |
41 | assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+2))); |
42 | assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+2), Iter2(ia), Iter2(ia+sa))); |
43 | assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+3))); |
44 | assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+3), Iter2(ia), Iter2(ia+sa))); |
45 | assert( std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib+1), Iter2(ib+3))); |
46 | assert(!std::lexicographical_compare(Iter1(ib+1), Iter1(ib+3), Iter2(ia), Iter2(ia+sa))); |
47 | } |
48 | |
49 | int main(int, char**) |
50 | { |
51 | test<cpp17_input_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
52 | test<cpp17_input_iterator<const int*>, forward_iterator<const int*> >(); |
53 | test<cpp17_input_iterator<const int*>, bidirectional_iterator<const int*> >(); |
54 | test<cpp17_input_iterator<const int*>, random_access_iterator<const int*> >(); |
55 | test<cpp17_input_iterator<const int*>, const int*>(); |
56 | |
57 | test<forward_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
58 | test<forward_iterator<const int*>, forward_iterator<const int*> >(); |
59 | test<forward_iterator<const int*>, bidirectional_iterator<const int*> >(); |
60 | test<forward_iterator<const int*>, random_access_iterator<const int*> >(); |
61 | test<forward_iterator<const int*>, const int*>(); |
62 | |
63 | test<bidirectional_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
64 | test<bidirectional_iterator<const int*>, forward_iterator<const int*> >(); |
65 | test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >(); |
66 | test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >(); |
67 | test<bidirectional_iterator<const int*>, const int*>(); |
68 | |
69 | test<random_access_iterator<const int*>, cpp17_input_iterator<const int*> >(); |
70 | test<random_access_iterator<const int*>, forward_iterator<const int*> >(); |
71 | test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); |
72 | test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); |
73 | test<random_access_iterator<const int*>, const int*>(); |
74 | |
75 | test<const int*, cpp17_input_iterator<const int*> >(); |
76 | test<const int*, forward_iterator<const int*> >(); |
77 | test<const int*, bidirectional_iterator<const int*> >(); |
78 | test<const int*, random_access_iterator<const int*> >(); |
79 | test<const int*, const int*>(); |
80 | |
81 | #if TEST_STD_VER > 17 |
82 | static_assert(test_constexpr()); |
83 | #endif |
84 | |
85 | return 0; |
86 | } |
87 | |