]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_MISMATCH_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP | |
13 | ||
14 | #include <iterator> | |
15 | #include <utility> | |
16 | ||
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> | |
24 | ||
25 | namespace boost { | |
26 | namespace compute { | |
27 | ||
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 | |
30 | /// differ. | |
31 | template<class InputIterator1, class InputIterator2> | |
32 | inline std::pair<InputIterator1, InputIterator2> | |
33 | mismatch(InputIterator1 first1, | |
34 | InputIterator1 last1, | |
35 | InputIterator2 first2, | |
36 | command_queue &queue = system::default_queue()) | |
37 | { | |
38 | typedef typename std::iterator_traits<InputIterator1>::value_type value_type; | |
39 | ||
40 | ::boost::compute::equal_to<value_type> op; | |
41 | ||
42 | InputIterator2 last2 = first2 + std::distance(first1, last1); | |
43 | ||
44 | InputIterator1 iter = | |
45 | boost::get<0>( | |
46 | ::boost::compute::find( | |
47 | ::boost::compute::make_transform_iterator( | |
48 | ::boost::compute::make_zip_iterator( | |
49 | boost::make_tuple(first1, first2) | |
50 | ), | |
51 | detail::unpack(op) | |
52 | ), | |
53 | ::boost::compute::make_transform_iterator( | |
54 | ::boost::compute::make_zip_iterator( | |
55 | boost::make_tuple(last1, last2) | |
56 | ), | |
57 | detail::unpack(op) | |
58 | ), | |
59 | false, | |
60 | queue | |
61 | ).base().get_iterator_tuple() | |
62 | ); | |
63 | ||
64 | return std::make_pair(iter, first2 + std::distance(first1, iter)); | |
65 | } | |
66 | ||
67 | /// \overload | |
68 | template<class InputIterator1, class InputIterator2> | |
69 | inline std::pair<InputIterator1, InputIterator2> | |
70 | mismatch(InputIterator1 first1, | |
71 | InputIterator1 last1, | |
72 | InputIterator2 first2, | |
73 | InputIterator2 last2, | |
74 | command_queue &queue = system::default_queue()) | |
75 | { | |
76 | if(std::distance(first1, last1) < std::distance(first2, last2)){ | |
77 | return ::boost::compute::mismatch(first1, last1, first2, queue); | |
78 | } | |
79 | else { | |
80 | return ::boost::compute::mismatch( | |
81 | first1, first1 + std::distance(first2, last2), first2, queue | |
82 | ); | |
83 | } | |
84 | } | |
85 | ||
86 | } // end compute namespace | |
87 | } // end boost namespace | |
88 | ||
89 | #endif // BOOST_COMPUTE_ALGORITHM_MISMATCH_HPP |