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/static_assert.hpp>
16 #include <boost/compute/algorithm/transform_if.hpp>
17 #include <boost/compute/functional/identity.hpp>
18 #include <boost/compute/type_traits/is_device_iterator.hpp>
24 // like the copy_if() algorithm but writes the indices of the values for which
25 // predicate returns true.
26 template<class InputIterator, class OutputIterator, class Predicate>
27 inline OutputIterator copy_index_if(InputIterator first,
29 OutputIterator result,
31 command_queue &queue = system::default_queue())
33 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
34 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
35 typedef typename std::iterator_traits<InputIterator>::value_type T;
37 return detail::transform_if_impl(
38 first, last, result, identity<T>(), predicate, true, queue
42 } // end detail namespace
44 /// Copies each element in the range [\p first, \p last) for which
45 /// \p predicate returns \c true to the range beginning at \p result.
47 /// Space complexity: \Omega(2n)
48 template<class InputIterator, class OutputIterator, class Predicate>
49 inline OutputIterator copy_if(InputIterator first,
51 OutputIterator result,
53 command_queue &queue = system::default_queue())
55 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
56 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
57 typedef typename std::iterator_traits<InputIterator>::value_type T;
59 return ::boost::compute::transform_if(
60 first, last, result, identity<T>(), predicate, queue
64 } // end compute namespace
65 } // end boost namespace
67 #endif // BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP