]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/unique.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / compute / algorithm / unique.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@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_UNIQUE_HPP
12 #define BOOST_COMPUTE_ALGORITHM_UNIQUE_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/unique_copy.hpp>
19 #include <boost/compute/container/vector.hpp>
20 #include <boost/compute/functional/operator.hpp>
21 #include <boost/compute/type_traits/is_device_iterator.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Removes all consecutive duplicate elements (determined by \p op) from the
27 /// range [first, last). If \p op is not provided, the equality operator is
28 /// used.
29 ///
30 /// \param first first element in the input range
31 /// \param last last element in the input range
32 /// \param op binary operator used to check for uniqueness
33 /// \param queue command queue to perform the operation
34 ///
35 /// \return \c InputIterator to the new logical end of the range
36 ///
37 /// Space complexity: \Omega(4n)
38 ///
39 /// \see unique_copy()
40 template<class InputIterator, class BinaryPredicate>
41 inline InputIterator unique(InputIterator first,
42 InputIterator last,
43 BinaryPredicate op,
44 command_queue &queue = system::default_queue())
45 {
46 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
47 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
48
49 vector<value_type> temp(first, last, queue);
50
51 return ::boost::compute::unique_copy(
52 temp.begin(), temp.end(), first, op, queue
53 );
54 }
55
56 /// \overload
57 template<class InputIterator>
58 inline InputIterator unique(InputIterator first,
59 InputIterator last,
60 command_queue &queue = system::default_queue())
61 {
62 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
63 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
64
65 return ::boost::compute::unique(
66 first, last, ::boost::compute::equal_to<value_type>(), queue
67 );
68 }
69
70 } // end compute namespace
71 } // end boost namespace
72
73 #endif // BOOST_COMPUTE_ALGORITHM_UNIQUE_HPP