ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
find_extremes.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_FIND_EXTREMES_HPP
2#define RITSUKO_FIND_EXTREMES_HPP
3
5#include <limits>
6
12namespace ritsuko {
13
21 bool has_lowest = false;
22
26 bool has_highest = false;
27
31 bool has_zero = false;
32};
33
52template<class Iterator, class Mask, class Type_ = typename std::remove_cv<typename std::remove_reference<decltype(*(std::declval<Iterator>()))>::type>::type>
53IntegerExtremes find_integer_extremes(Iterator start, Iterator end, Mask mask) {
54 static_assert(std::numeric_limits<Type_>::is_integer);
55
56 IntegerExtremes output;
57 output.has_zero = found(start, end, mask, 0);
58 output.has_highest = found(start, end, mask, std::numeric_limits<Type_>::max());
59
60 if constexpr(std::numeric_limits<Type_>::is_signed) {
61 output.has_lowest = found(start, end, mask, std::numeric_limits<Type_>::min());
62 } else {
63 output.has_lowest = output.has_zero;
64 }
65
66 return output;
67}
68
80template<class Iterator, class Type_ = typename std::remove_cv<typename std::remove_reference<decltype(*(std::declval<Iterator>()))>::type>::type>
81IntegerExtremes find_integer_extremes(Iterator start, Iterator end) {
82 return find_integer_extremes(start, end, false);
83}
84
92 bool has_nan = false;
93
97 bool has_positive_inf = false;
98
102 bool has_negative_inf = false;
103
108 bool has_lowest = false;
109
114 bool has_highest = false;
115
119 bool has_zero = false;
120};
121
143template<class Iterator, class Mask, class Type_ = typename std::remove_cv<typename std::remove_reference<decltype(*(std::declval<Iterator>()))>::type>::type>
144FloatExtremes find_float_extremes(Iterator start, Iterator end, Mask mask, bool skip_nan) {
145 FloatExtremes output;
146
147 if constexpr(std::numeric_limits<Type_>::is_iec559) {
148 if (!skip_nan) {
149 output.has_nan = check_for_nan(start, end, mask);
150 }
151
152 auto inf = std::numeric_limits<Type_>::infinity();
153 output.has_positive_inf = found(start, end, mask, inf);
154 output.has_negative_inf = found(start, end, mask, -inf);
155 }
156
157 output.has_lowest = found(start, end, mask, std::numeric_limits<Type_>::lowest());
158 output.has_highest = found(start, end, mask, std::numeric_limits<Type_>::max());
159 output.has_zero = found(start, end, mask, 0);
160
161 return output;
162}
163
177template<class Iterator, class Type_ = typename std::remove_cv<typename std::remove_reference<decltype(*(std::declval<Iterator>()))>::type>::type>
178FloatExtremes find_float_extremes(Iterator start, Iterator end, bool skip_nan = false) {
179 return find_float_extremes(start, end, false, skip_nan);
180}
181
182}
183
184#endif
Choose a placeholder for missing values.
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
FloatExtremes find_float_extremes(Iterator start, Iterator end, Mask mask, bool skip_nan)
Definition find_extremes.hpp:144
IntegerExtremes find_integer_extremes(Iterator start, Iterator end, Mask mask)
Definition find_extremes.hpp:53
Extremes for float types.
Definition find_extremes.hpp:88
bool has_lowest
Definition find_extremes.hpp:108
bool has_highest
Definition find_extremes.hpp:114
bool has_nan
Definition find_extremes.hpp:92
bool has_positive_inf
Definition find_extremes.hpp:97
bool has_negative_inf
Definition find_extremes.hpp:102
bool has_zero
Definition find_extremes.hpp:119
Extremes for integer types.
Definition find_extremes.hpp:17
bool has_lowest
Definition find_extremes.hpp:21
bool has_highest
Definition find_extremes.hpp:26
bool has_zero
Definition find_extremes.hpp:31