| Defined in header <experimental/ranges/algorithm>
|
||
| template< InputIterator I, Sentinel<I> S, class T, class Proj = ranges::identity > requires IndirectRelation<ranges::equal_to<>, projected<I, Proj>, const T*> ranges::difference_type_t<I> count( I first, S last, const T& value, Proj proj = Proj{} ); |
(1) | (ranges TS) |
| template< InputRange R, class T, class Proj = ranges::identity > requires IndirectRelation<ranges::equal_to<>, projected<ranges::iterator_t<R>, Proj>, const T*> ranges::difference_type_t<ranges::iterator_t<R>> count( R&& r, const T& value, Proj proj = Proj{} ); |
(2) | (ranges TS) |
| template< InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred > ranges::difference_type_t<I> count_if( I first, S last, Pred pred, Proj proj = Proj{} ); |
(3) | (ranges TS) |
| template< InputRange R, class Proj = ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > ranges::difference_type_t<ranges::iterator_t<R>> count_if( R&& r, Pred pred, Proj proj = Proj{} ); |
(4) | (ranges TS) |
Returns the number of elements in the range [first, last) satisfying specific criteria.
value (i.e., ranges::invoke(proj, *i) == value).pred (i.e., ranges::invoke(pred, ranges::invoke(proj, *i)) != false).r as the source range, as if using ranges::begin(r) as first and ranges::end(r) as last.Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable.
Parameters
| first, last | - | the range of elements to examine |
| r | - | the range of elements to examine |
| value | - | the value to search for |
| pred | - | predicate to apply to the projected elements |
| proj | - | projection to apply to the elements |
Return value
Number of elements satisfying the condition.
Complexity
Exactly last - first comparisons / applications of the predicate, and the same number of applications of the projection.
Notes
For the number of elements in the range [first, last) without any additional criteria, see ranges::distance.
Possible implementation
| First version |
|---|
|
| Second version |
|
Example
Reason: no example
See also
| returns the number of elements satisfying specific criteria (function template) | |
| returns the distance between an iterator and a sentinel, or between the beginning and the end of a range (function template) |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.