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_FIND_HPP
12 #define BOOST_COMPUTE_ALGORITHM_FIND_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/lambda.hpp>
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/command_queue.hpp>
19 #include <boost/compute/algorithm/find_if.hpp>
20 #include <boost/compute/type_traits/vector_size.hpp>
21 #include <boost/compute/type_traits/is_device_iterator.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Returns an iterator pointing to the first element in the range
27 /// [\p first, \p last) that equals \p value.
28 ///
29 /// Space complexity: \Omega(1)
30 template<class InputIterator, class T>
find(InputIterator first,InputIterator last,const T & value,command_queue & queue=system::default_queue ())31 inline InputIterator find(InputIterator first,
32 InputIterator last,
33 const T &value,
34 command_queue &queue = system::default_queue())
35 {
36 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
37 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
38
39 using ::boost::compute::_1;
40 using ::boost::compute::lambda::all;
41
42 if(vector_size<value_type>::value == 1){
43 return ::boost::compute::find_if(
44 first,
45 last,
46 _1 == value,
47 queue
48 );
49 }
50 else {
51 return ::boost::compute::find_if(
52 first,
53 last,
54 all(_1 == value),
55 queue
56 );
57 }
58 }
59
60 } // end compute namespace
61 } // end boost namespace
62
63 #endif // BOOST_COMPUTE_ALGORITHM_FIND_HPP
64