Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 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_COUNT_H |
| 10 | #define _LIBCPP___ALGORITHM_RANGES_COUNT_H |
| 11 | |
| 12 | #include <__algorithm/ranges_count_if.h> |
| 13 | #include <__config> |
| 14 | #include <__functional/identity.h> |
| 15 | #include <__functional/ranges_operations.h> |
| 16 | #include <__iterator/concepts.h> |
| 17 | #include <__iterator/incrementable_traits.h> |
| 18 | #include <__iterator/iterator_traits.h> |
| 19 | #include <__iterator/projected.h> |
| 20 | #include <__ranges/access.h> |
| 21 | #include <__ranges/concepts.h> |
| 22 | #include <__utility/move.h> |
| 23 | |
| 24 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 25 | # pragma GCC system_header |
| 26 | #endif |
| 27 | |
Kaido Kert | 56d7c4e | 2024-04-13 12:59:27 -0700 | [diff] [blame] | 28 | #if _LIBCPP_STD_VER >= 20 |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 29 | |
| 30 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 31 | |
| 32 | namespace ranges { |
| 33 | namespace __count { |
| 34 | struct __fn { |
| 35 | template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity> |
| 36 | requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*> |
| 37 | _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr |
| 38 | iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const { |
| 39 | auto __pred = [&](auto&& __e) { return __e == __value; }; |
| 40 | return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj); |
| 41 | } |
| 42 | |
| 43 | template <input_range _Range, class _Type, class _Proj = identity> |
| 44 | requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*> |
| 45 | _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr |
| 46 | range_difference_t<_Range> operator()(_Range&& __r, const _Type& __value, _Proj __proj = {}) const { |
| 47 | auto __pred = [&](auto&& __e) { return __e == __value; }; |
| 48 | return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); |
| 49 | } |
| 50 | }; |
| 51 | } // namespace __count |
| 52 | |
| 53 | inline namespace __cpo { |
| 54 | inline constexpr auto count = __count::__fn{}; |
| 55 | } // namespace __cpo |
| 56 | } // namespace ranges |
| 57 | |
| 58 | _LIBCPP_END_NAMESPACE_STD |
| 59 | |
Kaido Kert | 56d7c4e | 2024-04-13 12:59:27 -0700 | [diff] [blame] | 60 | #endif // _LIBCPP_STD_VER >= 20 |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 61 | |
| 62 | #endif // _LIBCPP___ALGORITHM_RANGES_COUNT_H |