]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/algorithm/max_element.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / include / 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 /// \see min_element()
47 template<class InputIterator, class Compare>
48 inline InputIterator
49 max_element(InputIterator first,
50 InputIterator last,
51 Compare compare,
52 command_queue &queue = system::default_queue())
53 {
54 return detail::find_extrema(first, last, compare, false, queue);
55 }
56
57 ///\overload
58 template<class InputIterator>
59 inline InputIterator
60 max_element(InputIterator first,
61 InputIterator last,
62 command_queue &queue = system::default_queue())
63 {
64 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
65
66 return ::boost::compute::max_element(
67 first, last, ::boost::compute::less<value_type>(), queue
68 );
69 }
70
71 } // end compute namespace
72 } // end boost namespace
73
74 #endif // BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP