brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · b35747d Raw
99 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_RANGES_MISMATCH_H10#define _LIBCPP___ALGORITHM_RANGES_MISMATCH_H11 12#include <__algorithm/in_in_result.h>13#include <__algorithm/mismatch.h>14#include <__algorithm/unwrap_range.h>15#include <__config>16#include <__functional/identity.h>17#include <__functional/invoke.h>18#include <__functional/ranges_operations.h>19#include <__iterator/concepts.h>20#include <__iterator/indirectly_comparable.h>21#include <__ranges/access.h>22#include <__ranges/concepts.h>23#include <__ranges/dangling.h>24#include <__utility/move.h>25 26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)27#  pragma GCC system_header28#endif29 30_LIBCPP_PUSH_MACROS31#include <__undef_macros>32 33_LIBCPP_BEGIN_NAMESPACE_STD34 35#if _LIBCPP_STD_VER >= 2036 37namespace ranges {38 39template <class _I1, class _I2>40using mismatch_result = in_in_result<_I1, _I2>;41 42struct __mismatch {43  template <class _I1, class _S1, class _I2, class _S2, class _Pred, class _Proj1, class _Proj2>44  static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2>45  __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {46    if constexpr (forward_iterator<_I1> && forward_iterator<_I2>) {47      auto __range1 = std::__unwrap_range(__first1, __last1);48      auto __range2 = std::__unwrap_range(__first2, __last2);49      auto __res =50          std::__mismatch(__range1.first, __range1.second, __range2.first, __range2.second, __pred, __proj1, __proj2);51      return {std::__rewrap_range<_S1>(__first1, __res.first), std::__rewrap_range<_S2>(__first2, __res.second)};52    } else {53      auto __res = std::__mismatch(54          std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __pred, __proj1, __proj2);55      return {std::move(__res.first), std::move(__res.second)};56    }57  }58 59  template <input_iterator _I1,60            sentinel_for<_I1> _S1,61            input_iterator _I2,62            sentinel_for<_I2> _S2,63            class _Pred  = ranges::equal_to,64            class _Proj1 = identity,65            class _Proj2 = identity>66    requires indirectly_comparable<_I1, _I2, _Pred, _Proj1, _Proj2>67  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> operator()(68      _I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {})69      const {70    return __go(std::move(__first1), __last1, std::move(__first2), __last2, __pred, __proj1, __proj2);71  }72 73  template <input_range _R1,74            input_range _R2,75            class _Pred  = ranges::equal_to,76            class _Proj1 = identity,77            class _Proj2 = identity>78    requires indirectly_comparable<iterator_t<_R1>, iterator_t<_R2>, _Pred, _Proj1, _Proj2>79  [[nodiscard]]80  _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<borrowed_iterator_t<_R1>, borrowed_iterator_t<_R2>>81  operator()(_R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {82    return __go(83        ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2);84  }85};86 87inline namespace __cpo {88constexpr inline auto mismatch = __mismatch{};89} // namespace __cpo90} // namespace ranges91 92#endif // _LIBCPP_STD_VER >= 2093 94_LIBCPP_END_NAMESPACE_STD95 96_LIBCPP_POP_MACROS97 98#endif // _LIBCPP___ALGORITHM_RANGES_MISMATCH_H99