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
31 template<class InputIterator1, class InputIterator2>
32 inline std::pair<InputIterator1, InputIterator2>
33 mismatch(InputIterator1 first1,
35 InputIterator2 first2,
36 command_queue &queue = system::default_queue())
38 typedef typename std::iterator_traits<InputIterator1>::value_type value_type;
40 ::boost::compute::equal_to<value_type> op;
42 InputIterator2 last2 = first2 + std::distance(first1, last1);
46 ::boost::compute::find(
47 ::boost::compute::make_transform_iterator(
48 ::boost::compute::make_zip_iterator(
49 boost::make_tuple(first1, first2)
53 ::boost::compute::make_transform_iterator(
54 ::boost::compute::make_zip_iterator(
55 boost::make_tuple(last1, last2)
61 ).base().get_iterator_tuple()
64 return std::make_pair(iter, first2 + std::distance(first1, iter));
68 template<class InputIterator1, class InputIterator2>
69 inline std::pair<InputIterator1, InputIterator2>
70 mismatch(InputIterator1 first1,
72 InputIterator2 first2,
74 command_queue &queue = system::default_queue())
76 if(std::distance(first1, last1) < std::distance(first2, last2)){
77 return ::boost::compute::mismatch(first1, last1, first2, queue);
80 return ::boost::compute::mismatch(
81 first1, first1 + std::distance(first2, last2), first2, queue
86 } // end compute namespace
87 } // end boost namespace
89 #endif // BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP