]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_IF_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_REMOVE_IF_HPP | |
13 | ||
92f5a8d4 TL |
14 | #include <boost/static_assert.hpp> |
15 | ||
7c673cae FG |
16 | #include <boost/compute/system.hpp> |
17 | #include <boost/compute/algorithm/copy_if.hpp> | |
18 | #include <boost/compute/container/vector.hpp> | |
19 | #include <boost/compute/functional/logical.hpp> | |
92f5a8d4 | 20 | #include <boost/compute/type_traits/is_device_iterator.hpp> |
7c673cae FG |
21 | |
22 | namespace boost { | |
23 | namespace compute { | |
24 | ||
25 | /// Removes each element for which \p predicate returns \c true in the | |
26 | /// range [\p first, \p last). | |
27 | /// | |
b32b8144 FG |
28 | /// Space complexity: \Omega(3n) |
29 | /// | |
7c673cae FG |
30 | /// \see remove() |
31 | template<class Iterator, class Predicate> | |
32 | inline Iterator remove_if(Iterator first, | |
33 | Iterator last, | |
34 | Predicate predicate, | |
35 | command_queue &queue = system::default_queue()) | |
36 | { | |
92f5a8d4 | 37 | BOOST_STATIC_ASSERT(is_device_iterator<Iterator>::value); |
7c673cae FG |
38 | typedef typename std::iterator_traits<Iterator>::value_type value_type; |
39 | ||
40 | // temporary storage for the input data | |
41 | ::boost::compute::vector<value_type> tmp(first, last, queue); | |
42 | ||
43 | return ::boost::compute::copy_if(tmp.begin(), | |
44 | tmp.end(), | |
45 | first, | |
46 | not1(predicate), | |
47 | queue); | |
48 | } | |
49 | ||
50 | } // end compute namespace | |
51 | } // end boost namespace | |
52 | ||
53 | #endif // BOOST_COMPUTE_ALGORITHM_REMOVE_IF_HPP |