some traits cleanup

This commit is contained in:
q66 2015-05-06 19:52:07 +01:00
parent a6bb089283
commit 680c0da0a6

View file

@ -24,8 +24,26 @@ namespace octa {
template<typename...> struct __OctaCommonType; template<typename...> struct __OctaCommonType;
template<typename T>
using RemoveCv = typename __OctaRemoveCv<T>::Type;
template<typename T>
using AddLvalueReference = typename __OctaAddLr<T>::Type;
template<typename T>
using AddRvalueReference = typename __OctaAddRr<T>::Type;
template<typename T>
using AddConst = typename __OctaAddConst<T>::Type;
template<typename T>
using RemoveReference = typename __OctaRemoveReference<T>::Type;
template<typename T>
using RemoveAllExtents = typename __OctaRemoveAllExtents<T>::Type;
/* declval also defined here to avoid including utility.h */ /* declval also defined here to avoid including utility.h */
template<typename T> typename __OctaAddRr<T>::Type __octa_declval(); template<typename T> AddRvalueReference<T> __octa_declval();
/* integral constant */ /* integral constant */
@ -51,16 +69,15 @@ namespace octa {
template< > struct __OctaIsVoid<void>: True {}; template< > struct __OctaIsVoid<void>: True {};
template<typename T> template<typename T>
struct IsVoid: __OctaIsVoid<typename __OctaRemoveCv<T>::Type> {}; struct IsVoid: __OctaIsVoid<RemoveCv<T>> {};
/* is null pointer */ /* is null pointer */
template<typename> struct __OctaIsNullPointer : False {}; template<typename> struct __OctaIsNullPointer : False {};
template< > struct __OctaIsNullPointer<nullptr_t>: True {}; template< > struct __OctaIsNullPointer<nullptr_t>: True {};
template<typename T> struct IsNullPointer: __OctaIsNullPointer< template<typename T> struct IsNullPointer:
typename __OctaRemoveCv<T>::Type __OctaIsNullPointer<RemoveCv<T>> {};
> {};
/* is integer */ /* is integer */
@ -84,7 +101,7 @@ namespace octa {
template<> struct __OctaIsIntegral< wchar_t>: True {}; template<> struct __OctaIsIntegral< wchar_t>: True {};
template<typename T> template<typename T>
struct IsIntegral: __OctaIsIntegral<typename __OctaRemoveCv<T>::Type> {}; struct IsIntegral: __OctaIsIntegral<RemoveCv<T>> {};
/* is floating point */ /* is floating point */
@ -95,7 +112,7 @@ namespace octa {
template<> struct __OctaIsFloatingPoint<ldouble>: True {}; template<> struct __OctaIsFloatingPoint<ldouble>: True {};
template<typename T> template<typename T>
struct IsFloatingPoint: __OctaIsFloatingPoint<typename __OctaRemoveCv<T>::Type> {}; struct IsFloatingPoint: __OctaIsFloatingPoint<RemoveCv<T>> {};
/* is array */ /* is array */
@ -109,7 +126,7 @@ namespace octa {
template<typename T> struct __OctaIsPointer<T *>: True {}; template<typename T> struct __OctaIsPointer<T *>: True {};
template<typename T> template<typename T>
struct IsPointer: __OctaIsPointer<typename __OctaRemoveCv<T>::Type> {}; struct IsPointer: __OctaIsPointer<RemoveCv<T>> {};
/* is lvalue reference */ /* is lvalue reference */
@ -182,9 +199,7 @@ namespace octa {
struct __OctaIsMemberPointer<T U::*>: True {}; struct __OctaIsMemberPointer<T U::*>: True {};
template<typename T> template<typename T>
struct IsMemberPointer: __OctaIsMemberPointer< struct IsMemberPointer: __OctaIsMemberPointer<RemoveCv<T>> {};
typename __OctaRemoveCv<T>::Type
> {};
/* is pointer to member object */ /* is pointer to member object */
@ -197,7 +212,7 @@ namespace octa {
> {}; > {};
template<typename T> struct IsMemberObjectPointer: template<typename T> struct IsMemberObjectPointer:
__OctaIsMemberObjectPointer<typename __OctaRemoveCv<T>::Type> {}; __OctaIsMemberObjectPointer<RemoveCv<T>> {};
/* is pointer to member function */ /* is pointer to member function */
@ -210,7 +225,7 @@ namespace octa {
> {}; > {};
template<typename T> struct IsMemberFunctionPointer: template<typename T> struct IsMemberFunctionPointer:
__OctaIsMemberFunctionPointer<typename __OctaRemoveCv<T>::Type> {}; __OctaIsMemberFunctionPointer<RemoveCv<T>> {};
/* is reference */ /* is reference */
@ -284,7 +299,7 @@ namespace octa {
template<typename T> template<typename T>
struct IsTriviallyCopyable: IntegralConstant<bool, struct IsTriviallyCopyable: IntegralConstant<bool,
IsScalar<typename __OctaRemoveAllExtents<T>::Type>::value IsScalar<RemoveAllExtents<T>>::value
> {}; > {};
/* is trivial */ /* is trivial */
@ -301,7 +316,7 @@ namespace octa {
/* is constructible */ /* is constructible */
#define __OCTA_MOVE(v) static_cast<typename __OctaRemoveReference<decltype(v)>::Type &&>(v) #define __OCTA_MOVE(v) static_cast<RemoveReference<decltype(v)> &&>(v)
template<typename, typename T> struct __OctaSelect2nd { typedef T Type; }; template<typename, typename T> struct __OctaSelect2nd { typedef T Type; };
struct __OctaAny { __OctaAny(...); }; struct __OctaAny { __OctaAny(...); };
@ -374,9 +389,7 @@ namespace octa {
/* array types are default constructible if their element type is */ /* array types are default constructible if their element type is */
template<typename T, size_t N> template<typename T, size_t N>
struct __OctaCtibleCore<false, T[N]>: __OctaCtible< struct __OctaCtibleCore<false, T[N]>: __OctaCtible<RemoveAllExtents<T>> {};
typename __OctaRemoveAllExtents<T>::Type
> {};
/* otherwise array types are not constructible by this syntax */ /* otherwise array types are not constructible by this syntax */
template<typename T, size_t N, typename ...A> template<typename T, size_t N, typename ...A>
@ -396,13 +409,13 @@ namespace octa {
/* is copy constructible */ /* is copy constructible */
template<typename T> struct IsCopyConstructible: IsConstructible<T, template<typename T> struct IsCopyConstructible: IsConstructible<T,
typename __OctaAddLr<typename __OctaAddConst<T>::Type>::Type AddLvalueReference<AddConst<T>>
> {}; > {};
/* is move constructible */ /* is move constructible */
template<typename T> struct IsMoveConstructible: IsConstructible<T, template<typename T> struct IsMoveConstructible: IsConstructible<T,
typename __OctaAddRr<T>::Type AddRvalueReference<T>
> {}; > {};
/* is assignable */ /* is assignable */
@ -427,15 +440,15 @@ namespace octa {
/* is copy assignable */ /* is copy assignable */
template<typename T> struct IsCopyAssignable: IsAssignable< template<typename T> struct IsCopyAssignable: IsAssignable<
typename __OctaAddLr<T>::Type, AddLvalueReference<T>,
typename __OctaAddLr<typename __OctaAddConst<T>::Type>::Type AddLvalueReference<AddConst<T>>
> {}; > {};
/* is move assignable */ /* is move assignable */
template<typename T> struct IsMoveAssignable: IsAssignable< template<typename T> struct IsMoveAssignable: IsAssignable<
typename __OctaAddLr<T>::Type, AddLvalueReference<T>,
const typename __OctaAddRr<T>::Type const AddRvalueReference<T>
> {}; > {};
/* is destructible */ /* is destructible */
@ -456,7 +469,7 @@ namespace octa {
template<typename T> template<typename T>
struct __OctaDtibleImpl<T, false>: IntegralConstant<bool, struct __OctaDtibleImpl<T, false>: IntegralConstant<bool,
IsDestructorWellformed<typename __OctaRemoveAllExtents<T>::Type>::value IsDestructorWellformed<RemoveAllExtents<T>>::value
> {}; > {};
template<typename T> template<typename T>
@ -509,14 +522,14 @@ namespace octa {
template<typename T> template<typename T>
struct IsTriviallyCopyConstructible: IsTriviallyConstructible<T, struct IsTriviallyCopyConstructible: IsTriviallyConstructible<T,
typename __OctaAddLr<const T>::Type AddLvalueReference<const T>
> {}; > {};
/* is trivially move constructible */ /* is trivially move constructible */
template<typename T> template<typename T>
struct IsTriviallyMoveConstructible: IsTriviallyConstructible<T, struct IsTriviallyMoveConstructible: IsTriviallyConstructible<T,
typename __OctaAddRr<T>::Type AddRvalueReference<T>
> {}; > {};
/* is trivially assignable */ /* is trivially assignable */
@ -548,14 +561,14 @@ namespace octa {
template<typename T> template<typename T>
struct IsTriviallyCopyAssignable: IsTriviallyAssignable<T, struct IsTriviallyCopyAssignable: IsTriviallyAssignable<T,
typename __OctaAddLr<const T>::Type AddLvalueReference<const T>
> {}; > {};
/* is trivially move assignable */ /* is trivially move assignable */
template<typename T> template<typename T>
struct IsTriviallyMoveAssignable: IsTriviallyAssignable<T, struct IsTriviallyMoveAssignable: IsTriviallyAssignable<T,
typename __OctaAddRr<T>::Type AddRvalueReference<T>
> {}; > {};
/* is trivially destructible */ /* is trivially destructible */
@ -599,14 +612,14 @@ namespace octa {
template<typename T> template<typename T>
struct IsNothrowCopyConstructible: IsNothrowConstructible<T, struct IsNothrowCopyConstructible: IsNothrowConstructible<T,
typename __OctaAddLr<const T>::Type AddLvalueReference<const T>
> {}; > {};
/* is nothrow move constructible */ /* is nothrow move constructible */
template<typename T> template<typename T>
struct IsNothrowMoveConstructible: IsNothrowConstructible<T, struct IsNothrowMoveConstructible: IsNothrowConstructible<T,
typename __OctaAddRr<T>::Type AddRvalueReference<T>
> {}; > {};
/* is nothrow assignable */ /* is nothrow assignable */
@ -638,14 +651,14 @@ namespace octa {
template<typename T> template<typename T>
struct IsNothrowCopyAssignable: IsNothrowAssignable<T, struct IsNothrowCopyAssignable: IsNothrowAssignable<T,
typename __OctaAddLr<const T>::Type AddLvalueReference<const T>
> {}; > {};
/* is nothrow move assignable */ /* is nothrow move assignable */
template<typename T> template<typename T>
struct IsNothrowMoveAssignable: IsNothrowAssignable<T, struct IsNothrowMoveAssignable: IsNothrowAssignable<T,
typename __OctaAddRr<T>::Type AddRvalueReference<T>
> {}; > {};
/* is nothrow destructible */ /* is nothrow destructible */
@ -746,57 +759,50 @@ namespace octa {
template<typename T> template<typename T>
struct __OctaRemoveVolatile<volatile T> { typedef T Type; }; struct __OctaRemoveVolatile<volatile T> { typedef T Type; };
template<typename T>
struct __OctaRemoveCv {
typedef typename __OctaRemoveVolatile<
typename __OctaRemoveConst<T>::Type
>::Type Type;
};
template<typename T> template<typename T>
using RemoveConst = typename __OctaRemoveConst<T>::Type; using RemoveConst = typename __OctaRemoveConst<T>::Type;
template<typename T> template<typename T>
using RemoveVolatile = typename __OctaRemoveVolatile<T>::Type; using RemoveVolatile = typename __OctaRemoveVolatile<T>::Type;
template<typename T> template<typename T>
using RemoveCv = typename __OctaRemoveCv<T>::Type; struct __OctaRemoveCv {
typedef RemoveVolatile<RemoveConst<T>> Type;
};
/* add const, volatile, cv */ /* add const, volatile, cv */
template<typename T, bool = IsReference<T>::value template<typename T, bool = IsReference<T>::value
|| IsFunction<T>::value || IsConst<T>::value> || IsFunction<T>::value || IsConst<T>::value>
struct __Octa__OctaAddConst { typedef T Type; }; struct __OctaAddConstBase { typedef T Type; };
template<typename T> struct __Octa__OctaAddConst<T, false> { template<typename T> struct __OctaAddConstBase<T, false> {
typedef const T Type; typedef const T Type;
}; };
template<typename T> struct __OctaAddConst { template<typename T> struct __OctaAddConst {
typedef typename __Octa__OctaAddConst<T>::Type Type; typedef typename __OctaAddConstBase<T>::Type Type;
}; };
template<typename T, bool = IsReference<T>::value template<typename T, bool = IsReference<T>::value
|| IsFunction<T>::value || IsVolatile<T>::value> || IsFunction<T>::value || IsVolatile<T>::value>
struct __Octa__OctaAddVolatile { typedef T Type; }; struct __OctaAddVolatileBase { typedef T Type; };
template<typename T> struct __Octa__OctaAddVolatile<T, false> { template<typename T> struct __OctaAddVolatileBase<T, false> {
typedef volatile T Type; typedef volatile T Type;
}; };
template<typename T> struct __OctaAddVolatile { template<typename T> struct __OctaAddVolatile {
typedef typename __Octa__OctaAddVolatile<T>::Type Type; typedef typename __OctaAddVolatileBase<T>::Type Type;
}; };
template<typename T>
using AddVolatile = typename __OctaAddVolatile<T>::Type;
template<typename T> template<typename T>
struct __OctaAddCv { struct __OctaAddCv {
typedef typename __OctaAddConst< typedef AddConst<AddVolatile<T>> Type;
typename __OctaAddVolatile<T>::Type
>::Type Type;
}; };
template<typename T>
using AddConst = typename __OctaAddConst<T>::Type;
template<typename T>
using AddVolatile = typename __OctaAddVolatile<T>::Type;
template<typename T> template<typename T>
using AddCv = typename __OctaAddCv<T>::Type; using AddCv = typename __OctaAddCv<T>::Type;
@ -809,9 +815,6 @@ namespace octa {
template<typename T> template<typename T>
struct __OctaRemoveReference<T &&> { typedef T Type; }; struct __OctaRemoveReference<T &&> { typedef T Type; };
template<typename T>
using RemoveReference = typename __OctaRemoveReference<T>::Type;
/* remove pointer */ /* remove pointer */
template<typename T> template<typename T>
@ -831,7 +834,7 @@ namespace octa {
/* add pointer */ /* add pointer */
template<typename T> struct __OctaAddPointer { template<typename T> struct __OctaAddPointer {
typedef typename __OctaRemoveReference<T>::Type *Type; typedef RemoveReference<T> *Type;
}; };
template<typename T> template<typename T>
@ -855,9 +858,6 @@ namespace octa {
typedef const volatile void Type; typedef const volatile void Type;
}; };
template<typename T>
using AddLvalueReference = typename __OctaAddLr<T>::Type;
/* add rvalue reference */ /* add rvalue reference */
template<typename T> struct __OctaAddRr { typedef T &&Type; }; template<typename T> struct __OctaAddRr { typedef T &&Type; };
@ -876,9 +876,6 @@ namespace octa {
typedef const volatile void Type; typedef const volatile void Type;
}; };
template<typename T>
using AddRvalueReference = typename __OctaAddRr<T>::Type;
/* remove extent */ /* remove extent */
template<typename T> template<typename T>
@ -896,16 +893,13 @@ namespace octa {
template<typename T> struct __OctaRemoveAllExtents { typedef T Type; }; template<typename T> struct __OctaRemoveAllExtents { typedef T Type; };
template<typename T> struct __OctaRemoveAllExtents<T[]> { template<typename T> struct __OctaRemoveAllExtents<T[]> {
typedef typename __OctaRemoveAllExtents<T>::Type Type; typedef RemoveAllExtents<T> Type;
}; };
template<typename T, size_t N> struct __OctaRemoveAllExtents<T[N]> { template<typename T, size_t N> struct __OctaRemoveAllExtents<T[N]> {
typedef typename __OctaRemoveAllExtents<T>::Type Type; typedef RemoveAllExtents<T> Type;
}; };
template<typename T>
using RemoveAllExtents = typename __OctaRemoveAllExtents<T>::Type;
/* make (un)signed /* make (un)signed
* *
* this is bad, but i don't see any better way * this is bad, but i don't see any better way
@ -951,8 +945,8 @@ namespace octa {
}; };
template<typename T, typename U, template<typename T, typename U,
bool = IsConst<typename __OctaRemoveReference<T>::Type>::value, bool = IsConst<RemoveReference<T>>::value,
bool = IsVolatile<typename __OctaRemoveReference<T>::Type>::value bool = IsVolatile<RemoveReference<T>>::value
> struct __OctaApplyCv { > struct __OctaApplyCv {
typedef U Type; typedef U Type;
}; };
@ -1029,17 +1023,13 @@ namespace octa {
template<typename T> struct __OctaMakeSignedBase { template<typename T> struct __OctaMakeSignedBase {
typedef typename __OctaApplyCv<T, typedef typename __OctaApplyCv<T,
typename __OctaMakeSigned< typename __OctaMakeSigned<RemoveCv<T>>::Type
typename __OctaRemoveCv<T>::Type
>::Type
>::Type Type; >::Type Type;
}; };
template<typename T> struct __OctaMakeUnsignedBase { template<typename T> struct __OctaMakeUnsignedBase {
typedef typename __OctaApplyCv<T, typedef typename __OctaApplyCv<T,
typename __OctaMakeUnsigned< typename __OctaMakeUnsigned<RemoveCv<T>>::Type
typename __OctaRemoveCv<T>::Type
>::Type
>::Type Type; >::Type Type;
}; };
@ -1121,15 +1111,12 @@ namespace octa {
template<typename T> template<typename T>
struct __OctaDecay { struct __OctaDecay {
private: private:
typedef typename __OctaRemoveReference<T>::Type U; typedef RemoveReference<T> U;
public: public:
typedef typename __OctaConditional<IsArray<U>::value, typedef Conditional<IsArray<U>::value,
typename __OctaRemoveExtent<U>::Type *, RemoveExtent<U> *,
typename __OctaConditional<IsFunction<U>::value, Conditional<IsFunction<U>::value, AddPointer<U>, RemoveCv<U>>
typename __OctaAddPointer<U>::Type, > Type;
typename __OctaRemoveCv<U>::Type
>::Type
>::Type Type;
}; };
template<typename T> template<typename T>