1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
14 #include <boost/compute/algorithm/transform_if.hpp>
15 #include <boost/compute/functional/identity.hpp>
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,
26 OutputIterator result,
28 command_queue &queue = system::default_queue())
30 typedef typename std::iterator_traits<InputIterator>::value_type T;
32 return detail::transform_if_impl(
33 first, last, result, identity<T>(), predicate, true, queue
37 } // end detail namespace
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.
42 /// Space complexity: \Omega(2n)
43 template<class InputIterator, class OutputIterator, class Predicate>
44 inline OutputIterator copy_if(InputIterator first,
46 OutputIterator result,
48 command_queue &queue = system::default_queue())
50 typedef typename std::iterator_traits<InputIterator>::value_type T;
52 return ::boost::compute::transform_if(
53 first, last, result, identity<T>(), predicate, queue
57 } // end compute namespace
58 } // end boost namespace
60 #endif // BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP