std::experimental::ranges::count,std::experimental::ranges::count_if (3) - Linux Manuals
std::experimental::ranges::count,std::experimental::ranges::count_if: std::experimental::ranges::count,std::experimental::ranges::count_if
Command to display std::experimental::ranges::count,std::experimental::ranges::count_if
manual in Linux: $ man 3 std::experimental::ranges::count,std::experimental::ranges::count_if
NAME
std::experimental::ranges::count,std::experimental::ranges::count_if - std::experimental::ranges::count,std::experimental::ranges::count_if
Synopsis
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*> (1) (ranges TS)
ranges::difference_type_t<I> count(I first, S last, const T& value, Proj proj = Proj{});
template< InputRange R, class T, class Proj = ranges::identity >
requires IndirectRelation<ranges::equal_to<>,
projected<ranges::iterator_t<R>, Proj>, const T*> (2) (ranges TS)
ranges::difference_type_t<ranges::iterator_t<R>>
count(R&& r, const T& value, Proj proj = Proj{});
template< InputIterator I, Sentinel<I> S, class Proj = ranges::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred > (3) (ranges TS)
ranges::difference_type_t<I> count_if(I first, S last, Pred pred, Proj proj = Proj{});
template< InputRange R, class Proj = ranges::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > (4) (ranges TS)
ranges::difference_type_t<ranges::iterator_t<R>>
count_if(R&& r, Pred pred, Proj proj = Proj{});
Returns the number of elements in the range [first, last) satisfying specific criteria.
1) counts the elements whose projected values are equal to value (i.e., ranges::invoke(proj, *i) == value).
3) counts the elements whose projected values satisfy the predicate pred (i.e., ranges::invoke(pred, ranges::invoke(proj, *i)) != false).
2,4) Same as (1,3), but uses 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
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{})
{
ranges::difference_type_t<I> ret = 0;
for (; first != last; ++first) {
if (ranges::invoke(proj, *first) == value) {
++ret;
}
}
return ret;
}
Second version
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{})
{
ranges::difference_type_t<I> ret = 0;
for (; first != last; ++first) {
if (ranges::invoke(pred, ranges::invoke(proj, *i))) {
++ret;
}
}
return ret;
}
Example
This section is incomplete
Reason: no example
See also
returns the number of elements satisfying specific criteria
count (function template)
count_if
returns the distance between an iterator and a sentinel, or between the beginning and the end of a range
distance (function template)
Pages related to std::experimental::ranges::count,std::experimental::ranges::count_if
- std::experimental::ranges::common_reference (3) - std::experimental::ranges::common_reference
- std::experimental::ranges::common_type (3) - std::experimental::ranges::common_type
- std::experimental::ranges::copy,std::experimental::ranges::copy_if (3) - std::experimental::ranges::copy,std::experimental::ranges::copy_if
- std::experimental::ranges::Assignable (3) - std::experimental::ranges::Assignable
- std::experimental::ranges::BidirectionalIterator (3) - std::experimental::ranges::BidirectionalIterator
- std::experimental::ranges::BidirectionalRange (3) - std::experimental::ranges::BidirectionalRange
- std::experimental::ranges::Boolean (3) - std::experimental::ranges::Boolean
- std::experimental::ranges::BoundedRange (3) - std::experimental::ranges::BoundedRange
- std::experimental::ranges::Common (3) - std::experimental::ranges::Common
- std::experimental::ranges::CommonReference (3) - std::experimental::ranges::CommonReference
- std::experimental::ranges::Constructible (3) - std::experimental::ranges::Constructible
- std::experimental::ranges::ConvertibleTo (3) - std::experimental::ranges::ConvertibleTo
- std::experimental::ranges::CopyConstructible (3) - std::experimental::ranges::CopyConstructible
- std::experimental::ranges::Copyable (3) - std::experimental::ranges::Copyable
- std::experimental::ranges::DefaultConstructible (3) - std::experimental::ranges::DefaultConstructible
- std::experimental::ranges::DerivedFrom (3) - std::experimental::ranges::DerivedFrom
- std::experimental::ranges::Destructible (3) - std::experimental::ranges::Destructible
- std::experimental::ranges::EqualityComparable, (3) - std::experimental::ranges::EqualityComparable,
- std::experimental::ranges::EqualityComparable,std::experimental::ranges::EqualityComparableWith (3) - std::experimental::ranges::EqualityComparable,std::experimental::ranges::EqualityComparableWith
- std::experimental::ranges::ForwardIterator (3) - std::experimental::ranges::ForwardIterator
- std::experimental::ranges::ForwardRange (3) - std::experimental::ranges::ForwardRange
- std::experimental::ranges::Incrementable (3) - std::experimental::ranges::Incrementable
- std::experimental::ranges::IndirectRelation (3) - std::experimental::ranges::IndirectRelation
- std::experimental::ranges::IndirectStrictWeakOrder (3) - std::experimental::ranges::IndirectStrictWeakOrder
- std::experimental::ranges::IndirectUnaryInvocable, (3) - std::experimental::ranges::IndirectUnaryInvocable,
- std::experimental::ranges::IndirectUnaryInvocable,std::experimental::ranges::IndirectRegularUnaryInvocable (3) - std::experimental::ranges::IndirectUnaryInvocable,std::experimental::ranges::IndirectRegularUnaryInvocable
- std::experimental::ranges::IndirectUnaryPredicate (3) - std::experimental::ranges::IndirectUnaryPredicate
- std::experimental::ranges::IndirectlyComparable (3) - std::experimental::ranges::IndirectlyComparable
- std::experimental::ranges::IndirectlyCopyable (3) - std::experimental::ranges::IndirectlyCopyable
- std::experimental::ranges::IndirectlyCopyableStorable (3) - std::experimental::ranges::IndirectlyCopyableStorable
- std::experimental::ranges::IndirectlyMovable (3) - std::experimental::ranges::IndirectlyMovable