Work around Windows's definition of min/max

This allows us to use `std::min`/`std::max`.
This commit is contained in:
heinrich5991 2022-05-31 17:26:35 +02:00
parent 369c217db5
commit eb2823231f
2 changed files with 5 additions and 4 deletions

View file

@ -3013,6 +3013,7 @@ foreach(target ${TARGETS_OWN})
target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool. target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool.
endif() endif()
if(TARGET_OS STREQUAL "windows") if(TARGET_OS STREQUAL "windows")
target_compile_definitions(${target} PRIVATE NOMINMAX) # windows.h shouldn't define min/max macros
target_compile_definitions(${target} PRIVATE UNICODE) # Windows headers target_compile_definitions(${target} PRIVATE UNICODE) # Windows headers
target_compile_definitions(${target} PRIVATE _UNICODE) # C-runtime target_compile_definitions(${target} PRIVATE _UNICODE) # C-runtime
endif() endif()

View file

@ -95,22 +95,22 @@ constexpr float pi = 3.1415926535897932384626433f;
template<typename T> template<typename T>
constexpr inline T minimum(T a, T b) constexpr inline T minimum(T a, T b)
{ {
return a < b ? a : b; return std::min(a, b);
} }
template<typename T> template<typename T>
constexpr inline T minimum(T a, T b, T c) constexpr inline T minimum(T a, T b, T c)
{ {
return minimum(minimum(a, b), c); return std::min(std::min(a, b), c);
} }
template<typename T> template<typename T>
constexpr inline T maximum(T a, T b) constexpr inline T maximum(T a, T b)
{ {
return a > b ? a : b; return std::max(a, b);
} }
template<typename T> template<typename T>
constexpr inline T maximum(T a, T b, T c) constexpr inline T maximum(T a, T b, T c)
{ {
return maximum(maximum(a, b), c); return std::max(std::max(a, b), c);
} }
template<typename T> template<typename T>
constexpr inline T absolute(T a) constexpr inline T absolute(T a)