From eb2823231f316887c7f067559e6542234123f524 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Tue, 31 May 2022 17:26:35 +0200 Subject: [PATCH] Work around Windows's definition of `min`/`max` This allows us to use `std::min`/`std::max`. --- CMakeLists.txt | 1 + src/base/math.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 820b11829..9997133fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3013,6 +3013,7 @@ foreach(target ${TARGETS_OWN}) target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool. endif() 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) # C-runtime endif() diff --git a/src/base/math.h b/src/base/math.h index 225d5dfd5..f8de092f7 100644 --- a/src/base/math.h +++ b/src/base/math.h @@ -95,22 +95,22 @@ constexpr float pi = 3.1415926535897932384626433f; template constexpr inline T minimum(T a, T b) { - return a < b ? a : b; + return std::min(a, b); } template 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 constexpr inline T maximum(T a, T b) { - return a > b ? a : b; + return std::max(a, b); } template 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 constexpr inline T absolute(T a)