61 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___ALGORITHM_ADJACENT_FIND_H11#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H12 13#include <__algorithm/comp.h>14#include <__config>15#include <__functional/identity.h>16#include <__type_traits/invoke.h>17#include <__utility/move.h>18 19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)20# pragma GCC system_header21#endif22 23_LIBCPP_PUSH_MACROS24#include <__undef_macros>25 26_LIBCPP_BEGIN_NAMESPACE_STD27 28template <class _Iter, class _Sent, class _Pred, class _Proj>29[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter30__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {31 if (__first == __last)32 return __first;33 34 _Iter __i = __first;35 while (++__i != __last) {36 if (std::__invoke(__pred, std::__invoke(__proj, *__first), std::__invoke(__proj, *__i)))37 return __first;38 __first = __i;39 }40 return __i;41}42 43template <class _ForwardIterator, class _BinaryPredicate>44[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator45adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {46 __identity __proj;47 return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj);48}49 50template <class _ForwardIterator>51[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator52adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {53 return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());54}55 56_LIBCPP_END_NAMESPACE_STD57 58_LIBCPP_POP_MACROS59 60#endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H61