]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/copy_if.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / copy_if.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_COPY_IF_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/algorithm/transform_if.hpp>
17 #include <boost/compute/functional/identity.hpp>
18 #include <boost/compute/type_traits/is_device_iterator.hpp>
19
20 namespace boost {
21 namespace compute {
22 namespace detail {
23
24 // like the copy_if() algorithm but writes the indices of the values for which
25 // predicate returns true.
26 template<class InputIterator, class OutputIterator, class Predicate>
27 inline OutputIterator copy_index_if(InputIterator first,
28 InputIterator last,
29 OutputIterator result,
30 Predicate predicate,
31 command_queue &queue = system::default_queue())
32 {
33 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
34 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
35 typedef typename std::iterator_traits<InputIterator>::value_type T;
36
37 return detail::transform_if_impl(
38 first, last, result, identity<T>(), predicate, true, queue
39 );
40 }
41
42 } // end detail namespace
43
44 /// Copies each element in the range [\p first, \p last) for which
45 /// \p predicate returns \c true to the range beginning at \p result.
46 ///
47 /// Space complexity: \Omega(2n)
48 template<class InputIterator, class OutputIterator, class Predicate>
49 inline OutputIterator copy_if(InputIterator first,
50 InputIterator last,
51 OutputIterator result,
52 Predicate predicate,
53 command_queue &queue = system::default_queue())
54 {
55 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
56 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
57 typedef typename std::iterator_traits<InputIterator>::value_type T;
58
59 return ::boost::compute::transform_if(
60 first, last, result, identity<T>(), predicate, queue
61 );
62 }
63
64 } // end compute namespace
65 } // end boost namespace
66
67 #endif // BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP