Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:56

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/algorithm/transform_if.hpp>
0017 #include <boost/compute/functional/identity.hpp>
0018 #include <boost/compute/type_traits/is_device_iterator.hpp>
0019 
0020 namespace boost {
0021 namespace compute {
0022 namespace detail {
0023 
0024 // like the copy_if() algorithm but writes the indices of the values for which
0025 // predicate returns true.
0026 template<class InputIterator, class OutputIterator, class Predicate>
0027 inline OutputIterator copy_index_if(InputIterator first,
0028                                     InputIterator last,
0029                                     OutputIterator result,
0030                                     Predicate predicate,
0031                                     command_queue &queue = system::default_queue())
0032 {
0033     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0034     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0035     typedef typename std::iterator_traits<InputIterator>::value_type T;
0036 
0037     return detail::transform_if_impl(
0038         first, last, result, identity<T>(), predicate, true, queue
0039     );
0040 }
0041 
0042 } // end detail namespace
0043 
0044 /// Copies each element in the range [\p first, \p last) for which
0045 /// \p predicate returns \c true to the range beginning at \p result.
0046 ///
0047 /// Space complexity: \Omega(2n)
0048 template<class InputIterator, class OutputIterator, class Predicate>
0049 inline OutputIterator copy_if(InputIterator first,
0050                               InputIterator last,
0051                               OutputIterator result,
0052                               Predicate predicate,
0053                               command_queue &queue = system::default_queue())
0054 {
0055     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0056     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0057     typedef typename std::iterator_traits<InputIterator>::value_type T;
0058 
0059     return ::boost::compute::transform_if(
0060         first, last, result, identity<T>(), predicate, queue
0061     );
0062 }
0063 
0064 } // end compute namespace
0065 } // end boost namespace
0066 
0067 #endif // BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP