File indexing completed on 2025-12-16 10:27:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RANGES_V3_ALGORITHM_COUNT_HPP
0014 #define RANGES_V3_ALGORITHM_COUNT_HPP
0015
0016 #include <utility>
0017
0018 #include <range/v3/range_fwd.hpp>
0019
0020 #include <range/v3/functional/identity.hpp>
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/iterator/concepts.hpp>
0023 #include <range/v3/iterator/traits.hpp>
0024 #include <range/v3/range/access.hpp>
0025 #include <range/v3/range/concepts.hpp>
0026 #include <range/v3/range/traits.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028
0029 #include <range/v3/detail/prologue.hpp>
0030
0031 namespace ranges
0032 {
0033
0034
0035 RANGES_FUNC_BEGIN(count)
0036
0037
0038 template(typename I, typename S, typename V, typename P = identity)(
0039 requires input_iterator<I> AND sentinel_for<S, I> AND
0040 indirect_relation<equal_to, projected<I, P>, V const *>)
0041 constexpr iter_difference_t<I>
0042 RANGES_FUNC(count)(I first, S last, V const & val, P proj = P{})
0043 {
0044 iter_difference_t<I> n = 0;
0045 for(; first != last; ++first)
0046 if(invoke(proj, *first) == val)
0047 ++n;
0048 return n;
0049 }
0050
0051
0052 template(typename Rng, typename V, typename P = identity)(
0053 requires input_range<Rng> AND
0054 indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
0055 constexpr iter_difference_t<iterator_t<Rng>>
0056 RANGES_FUNC(count)(Rng && rng, V const & val, P proj = P{})
0057 {
0058 return (*this)(begin(rng), end(rng), val, std::move(proj));
0059 }
0060
0061 RANGES_FUNC_END(count)
0062
0063 namespace cpp20
0064 {
0065 using ranges::count;
0066 }
0067
0068 }
0069
0070 #include <range/v3/detail/epilogue.hpp>
0071
0072 #endif