Template Function thrust::equal(InputIterator1, InputIterator1, InputIterator2, BinaryPredicate)¶
Function Documentation¶
-
template<typename
InputIterator1, typenameInputIterator2, typenameBinaryPredicate>
boolthrust::equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred) equalreturnstrueif the two ranges[first1, last1)and[first2, first2 + (last1 - first1))are identical when compared element-by-element, and otherwise returnsfalse.This version of
equalreturnstrueif and only if for every iteratoriin[first1, last1),binary_pred(*i, *(first2 + (i - first1)))istrue.The following code snippet demonstrates how to use
equalto compare the elements in two ranges modulo 2.- Return
true, if the sequences are equal;false, otherwise.- Parameters
first1: The beginning of the first sequence.last1: The end of the first sequence.first2: The beginning of the second sequence.binary_pred: Binary predicate used to test element equality.
- Template Parameters
InputIterator1: is a model of Input Iterator, andInputIterator1'svalue_typeis convertible toBinaryPredicate'sfirst_argument_type.InputIterator2: is a model of Input Iterator, andInputIterator2'svalue_typeis convertible toBinaryPredicate'ssecond_argument_type.BinaryPredicate: is a model of Binary Predicate.
#include <thrust/equal.h> struct compare_modulo_two { __host__ __device__ bool operator()(int x, int y) const { return (x % 2) == (y % 2); } }; ... int x[6] = {0, 2, 4, 6, 8, 10}; int y[6] = {1, 3, 5, 7, 9, 11}; bool result = thrust::equal(x, x + 5, y, compare_modulo_two()); // result is true