summaryrefslogtreecommitdiffstats
path: root/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
blob: 0cf06bbfba75ea38e376a2a1de5adb84529cf5c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <algorithm>

// template<InputIterator Iter1, InputIterator Iter2>
//   requires HasEqualTo<Iter1::value_type, Iter2::value_type>
//   pair<Iter1, Iter2>
//   mismatch(Iter1 first1, Iter1 last1, Iter2 first2);

#include <algorithm>
#include <cassert>

#include "test_iterators.h"

#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif

int main()
{
    int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
    const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
    const unsigned sb = sizeof(ib)/sizeof(ib[0]);

	typedef input_iterator<const int*> II;
	typedef random_access_iterator<const int*>  RAI;

    assert(std::mismatch(II(ia), II(ia + sa), II(ib))
    		== (std::pair<II, II>(II(ia+3), II(ib+3))));

    assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib))
    		== (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));

#ifdef HAS_FOUR_ITERATOR_VERSION
    assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb))
    		== (std::pair<II, II>(II(ia+3), II(ib+3))));

    assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb))
    		== (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3))));


    assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2))
    		== (std::pair<II, II>(II(ia+2), II(ib+2))));
#endif
}
OpenPOWER on IntegriCloud