| 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_ANY_OF_H |
| 11 | #define _LIBCPP___ALGORITHM_ANY_OF_H |
| 12 | |
| 13 | #include <__config> |
| 14 | #include <__functional/identity.h> |
| 15 | #include <__type_traits/invoke.h> |
| 16 | |
| 17 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 18 | # pragma GCC system_header |
| 19 | #endif |
| 20 | |
| 21 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 22 | |
| 23 | template <class _Iter, class _Sent, class _Proj, class _Pred> |
| 24 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool |
| 25 | __any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { |
| 26 | for (; __first != __last; ++__first) { |
| 27 | if (std::__invoke(__pred, std::__invoke(__proj, *__first))) |
| 28 | return true; |
| 29 | } |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | template <class _InputIterator, class _Predicate> |
| 34 | [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool |
| 35 | any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { |
| 36 | __identity __proj; |
| 37 | return std::__any_of(__first, __last, __pred, __proj); |
| 38 | } |
| 39 | |
| 40 | _LIBCPP_END_NAMESPACE_STD |
| 41 | |
| 42 | #endif // _LIBCPP___ALGORITHM_ANY_OF_H |
| 43 | |