]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/partition_copy.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / compute / algorithm / partition_copy.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP
12 #define BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/functional.hpp>
18 #include <boost/compute/command_queue.hpp>
19 #include <boost/compute/algorithm/copy_if.hpp>
20 #include <boost/compute/type_traits/is_device_iterator.hpp>
21
22 namespace boost {
23 namespace compute {
24
25 /// Copies all of the elements in the range [\p first, \p last) for which
26 /// \p predicate returns \c true to the range beginning at \p first_true
27 /// and all of the elements for which \p predicate returns \c false to
28 /// the range beginning at \p first_false.
29 ///
30 /// Space complexity: \Omega(2n)
31 ///
32 /// \see partition()
33 template<class InputIterator,
34 class OutputIterator1,
35 class OutputIterator2,
36 class UnaryPredicate>
37 inline std::pair<OutputIterator1, OutputIterator2>
38 partition_copy(InputIterator first,
39 InputIterator last,
40 OutputIterator1 first_true,
41 OutputIterator2 first_false,
42 UnaryPredicate predicate,
43 command_queue &queue = system::default_queue())
44 {
45 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
46 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator1>::value);
47 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator2>::value);
48
49 // copy true values
50 OutputIterator1 last_true =
51 ::boost::compute::copy_if(first,
52 last,
53 first_true,
54 predicate,
55 queue);
56
57 // copy false values
58 OutputIterator2 last_false =
59 ::boost::compute::copy_if(first,
60 last,
61 first_false,
62 not1(predicate),
63 queue);
64
65 // return iterators to the end of the true and the false ranges
66 return std::make_pair(last_true, last_false);
67 }
68
69 } // end compute namespace
70 } // end boost namespace
71
72 #endif // BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP