std::ranges::count() algorithm
- od C++20
- Simplified
- Detailed
// (1)
constexpr std::iter_difference_t<I>
count( I first, S last, const T& value, Proj proj = {} );
// (2)
constexpr ranges::range_difference_t<R>
count( R&& r, const T& value, Proj proj = {} );
The type of arguments are generic and have the following constraints:
I
-std::input_iterator
S
-std::sentinel_for<I>
R
-std::ranges::input_range
T
- (none)P
- (none)
The Proj
template argument has a default type of std::identity
for all overloads.
Additionally, each overload has the following constraints:
- (1) -
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
- (2) -
indirect_binary_predicate<ranges::equal_to, projected<ranges::iterator_t<R>, Proj>, const T*>
(The std::
namespace was ommitted here for readability)
// (1)
template<
std::input_iterator I,
std::sentinel_for<I> S,
class T,
class Proj = std::identity
>
requires std::indirect_binary_predicate<ranges::equal_to, std::projected<I, Proj>, const T*>
constexpr std::iter_difference_t<I>
count( I first, S last, const T& value, Proj proj = {} );
// (2)
template<
ranges::input_range R,
class T,
class Proj = std::identity
>
requires std::indirect_binary_predicate<ranges::equal_to, std::projected<ranges::iterator_t<R>, Proj>, const T*>
constexpr ranges::range_difference_t<R>
count( R&& r, const T& value, Proj proj = {} );
Returns the number of elements equal to value
in the given range.
- (1) Counts the elements that are equal to
value
(usingoperator==
). - (2) Same as (1), but uses
r
as the source range, as if usingranges::begin(r)
asfirst
andranges::end(r)
aslast
.
The function-like entities described on this page are niebloids.
Parameters
first last | The range of elements to examine. |
r | The range of elements to examine. |
value | The value to search for. |
proj | Projection to apply to the elements. |