1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP
12 #define BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP
14 #include <boost/static_assert.hpp>
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>
26 /// Returns \c true if the values in the range [\p first, \p last)
27 /// are in sorted order.
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
34 /// \return \c true if the range [\p first, \p last) is sorted
36 /// Space complexity: \Omega(1)
39 template<class InputIterator, class Compare>
40 inline bool is_sorted(InputIterator first,
43 command_queue &queue = system::default_queue())
45 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
46 using ::boost::compute::placeholders::_1;
47 using ::boost::compute::placeholders::_2;
49 return ::boost::compute::adjacent_find(
50 first, last, ::boost::compute::bind(compare, _2, _1), queue
55 template<class InputIterator>
56 inline bool is_sorted(InputIterator first,
58 command_queue &queue = system::default_queue())
60 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
61 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
63 return ::boost::compute::is_sorted(
64 first, last, ::boost::compute::less<value_type>(), queue
68 } // end compute namespace
69 } // end boost namespace
71 #endif // BOOST_COMPUTE_ALGORITHM_IS_SORTED_HPP