Back to home page

EIC code displayed by LXR

 
 

    


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

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_PARTITION_COPY_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/system.hpp>
0017 #include <boost/compute/functional.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/copy_if.hpp>
0020 #include <boost/compute/type_traits/is_device_iterator.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// Copies all of the elements in the range [\p first, \p last) for which
0026 /// \p predicate returns \c true to the range beginning at \p first_true
0027 /// and all of the elements for which \p predicate returns \c false to
0028 /// the range beginning at \p first_false.
0029 ///
0030 /// Space complexity: \Omega(2n)
0031 ///
0032 /// \see partition()
0033 template<class InputIterator,
0034          class OutputIterator1,
0035          class OutputIterator2,
0036          class UnaryPredicate>
0037 inline std::pair<OutputIterator1, OutputIterator2>
0038 partition_copy(InputIterator first,
0039                InputIterator last,
0040                OutputIterator1 first_true,
0041                OutputIterator2 first_false,
0042                UnaryPredicate predicate,
0043                command_queue &queue = system::default_queue())
0044 {
0045     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0046     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator1>::value);
0047     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator2>::value);
0048 
0049     // copy true values
0050     OutputIterator1 last_true =
0051         ::boost::compute::copy_if(first,
0052                                   last,
0053                                   first_true,
0054                                   predicate,
0055                                   queue);
0056 
0057     // copy false values
0058     OutputIterator2 last_false =
0059         ::boost::compute::copy_if(first,
0060                                   last,
0061                                   first_false,
0062                                   not1(predicate),
0063                                   queue);
0064 
0065     // return iterators to the end of the true and the false ranges
0066     return std::make_pair(last_true, last_false);
0067 }
0068 
0069 } // end compute namespace
0070 } // end boost namespace
0071 
0072 #endif // BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP