find_end.pass.cpp 2.5 KB

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