mismatch.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_iterators.h"
  17. #if _LIBCPP_STD_VER > 11
  18. #define HAS_FOUR_ITERATOR_VERSION
  19. #endif
  20. int main()
  21. {
  22. int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
  23. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  24. int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
  25. const unsigned sb = sizeof(ib)/sizeof(ib[0]);
  26. typedef input_iterator<const int*> II;
  27. typedef random_access_iterator<const int*> RAI;
  28. assert(std::mismatch(II(ia), II(ia + sa), II(ib))
  29. == (std::pair<II, II>(II(ia+3), II(ib+3))));
  30. assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib))
  31. == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
  32. #ifdef HAS_FOUR_ITERATOR_VERSION
  33. assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb))
  34. == (std::pair<II, II>(II(ia+3), II(ib+3))));
  35. assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb))
  36. == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
  37. assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
  38. == (std::pair<II, II>(II(ia+2), II(ib+2))));
  39. #endif
  40. }