GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::experimental::ranges::count,std::experimental::ranges::count_if(3) C++ Standard Libary std::experimental::ranges::count,std::experimental::ranges::count_if(3)

std::experimental::ranges::count,std::experimental::ranges::count_if - std::experimental::ranges::count,std::experimental::ranges::count_if


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>, (1) (ranges TS)
const T*>


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.


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


number of elements satisfying the condition.


exactly last - first comparisons / applications of the predicate, and the same
number of applications of the projection.


For the number of elements in the range [first, last) without any additional
criteria, see ranges::distance.


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;
}


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;
}


This section is incomplete
Reason: no example


count returns the number of elements satisfying specific criteria
count_if (function template)
returns the distance between an iterator and a sentinel, or between the
distance beginning and the end of a range
(function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.