diff options
Diffstat (limited to 'test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp')
-rw-r--r-- | test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp new file mode 100644 index 0000000000000..8d85d993cd612 --- /dev/null +++ b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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, +// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred> +// requires CopyConstructible<Pred> +// pair<Iter1, Iter2> +// mismatch(Iter1 first1, Iter1 last1, Iter2 first2, Pred pred); + +#include <algorithm> +#include <functional> +#include <cassert> + +#include "test_iterators.h" +#include "counting_predicates.hpp" + +#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; + typedef std::equal_to<int> EQ; + + assert(std::mismatch(II(ia), II(ia + sa), II(ib), EQ()) + == (std::pair<II, II>(II(ia+3), II(ib+3)))); + assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), EQ()) + == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); + + binary_counting_predicate<EQ, int> bcp((EQ())); + assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), std::ref(bcp)) + == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); + assert(bcp.count() > 0 && bcp.count() < sa); + bcp.reset(); + +#ifdef HAS_FOUR_ITERATOR_VERSION + assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), EQ()) + == (std::pair<II, II>(II(ia+3), II(ib+3)))); + assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib + sb), EQ()) + == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); + + assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib + sb), std::ref(bcp)) + == (std::pair<II, II>(II(ia+3), II(ib+3)))); + assert(bcp.count() > 0 && bcp.count() < std::min(sa, sb)); +#endif + + assert(std::mismatch(ia, ia + sa, ib, EQ()) == + (std::pair<int*,int*>(ia+3,ib+3))); + +#ifdef HAS_FOUR_ITERATOR_VERSION + assert(std::mismatch(ia, ia + sa, ib, ib + sb, EQ()) == + (std::pair<int*,int*>(ia+3,ib+3))); + assert(std::mismatch(ia, ia + sa, ib, ib + 2, EQ()) == + (std::pair<int*,int*>(ia+2,ib+2))); +#endif +} |