xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/ranges_mismatch.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
1081ad6265SDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
1181ad6265SDimitry Andric 
1281ad6265SDimitry Andric #include <__algorithm/in_in_result.h>
13*0fca6ea1SDimitry Andric #include <__algorithm/mismatch.h>
14*0fca6ea1SDimitry Andric #include <__algorithm/unwrap_range.h>
1581ad6265SDimitry Andric #include <__config>
1681ad6265SDimitry Andric #include <__functional/identity.h>
1781ad6265SDimitry Andric #include <__functional/invoke.h>
1881ad6265SDimitry Andric #include <__functional/ranges_operations.h>
1981ad6265SDimitry Andric #include <__iterator/concepts.h>
2081ad6265SDimitry Andric #include <__iterator/indirectly_comparable.h>
2181ad6265SDimitry Andric #include <__ranges/access.h>
2281ad6265SDimitry Andric #include <__ranges/concepts.h>
2381ad6265SDimitry Andric #include <__ranges/dangling.h>
2481ad6265SDimitry Andric #include <__utility/move.h>
2581ad6265SDimitry Andric 
2681ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2781ad6265SDimitry Andric #  pragma GCC system_header
2881ad6265SDimitry Andric #endif
2981ad6265SDimitry Andric 
30b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
31b3edf446SDimitry Andric #include <__undef_macros>
32b3edf446SDimitry Andric 
3381ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
3481ad6265SDimitry Andric 
3506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
3681ad6265SDimitry Andric 
3781ad6265SDimitry Andric namespace ranges {
3881ad6265SDimitry Andric 
3981ad6265SDimitry Andric template <class _I1, class _I2>
4081ad6265SDimitry Andric using mismatch_result = in_in_result<_I1, _I2>;
4181ad6265SDimitry Andric 
4281ad6265SDimitry Andric namespace __mismatch {
4381ad6265SDimitry Andric struct __fn {
4406c3fb27SDimitry Andric   template <class _I1, class _S1, class _I2, class _S2, class _Pred, class _Proj1, class _Proj2>
4506c3fb27SDimitry Andric   static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2>
__go__fn4606c3fb27SDimitry Andric   __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
47*0fca6ea1SDimitry Andric     if constexpr (forward_iterator<_I1> && forward_iterator<_I2>) {
48*0fca6ea1SDimitry Andric       auto __range1 = std::__unwrap_range(__first1, __last1);
49*0fca6ea1SDimitry Andric       auto __range2 = std::__unwrap_range(__first2, __last2);
50*0fca6ea1SDimitry Andric       auto __res =
51*0fca6ea1SDimitry Andric           std::__mismatch(__range1.first, __range1.second, __range2.first, __range2.second, __pred, __proj1, __proj2);
52*0fca6ea1SDimitry Andric       return {std::__rewrap_range<_S1>(__first1, __res.first), std::__rewrap_range<_S2>(__first2, __res.second)};
53*0fca6ea1SDimitry Andric     } else {
54*0fca6ea1SDimitry Andric       auto __res = std::__mismatch(
55*0fca6ea1SDimitry Andric           std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);
56*0fca6ea1SDimitry Andric       return {std::move(__res.first), std::move(__res.second)};
5781ad6265SDimitry Andric     }
5881ad6265SDimitry Andric   }
5981ad6265SDimitry Andric 
6006c3fb27SDimitry Andric   template <input_iterator _I1,
6106c3fb27SDimitry Andric             sentinel_for<_I1> _S1,
6206c3fb27SDimitry Andric             input_iterator _I2,
6306c3fb27SDimitry Andric             sentinel_for<_I2> _S2,
6406c3fb27SDimitry Andric             class _Pred  = ranges::equal_to,
6506c3fb27SDimitry Andric             class _Proj1 = identity,
6606c3fb27SDimitry Andric             class _Proj2 = identity>
6781ad6265SDimitry Andric     requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2>
operator__fn68*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> operator()(
6906c3fb27SDimitry Andric       _I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {})
7006c3fb27SDimitry Andric       const {
7181ad6265SDimitry Andric     return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2);
7281ad6265SDimitry Andric   }
7381ad6265SDimitry Andric 
7406c3fb27SDimitry Andric   template <input_range _R1,
7506c3fb27SDimitry Andric             input_range _R2,
7606c3fb27SDimitry Andric             class _Pred  = ranges::equal_to,
7706c3fb27SDimitry Andric             class _Proj1 = identity,
7806c3fb27SDimitry Andric             class _Proj2 = identity>
7981ad6265SDimitry Andric     requires indirectly_comparable<iterator_t<_R1>, iterator_t<_R2>, _Pred, _Proj1, _Proj2>
80*0fca6ea1SDimitry Andric   [[nodiscard]]
81*0fca6ea1SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<borrowed_iterator_t<_R1>, borrowed_iterator_t<_R2>>
operator__fn8281ad6265SDimitry Andric   operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
8306c3fb27SDimitry Andric     return __go(
8406c3fb27SDimitry Andric         ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2);
8581ad6265SDimitry Andric   }
8681ad6265SDimitry Andric };
8781ad6265SDimitry Andric } // namespace __mismatch
8881ad6265SDimitry Andric 
8981ad6265SDimitry Andric inline namespace __cpo {
9081ad6265SDimitry Andric constexpr inline auto mismatch = __mismatch::__fn{};
9181ad6265SDimitry Andric } // namespace __cpo
9281ad6265SDimitry Andric } // namespace ranges
9381ad6265SDimitry Andric 
9406c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
9581ad6265SDimitry Andric 
9681ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
9781ad6265SDimitry Andric 
98b3edf446SDimitry Andric _LIBCPP_POP_MACROS
99b3edf446SDimitry Andric 
10081ad6265SDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_MISMATCH_H
101