◆ find_if()

template<typename T , typename Pred >
T const* boost::simd::find_if ( T const *  first,
T const *  last,
Pred const &  pred 
)

Returns an iterator to the first element in the range [first,last) for which std::forward<Pred>(pred) returns true.

If no such element is found, the function returns last.

Parameters
firstBeginning of the range of elements
lastEnd of the range of elements
std::forward<Pred>(pred)Predicate to apply to each element in the range.
Requirement
  • first, last and out must be pointers to Vectorizable type.
Example:
#include <boost/simd/algorithm/find_if.hpp>
#include <boost/simd/function/is_gtz.hpp>
#include <boost/simd/function/is_ltz.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, 4.0f};
auto r1 = bs::find_if( d.data(), d.data()+7, bs::is_gtz );
std::cout << "r1 " << r1 << " *r1 " << *r1 << "\n";
auto r2 = bs::find_if( d.data(), d.data()+7, bs::is_ltz );
std::cout << "r2 " << r2 << " *r2 " << *r2 << "\n";
auto r3 = bs::find_if( d.data()+1, d.data()+8, bs::is_gtz );
std::cout << "r3 " << r3 << " *r3 " << *r3 << "\n";
auto r4 = bs::find_if( d.data()+1, d.data()+8, bs::is_ltz );
std::cout << "r4 " << r4 << " *r4 " << *r4 << "\n";
return 0;
}
possible output:
r1 0x1354c24 *r1 2
r2 0x1354c30 *r2 -1
r3 0x1354c24 *r3 2
r4 0x1354c30 *r4 -1