Sunteți pe pagina 1din 2

This website uses cookies. By continuing, you give permission to deploy cookies, as detailed in our privacy policy.

ok

Search: Go
Not logged in

Reference <algorithm> count_if register log in

C++
Information Record Prices Achieved
Tutorials OPEN
Fine Art and Rare Book auctions and valuations. Regular in-house auctions.
Reference
Articles Fonsie Mealy Auctioneers
Forum
function template
Reference
count_if
<algorithm>
C library: std::
Containers: template <class InputIterator, class UnaryPredicate>
Input/Output: typename iterator_traits<InputIterator>::difference_type
Multi-threading: count_if (InputIterator first, InputIterator last, UnaryPredicate pred);
Other: Return number of elements in range satisfying condition
<algorithm>
Returns the number of elements in the range [first,last) for which pred is true.
<bitset>
<chrono> The behavior of this function template is equivalent to:
<codecvt> 1 template <class InputIterator, class UnaryPredicate>
<complex> 2 typename iterator_traits<InputIterator>::difference_type
<exception> 3 count_if (InputIterator first, InputIterator last, UnaryPredicate pred)
<functional> 4 {
<initializer_list> 5 typename iterator_traits<InputIterator>::difference_type ret = 0;
<iterator> 6 while (first!=last) {
7 if (pred(*first)) ++ret;
<limits>
8 ++first;
<locale> 9 }
<memory> 10 return ret;
<new> 11 }
<numeric>
<random>
<ratio>
<regex> Parameters
<stdexcept>
<string> first, last
<system_error> Input iterators to the initial and final positions of the sequence of elements. The range used is [first,last),
<tuple> which contains all the elements between first and last, including the element pointed by first but not the element
<typeindex> pointed by last.
<typeinfo> pred
<type_traits> Unary function that accepts an element in the range as argument, and returns a value convertible to bool. The
<utility> value returned indicates whether the element is counted by this function.
<valarray> The function shall not modify its argument.
This can either be a function pointer or a function object.
<algorithm>
adjacent_find
all_of
any_of Return value
binary_search The number of elements in the range [first,last) for which pred does not return false.
copy The return type (iterator_traits<InputIterator>::difference_type) is a signed integral type.
copy_backward
copy_if
copy_n Example
count
1 // count_if example
count_if
2 #include <iostream> // std::cout
equal 3 #include <algorithm> // std::count_if
equal_range 4 #include <vector> // std::vector
fill 5
fill_n 6 bool IsOdd (int i) { return ((i%2)==1); }
find 7
find_end 8 int main () {
9 std::vector<int> myvector;
find_first_of
10 for (int i=1; i<10; i++) myvector.push_back(i); // myvector: 1 2 3 4 5 6 7 8 9
find_if 11
find_if_not 12 int mycount = count_if (myvector.begin(), myvector.end(), IsOdd);
for_each 13 std::cout << "myvector contains " << mycount << " odd values.\n";
generate 14
generate_n 15 return 0;
includes 16 }
inplace_merge
is_heap
is_heap_until Output:
is_partitioned myvector contains 5 odd values.
is_permutation
is_sorted
is_sorted_until Complexity
iter_swap
Linear in the distance between first and last: Calls pred once for each element.
lexicographical_compare
lower_bound
make_heap Data races
max
max_element
The objects in the range [first,last) are accessed (each object is accessed exactly once).
merge
min
minmax
Exceptions
minmax_element Throws if pred throws or if any of the operations on iterators throws.
min_element Note that invalid arguments cause undefined behavior.
mismatch
move
move_backward See also
next_permutation count Count appearances of value in range (function template )
none_of
for_each Apply function to range (function template )
nth_element
partial_sort find Find value in range (function template )
partial_sort_copy
partition
partition_copy
partition_point
pop_heap
prev_permutation
push_heap
random_shuffle
remove
remove_copy
remove_copy_if
remove_if
replace
replace_copy
replace_copy_if
replace_if
reverse
reverse_copy
rotate
rotate_copy
search
search_n
set_difference
set_intersection
set_symmetric_difference
set_union
shuffle
sort
sort_heap
stable_partition
stable_sort
swap
swap_ranges
transform
unique
unique_copy
upper_bound

Home page | Privacy policy


© cplusplus.com, 2000-2019 - All rights reserved - v3.1
Spotted an error? contact us

S-ar putea să vă placă și