◆ count_if()

template<typename T , typename Pred >
std::iterator_traits<const T*>::difference_type boost::simd::count_if ( T const *  first,
T const *  last,
Pred  pred 
)

Returns he number of elements in the range [first,last) for which pred returns true.

Parameters
firstBeginning of the range of elements
lastEnd of the range of elements
predpredicate to apply to each element.
Requirement
  • first, last and out must be pointers to Vectorizable type.
Example:
#include <boost/simd/algorithm/count_if.hpp>
#include <boost/simd/function/is_gtz.hpp>
#include <iostream>
#include <vector>
int main()
{
namespace bs = boost::simd;
std::vector<float> d{ 0.0f, 2.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f, 3.0f};
auto r1 = bs::count_if( d.data(), d.data()+7, bs::is_gtz );
std::cout << "r1 " << r1 << "\n";
d[1] = -1.0f;
auto r2 = bs::count_if( d.data(), d.data()+7, bs::is_gtz );
std::cout << "r2 " << r2 << "\n";
auto r3= bs::count_if( d.data()+1, d.data()+8, bs::is_gtz );
std::cout << "r3 " << r3 << "\n";
return 0;
}
Possible output:
r1 2
r2 1
r3 2