]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_MIN_ELEMENT_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_MIN_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 range | |
23 | /// [\p first, \p last) with the minimum 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 minimum 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 min = | |
43 | /// boost::compute::min_element(data.begin(), data.end(), compare_first, queue); | |
44 | /// \endcode | |
45 | /// | |
46 | /// \see max_element() | |
47 | template<class InputIterator, class Compare> | |
48 | inline InputIterator | |
49 | min_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, true, queue); | |
55 | } | |
56 | ||
57 | ///\overload | |
58 | template<class InputIterator> | |
59 | inline InputIterator | |
60 | min_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::min_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_MIN_ELEMENT_HPP |