mismatch.pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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<InputIterator Iter1, InputIterator Iter2>
  11. // requires HasEqualTo<Iter1::value_type, Iter2::value_type>
  12. // pair<Iter1, Iter2>
  13. // mismatch(Iter1 first1, Iter1 last1, Iter2 first2);
  14. #include <algorithm>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_iterators.h"
  18. int main()
  19. {
  20. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  21. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  22. int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
  23. const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in C++11
  24. typedef input_iterator<const int*> II;
  25. typedef random_access_iterator<const int*> RAI;
  26. assert(std::mismatch(II(ia), II(ia + sa), II(ib))
  27. == (std::pair<II, II>(II(ia+3), II(ib+3))));
  28. assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib))
  29. == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
  30. #if TEST_STD_VER > 11 // We have the four iteration version
  31. assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb))
  32. == (std::pair<II, II>(II(ia+3), II(ib+3))));
  33. assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb))
  34. == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
  35. assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
  36. == (std::pair<II, II>(II(ia+2), II(ib+2))));
  37. #endif
  38. }