remove.hpp 2.0 KB

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