mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Add absolute array comparators
Check for highest/lowest value in array (absolute).
This commit is contained in:
parent
16910aa45c
commit
4890593203
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user