]>
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_COPY_IF_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP | |
13 | ||
14 | #include <boost/compute/algorithm/transform_if.hpp> | |
15 | #include <boost/compute/functional/identity.hpp> | |
16 | ||
17 | namespace boost { | |
18 | namespace compute { | |
19 | namespace detail { | |
20 | ||
21 | // like the copy_if() algorithm but writes the indices of the values for which | |
22 | // predicate returns true. | |
23 | template<class InputIterator, class OutputIterator, class Predicate> | |
24 | inline OutputIterator copy_index_if(InputIterator first, | |
25 | InputIterator last, | |
26 | OutputIterator result, | |
27 | Predicate predicate, | |
28 | command_queue &queue = system::default_queue()) | |
29 | { | |
30 | typedef typename std::iterator_traits<InputIterator>::value_type T; | |
31 | ||
32 | return detail::transform_if_impl( | |
33 | first, last, result, identity<T>(), predicate, true, queue | |
34 | ); | |
35 | } | |
36 | ||
37 | } // end detail namespace | |
38 | ||
39 | /// Copies each element in the range [\p first, \p last) for which | |
40 | /// \p predicate returns \c true to the range beginning at \p result. | |
41 | template<class InputIterator, class OutputIterator, class Predicate> | |
42 | inline OutputIterator copy_if(InputIterator first, | |
43 | InputIterator last, | |
44 | OutputIterator result, | |
45 | Predicate predicate, | |
46 | command_queue &queue = system::default_queue()) | |
47 | { | |
48 | typedef typename std::iterator_traits<InputIterator>::value_type T; | |
49 | ||
50 | return ::boost::compute::transform_if( | |
51 | first, last, result, identity<T>(), predicate, queue | |
52 | ); | |
53 | } | |
54 | ||
55 | } // end compute namespace | |
56 | } // end boost namespace | |
57 | ||
58 | #endif // BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP |