Horizon
Loading...
Searching...
No Matches
count.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2014-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13#ifndef RANGES_V3_ALGORITHM_COUNT_HPP
14#define RANGES_V3_ALGORITHM_COUNT_HPP
15
16#include <utility>
17
19
27#include <range/v3/utility/static_const.hpp>
28
29#include <range/v3/detail/prologue.hpp>
30
31namespace ranges
32{
35 RANGES_FUNC_BEGIN(count)
36
37
38 template(typename I, typename S, typename V, typename P = identity)(
39 requires input_iterator<I> AND sentinel_for<S, I> AND
40 indirect_relation<equal_to, projected<I, P>, V const *>)
41 constexpr iter_difference_t<I> //
42 RANGES_FUNC(count)(I first, S last, V const & val, P proj = P{})
43 {
44 iter_difference_t<I> n = 0;
45 for(; first != last; ++first)
46 if(invoke(proj, *first) == val)
47 ++n;
48 return n;
49 }
50
52 template(typename Rng, typename V, typename P = identity)(
53 requires input_range<Rng> AND
54 indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
55 constexpr iter_difference_t<iterator_t<Rng>> //
56 RANGES_FUNC(count)(Rng && rng, V const & val, P proj = P{})
57 {
58 return (*this)(begin(rng), end(rng), val, std::move(proj));
59 }
60
61 RANGES_FUNC_END(count)
62
63 namespace cpp20
64 {
65 using ranges::count;
66 }
68} // namespace ranges
69
70#include <range/v3/detail/epilogue.hpp>
71
72#endif
The indirect_relation concept.
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
Definition comparisons.hpp:28
Definition identity.hpp:25