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_ADJACENT_FIND_H
11 #define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
12 
13 #include <__algorithm/comp.h>
14 #include <__algorithm/iterator_operations.h>
15 #include <__config>
16 #include <__iterator/iterator_traits.h>
17 #include <__utility/move.h>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 template <class _Iter, class _Sent, class _BinaryPredicate>
26 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Iter
27 __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
28   if (__first == __last)
29     return __first;
30   _Iter __i = __first;
31   while (++__i != __last) {
32     if (__pred(*__first, *__i))
33       return __first;
34     __first = __i;
35   }
36   return __i;
37 }
38 
39 template <class _ForwardIterator, class _BinaryPredicate>
40 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
41 adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
42   return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
43 }
44 
45 template <class _ForwardIterator>
46 _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
47 adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
48   typedef typename iterator_traits<_ForwardIterator>::value_type __v;
49   return std::adjacent_find(std::move(__first), std::move(__last), __equal_to<__v>());
50 }
51 
52 _LIBCPP_END_NAMESPACE_STD
53 
54 #endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H
55