2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * \brief Equality between ranges
24 #include <thrust/detail/config.h>
25 #include <thrust/detail/execution_policy.h>
31 /*! \addtogroup reductions
33 * \addtogroup comparisons
39 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
40 * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
41 * compared element-by-element, and otherwise returns \c false.
43 * This version of \p equal returns \c true if and only if for every
44 * iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
46 * The algorithm's execution is parallelized as determined by \p exec.
48 * \param exec The execution policy to use for parallelization.
49 * \param first1 The beginning of the first sequence.
50 * \param last1 The end of the first sequence.
51 * \param first2 The beginning of the second sequence.
52 * \return \c true, if the sequences are equal; \c false, otherwise.
54 * \tparam DerivedPolicy The name of the derived execution policy.
55 * \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
56 * and \p InputIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
57 * and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type.
58 * \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
59 * and \p InputIterator2's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
60 * and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
62 * The following code snippet demonstrates how to use \p equal to test
63 * two ranges for equality using the \p thrust::host execution policy:
66 * #include <thrust/equal.h>
67 * #include <thrust/execution_policy.h>
69 * int A1[7] = {3, 1, 4, 1, 5, 9, 3};
70 * int A2[7] = {3, 1, 4, 2, 8, 5, 7};
72 * bool result = thrust::equal(thrust::host, A1, A1 + 7, A2);
77 * \see http://www.sgi.com/tech/stl/equal.html
79 template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2>
80 bool equal(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
83 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
84 * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
85 * compared element-by-element, and otherwise returns \c false.
87 * This version of \p equal returns \c true if and only if for every
88 * iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
90 * \param first1 The beginning of the first sequence.
91 * \param last1 The end of the first sequence.
92 * \param first2 The beginning of the second sequence.
93 * \return \c true, if the sequences are equal; \c false, otherwise.
95 * \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
96 * and \p InputIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
97 * and \p InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type.
98 * \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
99 * and \p InputIterator2's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality Comparable</a>,
100 * and \p InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
102 * The following code snippet demonstrates how to use \p equal to test
103 * two ranges for equality.
106 * #include <thrust/equal.h>
108 * int A1[7] = {3, 1, 4, 1, 5, 9, 3};
109 * int A2[7] = {3, 1, 4, 2, 8, 5, 7};
111 * bool result = thrust::equal(A1, A1 + 7, A2);
116 * \see http://www.sgi.com/tech/stl/equal.html
118 template <typename InputIterator1, typename InputIterator2>
119 bool equal(InputIterator1 first1, InputIterator1 last1,
120 InputIterator2 first2);
123 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
124 * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
125 * compared element-by-element, and otherwise returns \c false.
127 * This version of \p equal returns \c true if and only if for every
128 * iterator \c i in <tt>[first1, last1)</tt>,
129 * <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
131 * The algorithm's execution is parallelized as determined by \p exec.
133 * \param exec The execution policy to use for parallelization.
134 * \param first1 The beginning of the first sequence.
135 * \param last1 The end of the first sequence.
136 * \param first2 The beginning of the second sequence.
137 * \param binary_pred Binary predicate used to test element equality.
138 * \return \c true, if the sequences are equal; \c false, otherwise.
140 * \tparam DerivedPolicy The name of the derived execution policy.
141 * \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
142 * and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
143 * \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
144 * and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
145 * \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
147 * The following code snippet demonstrates how to use \p equal to compare the
148 * elements in two ranges modulo 2 using the \p thrust::host execution policy.
151 * #include <thrust/equal.h>
152 * #include <thrust/execution_policy.h>
155 * __host__ __device__
156 * struct compare_modulo_two
158 * bool operator()(int x, int y)
160 * return (x % 2) == (y % 2);
164 * int x[5] = {0, 2, 4, 6, 8, 10};
165 * int y[5] = {1, 3, 5, 7, 9, 11};
167 * bool result = thrust::equal(x, x + 5, y, compare_modulo_two());
172 * \see http://www.sgi.com/tech/stl/equal.html
174 template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
175 bool equal(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred);
178 /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
179 * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
180 * compared element-by-element, and otherwise returns \c false.
182 * This version of \p equal returns \c true if and only if for every
183 * iterator \c i in <tt>[first1, last1)</tt>,
184 * <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
186 * \param first1 The beginning of the first sequence.
187 * \param last1 The end of the first sequence.
188 * \param first2 The beginning of the second sequence.
189 * \param binary_pred Binary predicate used to test element equality.
190 * \return \c true, if the sequences are equal; \c false, otherwise.
192 * \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
193 * and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
194 * \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
195 * and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
196 * \tparam BinaryPredicate is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary Predicate</a>.
198 * The following code snippet demonstrates how to use \p equal to compare the
199 * elements in two ranges modulo 2.
202 * #include <thrust/equal.h>
204 * __host__ __device__
205 * struct compare_modulo_two
207 * bool operator()(int x, int y)
209 * return (x % 2) == (y % 2);
213 * int x[5] = {0, 2, 4, 6, 8, 10};
214 * int y[5] = {1, 3, 5, 7, 9, 11};
216 * bool result = thrust::equal(x, x + 5, y, compare_modulo_two());
221 * \see http://www.sgi.com/tech/stl/equal.html
223 template <typename InputIterator1, typename InputIterator2,
224 typename BinaryPredicate>
225 bool equal(InputIterator1 first1, InputIterator1 last1,
226 InputIterator2 first2, BinaryPredicate binary_pred);
229 /*! \} // end comparisons
230 * \} // end reductions
233 } // end namespace thrust
235 #include <thrust/detail/equal.inl>