Bolt  1.3
C++ template library with support for OpenCL
Functions
AMP-find

Functions

template<typename InputIterator , typename T >
InputIterator bolt::amp::find (InputIterator first, InputIterator last, const T &value)
 
template<typename InputIterator , typename T >
InputIterator bolt::amp::find (bolt::amp::control &ctl, InputIterator first, InputIterator last, const T &value)
 
template<typename InputIterator , typename Predicate >
InputIterator bolt::amp::find_if (InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
InputIterator bolt::amp::find_if (bolt::amp::control &ctl, InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
InputIterator bolt::amp::find_if_not (InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
InputIterator bolt::amp::find_if_not (bolt::amp::control &ctl, InputIterator first, InputIterator last, Predicate pred)
 

Detailed Description

Function Documentation

template<typename InputIterator , typename T >
InputIterator bolt::amp::find ( InputIterator  first,
InputIterator  last,
const T &  value 
)

find returns the first iterator i in the range [first, last) such that *i == value or last if no such iterator exists. find_if returns the first iterator i in the range [first, last) such that pred(*i) is true or last if no such iterator exists. find_if_not returns the first iterator i in the range [first, last) such that pred(*i) is false or last if no such iterator exists.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
firstBeginning of the source copy sequence.
lastEnd of the source copy sequence.
valuevalue to search
predThe predicate to test
resultThe first iterator i such that *i == value or pred(*i) is true and last otherwise.
      \tInputIterator is a model of Input Iterator and InputIterator's value_type is equality comparable to type T.  
      \tT is a model of EqualityComparable. 

The following demonstrates how to use find, find_if and find_if_not

#include <bolt/amp/find.h>
...
template <typename T>
struct is_even
{
bool operator()(T x) const restrict(amp, cpu)
{
if (((int)x) % 2)
return true;
else
return false;
}
};
template <typename T>
struct is_negative
{
bool operator()(T x) const restrict(amp, cpu)
{
if (x<0)
return true;
else
return false;
}
};
int length = 1024;
std::vector<int> vecSrc(length);
std::vector<int> vecSrc2(length);
for(int i = 0; i<length; i++)
{
vecSrc[i] = i;
vecSrc2[i] = i * 2;
}
...
int index = rand()%length;
int val = vecSrc[index];
int val2 = rand();
//A Hit
std::vector<int>::iterator itr = bolt::amp::find(ctrl, vecSrc.begin(), vecSrc.end(), val);
//*itr = val
//May be Hit / Miss
std::vector<int>::iterator itr2 = bolt::amp::find(ctrl, vecSrc.begin(), vecSrc.end(), val2);
//*itr2 = val if hit / itr2 = vecSrc2.end() if miss
//A Hit
std::vector<int>::iterator itr3 = bolt::amp::find_if(ctrl, vecSrc.begin(), vecSrc.end(), is_even());
//*itr3 = 0 the first value itself satisfies the even condition
//A Miss
std::vector<int>::iterator itr4 = bolt::amp::find_if(ctrl, vecSrc.begin(), vecSrc.end(), is_negative());
//itr4 = vecSrc.end() since no element is negative.
//A Hit
std::vector<int>::iterator itr5 = bolt::amp::find_if_not(ctrl, vecSrc.begin(), vecSrc.end(), is_even());
//*itr5 = 1 the second value itself violates the even condition
//A Hit
std::vector<int>::iterator itr6 = bolt::amp::find_if_not(ctrl, vecSrc.begin(), vecSrc.end(), is_negative());
//itr6 = 0 the first value itself violates the is_negative condition
//A Miss
std::vector<int>::iterator itr7 = bolt::amp::find_if_not(ctrl, vecSrc2.begin(), vecSrc2.end(), is_even());
//itr7 = vecSrc2.end() since no element violates the condition is_even
See Also
http://www.sgi.com/tech/stl/find.html
http://www.sgi.com/tech/stl/InputIterator.html