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