find.hpp 1.8 KB

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