]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/partition_copy.hpp
update sources to v12.2.3
[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/compute/system.hpp>
15 #include <boost/compute/functional.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/copy_if.hpp>
18
19 namespace boost {
20 namespace compute {
21
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.
26 ///
27 /// Space complexity: \Omega(2n)
28 ///
29 /// \see partition()
30 template<class InputIterator,
31 class OutputIterator1,
32 class OutputIterator2,
33 class UnaryPredicate>
34 inline std::pair<OutputIterator1, OutputIterator2>
35 partition_copy(InputIterator first,
36 InputIterator last,
37 OutputIterator1 first_true,
38 OutputIterator2 first_false,
39 UnaryPredicate predicate,
40 command_queue &queue = system::default_queue())
41 {
42 // copy true values
43 OutputIterator1 last_true =
44 ::boost::compute::copy_if(first,
45 last,
46 first_true,
47 predicate,
48 queue);
49
50 // copy false values
51 OutputIterator2 last_false =
52 ::boost::compute::copy_if(first,
53 last,
54 first_false,
55 not1(predicate),
56 queue);
57
58 // return iterators to the end of the true and the false ranges
59 return std::make_pair(last_true, last_false);
60 }
61
62 } // end compute namespace
63 } // end boost namespace
64
65 #endif // BOOST_COMPUTE_ALGORITHM_PARTITION_COPY_HPP