algorithm (2203B)
1 // -*- c++ -*- 2 #pragma once 3 4 #include <xmemory> 5 6 #pragma push_macro("_Ty") 7 #define _Ty(x) constexpr _Ty(x) 8 #pragma push_macro("_Ty") 9 #define _Ty(x) _Ty(x) _Pragma("pop_macro(\"_Ty\")") 10 11 12 #pragma push_macro("max_element") 13 #define max_element constexpr max_element _Pragma("pop_macro(\"max_element\")") 14 #pragma push_macro("max_element") 15 #define max_element constexpr max_element _Pragma("pop_macro(\"max_element\")") 16 17 #pragma push_macro("min_element") 18 #define min_element constexpr min_element _Pragma("pop_macro(\"min_element\")") 19 #pragma push_macro("min_element") 20 #define min_element constexpr min_element _Pragma("pop_macro(\"min_element\")") 21 22 23 #pragma push_macro("_Max_element") 24 #define _Max_element constexpr _Max_element _Pragma("pop_macro(\"_Max_element\")") 25 #pragma push_macro("_Min_element") 26 #define _Min_element constexpr _Min_element _Pragma("pop_macro(\"_Min_element\")") 27 28 // min/max 29 #pragma push_macro("_Post_equal_to_") 30 #define _Post_equal_to_(x) constexpr 31 32 #include_next <algorithm> 33 34 #pragma pop_macro("_Post_equal_to_") 35 #pragma pop_macro("_Ty") 36 37 namespace std 38 { 39 40 template <typename InputIt1, typename InputIt2> 41 inline bool equal( 42 InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) 43 { 44 return equal(first1, last1, first2, last2, std::equal_to<>{}); 45 } 46 47 template <typename InputIt1, typename InputIt2, typename BinaryPredicate> 48 inline bool equal( 49 InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, 50 BinaryPredicate p) 51 { 52 if constexpr(std::is_same_v< 53 std::random_access_iterator_tag, 54 typename std::iterator_traits<InputIt1>::iterator_category> && 55 std::is_same_v< 56 std::random_access_iterator_tag, 57 typename std::iterator_traits<InputIt2>::iterator_category>) 58 { 59 if (last1 - first1 != last2 - first2) return false; 60 for (; first1 != last1; ++first1, ++first2) 61 if (!p(*first1, *first2)) return false; 62 63 return true; 64 } 65 else 66 { 67 for (; first1 != last1 && first2 != last2; ++first1, ++first2) 68 if (!p(*first1, *first2)) return false; 69 70 return first1 == last1 && first2 == last2; 71 } 72 } 73 74 }