[+] AuSizeOf

[+] AuOffsetOf
This commit is contained in:
Reece Wilson 2023-02-04 23:54:19 +00:00
parent ecc13f0349
commit c82dd26f03

View File

@ -189,6 +189,52 @@ static constexpr AuUInt AuArraySize(const T(&array)[Z])
return Z;
}
template <typename T, typename C>
#if defined(__INTELLISENSE__)
// Visual Studio is smart enough to parse the constexpr expression properly
// CL.exe however, will not. It's useful enough for figuring out magic numbers
// in the VS, but not much else.
constexpr
#else
static
#endif
AuUInt AuOffsetOf(C T:: *offset)
{
#if defined(__INTELLISENSE__)
constexpr T *nil = nullptr;
constexpr C *nil2 = &(nil->*offset);
return AuUInt(nil2);
#else
return AuUInt(
&(((const T *)(nullptr))->*offset)
);
#endif
}
template <typename T>
constexpr AuUInt AuSizeOf()
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T &)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const T *)
{
return sizeof(T);
}
template <typename T>
constexpr AuUInt AuSizeOf(const AuSPtr<T>)
{
return sizeof(T);
}
#if defined(DEBUG) || defined(STAGING)
template <class ... T>