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_PARTITION_COPY_HPP
12 #define BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/functional.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/copy_if.hpp>
22 /// Copies all of the elements in the range [\p first, \p last) for which
23 /// \p predicate returns \c true to the range beginning at \p first_true
24 /// and all of the elements for which \p predicate returns \c false to
25 /// the range beginning at \p first_false.
27 /// Space complexity: \Omega(2n)
30 template<class InputIterator,
31 class OutputIterator1,
32 class OutputIterator2,
34 inline std::pair<OutputIterator1, OutputIterator2>
35 partition_copy(InputIterator first,
37 OutputIterator1 first_true,
38 OutputIterator2 first_false,
39 UnaryPredicate predicate,
40 command_queue &queue = system::default_queue())
43 OutputIterator1 last_true =
44 ::boost::compute::copy_if(first,
51 OutputIterator2 last_false =
52 ::boost::compute::copy_if(first,
58 // return iterators to the end of the true and the false ranges
59 return std::make_pair(last_true, last_false);
62 } // end compute namespace
63 } // end boost namespace
65 #endif // BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP