xref: /freebsd-src/contrib/llvm-project/libcxx/include/__algorithm/ranges_all_of.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
1081ad6265SDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
1181ad6265SDimitry Andric 
1281ad6265SDimitry Andric #include <__config>
1381ad6265SDimitry Andric #include <__functional/identity.h>
1481ad6265SDimitry Andric #include <__functional/invoke.h>
1581ad6265SDimitry Andric #include <__iterator/concepts.h>
1681ad6265SDimitry Andric #include <__iterator/projected.h>
1781ad6265SDimitry Andric #include <__ranges/access.h>
1881ad6265SDimitry Andric #include <__ranges/concepts.h>
1981ad6265SDimitry Andric #include <__utility/move.h>
2081ad6265SDimitry Andric 
2181ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2281ad6265SDimitry Andric #  pragma GCC system_header
2381ad6265SDimitry Andric #endif
2481ad6265SDimitry Andric 
25b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
26b3edf446SDimitry Andric #include <__undef_macros>
27b3edf446SDimitry Andric 
2806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
2981ad6265SDimitry Andric 
3081ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
3181ad6265SDimitry Andric 
3281ad6265SDimitry Andric namespace ranges {
3381ad6265SDimitry Andric namespace __all_of {
3481ad6265SDimitry Andric struct __fn {
3581ad6265SDimitry Andric   template <class _Iter, class _Sent, class _Proj, class _Pred>
3606c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
3781ad6265SDimitry Andric     for (; __first != __last; ++__first) {
3881ad6265SDimitry Andric       if (!std::invoke(__pred, std::invoke(__proj, *__first)))
3981ad6265SDimitry Andric         return false;
4081ad6265SDimitry Andric     }
4181ad6265SDimitry Andric     return true;
4281ad6265SDimitry Andric   }
4381ad6265SDimitry Andric 
4406c3fb27SDimitry Andric   template <input_iterator _Iter,
4506c3fb27SDimitry Andric             sentinel_for<_Iter> _Sent,
4606c3fb27SDimitry Andric             class _Proj = identity,
4781ad6265SDimitry Andric             indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
48*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
4906c3fb27SDimitry Andric   operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
5081ad6265SDimitry Andric     return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj);
5181ad6265SDimitry Andric   }
5281ad6265SDimitry Andric 
5306c3fb27SDimitry Andric   template <input_range _Range,
5406c3fb27SDimitry Andric             class _Proj = identity,
5581ad6265SDimitry Andric             indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
56*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
5706c3fb27SDimitry Andric   operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
5881ad6265SDimitry Andric     return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5981ad6265SDimitry Andric   }
6081ad6265SDimitry Andric };
6181ad6265SDimitry Andric } // namespace __all_of
6281ad6265SDimitry Andric 
6381ad6265SDimitry Andric inline namespace __cpo {
6481ad6265SDimitry Andric inline constexpr auto all_of = __all_of::__fn{};
6581ad6265SDimitry Andric } // namespace __cpo
6681ad6265SDimitry Andric } // namespace ranges
6781ad6265SDimitry Andric 
6881ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
6981ad6265SDimitry Andric 
7006c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
7181ad6265SDimitry Andric 
72b3edf446SDimitry Andric _LIBCPP_POP_MACROS
73b3edf446SDimitry Andric 
7481ad6265SDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
75