[*] Terachad casts

This commit is contained in:
Reece Wilson 2022-03-09 16:09:13 +00:00
parent a7d0e0a261
commit e4ed0856de
2 changed files with 51 additions and 6 deletions

View File

@ -8,9 +8,27 @@
#pragma once
template<class T, class Z>
T *AuStaticCast(Z *other)
AuConditional_t<AuIsPointer_v<T>, T, T *> AuStaticCast(Z *other)
{
return static_cast<T *>(other);
return static_cast<AuConditional_t<AuIsPointer_v<T>, T, T *>>(other);
}
template<class T, class Z>
AuConditional_t<AuIsReference_v<T>, T, T &> AuStaticCast(Z &other)
{
return static_cast<AuConditional_t<AuIsReference_v<T>, T, T &>>(other);
}
template<class T, class Z>
AuConditional_t<AuIsReference_v<T>, T, T &&> AuStaticCast(Z &&other)
{
return static_cast<AuConditional_t<AuIsReference_v<T>, T, T &&>>(other);
}
template<typename T, class Z>
T AuStaticCast(Z other)
{
return static_cast<T>(other);
}
template<class T, class Z>
@ -26,9 +44,27 @@ AuSPtr<T> AuStaticCast(AuSPtr<Z> &&other)
}
template<class T, class Z>
T *AuConstCast(Z *other)
AuConditional_t<AuIsPointer_v<T>, T, T *> AuConstCast(Z *other)
{
return const_cast<T *>(other);
return const_cast<AuConditional_t<AuIsPointer_v<T>, T, T *>>(other);
}
template<class T, class Z>
AuConditional_t<AuIsReference_v<T>, T, T &> AuConstCast(Z &other)
{
return const_cast<AuConditional_t<AuIsReference_v<T>, T, T &>>(other);
}
template<class T, class Z>
AuConditional_t<AuIsReference_v<T>, T, T &&> AuConstCast(Z &&other)
{
return const_cast<AuConditional_t<AuIsReference_v<T>, T, T &&>>(other);
}
template<typename T, class Z>
T AuConstCast(Z other)
{
return const_cast<T>(other);
}
template<class T, class Z>
@ -44,9 +80,9 @@ AuSPtr<T> AuConstCast(AuSPtr<Z> &&other)
}
template<class T, class Z>
T *AuReinterpretCast(Z *other)
AuConditional_t<AuIsClass_v<T> && !AuIsPointer_v<T> && AuIsPointer_v<Z>, T *, T> AuReinterpretCast(Z other)
{
return reinterpret_cast<T *>(other);
return reinterpret_cast<AuConditional_t<AuIsClass_v<T> && !AuIsPointer_v<T> &&AuIsPointer_v<Z>, T *, T>>(other);
}
template<class T, class Z>

View File

@ -99,6 +99,15 @@ inline constexpr bool AuIsPointer_v<T *volatile> = true;
template<class T>
inline constexpr bool AuIsPointer_v<T *const volatile> = true;
template<class>
inline constexpr bool AuIsReference_v = false;
template<class T>
inline constexpr bool AuIsReference_v<T &> = true;
template<class T>
inline constexpr bool AuIsReference_v<T &&> = true;
template<class T>
struct AuRemovePointer
{