os_count_if |
Counts items in a container that satisfy a predicate.
A helper algorithm for count_if()
. Returns the number of elements in container c that
cause predicate pred to return true
.
#include <ospace/helper/helpalgo.h>
template< class Container, class Predicate >
int os_count_if( const Container& c, Predicate pred )
#include <iostream>
#include <vector>
#include <ospace/helper.h>
int
odd( int a_ )
{
return a_ % 2;
}
void
main()
{
vector< int > numbers( 100 );
for ( int i = 0; i < 100; ++i )
numbers[ i ] = i % 3;
int elements = os_count_if( numbers, odd );
cout << "Found " << elements << " odd elements.\n";
}
Found 33 odd elements.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.