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<ForwardIterator Iter1, ForwardIterator Iter2>
13 // requires HasEqualTo<Iter1::value_type, Iter2::value_type>
14 // Iter1
15 // find_end(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
16
17 #include <algorithm>
18 #include <cassert>
19
20 #include "test_iterators.h"
21
22 template <class Iter1, class Iter2>
23 void
test()24 test()
25 {
26 int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
27 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
28 int b[] = {0};
29 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b+1)) == Iter1(ia+sa-1));
30 int c[] = {0, 1};
31 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(c), Iter2(c+2)) == Iter1(ia+18));
32 int d[] = {0, 1, 2};
33 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(d), Iter2(d+3)) == Iter1(ia+15));
34 int e[] = {0, 1, 2, 3};
35 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(e), Iter2(e+4)) == Iter1(ia+11));
36 int f[] = {0, 1, 2, 3, 4};
37 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(f), Iter2(f+5)) == Iter1(ia+6));
38 int g[] = {0, 1, 2, 3, 4, 5};
39 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(g), Iter2(g+6)) == Iter1(ia));
40 int h[] = {0, 1, 2, 3, 4, 5, 6};
41 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(h), Iter2(h+7)) == Iter1(ia+sa));
42 assert(std::find_end(Iter1(ia), Iter1(ia+sa), Iter2(b), Iter2(b)) == Iter1(ia+sa));
43 assert(std::find_end(Iter1(ia), Iter1(ia), Iter2(b), Iter2(b+1)) == Iter1(ia));
44 }
45
main()46 int main()
47 {
48 test<forward_iterator<const int*>, forward_iterator<const int*> >();
49 test<forward_iterator<const int*>, bidirectional_iterator<const int*> >();
50 test<forward_iterator<const int*>, random_access_iterator<const int*> >();
51 test<bidirectional_iterator<const int*>, forward_iterator<const int*> >();
52 test<bidirectional_iterator<const int*>, bidirectional_iterator<const int*> >();
53 test<bidirectional_iterator<const int*>, random_access_iterator<const int*> >();
54 test<random_access_iterator<const int*>, forward_iterator<const int*> >();
55 test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
56 test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
57 }
58