compat.h: Add new types, native_t and unative_t, functionally equivalent to our current bssize_t and bsize_t, respectively, but generated dependably using template metaprogramming when building with C++ >= 11.

git-svn-id: https://svn.eduke32.com/eduke32@6118 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-04-12 08:30:32 +00:00
parent 7a40df33b6
commit 73654c2079

View file

@ -650,6 +650,33 @@ template<bool B, class T, class F>
using conditional_t = typename std::conditional<B, T, F>::type;
# endif
template <size_t size>
struct integers_of_size { };
template <>
struct integers_of_size<sizeof(int8_t)>
{
typedef int8_t i;
typedef uint8_t u;
};
template <>
struct integers_of_size<sizeof(int16_t)>
{
typedef int16_t i;
typedef uint16_t u;
};
template <>
struct integers_of_size<sizeof(int32_t)>
{
typedef int32_t i;
typedef uint32_t u;
};
template <>
struct integers_of_size<sizeof(int64_t)>
{
typedef int64_t i;
typedef uint64_t u;
};
#endif
@ -666,6 +693,15 @@ private:
};
#endif
#if CXXSTD >= 2011
using native_t = typename integers_of_size<sizeof(size_t)>::i;
using unative_t = typename integers_of_size<sizeof(size_t)>::u;
#else
typedef ssize_t native_t;
typedef size_t unative_t;
#endif
EDUKE32_STATIC_ASSERT(sizeof(native_t) == sizeof(unative_t));
typedef struct {
int32_t x, y;
} vec2_t;