Horizon
Loading...
Searching...
No Matches
count_if.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_IF_HPP
14#define RANGES_V3_ALGORITHM_COUNT_IF_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_if)
36
37
38 template(typename I, typename S, typename R, typename P = identity)(
39 requires input_iterator<I> AND sentinel_for<S, I> AND
40 indirect_unary_predicate<R, projected<I, P>>)
41 constexpr iter_difference_t<I> RANGES_FUNC(count_if)(I first, S last, R pred, P proj = P{})
42 {
43 iter_difference_t<I> n = 0;
44 for(; first != last; ++first)
45 if(invoke(pred, invoke(proj, *first)))
46 ++n;
47 return n;
48 }
49
51 template(typename Rng, typename R, typename P = identity)(
52 requires input_range<Rng> AND
54 constexpr iter_difference_t<iterator_t<Rng>> //
55 RANGES_FUNC(count_if)(Rng && rng, R pred, P proj = P{})
56 {
57 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
58 }
59
60 RANGES_FUNC_END(count_if)
61
62 namespace cpp20
63 {
64 using ranges::count_if;
65 }
67} // namespace ranges
68
69#include <range/v3/detail/epilogue.hpp>
70
71#endif
The indirect_unary_predicate concept.
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
Definition identity.hpp:25