File indexing completed on 2026-05-03 08:13:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
0010 #define _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
0011
0012 #include <__algorithm/in_in_result.h>
0013 #include <__algorithm/mismatch.h>
0014 #include <__algorithm/unwrap_range.h>
0015 #include <__config>
0016 #include <__functional/identity.h>
0017 #include <__functional/invoke.h>
0018 #include <__functional/ranges_operations.h>
0019 #include <__iterator/concepts.h>
0020 #include <__iterator/indirectly_comparable.h>
0021 #include <__ranges/access.h>
0022 #include <__ranges/concepts.h>
0023 #include <__ranges/dangling.h>
0024 #include <__utility/move.h>
0025
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 # pragma GCC system_header
0028 #endif
0029
0030 _LIBCPP_PUSH_MACROS
0031 #include <__undef_macros>
0032
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034
0035 #if _LIBCPP_STD_VER >= 20
0036
0037 namespace ranges {
0038
0039 template <class _I1, class _I2>
0040 using mismatch_result = in_in_result<_I1, _I2>;
0041
0042 struct __mismatch {
0043 template <class _I1, class _S1, class _I2, class _S2, class _Pred, class _Proj1, class _Proj2>
0044 static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2>
0045 __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
0046 if constexpr (forward_iterator<_I1> && forward_iterator<_I2>) {
0047 auto __range1 = std::__unwrap_range(__first1, __last1);
0048 auto __range2 = std::__unwrap_range(__first2, __last2);
0049 auto __res =
0050 std::__mismatch(__range1.first, __range1.second, __range2.first, __range2.second, __pred, __proj1, __proj2);
0051 return {std::__rewrap_range<_S1>(__first1, __res.first), std::__rewrap_range<_S2>(__first2, __res.second)};
0052 } else {
0053 auto __res = std::__mismatch(
0054 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
0055 return {std::move(__res.first), std::move(__res.second)};
0056 }
0057 }
0058
0059 template <input_iterator _I1,
0060 sentinel_for<_I1> _S1,
0061 input_iterator _I2,
0062 sentinel_for<_I2> _S2,
0063 class _Pred = ranges::equal_to,
0064 class _Proj1 = identity,
0065 class _Proj2 = identity>
0066 requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2>
0067 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> operator()(
0068 _I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
0069 const {
0070 return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2);
0071 }
0072
0073 template <input_range _R1,
0074 input_range _R2,
0075 class _Pred = ranges::equal_to,
0076 class _Proj1 = identity,
0077 class _Proj2 = identity>
0078 requires indirectly_comparable<iterator_t<_R1>, iterator_t<_R2>, _Pred, _Proj1, _Proj2>
0079 [[nodiscard]]
0080 _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<borrowed_iterator_t<_R1>, borrowed_iterator_t<_R2>>
0081 operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
0082 return __go(
0083 ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2);
0084 }
0085 };
0086
0087 inline namespace __cpo {
0088 constexpr inline auto mismatch = __mismatch{};
0089 }
0090 }
0091
0092 #endif
0093
0094 _LIBCPP_END_NAMESPACE_STD
0095
0096 _LIBCPP_POP_MACROS
0097
0098 #endif