17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_MIN_MAX_CLAMP_HPP
23#define KOKKOS_MIN_MAX_CLAMP_HPP
25#include <Kokkos_Macros.hpp>
28#include <initializer_list>
34constexpr KOKKOS_INLINE_FUNCTION
const T& clamp(
const T& value,
const T& lo,
36 KOKKOS_EXPECTS(!(hi < lo));
37 return (value < lo) ? lo : (hi < value) ? hi : value;
40template <
class T,
class ComparatorType>
41constexpr KOKKOS_INLINE_FUNCTION
const T& clamp(
const T& value,
const T& lo,
43 ComparatorType comp) {
44 KOKKOS_EXPECTS(!comp(hi, lo));
45 return comp(value, lo) ? lo : comp(hi, value) ? hi : value;
50constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b) {
51 return (a < b) ? b : a;
54template <
class T,
class ComparatorType>
55constexpr KOKKOS_INLINE_FUNCTION
const T& max(
const T& a,
const T& b,
56 ComparatorType comp) {
57 return comp(a, b) ? b : a;
61KOKKOS_INLINE_FUNCTION
constexpr T max(std::initializer_list<T> ilist) {
62 auto first = ilist.begin();
63 auto const last = ilist.end();
65 if (first == last)
return result;
66 while (++first != last) {
67 if (result < *first) result = *first;
72template <
class T,
class Compare>
73KOKKOS_INLINE_FUNCTION
constexpr T max(std::initializer_list<T> ilist,
75 auto first = ilist.begin();
76 auto const last = ilist.end();
78 if (first == last)
return result;
79 while (++first != last) {
80 if (comp(result, *first)) result = *first;
87constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b) {
88 return (b < a) ? b : a;
91template <
class T,
class ComparatorType>
92constexpr KOKKOS_INLINE_FUNCTION
const T& min(
const T& a,
const T& b,
93 ComparatorType comp) {
94 return comp(b, a) ? b : a;
98KOKKOS_INLINE_FUNCTION
constexpr T min(std::initializer_list<T> ilist) {
99 auto first = ilist.begin();
100 auto const last = ilist.end();
101 auto result = *first;
102 if (first == last)
return result;
103 while (++first != last) {
104 if (*first < result) result = *first;
109template <
class T,
class Compare>
110KOKKOS_INLINE_FUNCTION
constexpr T min(std::initializer_list<T> ilist,
112 auto first = ilist.begin();
113 auto const last = ilist.end();
114 auto result = *first;
115 if (first == last)
return result;
116 while (++first != last) {
117 if (comp(*first, result)) result = *first;
124constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b) {
126 return (b < a) ? return_t{b, a} : return_t{a, b};
129template <
class T,
class ComparatorType>
130constexpr KOKKOS_INLINE_FUNCTION
auto minmax(
const T& a,
const T& b,
131 ComparatorType comp) {
133 return comp(b, a) ? return_t{b, a} : return_t{a, b};
138 std::initializer_list<T> ilist) {
139 auto first = ilist.begin();
140 auto const last = ilist.end();
143 if (first == last || ++next == last)
return result;
145 result.first = *next;
147 result.second = *next;
149 while (++first != last) {
150 if (++next == last) {
151 if (*first < result.first)
152 result.first = *first;
153 else if (!(*first < result.second))
154 result.second = *first;
157 if (*next < *first) {
158 if (*next < result.first) result.first = *next;
159 if (!(*first < result.second)) result.second = *first;
161 if (*first < result.first) result.first = *first;
162 if (!(*next < result.second)) result.second = *next;
169template <
class T,
class Compare>
171 std::initializer_list<T> ilist, Compare comp) {
172 auto first = ilist.begin();
173 auto const last = ilist.end();
176 if (first == last || ++next == last)
return result;
177 if (comp(*next, *first))
178 result.first = *next;
180 result.second = *next;
182 while (++first != last) {
183 if (++next == last) {
184 if (comp(*first, result.first))
185 result.first = *first;
186 else if (!comp(*first, result.second))
187 result.second = *first;
190 if (comp(*next, *first)) {
191 if (comp(*next, result.first)) result.first = *next;
192 if (!comp(*first, result.second)) result.second = *first;
194 if (comp(*first, result.first)) result.first = *first;
195 if (!comp(*next, result.second)) result.second = *next;
202#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
204using ::Kokkos::clamp;
207using ::Kokkos::minmax;
Declaration and definition of Kokkos::pair.
A thread safe view to a bitset.