• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #ifndef BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
12 #define BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
13 
14 #include <boost/static_assert.hpp>
15 
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/mismatch.hpp>
19 #include <boost/compute/type_traits/is_device_iterator.hpp>
20 
21 namespace boost {
22 namespace compute {
23 
24 /// Returns \c true if the range [\p first1, \p last1) and the range
25 /// beginning at \p first2 are equal.
26 ///
27 /// Space complexity: \Omega(1)
28 template<class InputIterator1, class InputIterator2>
equal(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,command_queue & queue=system::default_queue ())29 inline bool equal(InputIterator1 first1,
30                   InputIterator1 last1,
31                   InputIterator2 first2,
32                   command_queue &queue = system::default_queue())
33 {
34     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
35     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
36     return ::boost::compute::mismatch(first1,
37                                       last1,
38                                       first2,
39                                       queue).first == last1;
40 }
41 
42 /// \overload
43 template<class InputIterator1, class InputIterator2>
equal(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,InputIterator2 last2,command_queue & queue=system::default_queue ())44 inline bool equal(InputIterator1 first1,
45                   InputIterator1 last1,
46                   InputIterator2 first2,
47                   InputIterator2 last2,
48                   command_queue &queue = system::default_queue())
49 {
50     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
51     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
52     if(std::distance(first1, last1) != std::distance(first2, last2)){
53         return false;
54     }
55 
56     return ::boost::compute::equal(first1, last1, first2, queue);
57 }
58 
59 } // end compute namespace
60 } // end boost namespace
61 
62 #endif // BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
63