1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 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_MAX_ELEMENT_HPP
12 #define BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP
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>
22 /// Returns an iterator pointing to the element in the range
23 /// [\p first, \p last) with the maximum value.
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
31 /// For example, to find \c int2 value with maximum first component in given vector:
33 /// // comparison function object
34 /// BOOST_COMPUTE_FUNCTION(bool, compare_first, (const int2_ &a, const int2_ &b),
40 /// boost::compute::vector<uint2_> data = ...
42 /// boost::compute::vector<uint2_>::iterator max =
43 /// boost::compute::max_element(data.begin(), data.end(), compare_first, queue);
46 /// \see min_element()
47 template<class InputIterator, class Compare>
49 max_element(InputIterator first,
52 command_queue &queue = system::default_queue())
54 return detail::find_extrema(first, last, compare, false, queue);
58 template<class InputIterator>
60 max_element(InputIterator first,
62 command_queue &queue = system::default_queue())
64 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
66 return ::boost::compute::max_element(
67 first, last, ::boost::compute::less<value_type>(), queue
71 } // end compute namespace
72 } // end boost namespace
74 #endif // BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP