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

Functions

template<typename InputIterator , typename Predicate >
bool bolt::amp::all_of (bolt::amp::control &ctl, InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool bolt::amp::all_of (InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool bolt::amp::any_of (bolt::amp::control &ctl, InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool bolt::amp::any_of (InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool bolt::amp::none_of (bolt::amp::control &ctl, InputIterator first, InputIterator last, Predicate pred)
 
template<typename InputIterator , typename Predicate >
bool bolt::amp::none_of (InputIterator first, InputIterator last, Predicate pred)
 

Detailed Description

Function Documentation

template<typename InputIterator , typename Predicate >
bool bolt::amp::all_of ( bolt::amp::control ctl,
InputIterator  first,
InputIterator  last,
Predicate  pred 
)

all_of returns true if pred(*i) is true for every iterator i in the range [first, last) and false otherwise. any_of returns true if pred(*i) is true for any iterator i in the range [first, last) and false otherwise. none_of returns true if there is no iterator i in the range [first, last) such that pred(*i) is true, and false otherwise.

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.
predThe predicate to test
Returns
bool variable
Template Parameters
InputIteratoris a model of InputIterator and InputIterator's value_type is convertible to UnaryFunction's

The following demonstrates how to use alll_of, any_of and none_of

...
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 * 2;
vecSrc2[i] = i;
}
int n = rand()% (length+1);
...
bool out1 = bolt::amp::all_of(ctrl, vecSrc.begin(), vecSrc.begin() + n, is_even()); //true
bool out2 = bolt::amp::all_of(ctrl, vecSrc2.begin(), vecSrc2.end(), is_even()); //false
bool out3 = bolt::amp::any_of(ctrl, vecSrc.begin(), vecSrc.end(), is_negative()); //false
bool out4 = bolt::amp::any_of(ctrl, vecSrc2.begin(), vecSrc2.end(), is_even()); //true
bool out5 = bolt::amp::none_of(ctrl, vecSrc.begin(), vecSrc.end(), is_negative()); //true
bool out6 = bolt::amp::none_of(ctrl, vecSrc2.begin(), vecSrc2.begin() + n, is_even()); //false