]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/max_element.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / max_element.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_MAX_ELEMENT_HPP
12 #define BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP
13
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/functional.hpp>
17 #include <boost/compute/algorithm/detail/find_extrema.hpp>
18
19 namespace boost {
20 namespace compute {
21
22 /// Returns an iterator pointing to the element in the range
23 /// [\p first, \p last) with the maximum value.
24 ///
25 /// \param first first element in the input range
26 /// \param last last element in the input range
27 /// \param compare comparison function object which returns true if the first
28 /// argument is less than (i.e. is ordered before) the second.
29 /// \param queue command queue to perform the operation
30 ///
31 /// For example, to find \c int2 value with maximum first component in given vector:
32 /// \code
33 /// // comparison function object
34 /// BOOST_COMPUTE_FUNCTION(bool, compare_first, (const int2_ &a, const int2_ &b),
35 /// {
36 /// return a.x < b.x;
37 /// });
38 ///
39 /// // create vector
40 /// boost::compute::vector<uint2_> data = ...
41 ///
42 /// boost::compute::vector<uint2_>::iterator max =
43 /// boost::compute::max_element(data.begin(), data.end(), compare_first, queue);
44 /// \endcode
45 ///
46 /// Space complexity on CPUs: \Omega(1)<br>
47 /// Space complexity on GPUs: \Omega(N)
48 ///
49 /// \see min_element()
50 template<class InputIterator, class Compare>
51 inline InputIterator
52 max_element(InputIterator first,
53 InputIterator last,
54 Compare compare,
55 command_queue &queue = system::default_queue())
56 {
57 return detail::find_extrema(first, last, compare, false, queue);
58 }
59
60 ///\overload
61 template<class InputIterator>
62 inline InputIterator
63 max_element(InputIterator first,
64 InputIterator last,
65 command_queue &queue = system::default_queue())
66 {
67 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
68
69 return ::boost::compute::max_element(
70 first, last, ::boost::compute::less<value_type>(), queue
71 );
72 }
73
74 } // end compute namespace
75 } // end boost namespace
76
77 #endif // BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP