defs: use C++ min/max when compiling in C++ mode

This commit is contained in:
Lephe 2023-01-01 18:49:13 +01:00
parent 1272a6a71a
commit d3b29c50e6
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -14,6 +14,11 @@
#define GAUTOTYPE __auto_type #define GAUTOTYPE __auto_type
#endif #endif
#ifdef __cplusplus
#include <algorithm>
using std::min;
using std::max;
#else
/* min(), max() (without double evaluation) */ /* min(), max() (without double evaluation) */
#define min(a, b) ({ \ #define min(a, b) ({ \
GAUTOTYPE _a = (a); \ GAUTOTYPE _a = (a); \
@ -25,6 +30,7 @@
GAUTOTYPE _b = (b); \ GAUTOTYPE _b = (b); \
_a > _b ? _a : _b; \ _a > _b ? _a : _b; \
}) })
#endif
/* sgn() (without double evaluation) */ /* sgn() (without double evaluation) */
#define sgn(s) ({ \ #define sgn(s) ({ \