1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP
12 #define BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP
17 #include <boost/static_assert.hpp>
19 #include <boost/compute/system.hpp>
20 #include <boost/compute/functional.hpp>
21 #include <boost/compute/command_queue.hpp>
22 #include <boost/compute/algorithm/find.hpp>
23 #include <boost/compute/iterator/transform_iterator.hpp>
24 #include <boost/compute/iterator/zip_iterator.hpp>
25 #include <boost/compute/functional/detail/unpack.hpp>
26 #include <boost/compute/type_traits/is_device_iterator.hpp>
31 /// Returns a pair of iterators pointing to the first position where the
32 /// range [\p first1, \p last1) and the range starting at \p first2
35 /// Space complexity: \Omega(1)
36 template<class InputIterator1, class InputIterator2>
37 inline std::pair<InputIterator1, InputIterator2>
38 mismatch(InputIterator1 first1,
40 InputIterator2 first2,
41 command_queue &queue = system::default_queue())
43 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
44 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
45 typedef typename std::iterator_traits<InputIterator1>::value_type value_type;
47 ::boost::compute::equal_to<value_type> op;
49 InputIterator2 last2 = first2 + std::distance(first1, last1);
53 ::boost::compute::find(
54 ::boost::compute::make_transform_iterator(
55 ::boost::compute::make_zip_iterator(
56 boost::make_tuple(first1, first2)
60 ::boost::compute::make_transform_iterator(
61 ::boost::compute::make_zip_iterator(
62 boost::make_tuple(last1, last2)
68 ).base().get_iterator_tuple()
71 return std::make_pair(iter, first2 + std::distance(first1, iter));
75 template<class InputIterator1, class InputIterator2>
76 inline std::pair<InputIterator1, InputIterator2>
77 mismatch(InputIterator1 first1,
79 InputIterator2 first2,
81 command_queue &queue = system::default_queue())
83 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
84 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
85 if(std::distance(first1, last1) < std::distance(first2, last2)){
86 return ::boost::compute::mismatch(first1, last1, first2, queue);
89 return ::boost::compute::mismatch(
90 first1, first1 + std::distance(first2, last2), first2, queue
95 } // end compute namespace
96 } // end boost namespace
98 #endif // BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP