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 // constexpr bool // constexpr after c++17 15 // equal(Iter1 first1, Iter1 last1, Iter2 first2); 16 // 17 // Introduced in C++14: 18 // template<InputIterator Iter1, InputIterator Iter2> 19 // constexpr bool // constexpr after c++17 20 // equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2); 21 22 #include <algorithm> 23 #include <cassert> 24 25 #include "test_macros.h" 26 #include "test_iterators.h" 27 28 #if TEST_STD_VER > 17 29 TEST_CONSTEXPR bool test_constexpr() { 30 int ia[] = {1, 3, 6, 7}; 31 int ib[] = {1, 3}; 32 int ic[] = {1, 3, 5, 7}; 33 typedef input_iterator<int*> II; 34 typedef bidirectional_iterator<int*> BI; 35 36 return !std::equal(std::begin(ia), std::end(ia), std::begin(ic)) 37 && !std::equal(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic)) 38 && std::equal(std::begin(ib), std::end(ib), std::begin(ic)) 39 && !std::equal(std::begin(ib), std::end(ib), std::begin(ic), std::end(ic)) 40 41 && std::equal(II(std::begin(ib)), II(std::end(ib)), II(std::begin(ic))) 42 && !std::equal(BI(std::begin(ib)), BI(std::end(ib)), BI(std::begin(ic)), BI(std::end(ic))) 43 ; 44 } 45 #endif 46 47 48 int main() 49 { 50 int ia[] = {0, 1, 2, 3, 4, 5}; 51 const unsigned s = sizeof(ia)/sizeof(ia[0]); 52 int ib[s] = {0, 1, 2, 5, 4, 5}; 53 assert(std::equal(input_iterator<const int*>(ia), 54 input_iterator<const int*>(ia+s), 55 input_iterator<const int*>(ia))); 56 #if TEST_STD_VER >= 14 57 assert(std::equal(input_iterator<const int*>(ia), 58 input_iterator<const int*>(ia+s), 59 input_iterator<const int*>(ia), 60 input_iterator<const int*>(ia+s))); 61 assert(std::equal(random_access_iterator<const int*>(ia), 62 random_access_iterator<const int*>(ia+s), 63 random_access_iterator<const int*>(ia), 64 random_access_iterator<const int*>(ia+s))); 65 #endif 66 assert(!std::equal(input_iterator<const int*>(ia), 67 input_iterator<const int*>(ia+s), 68 input_iterator<const int*>(ib))); 69 #if TEST_STD_VER >= 14 70 assert(!std::equal(input_iterator<const int*>(ia), 71 input_iterator<const int*>(ia+s), 72 input_iterator<const int*>(ib), 73 input_iterator<const int*>(ib+s))); 74 assert(!std::equal(random_access_iterator<const int*>(ia), 75 random_access_iterator<const int*>(ia+s), 76 random_access_iterator<const int*>(ib), 77 random_access_iterator<const int*>(ib+s))); 78 assert(!std::equal(input_iterator<const int*>(ia), 79 input_iterator<const int*>(ia+s), 80 input_iterator<const int*>(ia), 81 input_iterator<const int*>(ia+s-1))); 82 assert(!std::equal(random_access_iterator<const int*>(ia), 83 random_access_iterator<const int*>(ia+s), 84 random_access_iterator<const int*>(ia), 85 random_access_iterator<const int*>(ia+s-1))); 86 87 #endif 88 89 #if TEST_STD_VER > 17 90 static_assert(test_constexpr()); 91 #endif 92 } 93