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/compute/system.hpp>
18 #include <boost/compute/functional.hpp>
19 #include <boost/compute/command_queue.hpp>
20 #include <boost/compute/algorithm/find.hpp>
21 #include <boost/compute/iterator/transform_iterator.hpp>
22 #include <boost/compute/iterator/zip_iterator.hpp>
23 #include <boost/compute/functional/detail/unpack.hpp>
28 /// Returns a pair of iterators pointing to the first position where the
29 /// range [\p first1, \p last1) and the range starting at \p first2
32 /// Space complexity: \Omega(1)
33 template<class InputIterator1, class InputIterator2>
34 inline std::pair<InputIterator1, InputIterator2>
35 mismatch(InputIterator1 first1,
37 InputIterator2 first2,
38 command_queue &queue = system::default_queue())
40 typedef typename std::iterator_traits<InputIterator1>::value_type value_type;
42 ::boost::compute::equal_to<value_type> op;
44 InputIterator2 last2 = first2 + std::distance(first1, last1);
48 ::boost::compute::find(
49 ::boost::compute::make_transform_iterator(
50 ::boost::compute::make_zip_iterator(
51 boost::make_tuple(first1, first2)
55 ::boost::compute::make_transform_iterator(
56 ::boost::compute::make_zip_iterator(
57 boost::make_tuple(last1, last2)
63 ).base().get_iterator_tuple()
66 return std::make_pair(iter, first2 + std::distance(first1, iter));
70 template<class InputIterator1, class InputIterator2>
71 inline std::pair<InputIterator1, InputIterator2>
72 mismatch(InputIterator1 first1,
74 InputIterator2 first2,
76 command_queue &queue = system::default_queue())
78 if(std::distance(first1, last1) < std::distance(first2, last2)){
79 return ::boost::compute::mismatch(first1, last1, first2, queue);
82 return ::boost::compute::mismatch(
83 first1, first1 + std::distance(first2, last2), first2, queue
88 } // end compute namespace
89 } // end boost namespace
91 #endif // BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP