1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H 10 #define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H 11 12 #include <__config> 13 #include <__functional/identity.h> 14 #include <__functional/invoke.h> 15 #include <__iterator/concepts.h> 16 #include <__iterator/projected.h> 17 #include <__ranges/access.h> 18 #include <__ranges/concepts.h> 19 #include <__utility/move.h> 20 21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 22 # pragma GCC system_header 23 #endif 24 25 _LIBCPP_PUSH_MACROS 26 #include <__undef_macros> 27 28 #if _LIBCPP_STD_VER >= 20 29 30 _LIBCPP_BEGIN_NAMESPACE_STD 31 32 namespace ranges { 33 struct __all_of { 34 template <class _Iter, class _Sent, class _Proj, class _Pred> 35 _LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { 36 for (; __first != __last; ++__first) { 37 if (!std::invoke(__pred, std::invoke(__proj, *__first))) 38 return false; 39 } 40 return true; 41 } 42 43 template <input_iterator _Iter, 44 sentinel_for<_Iter> _Sent, 45 class _Proj = identity, 46 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred> 47 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool 48 operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { 49 return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj); 50 } 51 52 template <input_range _Range, 53 class _Proj = identity, 54 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred> 55 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool 56 operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { 57 return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); 58 } 59 }; 60 61 inline namespace __cpo { 62 inline constexpr auto all_of = __all_of{}; 63 } // namespace __cpo 64 } // namespace ranges 65 66 _LIBCPP_END_NAMESPACE_STD 67 68 #endif // _LIBCPP_STD_VER >= 20 69 70 _LIBCPP_POP_MACROS 71 72 #endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H 73