--- a/sources/basics.h Wed Jan 27 12:41:50 2021 +0200 +++ b/sources/basics.h Wed Jan 27 19:48:41 2021 +0200 @@ -1,5 +1,5 @@ /* - Copyright 2014 - 2016 Teemu Piippo + Copyright 2014 - 2021 Teemu Piippo All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,7 +29,9 @@ */ #pragma once -#include <stdlib.h> +#include <cassert> +#include <cstdlib> +#include <type_traits> #if !defined(_MSC_VER) && !defined(__cdecl) # define __cdecl @@ -72,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; } @@ -89,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; } @@ -106,8 +108,8 @@ return result; } -template<typename T> -T clamp (T a, T b, T c) +template<typename T, typename TT, typename TTT> +constexpr std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c) { return (a < b) ? b : (a > c) ? c : a; } @@ -117,10 +119,16 @@ 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 {}; +#ifdef __GNUC__ +# define GNUATTRIBUTE(X) __attribute__(X) +#else +# define GNUATTRIBUTE(X) +#endif END_ZFC_NAMESPACE