mismatch.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_AFTER_CXX17 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_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
  31. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
  32. typedef typename iterator_traits<_InputIterator1>::value_type __v1;
  33. typedef typename iterator_traits<_InputIterator2>::value_type __v2;
  34. return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
  35. }
  36. #if _LIBCPP_STD_VER > 11
  37. template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
  38. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  39. _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
  40. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
  41. _BinaryPredicate __pred) {
  42. for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
  43. if (!__pred(*__first1, *__first2))
  44. break;
  45. return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
  46. }
  47. template <class _InputIterator1, class _InputIterator2>
  48. _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
  49. _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
  50. mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
  51. typedef typename iterator_traits<_InputIterator1>::value_type __v1;
  52. typedef typename iterator_traits<_InputIterator2>::value_type __v2;
  53. return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
  54. }
  55. #endif
  56. _LIBCPP_END_NAMESPACE_STD
  57. #endif // _LIBCPP___ALGORITHM_MISMATCH_H