remove.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_REMOVE_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_REMOVE_HPP
  12. #include <boost/compute/lambda.hpp>
  13. #include <boost/compute/system.hpp>
  14. #include <boost/compute/algorithm/remove_if.hpp>
  15. #include <boost/compute/type_traits/vector_size.hpp>
  16. namespace boost {
  17. namespace compute {
  18. /// Removes each element equal to \p value in the range [\p first,
  19. /// \p last).
  20. ///
  21. /// \see remove_if()
  22. template<class Iterator, class T>
  23. inline Iterator remove(Iterator first,
  24. Iterator last,
  25. const T &value,
  26. command_queue &queue = system::default_queue())
  27. {
  28. typedef typename std::iterator_traits<Iterator>::value_type value_type;
  29. using ::boost::compute::_1;
  30. using ::boost::compute::lambda::all;
  31. if(vector_size<value_type>::value == 1){
  32. return ::boost::compute::remove_if(first,
  33. last,
  34. _1 == value,
  35. queue);
  36. }
  37. else {
  38. return ::boost::compute::remove_if(first,
  39. last,
  40. all(_1 == value),
  41. queue);
  42. }
  43. }
  44. } // end compute namespace
  45. } // end boost namespace
  46. #endif // BOOST_COMPUTE_ALGORITHM_REMOVE_HPP