Tier0: fix compiler specific compile error

This code doesn't compile on VS2017 15.6 (does on 2019 and above). We also don't need to ABS; removed the ABS code as the code is currently only used for unsigned types and we probably do want to take the sign into account when getting mins/maxs from signed values too. If not then this could always be ABS'd by the caller to explicitly set the behavior.
This commit is contained in:
Kawe Mazidjatari 2024-11-11 19:50:01 +01:00
parent a809b1f262
commit 9a9e84f974
2 changed files with 7 additions and 20 deletions

View File

@ -92,34 +92,21 @@ string Format(const char* szFormat, ...);
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Array // Array
template <typename Iter, typename Compare> template <typename Iter, typename Compare>
Iter ExtremeElementABS(Iter first, Iter last, Compare compare) inline Iter ExtremeElement(Iter first, Iter last, Compare compare)
{ {
using ValueType = typename std::iterator_traits<Iter>::value_type; return std::min_element(first, last, compare);
auto abs_compare = [compare](ValueType a, ValueType b)
{
if constexpr (std::is_signed_v<ValueType>)
{
return compare(abs(a), abs(b));
}
else
{
return compare(a, b);
}
};
return std::min_element(first, last, abs_compare);
} }
template <typename Iter> // Return lowest element in array. template <typename Iter> // Return lowest element in array.
Iter MinElementABS(Iter first, Iter last) inline Iter MinElement(Iter first, Iter last)
{ {
return ExtremeElementABS(first, last, std::less<>()); return ExtremeElement(first, last, std::less<>());
} }
template <typename Iter> // Return highest element in array. template <typename Iter> // Return highest element in array.
Iter MaxElementABS(Iter first, Iter last) inline Iter MaxElement(Iter first, Iter last)
{ {
return ExtremeElementABS(first, last, std::greater<>()); return ExtremeElement(first, last, std::greater<>());
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -379,7 +379,7 @@ void CCrashHandler::FormatFPU(const char* const pszRegister, const M128A* const
*reinterpret_cast<const FLOAT*>(&nVec[2]), *reinterpret_cast<const FLOAT*>(&nVec[2]),
*reinterpret_cast<const FLOAT*>(&nVec[3])); *reinterpret_cast<const FLOAT*>(&nVec[3]));
const DWORD nHighest = *MaxElementABS(std::begin(nVec), std::end(nVec)); const DWORD nHighest = *MaxElement(std::begin(nVec), std::end(nVec));
if (nHighest >= 1000000) if (nHighest >= 1000000)
{ {