Home | History | Annotate | Download | only in mismatch
      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 
     24 #if _LIBCPP_STD_VER > 11
     25 #define HAS_FOUR_ITERATOR_VERSION
     26 #endif
     27 
     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     assert(std::mismatch(input_iterator<const int*>(ia),
     35                          input_iterator<const int*>(ia + sa),
     36                          input_iterator<const int*>(ib),
     37                          std::equal_to<int>()) ==
     38                          (std::pair<input_iterator<const int*>,
     39                                     input_iterator<const int*> >(
     40                             input_iterator<const int*>(ia+3),
     41                             input_iterator<const int*>(ib+3))));
     42 #ifdef HAS_FOUR_ITERATOR_VERSION
     43     assert(std::mismatch(input_iterator<const int*>(ia),
     44                          input_iterator<const int*>(ia + sa),
     45                          input_iterator<const int*>(ib),
     46                          input_iterator<const int*>(ib + sa),
     47                          std::equal_to<int>()) ==
     48                          (std::pair<input_iterator<const int*>,
     49                                     input_iterator<const int*> >(
     50                             input_iterator<const int*>(ia+3),
     51                             input_iterator<const int*>(ib+3))));
     52 #endif
     53 
     54     assert(std::mismatch(ia, ia + sa, ib, std::equal_to<int>()) ==
     55            (std::pair<int*,int*>(ia+3,ib+3)));
     56 #ifdef HAS_FOUR_ITERATOR_VERSION
     57     assert(std::mismatch(ia, ia + sa, ib, ib + sa, std::equal_to<int>()) ==
     58            (std::pair<int*,int*>(ia+3,ib+3)));
     59     assert(std::mismatch(ia, ia + sa, ib, ib + 2, std::equal_to<int>()) ==
     60            (std::pair<int*,int*>(ia+2,ib+2)));
     61 #endif
     62 }
     63