Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:19

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_COUNT_IF_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_COUNT_IF_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__functional/identity.h>
0014 #include <__cxx03/__functional/invoke.h>
0015 #include <__cxx03/__functional/ranges_operations.h>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/incrementable_traits.h>
0018 #include <__cxx03/__iterator/iterator_traits.h>
0019 #include <__cxx03/__iterator/projected.h>
0020 #include <__cxx03/__ranges/access.h>
0021 #include <__cxx03/__ranges/concepts.h>
0022 #include <__cxx03/__utility/move.h>
0023 
0024 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0025 #  pragma GCC system_header
0026 #endif
0027 
0028 _LIBCPP_PUSH_MACROS
0029 #include <__cxx03/__undef_macros>
0030 
0031 #if _LIBCPP_STD_VER >= 20
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034 
0035 namespace ranges {
0036 template <class _Iter, class _Sent, class _Proj, class _Pred>
0037 _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
0038 __count_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
0039   iter_difference_t<_Iter> __counter(0);
0040   for (; __first != __last; ++__first) {
0041     if (std::invoke(__pred, std::invoke(__proj, *__first)))
0042       ++__counter;
0043   }
0044   return __counter;
0045 }
0046 
0047 namespace __count_if {
0048 struct __fn {
0049   template <input_iterator _Iter,
0050             sentinel_for<_Iter> _Sent,
0051             class _Proj = identity,
0052             indirect_unary_predicate<projected<_Iter, _Proj>> _Predicate>
0053   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
0054   operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const {
0055     return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
0056   }
0057 
0058   template <input_range _Range,
0059             class _Proj = identity,
0060             indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Predicate>
0061   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range>
0062   operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const {
0063     return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
0064   }
0065 };
0066 } // namespace __count_if
0067 
0068 inline namespace __cpo {
0069 inline constexpr auto count_if = __count_if::__fn{};
0070 } // namespace __cpo
0071 } // namespace ranges
0072 
0073 _LIBCPP_END_NAMESPACE_STD
0074 
0075 #endif // _LIBCPP_STD_VER >= 20
0076 
0077 _LIBCPP_POP_MACROS
0078 
0079 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_COUNT_IF_H