xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/mismatch.h (revision ec0ea6efa1ad229d75c394c1a9b9cac33af2b1d3)
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 
10 #ifndef _LIBCPP___ALGORITHM_MISMATCH_H
11 #define _LIBCPP___ALGORITHM_MISMATCH_H
12 
13 #include <__config>
14 #include <__algorithm/comp.h>
15 #include <__iterator/iterator_traits.h>
16 #include <utility>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #pragma GCC system_header
20 #endif
21 
22 _LIBCPP_PUSH_MACROS
23 #include <__undef_macros>
24 
25 _LIBCPP_BEGIN_NAMESPACE_STD
26 
27 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
28 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
29     _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
30     mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
31   for (; __first1 != __last1; ++__first1, (void)++__first2)
32     if (!__pred(*__first1, *__first2))
33       break;
34   return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
35 }
36 
37 template <class _InputIterator1, class _InputIterator2>
38 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
39     _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
40     mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
41   typedef typename iterator_traits<_InputIterator1>::value_type __v1;
42   typedef typename iterator_traits<_InputIterator2>::value_type __v2;
43   return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
44 }
45 
46 #if _LIBCPP_STD_VER > 11
47 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
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              _BinaryPredicate __pred) {
52   for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
53     if (!__pred(*__first1, *__first2))
54       break;
55   return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
56 }
57 
58 template <class _InputIterator1, class _InputIterator2>
59 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY
60     _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2>
61     mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
62   typedef typename iterator_traits<_InputIterator1>::value_type __v1;
63   typedef typename iterator_traits<_InputIterator2>::value_type __v2;
64   return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
65 }
66 #endif
67 
68 _LIBCPP_END_NAMESPACE_STD
69 
70 _LIBCPP_POP_MACROS
71 
72 #endif // _LIBCPP___ALGORITHM_MISMATCH_H
73