xref: /llvm-project/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp (revision c57d98ae86ae0f6ac6fe14048610344220c361c1)
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 //   requires HasEqualTo<Iter1::value_type, Iter2::value_type>
14 //   pair<Iter1, Iter2>
15 //   mismatch(Iter1 first1, Iter1 last1, Iter2 first2);
16 
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_iterators.h"
21 
22 #if _LIBCPP_STD_VER > 11
23 #define HAS_FOUR_ITERATOR_VERSION
24 #endif
25 
26 int main()
27 {
28     int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
29     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
30     int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
31     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
32 
33     typedef input_iterator<const int*> II;
34     typedef random_access_iterator<const int*>  RAI;
35 
36     assert(std::mismatch(II(ia), II(ia + sa), II(ib))
37             == (std::pair<II, II>(II(ia+3), II(ib+3))));
38 
39     assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib))
40             == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
41 
42 #ifdef HAS_FOUR_ITERATOR_VERSION
43     assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb))
44             == (std::pair<II, II>(II(ia+3), II(ib+3))));
45 
46     assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb))
47             == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));
48 
49 
50     assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
51             == (std::pair<II, II>(II(ia+2), II(ib+2))));
52 #endif
53 }
54