sources/basics.h

changeset 191
2e6cbacafdc7
parent 190
90bf9049e5eb
child 192
94c67ae846fc
--- a/sources/basics.h	Wed Jan 27 19:28:18 2021 +0200
+++ b/sources/basics.h	Wed Jan 27 19:32:55 2021 +0200
@@ -30,8 +30,8 @@
 
 #pragma once
 #include <cassert>
+#include <cstdlib>
 #include <type_traits>
-#include <stdlib.h>
 
 #if !defined(_MSC_VER) && !defined(__cdecl)
 # define __cdecl
@@ -74,8 +74,8 @@
 
 BEGIN_ZFC_NAMESPACE
 
-template<typename T>
-T min (T a, T b)
+template<typename T, typename TT>
+constexpr std::common_type_t<T, TT> min(T a, TT b)
 {
 	return (a < b) ? a : b;
 }
@@ -91,8 +91,8 @@
 	return result;
 }
 
-template<typename T>
-T max (T a, T b)
+template<typename T, typename TT>
+constexpr std::common_type_t<T, TT> max(T a, TT b)
 {
 	return (a > b) ? a : b;
 }
@@ -109,7 +109,7 @@
 }
 
 template<typename T, typename TT, typename TTT>
-std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c)
+constexpr std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c)
 {
 	return (a < b) ? b : (a > c) ? c : a;
 }
@@ -119,9 +119,11 @@
 	return value != 1 ? "s" : "";
 }
 
-template <typename T, size_t N>
-char (&_ArraySizeHelper(T (&array)[N]))[N];
-#define countof(array) (sizeof(_ArraySizeHelper( array )))
+template<typename T, std::size_t N>
+constexpr std::size_t countof(T(&)[N])
+{
+	return N;
+}
 
 struct Exitception {};
 

mercurial