1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <algorithm> 10 11 // template<InputIterator Iter1, InputIterator Iter2> 12 // requires HasEqualTo<Iter1::value_type, Iter2::value_type> 13 // constexpr pair<Iter1, Iter2> // constexpr after c++17 14 // mismatch(Iter1 first1, Iter1 last1, Iter2 first2); 15 // 16 // template<InputIterator Iter1, InputIterator Iter2Pred> 17 // constexpr pair<Iter1, Iter2> // constexpr after c++17 18 // mismatch(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2); // C++14 19 20 #include <algorithm> 21 #include <cassert> 22 23 #include "test_macros.h" 24 #include "test_iterators.h" 25 26 #if TEST_STD_VER > 17 27 TEST_CONSTEXPR bool test_constexpr() { 28 int ia[] = {1, 3, 6, 7}; 29 int ib[] = {1, 3}; 30 int ic[] = {1, 3, 5, 7}; 31 typedef cpp17_input_iterator<int*> II; 32 typedef bidirectional_iterator<int*> BI; 33 34 auto p1 = std::mismatch(std::begin(ia), std::end(ia), std::begin(ic)); 35 if (p1.first != ia+2 || p1.second != ic+2) 36 return false; 37 38 auto p2 = std::mismatch(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic)); 39 if (p2.first != ia+2 || p2.second != ic+2) 40 return false; 41 42 auto p3 = std::mismatch(std::begin(ib), std::end(ib), std::begin(ic)); 43 if (p3.first != ib+2 || p3.second != ic+2) 44 return false; 45 46 auto p4 = std::mismatch(std::begin(ib), std::end(ib), std::begin(ic), std::end(ic)); 47 if (p4.first != ib+2 || p4.second != ic+2) 48 return false; 49 50 auto p5 = std::mismatch(II(std::begin(ib)), II(std::end(ib)), II(std::begin(ic))); 51 if (p5.first != II(ib+2) || p5.second != II(ic+2)) 52 return false; 53 auto p6 = std::mismatch(BI(std::begin(ib)), BI(std::end(ib)), BI(std::begin(ic)), BI(std::end(ic))); 54 if (p6.first != BI(ib+2) || p6.second != BI(ic+2)) 55 return false; 56 57 return true; 58 } 59 #endif 60 61 int main(int, char**) 62 { 63 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3}; 64 const unsigned sa = sizeof(ia)/sizeof(ia[0]); 65 int ib[] = {0, 1, 2, 3, 0, 1, 2, 3}; 66 const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in C++11 67 68 typedef cpp17_input_iterator<const int*> II; 69 typedef random_access_iterator<const int*> RAI; 70 71 assert(std::mismatch(II(ia), II(ia + sa), II(ib)) 72 == (std::pair<II, II>(II(ia+3), II(ib+3)))); 73 74 assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib)) 75 == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); 76 77 #if TEST_STD_VER > 11 // We have the four iteration version 78 assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+sb)) 79 == (std::pair<II, II>(II(ia+3), II(ib+3)))); 80 81 assert(std::mismatch(RAI(ia), RAI(ia + sa), RAI(ib), RAI(ib+sb)) 82 == (std::pair<RAI, RAI>(RAI(ia+3), RAI(ib+3)))); 83 84 85 assert(std::mismatch(II(ia), II(ia + sa), II(ib), II(ib+2)) 86 == (std::pair<II, II>(II(ia+2), II(ib+2)))); 87 #endif 88 89 #if TEST_STD_VER > 17 90 static_assert(test_constexpr()); 91 #endif 92 93 return 0; 94 } 95