]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/is_sorted.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / compute / algorithm / is_sorted.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 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_IS_SORTED_HPP
12 #define BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/functional/bind.hpp>
19 #include <boost/compute/functional/operator.hpp>
20 #include <boost/compute/algorithm/adjacent_find.hpp>
21 #include <boost/compute/type_traits/is_device_iterator.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Returns \c true if the values in the range [\p first, \p last)
27 /// are in sorted order.
28 ///
29 /// \param first first element in the range to check
30 /// \param last last element in the range to check
31 /// \param compare comparison function (by default \c less)
32 /// \param queue command queue to perform the operation
33 ///
34 /// \return \c true if the range [\p first, \p last) is sorted
35 ///
36 /// Space complexity: \Omega(1)
37 ///
38 /// \see sort()
39 template<class InputIterator, class Compare>
40 inline bool is_sorted(InputIterator first,
41 InputIterator last,
42 Compare compare,
43 command_queue &queue = system::default_queue())
44 {
45 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
46 using ::boost::compute::placeholders::_1;
47 using ::boost::compute::placeholders::_2;
48
49 return ::boost::compute::adjacent_find(
50 first, last, ::boost::compute::bind(compare, _2, _1), queue
51 ) == last;
52 }
53
54 /// \overload
55 template<class InputIterator>
56 inline bool is_sorted(InputIterator first,
57 InputIterator last,
58 command_queue &queue = system::default_queue())
59 {
60 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
61 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
62
63 return ::boost::compute::is_sorted(
64 first, last, ::boost::compute::less<value_type>(), queue
65 );
66 }
67
68 } // end compute namespace
69 } // end boost namespace
70
71 #endif // BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP