find.hpp 2.0 KB

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