• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REMOVE_HPP
12 #define BOOST_COMPUTE_ALGORITHM_REMOVE_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/algorithm/remove_if.hpp>
19 #include <boost/compute/type_traits/vector_size.hpp>
20 #include <boost/compute/type_traits/is_device_iterator.hpp>
21 
22 namespace boost {
23 namespace compute {
24 
25 /// Removes each element equal to \p value in the range [\p first,
26 /// \p last).
27 ///
28 /// Space complexity: \Omega(3n)
29 ///
30 /// \see remove_if()
31 template<class Iterator, class T>
remove(Iterator first,Iterator last,const T & value,command_queue & queue=system::default_queue ())32 inline Iterator remove(Iterator first,
33                        Iterator last,
34                        const T &value,
35                        command_queue &queue = system::default_queue())
36 {
37     BOOST_STATIC_ASSERT(is_device_iterator<Iterator>::value);
38     typedef typename std::iterator_traits<Iterator>::value_type value_type;
39 
40     using ::boost::compute::_1;
41     using ::boost::compute::lambda::all;
42 
43     if(vector_size<value_type>::value == 1){
44         return ::boost::compute::remove_if(first,
45                                            last,
46                                            _1 == value,
47                                            queue);
48     }
49     else {
50         return ::boost::compute::remove_if(first,
51                                            last,
52                                            all(_1 == value),
53                                            queue);
54     }
55 }
56 
57 } // end compute namespace
58 } // end boost namespace
59 
60 #endif // BOOST_COMPUTE_ALGORITHM_REMOVE_HPP
61