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 // Predicate<auto, Iter1::value_type, Iter2::value_type> Pred> 14 // requires CopyConstructible<Pred> 15 // pair<Iter1, Iter2> 16 // mismatch(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred); 17 18 #include <algorithm> 19 #include <functional> 20 #include <cassert> 21 22 #include "test_iterators.h" 23 #include "counting_predicates.hpp" 24 25 #if _LIBCPP_STD_VER > 11 26 #define HAS_FOUR_ITERATOR_VERSION 27 #endif 28 29 int main() 30 { 31 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3}; 32 const unsigned sa = sizeof(ia)/sizeof(ia[0]); 33 int ib[] = {0, 1, 2, 3, 0, 1, 2, 3}; 34 const unsigned sb = sizeof(ib)/sizeof(ib[0]); 35 36 typedef input_iterator<const int*> II; 37 typedef random_access_iterator<const int*> RAI; 38 typedef std::equal_to<int> EQ; 39 40 assert(std::mismatch(II(ia), II(ia + sa), II(ib), EQ()) 41 == (std::pair<II, II>(II(ia+3), II(ib+3)))); 42 assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), EQ()) 43 == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); 44 45 binary_counting_predicate<EQ, int> bcp((EQ())); 46 assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), std::ref(bcp)) 47 == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); 48 assert(bcp.count() > 0 && bcp.count() < sa); 49 bcp.reset(); 50 51 #ifdef HAS_FOUR_ITERATOR_VERSION 52 assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), EQ()) 53 == (std::pair<II, II>(II(ia+3), II(ib+3)))); 54 assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib + sb), EQ()) 55 == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); 56 57 assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), std::ref(bcp)) 58 == (std::pair<II, II>(II(ia+3), II(ib+3)))); 59 assert(bcp.count() > 0 && bcp.count() < std::min(sa, sb)); 60 #endif 61 62 assert(std::mismatch(ia, ia + sa, ib, EQ()) == 63 (std::pair<int*,int*>(ia+3,ib+3))); 64 65 #ifdef HAS_FOUR_ITERATOR_VERSION 66 assert(std::mismatch(ia, ia + sa, ib, ib + sb, EQ()) == 67 (std::pair<int*,int*>(ia+3,ib+3))); 68 assert(std::mismatch(ia, ia + sa, ib, ib + 2, EQ()) == 69 (std::pair<int*,int*>(ia+2,ib+2))); 70 #endif 71 } 72