]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/minmax_element.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / minmax_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_MINMAX_ELEMENT_HPP
12 #define BOOST_COMPUTE_ALGORITHM_MINMAX_ELEMENT_HPP
13
14 #include <utility>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/max_element.hpp>
19 #include <boost/compute/algorithm/min_element.hpp>
20
21 namespace boost {
22 namespace compute {
23
24 /// Returns a pair of iterators with the first pointing to the minimum
25 /// element and the second pointing to the maximum element in the range
26 /// [\p first, \p last).
27 ///
28 /// \param first first element in the input range
29 /// \param last last element in the input range
30 /// \param compare comparison function object which returns true if the first
31 /// argument is less than (i.e. is ordered before) the second.
32 /// \param queue command queue to perform the operation
33 ///
34 /// Space complexity on CPUs: \Omega(1)<br>
35 /// Space complexity on GPUs: \Omega(N)
36 ///
37 /// \see max_element(), min_element()
38 template<class InputIterator, class Compare>
39 inline std::pair<InputIterator, InputIterator>
40 minmax_element(InputIterator first,
41 InputIterator last,
42 Compare compare,
43 command_queue &queue = system::default_queue())
44 {
45 if(first == last){
46 // empty range
47 return std::make_pair(first, first);
48 }
49
50 return std::make_pair(min_element(first, last, compare, queue),
51 max_element(first, last, compare, queue));
52 }
53
54 ///\overload
55 template<class InputIterator>
56 inline std::pair<InputIterator, InputIterator>
57 minmax_element(InputIterator first,
58 InputIterator last,
59 command_queue &queue = system::default_queue())
60 {
61 if(first == last){
62 // empty range
63 return std::make_pair(first, first);
64 }
65
66 return std::make_pair(min_element(first, last, queue),
67 max_element(first, last, queue));
68 }
69
70 } // end compute namespace
71 } // end boost namespace
72
73 #endif // BOOST_COMPUTE_ALGORITHM_MINMAX_ELEMENT_HPP