mismatch.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___ALGORITHM_MISMATCH_H
  10. #define _LIBCPP___ALGORITHM_MISMATCH_H
  11. #include <__algorithm/comp.h>
  12. #include <__config>
  13. #include <__iterator/iterator_traits.h>
  14. #include <__utility/pair.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
  20. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  21. _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  22. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
  23. for (; __first1 != __last1; ++__first1, (void)++__first2)
  24. if (!__pred(*__first1, *__first2))
  25. break;
  26. return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
  27. }
  28. template <class _InputIterator1, class _InputIterator2>
  29. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  30. _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  31. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
  32. return std::mismatch(__first1, __last1, __first2, __equal_to());
  33. }
  34. #if _LIBCPP_STD_VER >= 14
  35. template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
  36. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  37. _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  38. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
  39. _BinaryPredicate __pred) {
  40. for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
  41. if (!__pred(*__first1, *__first2))
  42. break;
  43. return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
  44. }
  45. template <class _InputIterator1, class _InputIterator2>
  46. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  47. _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  48. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
  49. return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
  50. }
  51. #endif
  52. _LIBCPP_END_NAMESPACE_STD
  53. #endif // _LIBCPP___ALGORITHM_MISMATCH_H