mismatch.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  21. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
  22. for (; __first1 != __last1; ++__first1, (void)++__first2)
  23. if (!__pred(*__first1, *__first2))
  24. break;
  25. return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
  26. }
  27. template <class _InputIterator1, class _InputIterator2>
  28. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  29. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
  30. return std::mismatch(__first1, __last1, __first2, __equal_to());
  31. }
  32. #if _LIBCPP_STD_VER >= 14
  33. template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
  34. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  35. mismatch(_InputIterator1 __first1,
  36. _InputIterator1 __last1,
  37. _InputIterator2 __first2,
  38. _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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
  47. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
  48. return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
  49. }
  50. #endif
  51. _LIBCPP_END_NAMESPACE_STD
  52. #endif // _LIBCPP___ALGORITHM_MISMATCH_H