Add absolute array comparators

Check for highest/lowest value in array (absolute).
This commit is contained in:
Kawe Mazidjatari 2023-04-08 13:32:34 +02:00
parent 16910aa45c
commit 4890593203

View File

@ -84,6 +84,31 @@ string PrintPercentageEscape(const string& svInput);
string FormatV(const char* szFormat, va_list args);
string Format(const char* szFormat, ...);
/////////////////////////////////////////////////////////////////////////////
// Array
template <typename Iter, typename Compare>
Iter ExtremeElementABS(Iter first, Iter last, Compare compare)
{
auto abs_compare = [compare](LONG a, LONG b)
{
return compare(abs(a), abs(b));
};
return std::min_element(first, last, abs_compare);
}
template <typename Iter> // Return lowest element in array.
Iter MinElementABS(Iter first, Iter last)
{
return ExtremeElementABS(first, last, std::less<>());
}
template <typename Iter> // Return highest element in array.
Iter MaxElementABS(Iter first, Iter last)
{
return ExtremeElementABS(first, last, std::greater<>());
}
/////////////////////////////////////////////////////////////////////////////
// Time
std::chrono::nanoseconds IntervalToDuration(const float flInterval);