From 7a40df33b649b1d2238f5f5da43283c0ba2ecc9e Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 12 Apr 2017 08:30:29 +0000 Subject: [PATCH] compat.h: Add some infrastructure for C++ template metaprogramming. git-svn-id: https://svn.eduke32.com/eduke32@6117 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/compat.h | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 13ca8b3da..2d37bb5f3 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -197,6 +197,12 @@ # define CONSTEXPR #endif +#if CXXSTD >= 2011 +# define FINAL final +#else +# define FINAL +#endif + #if CXXSTD >= 2014 # define CONSTEXPR_CXX14 CONSTEXPR #else @@ -345,6 +351,11 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 || #include +#ifdef __cplusplus +# if CXXSTD >= 2011 +# include +# endif +#endif ////////// Platform headers ////////// @@ -621,8 +632,40 @@ void eduke32_exit_return(int) ATTRIBUTE((noreturn)); #endif +////////// Metaprogramming structs ////////// + +#ifdef __cplusplus + +# if CXXSTD >= 2011 +using std::is_integral; +# endif + +# if CXXSTD >= 2014 +using std::enable_if_t; +using std::conditional_t; +# elif CXXSTD >= 2011 +template +using enable_if_t = typename std::enable_if::type; +template +using conditional_t = typename std::conditional::type; +# endif + +#endif + + ////////// Typedefs ////////// +#ifdef __cplusplus +// for use in SFINAE constructs in place of the pointer trick (to which 0 can unintentionally be implicitly cast) +struct Dummy FINAL +{ + FORCE_INLINE CONSTEXPR Dummy() : dummy(0) { } + +private: + char dummy; +}; +#endif + typedef struct { int32_t x, y; } vec2_t;