1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <algorithm>
11
12// template<InputIterator Iter1, InputIterator Iter2>
13//   requires HasLess<Iter1::value_type, Iter2::value_type>
14//         && HasLess<Iter2::value_type, Iter1::value_type>
15//   bool
16//   lexicographical_compare(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
17
18#include <algorithm>
19#include <cassert>
20
21#include "test_iterators.h"
22
23template <class Iter1, class Iter2>
24void
25test()
26{
27    int ia[] = {1, 2, 3, 4};
28    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
29    int ib[] = {1, 2, 3};
30    assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+2));
31    assert(std::lexicographical_compare(ib, ib+2, ia, ia+sa));
32    assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+3));
33    assert(std::lexicographical_compare(ib, ib+3, ia, ia+sa));
34    assert(std::lexicographical_compare(ia, ia+sa, ib+1, ib+3));
35    assert(!std::lexicographical_compare(ib+1, ib+3, ia, ia+sa));
36}
37
38int main()
39{
40    test<input_iterator<const int*>, input_iterator<const int*> >();
41    test<input_iterator<const int*>, forward_iterator<const int*> >();
42    test<input_iterator<const int*>, bidirectional_iterator<const int*> >();
43    test<input_iterator<const int*>, random_access_iterator<const int*> >();
44    test<input_iterator<const int*>, const int*>();
45
46    test<forward_iterator<const int*>, input_iterator<const int*> >();
47    test<forward_iterator<const int*>, forward_iterator<const int*> >();
48    test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
49    test<forward_iterator<const int*>, random_access_iterator<const int*> >();
50    test<forward_iterator<const int*>, const int*>();
51
52    test<bidirectional_iterator<const int*>, input_iterator<const int*> >();
53    test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
54    test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
55    test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
56    test<bidirectional_iterator<const int*>, const int*>();
57
58    test<random_access_iterator<const int*>, input_iterator<const int*> >();
59    test<random_access_iterator<const int*>, forward_iterator<const int*> >();
60    test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
61    test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
62    test<random_access_iterator<const int*>, const int*>();
63
64    test<const int*, input_iterator<const int*> >();
65    test<const int*, forward_iterator<const int*> >();
66    test<const int*, bidirectional_iterator<const int*> >();
67    test<const int*, random_access_iterator<const int*> >();
68    test<const int*, const int*>();
69}
70