more type traits cleanups

master
Daniel Kolesa 2015-06-04 21:19:05 +01:00
parent 1aeebb69a7
commit 49188f78ea
1 changed files with 226 additions and 208 deletions

View File

@ -24,8 +24,6 @@ namespace detail {
template<typename ...> struct CommonTypeBase; template<typename ...> struct CommonTypeBase;
} }
template<typename> struct __OctaAddLr;
template<typename> struct __OctaAddRr;
template<typename> struct __OctaAddConst; template<typename> struct __OctaAddConst;
template<typename> struct IsReference; template<typename> struct IsReference;
template<typename> struct __OctaRemoveReference; template<typename> struct __OctaRemoveReference;
@ -36,10 +34,10 @@ namespace detail {
using RemoveCv = typename octa::detail::RemoveCv<_T>::Type; using RemoveCv = typename octa::detail::RemoveCv<_T>::Type;
template<typename _T> template<typename _T>
using AddLvalueReference = typename __OctaAddLr<_T>::Type; using AddLvalueReference = typename octa::detail::AddLr<_T>::Type;
template<typename _T> template<typename _T>
using AddRvalueReference = typename __OctaAddRr<_T>::Type; using AddRvalueReference = typename octa::detail::AddRr<_T>::Type;
template<typename _T> template<typename _T>
using AddConst = typename __OctaAddConst<_T>::Type; using AddConst = typename __OctaAddConst<_T>::Type;
@ -56,12 +54,12 @@ namespace detail {
/* integral constant */ /* integral constant */
template<typename _T, _T __val> template<typename _T, _T val>
struct IntegralConstant { struct IntegralConstant {
static constexpr _T value = __val; static constexpr _T value = val;
typedef _T Value; typedef _T Value;
typedef IntegralConstant<_T, __val> Type; typedef IntegralConstant<_T, val> Type;
constexpr operator Value() const { return value; } constexpr operator Value() const { return value; }
constexpr Value operator()() const { return value; } constexpr Value operator()() const { return value; }
@ -74,54 +72,62 @@ namespace detail {
/* is void */ /* is void */
template<typename _T> struct __OctaIsVoid : False {}; namespace detail {
template< > struct __OctaIsVoid<void>: True {}; template<typename _T> struct IsVoidBase : False {};
template< > struct IsVoidBase<void>: True {};
}
template<typename _T> template<typename _T>
struct IsVoid: __OctaIsVoid<RemoveCv<_T>> {}; struct IsVoid: octa::detail::IsVoidBase<RemoveCv<_T>> {};
/* is null pointer */ /* is null pointer */
template<typename> struct __OctaIsNullPointer : False {}; namespace detail {
template< > struct __OctaIsNullPointer<nullptr_t>: True {}; template<typename> struct IsNullPointerBase : False {};
template< > struct IsNullPointerBase<nullptr_t>: True {};
}
template<typename _T> struct IsNullPointer: template<typename _T> struct IsNullPointer:
__OctaIsNullPointer<RemoveCv<_T>> {}; octa::detail::IsNullPointerBase<RemoveCv<_T>> {};
/* is integer */ /* is integer */
template<typename _T> struct __OctaIsIntegral: False {}; namespace detail {
template<typename _T> struct IsIntegralBase: False {};
template<> struct __OctaIsIntegral<bool >: True {}; template<> struct IsIntegralBase<bool >: True {};
template<> struct __OctaIsIntegral<char >: True {}; template<> struct IsIntegralBase<char >: True {};
template<> struct __OctaIsIntegral<uchar >: True {}; template<> struct IsIntegralBase<uchar >: True {};
template<> struct __OctaIsIntegral<schar >: True {}; template<> struct IsIntegralBase<schar >: True {};
template<> struct __OctaIsIntegral<short >: True {}; template<> struct IsIntegralBase<short >: True {};
template<> struct __OctaIsIntegral<ushort>: True {}; template<> struct IsIntegralBase<ushort>: True {};
template<> struct __OctaIsIntegral<int >: True {}; template<> struct IsIntegralBase<int >: True {};
template<> struct __OctaIsIntegral<uint >: True {}; template<> struct IsIntegralBase<uint >: True {};
template<> struct __OctaIsIntegral<long >: True {}; template<> struct IsIntegralBase<long >: True {};
template<> struct __OctaIsIntegral<ulong >: True {}; template<> struct IsIntegralBase<ulong >: True {};
template<> struct __OctaIsIntegral<llong >: True {}; template<> struct IsIntegralBase<llong >: True {};
template<> struct __OctaIsIntegral<ullong>: True {}; template<> struct IsIntegralBase<ullong>: True {};
template<> struct __OctaIsIntegral<char16_t>: True {}; template<> struct IsIntegralBase<char16_t>: True {};
template<> struct __OctaIsIntegral<char32_t>: True {}; template<> struct IsIntegralBase<char32_t>: True {};
template<> struct __OctaIsIntegral< wchar_t>: True {}; template<> struct IsIntegralBase< wchar_t>: True {};
}
template<typename _T> template<typename _T>
struct IsIntegral: __OctaIsIntegral<RemoveCv<_T>> {}; struct IsIntegral: octa::detail::IsIntegralBase<RemoveCv<_T>> {};
/* is floating point */ /* is floating point */
template<typename _T> struct __OctaIsFloatingPoint: False {}; namespace detail {
template<typename _T> struct IsFloatingPointBase: False {};
template<> struct __OctaIsFloatingPoint<float >: True {}; template<> struct IsFloatingPointBase<float >: True {};
template<> struct __OctaIsFloatingPoint<double >: True {}; template<> struct IsFloatingPointBase<double >: True {};
template<> struct __OctaIsFloatingPoint<ldouble>: True {}; template<> struct IsFloatingPointBase<ldouble>: True {};
}
template<typename _T> template<typename _T>
struct IsFloatingPoint: __OctaIsFloatingPoint<RemoveCv<_T>> {}; struct IsFloatingPoint: octa::detail::IsFloatingPointBase<RemoveCv<_T>> {};
/* is array */ /* is array */
@ -131,11 +137,13 @@ namespace detail {
/* is pointer */ /* is pointer */
template<typename > struct __OctaIsPointer : False {}; namespace detail {
template<typename _T> struct __OctaIsPointer<_T *>: True {}; template<typename > struct IsPointerBase : False {};
template<typename _T> struct IsPointerBase<_T *>: True {};
}
template<typename _T> template<typename _T>
struct IsPointer: __OctaIsPointer<RemoveCv<_T>> {}; struct IsPointer: octa::detail::IsPointerBase<RemoveCv<_T>> {};
/* is lvalue reference */ /* is lvalue reference */
@ -205,40 +213,46 @@ template<typename _T> struct IsFunction: octa::detail::IsFunctionBase<_T> {};
/* is pointer to member */ /* is pointer to member */
namespace detail {
template<typename> template<typename>
struct __OctaIsMemberPointer: False {}; struct IsMemberPointerBase: False {};
template<typename _T, typename _U> template<typename _T, typename _U>
struct __OctaIsMemberPointer<_T _U::*>: True {}; struct IsMemberPointerBase<_T _U::*>: True {};
}
template<typename _T> template<typename _T>
struct IsMemberPointer: __OctaIsMemberPointer<RemoveCv<_T>> {}; struct IsMemberPointer: octa::detail::IsMemberPointerBase<RemoveCv<_T>> {};
/* is pointer to member object */ /* is pointer to member object */
namespace detail {
template<typename> template<typename>
struct __OctaIsMemberObjectPointer: False {}; struct IsMemberObjectPointerBase: False {};
template<typename _T, typename _U> template<typename _T, typename _U>
struct __OctaIsMemberObjectPointer<_T _U::*>: IntegralConstant<bool, struct IsMemberObjectPointerBase<_T _U::*>: IntegralConstant<bool,
!IsFunction<_T>::value !octa::IsFunction<_T>::value
> {}; > {};
}
template<typename _T> struct IsMemberObjectPointer: template<typename _T> struct IsMemberObjectPointer:
__OctaIsMemberObjectPointer<RemoveCv<_T>> {}; octa::detail::IsMemberObjectPointerBase<RemoveCv<_T>> {};
/* is pointer to member function */ /* is pointer to member function */
namespace detail {
template<typename> template<typename>
struct __OctaIsMemberFunctionPointer: False {}; struct IsMemberFunctionPointerBase: False {};
template<typename _T, typename _U> template<typename _T, typename _U>
struct __OctaIsMemberFunctionPointer<_T _U::*>: IntegralConstant<bool, struct IsMemberFunctionPointerBase<_T _U::*>: IntegralConstant<bool,
IsFunction<_T>::value octa::IsFunction<_T>::value
> {}; > {};
}
template<typename _T> struct IsMemberFunctionPointer: template<typename _T> struct IsMemberFunctionPointer:
__OctaIsMemberFunctionPointer<RemoveCv<_T>> {}; octa::detail::IsMemberFunctionPointerBase<RemoveCv<_T>> {};
/* is reference */ /* is reference */
@ -753,39 +767,43 @@ namespace detail {
/* add lvalue reference */ /* add lvalue reference */
template<typename _T> struct __OctaAddLr { typedef _T &Type; }; namespace detail {
template<typename _T> struct __OctaAddLr<_T &> { typedef _T &Type; }; template<typename _T> struct AddLr { typedef _T &Type; };
template<typename _T> struct __OctaAddLr<_T &&> { typedef _T &Type; }; template<typename _T> struct AddLr<_T &> { typedef _T &Type; };
template<> struct __OctaAddLr<void> { template<typename _T> struct AddLr<_T &&> { typedef _T &Type; };
template<> struct AddLr<void> {
typedef void Type; typedef void Type;
}; };
template<> struct __OctaAddLr<const void> { template<> struct AddLr<const void> {
typedef const void Type; typedef const void Type;
}; };
template<> struct __OctaAddLr<volatile void> { template<> struct AddLr<volatile void> {
typedef volatile void Type; typedef volatile void Type;
}; };
template<> struct __OctaAddLr<const volatile void> { template<> struct AddLr<const volatile void> {
typedef const volatile void Type; typedef const volatile void Type;
}; };
}
/* add rvalue reference */ /* add rvalue reference */
template<typename _T> struct __OctaAddRr { typedef _T &&Type; }; namespace detail {
template<typename _T> struct __OctaAddRr<_T &> { typedef _T &&Type; }; template<typename _T> struct AddRr { typedef _T &&Type; };
template<typename _T> struct __OctaAddRr<_T &&> { typedef _T &&Type; }; template<typename _T> struct AddRr<_T &> { typedef _T &&Type; };
template<> struct __OctaAddRr<void> { template<typename _T> struct AddRr<_T &&> { typedef _T &&Type; };
template<> struct AddRr<void> {
typedef void Type; typedef void Type;
}; };
template<> struct __OctaAddRr<const void> { template<> struct AddRr<const void> {
typedef const void Type; typedef const void Type;
}; };
template<> struct __OctaAddRr<volatile void> { template<> struct AddRr<volatile void> {
typedef volatile void Type; typedef volatile void Type;
}; };
template<> struct __OctaAddRr<const volatile void> { template<> struct AddRr<const volatile void> {
typedef const volatile void Type; typedef const volatile void Type;
}; };
}
/* remove extent */ /* remove extent */