◆ count()

template<typename T , typename U >
std::iterator_traits<const T*>::difference_type boost::simd::count ( T const *  first,
T const *  last,
U const &  val 
)

Returns the number of elements in the ContiguousRange [first,last) that compare equal to val.

Parameters
firstBeginning of the range of elements to count
lastEnd of the range of elements to count
valValue to search for in the range.
Requirement
  • first, last and out must be pointers to Vectorizable type.
  • val must be a scalar value convertible to the pointee type of first.
Example:
#include <boost/simd/algorithm/count.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};
auto r1 = bs::count( d.data(), d.data()+7, 0.0f );
std::cout << "r1 " << r1 << "\n";
auto r2 = bs::count( d.data(), d.data()+7, 2.0f);
std::cout << "r2 " << r2 << "\n";
return 0;
}
Possible output:
r1 4
r2 2