From 6de48f1f21c11fb092e5244b4cf04159e10bcbf6 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 24 Apr 2015 19:43:20 +0100 Subject: [PATCH] refactor traits: e.g. "RemoveCV" instead of "typename RemoveCV::type" --- octa/functional.h | 5 +- octa/traits.h | 454 +++++++++++++++++++++++++++------------------- octa/utility.h | 10 +- octa/vector.h | 12 +- 4 files changed, 280 insertions(+), 201 deletions(-) diff --git a/octa/functional.h b/octa/functional.h index 71cbc0c..532fdb7 100644 --- a/octa/functional.h +++ b/octa/functional.h @@ -204,7 +204,7 @@ namespace octa { struct __OctaFunctorInPlace { static constexpr bool value = sizeof(T) <= sizeof(__OctaFunctorData) && (alignof(__OctaFunctorData) % alignof(T)) == 0 - && octa::IsNothrowMoveConstructible::value; + && octa::IsNothrowMoveConstructible(); }; template @@ -232,8 +232,7 @@ namespace octa { }; template - struct __OctaFunctorDataManager - ::value>::type> { + struct __OctaFunctorDataManager::value>> { template static R call(const __OctaFunctorData &s, A ...args) { return (*(T *&)s)(forward(args)...); diff --git a/octa/traits.h b/octa/traits.h index a5241e8..ee12916 100644 --- a/octa/traits.h +++ b/octa/traits.h @@ -13,19 +13,19 @@ namespace octa { /* forward declarations */ - template struct RemoveCV; - template struct AddLvalueReference; - template struct AddRvalueReference; - template struct AddConst; + template struct __OctaRemoveCV; + template struct __OctaAddLR; + template struct __OctaAddRR; + template struct __OctaAddConst; template struct IsReference; - template struct RemoveReference; - template struct RemoveAllExtents; + template struct __OctaRemoveReference; + template struct __OctaRemoveAllExtents; template struct IsTriviallyDefaultConstructible; - template struct CommonType; + template struct __OctaCommonType; /* declval also defined here to avoid including utility.h */ - template typename AddRvalueReference::type __octa_declval(); + template typename __OctaAddRR::type __octa_declval(); /* integral constant */ @@ -40,82 +40,82 @@ namespace octa { constexpr value_type operator()() const { return value; } }; - typedef IntegralConstant true_t; - typedef IntegralConstant false_t; + typedef IntegralConstant True; + typedef IntegralConstant False; template constexpr T IntegralConstant::value; /* is void */ - template struct __OctaIsVoid : false_t {}; - template< > struct __OctaIsVoid: true_t {}; + template struct __OctaIsVoid : False {}; + template< > struct __OctaIsVoid: True {}; template - struct IsVoid: __OctaIsVoid::type> {}; + struct IsVoid: __OctaIsVoid::type> {}; /* is null pointer */ - template struct __OctaIsNullPointer : false_t {}; - template< > struct __OctaIsNullPointer: true_t {}; + template struct __OctaIsNullPointer : False {}; + template< > struct __OctaIsNullPointer: True {}; template struct IsNullPointer: __OctaIsNullPointer< - typename RemoveCV::type + typename __OctaRemoveCV::type > {}; /* is integer */ - template struct __OctaIsIntegral: false_t {}; + template struct __OctaIsIntegral: False {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; - template<> struct __OctaIsIntegral: true_t {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; + template<> struct __OctaIsIntegral: True {}; template - struct IsIntegral: __OctaIsIntegral::type> {}; + struct IsIntegral: __OctaIsIntegral::type> {}; /* is floating point */ - template struct __OctaIsFloatingPoint: false_t {}; + template struct __OctaIsFloatingPoint: False {}; - template<> struct __OctaIsFloatingPoint: true_t {}; - template<> struct __OctaIsFloatingPoint: true_t {}; - template<> struct __OctaIsFloatingPoint: true_t {}; + template<> struct __OctaIsFloatingPoint: True {}; + template<> struct __OctaIsFloatingPoint: True {}; + template<> struct __OctaIsFloatingPoint: True {}; template - struct IsFloatingPoint: __OctaIsFloatingPoint::type> {}; + struct IsFloatingPoint: __OctaIsFloatingPoint::type> {}; /* is array */ - template struct IsArray : false_t {}; - template struct IsArray: true_t {}; - template struct IsArray: true_t {}; + template struct IsArray : False {}; + template struct IsArray: True {}; + template struct IsArray: True {}; /* is pointer */ - template struct __OctaIsPointer : false_t {}; - template struct __OctaIsPointer: true_t {}; + template struct __OctaIsPointer : False {}; + template struct __OctaIsPointer: True {}; template - struct IsPointer: __OctaIsPointer::type> {}; + struct IsPointer: __OctaIsPointer::type> {}; /* is lvalue reference */ - template struct IsLvalueReference : false_t {}; - template struct IsLvalueReference: true_t {}; + template struct IsLvalueReference : False {}; + template struct IsLvalueReference: True {}; /* is rvalue reference */ - template struct IsRvalueReference : false_t {}; - template struct IsRvalueReference: true_t {}; + template struct IsRvalueReference : False {}; + template struct IsRvalueReference: True {}; /* is enum */ @@ -147,7 +147,7 @@ namespace octa { sizeof(__octa_function_test(__octa_function_source(0))) == 1 > {}; - template struct __OctaIsFunction: false_t {}; + template struct __OctaIsFunction: False {}; template struct IsFunction: __OctaIsFunction {}; @@ -172,20 +172,20 @@ namespace octa { /* is pointer to member */ template - struct __OctaIsMemberPointer: false_t {}; + struct __OctaIsMemberPointer: False {}; template - struct __OctaIsMemberPointer: true_t {}; + struct __OctaIsMemberPointer: True {}; template struct IsMemberPointer: __OctaIsMemberPointer< - typename RemoveCV::type + typename __OctaRemoveCV::type > {}; /* is pointer to member object */ template - struct __OctaIsMemberObjectPointer: false_t {}; + struct __OctaIsMemberObjectPointer: False {}; template struct __OctaIsMemberObjectPointer: IntegralConstant {}; template struct IsMemberObjectPointer: - __OctaIsMemberObjectPointer::type> {}; + __OctaIsMemberObjectPointer::type> {}; /* is pointer to member function */ template - struct __OctaIsMemberFunctionPointer: false_t {}; + struct __OctaIsMemberFunctionPointer: False {}; template struct __OctaIsMemberFunctionPointer: IntegralConstant {}; template struct IsMemberFunctionPointer: - __OctaIsMemberFunctionPointer::type> {}; + __OctaIsMemberFunctionPointer::type> {}; /* is reference */ @@ -234,13 +234,13 @@ namespace octa { /* is const */ - template struct IsConst : false_t {}; - template struct IsConst: true_t {}; + template struct IsConst : False {}; + template struct IsConst: True {}; /* is volatile */ - template struct IsVolatile : false_t {}; - template struct IsVolatile: true_t {}; + template struct IsVolatile : False {}; + template struct IsVolatile: True {}; /* is empty */ @@ -270,14 +270,14 @@ namespace octa { template struct IsStandardLayout: IntegralConstant::type>::value + IsScalar::type>::value > {}; /* is literal type */ template struct IsLiteralType: IntegralConstant::type>::value + IsReference::type>::value || IsStandardLayout::value > {}; @@ -285,7 +285,7 @@ namespace octa { template struct IsTriviallyCopyable: IntegralConstant::type>::value + IsScalar::type>::value > {}; /* is trivial */ @@ -304,28 +304,28 @@ namespace octa { /* is constructible */ -#define __OCTA_MOVE(v) static_cast::type &&>(v) +#define __OCTA_MOVE(v) static_cast::type &&>(v) template struct __OctaSelect2nd { typedef T type; }; struct __OctaAny { __OctaAny(...); }; template typename __OctaSelect2nd< - decltype(__OCTA_MOVE(T(__octa_declval()...))), true_t + decltype(__OCTA_MOVE(T(__octa_declval()...))), True >::type __octa_is_ctible_test(T &&, A &&...); #undef __OCTA_MOVE - template false_t __octa_is_ctible_test(__OctaAny, A &&...); + template False __octa_is_ctible_test(__OctaAny, A &&...); template - struct __OctaCtibleCore: CommonType< + struct __OctaCtibleCore: __OctaCommonType< decltype(__octa_is_ctible_test(__octa_declval(), __octa_declval()...)) >::type {}; /* function types are not constructible */ template - struct __OctaCtibleCore: false_t {}; + struct __OctaCtibleCore: False {}; /* scalars are default constructible, refs are not */ template @@ -335,18 +335,18 @@ namespace octa { * implicitly convertible to scalar or reference */ template struct __OctaCtibleRef { - static true_t test(T); - static false_t test(...); + static True test(T); + static False test(...); }; template - struct __OctaCtibleCore: CommonType< + struct __OctaCtibleCore: __OctaCommonType< decltype(__OctaCtibleRef::test(__octa_declval())) >::type {}; /* scalars and references are not constructible from multiple args */ template - struct __OctaCtibleCore: false_t {}; + struct __OctaCtibleCore: False {}; /* treat scalars and refs separately */ template @@ -356,11 +356,11 @@ namespace octa { /* if any of T or A is void, IsConstructible should be false */ template - struct __OctaCtibleVoidCheck: false_t {}; + struct __OctaCtibleVoidCheck: False {}; template struct __OctaCtibleContainsVoid; - template<> struct __OctaCtibleContainsVoid<>: false_t {}; + template<> struct __OctaCtibleContainsVoid<>: False {}; template struct __OctaCtibleContainsVoid { @@ -378,16 +378,16 @@ namespace octa { /* array types are default constructible if their element type is */ template struct __OctaCtibleCore: __OctaCtible< - typename RemoveAllExtents::type + typename __OctaRemoveAllExtents::type > {}; /* otherwise array types are not constructible by this syntax */ template - struct __OctaCtibleCore: false_t {}; + struct __OctaCtibleCore: False {}; /* incomplete array types are not constructible */ template - struct __OctaCtibleCore: false_t {}; + struct __OctaCtibleCore: False {}; template struct IsConstructible: __OctaCtible {}; @@ -399,30 +399,30 @@ namespace octa { /* is copy constructible */ template struct IsCopyConstructible: IsConstructible::type>::type + typename __OctaAddLR::type>::type > {}; /* is move constructible */ template struct IsMoveConstructible: IsConstructible::type + typename __OctaAddRR::type > {}; /* is assignable */ template typename __OctaSelect2nd< - decltype((__octa_declval() = __octa_declval())), true_t + decltype((__octa_declval() = __octa_declval())), True >::type __octa_assign_test(T &&, U &&); - template false_t __octa_assign_test(__OctaAny, T &&); + template False __octa_assign_test(__OctaAny, T &&); template::value || IsVoid::value> - struct __OctaIsAssignable: CommonType< + struct __OctaIsAssignable: __OctaCommonType< decltype(__octa_assign_test(__octa_declval(), __octa_declval())) >::type {}; template - struct __OctaIsAssignable: false_t {}; + struct __OctaIsAssignable: False {}; template struct IsAssignable: __OctaIsAssignable {}; @@ -430,15 +430,15 @@ namespace octa { /* is copy assignable */ template struct IsCopyAssignable: IsAssignable< - typename AddLvalueReference::type, - typename AddLvalueReference::type>::type + typename __OctaAddLR::type, + typename __OctaAddLR::type>::type > {}; /* is move assignable */ template struct IsMoveAssignable: IsAssignable< - typename AddLvalueReference::type, - const typename AddRvalueReference::type + typename __OctaAddLR::type, + const typename __OctaAddRR::type > {}; /* is destructible */ @@ -459,29 +459,29 @@ namespace octa { template struct __OctaDtibleImpl: IntegralConstant::type>::value + IsDestructorWellformed::type>::value > {}; template - struct __OctaDtibleImpl: true_t {}; + struct __OctaDtibleImpl: True {}; template struct __OctaDtibleFalse; template struct __OctaDtibleFalse : __OctaDtibleImpl::value> {}; - template struct __OctaDtibleFalse: false_t {}; + template struct __OctaDtibleFalse: False {}; template struct IsDestructible: __OctaDtibleFalse::value> {}; - template struct IsDestructible: false_t {}; - template< > struct IsDestructible: false_t {}; + template struct IsDestructible: False {}; + template< > struct IsDestructible: False {}; /* is trivially constructible */ template - struct IsTriviallyConstructible: false_t {}; + struct IsTriviallyConstructible: False {}; template struct IsTriviallyConstructible: IntegralConstant struct IsTriviallyCopyConstructible: IsTriviallyConstructible::type + typename __OctaAddLR::type > {}; /* is trivially move constructible */ template struct IsTriviallyMoveConstructible: IsTriviallyConstructible::type + typename __OctaAddRR::type > {}; /* is trivially assignable */ template - struct IsTriviallyAssignable: false_t {}; + struct IsTriviallyAssignable: False {}; template struct IsTriviallyAssignable: IntegralConstant struct IsTriviallyCopyAssignable: IsTriviallyAssignable::type + typename __OctaAddLR::type > {}; /* is trivially move assignable */ template struct IsTriviallyMoveAssignable: IsTriviallyAssignable::type + typename __OctaAddRR::type > {}; /* is trivially destructible */ @@ -571,7 +571,7 @@ namespace octa { /* is nothrow constructible */ template - struct IsNothrowConstructible: false_t {}; + struct IsNothrowConstructible: False {}; template struct IsNothrowConstructible: IntegralConstant struct IsNothrowCopyConstructible: IsNothrowConstructible::type + typename __OctaAddLR::type > {}; /* is nothrow move constructible */ template struct IsNothrowMoveConstructible: IsNothrowConstructible::type + typename __OctaAddRR::type > {}; /* is nothrow assignable */ template - struct IsNothrowAssignable: false_t {}; + struct IsNothrowAssignable: False {}; template struct IsNothrowAssignable: IntegralConstant struct IsNothrowCopyAssignable: IsNothrowAssignable::type + typename __OctaAddLR::type > {}; /* is nothrow move assignable */ template struct IsNothrowMoveAssignable: IsNothrowAssignable::type + typename __OctaAddRR::type > {}; /* is nothrow destructible */ @@ -692,9 +692,9 @@ namespace octa { template(__octa_declval())) - > static true_t test(int); + > static True test(int); - template static false_t test(...); + template static False test(...); typedef decltype(test(0)) type; }; @@ -704,8 +704,8 @@ namespace octa { /* type equality */ - template struct IsSame : false_t {}; - template struct IsSame: true_t {}; + template struct IsSame : False {}; + template struct IsSame: True {}; /* extent */ @@ -736,122 +736,176 @@ namespace octa { /* remove const, volatile, cv */ - template struct RemoveConst { typedef T type; }; - template struct RemoveConst { typedef T type; }; - - template struct RemoveVolatile { typedef T type; }; - template struct RemoveVolatile { typedef T type; }; + template + struct __OctaRemoveConst { typedef T type; }; + template + struct __OctaRemoveConst { typedef T type; }; template - struct RemoveCV { - typedef typename RemoveVolatile::type>::type type; + struct __OctaRemoveVolatile { typedef T type; }; + template + struct __OctaRemoveVolatile { typedef T type; }; + + template + struct __OctaRemoveCV { + typedef typename __OctaRemoveVolatile< + typename __OctaRemoveConst::type + >::type type; }; + template + using RemoveConst = typename __OctaRemoveConst::type; + template + using RemoveVolatile = typename __OctaRemoveVolatile::type; + template + using RemoveCV = typename __OctaRemoveCV::type; + /* add const, volatile, cv */ template::value || IsFunction::value || IsConst::value> - struct __OctaAddConst { typedef T type; }; + struct __Octa__OctaAddConst { typedef T type; }; - template struct __OctaAddConst { + template struct __Octa__OctaAddConst { typedef const T type; }; - template struct AddConst { - typedef typename __OctaAddConst::type type; + template struct __OctaAddConst { + typedef typename __Octa__OctaAddConst::type type; }; template::value || IsFunction::value || IsVolatile::value> - struct __OctaAddVolatile { typedef T type; }; + struct __Octa__OctaAddVolatile { typedef T type; }; - template struct __OctaAddVolatile { + template struct __Octa__OctaAddVolatile { typedef volatile T type; }; - template struct AddVolatile { - typedef typename __OctaAddVolatile::type type; + template struct __OctaAddVolatile { + typedef typename __Octa__OctaAddVolatile::type type; }; template - struct AddCV { - typedef typename AddConst::type>::type type; + struct __OctaAddCV { + typedef typename __OctaAddConst< + typename __OctaAddVolatile::type + >::type type; }; + template + using AddConst = typename __OctaAddConst::type; + template + using AddVolatile = typename __OctaAddVolatile::type; + template + using AddCV = typename __OctaAddCV::type; + /* remove reference */ - template struct RemoveReference { typedef T type; }; - template struct RemoveReference { typedef T type; }; - template struct RemoveReference { typedef T type; }; + template + struct __OctaRemoveReference { typedef T type; }; + template + struct __OctaRemoveReference { typedef T type; }; + template + struct __OctaRemoveReference { typedef T type; }; + + template + using RemoveReference = typename __OctaRemoveReference::type; /* remove pointer */ - template struct RemovePointer { typedef T type; }; - template struct RemovePointer { typedef T type; }; - template struct RemovePointer { typedef T type; }; - template struct RemovePointer { typedef T type; }; - template struct RemovePointer { typedef T type; }; + template + struct __OctaRemovePointer { typedef T type; }; + template + struct __OctaRemovePointer { typedef T type; }; + template + struct __OctaRemovePointer { typedef T type; }; + template + struct __OctaRemovePointer { typedef T type; }; + template + struct __OctaRemovePointer { typedef T type; }; + + template + using RemovePointer = typename __OctaRemovePointer::type; /* add pointer */ - template struct AddPointer { - typedef typename RemoveReference::type *type; + template struct __OctaAddPointer { + typedef typename __OctaRemoveReference::type *type; }; + template + using AddPointer = typename __OctaAddPointer::type; + /* add lvalue reference */ - template struct AddLvalueReference { typedef T &type; }; - template struct AddLvalueReference { typedef T &type; }; - template struct AddLvalueReference { typedef T &type; }; - template<> struct AddLvalueReference { + template struct __OctaAddLR { typedef T &type; }; + template struct __OctaAddLR { typedef T &type; }; + template struct __OctaAddLR { typedef T &type; }; + template<> struct __OctaAddLR { typedef void type; }; - template<> struct AddLvalueReference { + template<> struct __OctaAddLR { typedef const void type; }; - template<> struct AddLvalueReference { + template<> struct __OctaAddLR { typedef volatile void type; }; - template<> struct AddLvalueReference { + template<> struct __OctaAddLR { typedef const volatile void type; }; + template + using AddLvalueReference = typename __OctaAddLR::type; + /* add rvalue reference */ - template struct AddRvalueReference { typedef T &&type; }; - template struct AddRvalueReference { typedef T &&type; }; - template struct AddRvalueReference { typedef T &&type; }; - template<> struct AddRvalueReference { + template struct __OctaAddRR { typedef T &&type; }; + template struct __OctaAddRR { typedef T &&type; }; + template struct __OctaAddRR { typedef T &&type; }; + template<> struct __OctaAddRR { typedef void type; }; - template<> struct AddRvalueReference { + template<> struct __OctaAddRR { typedef const void type; }; - template<> struct AddRvalueReference { + template<> struct __OctaAddRR { typedef volatile void type; }; - template<> struct AddRvalueReference { + template<> struct __OctaAddRR { typedef const volatile void type; }; + template + using AddRvalueReference = typename __OctaAddRR::type; + /* remove extent */ - template struct RemoveExtent { typedef T type; }; - template struct RemoveExtent { typedef T type; }; - template struct RemoveExtent { typedef T type; }; + template + struct __OctaRemoveExtent { typedef T type; }; + template + struct __OctaRemoveExtent { typedef T type; }; + template + struct __OctaRemoveExtent { typedef T type; }; + + template + using RemoveExtent = typename __OctaRemoveExtent::type; /* remove all extents */ - template struct RemoveAllExtents { typedef T type; }; + template struct __OctaRemoveAllExtents { typedef T type; }; - template struct RemoveAllExtents { - typedef typename RemoveAllExtents::type type; + template struct __OctaRemoveAllExtents { + typedef typename __OctaRemoveAllExtents::type type; }; - template struct RemoveAllExtents { - typedef typename RemoveAllExtents::type type; + template struct __OctaRemoveAllExtents { + typedef typename __OctaRemoveAllExtents::type type; }; + template + using RemoveAllExtents = typename __OctaRemoveAllExtents::type; + /* make (un)signed * * this is bad, but i don't see any better way @@ -897,8 +951,8 @@ namespace octa { }; template::type>::value, - bool = IsVolatile::type>::value + bool = IsConst::type>::value, + bool = IsVolatile::type>::value > struct __OctaApplyCV { typedef U type; }; @@ -973,34 +1027,42 @@ namespace octa { template<> struct __OctaMakeUnsigned { typedef ullong type; }; template<> struct __OctaMakeUnsigned { typedef ullong type; }; - template struct MakeSigned { + template struct __OctaMakeSignedBase { typedef typename __OctaApplyCV::type + typename __OctaRemoveCV::type >::type >::type type; }; - template struct MakeUnsigned { + template struct __OctaMakeUnsignedBase { typedef typename __OctaApplyCV::type + typename __OctaRemoveCV::type >::type >::type type; }; + template + using MakeSigned = typename __OctaMakeSignedBase::type; + template + using MakeUnsigned = typename __OctaMakeUnsignedBase::type; + /* conditional */ template - struct Conditional { + struct __OctaConditional { typedef T type; }; template - struct Conditional { + struct __OctaConditional { typedef U type; }; + template + using Conditional = typename __OctaConditional::type; + /* result of call at compile time */ #define __OCTA_FWD(T, v) static_cast(v) @@ -1040,47 +1102,61 @@ namespace octa { __octa_declval()...)); }; - template struct ResultOf: __OctaResultOf {}; + template struct __OctaResultOfBase: __OctaResultOf {}; + + template + using ResultOf = typename __OctaResultOfBase::type; /* enable if */ - template struct EnableIf {}; + template struct __OctaEnableIf {}; - template struct EnableIf { typedef T type; }; + template struct __OctaEnableIf { typedef T type; }; + + template + using EnableIf = typename __OctaEnableIf::type; /* decay */ template - struct Decay { + struct __OctaDecay { private: - typedef typename RemoveReference::type U; + typedef typename __OctaRemoveReference::type U; public: - typedef typename Conditional::value, - typename RemoveExtent::type *, - typename Conditional::value, - typename AddPointer::type, - typename RemoveCV::type + typedef typename __OctaConditional::value, + typename __OctaRemoveExtent::type *, + typename __OctaConditional::value, + typename __OctaAddPointer::type, + typename __OctaRemoveCV::type >::type >::type type; }; + template + using Decay = typename __OctaDecay::type; + /* common type */ - template struct CommonType; + template struct __OctaCommonType; - template struct CommonType { - typedef Decay type; + template struct __OctaCommonType { + typedef __OctaDecay type; }; - template struct CommonType { - typedef Decay() : __octa_declval())> type; + template struct __OctaCommonType { + typedef __OctaDecay() + : __octa_declval())> type; }; template - struct CommonType { - typedef typename CommonType::type, V...>::type type; + struct __OctaCommonType { + typedef typename __OctaCommonType::type, + V...>::type type; }; + template + using CommonType = typename __OctaCommonType::type; + /* aligned storage */ template struct __OctaAlignedTest { @@ -1090,14 +1166,16 @@ namespace octa { }; }; - template::type) - > struct AlignedStorage { + template struct __OctaAlignedStorage { struct type { alignas(A) uchar data[N]; }; }; + template::type) + > using AlignedStorage = typename __OctaAlignedStorage::type; + /* aligned union */ template struct __OctaAlignMax; @@ -1116,7 +1194,7 @@ namespace octa { = __OctaAlignMax<__OctaAlignMax::value, N...>::value; }; - template struct AlignedUnion { + template struct __OctaAlignedUnion { static constexpr size_t alignment_value = __OctaAlignMax::value; @@ -1126,20 +1204,22 @@ namespace octa { }; }; + template + using AlignedUnion = typename __OctaAlignedUnion::type; + /* underlying type */ template::value> struct __OctaUnderlyingType; template struct __OctaUnderlyingType { - typedef typename Conditional::value, + typedef typename __OctaConditional::value, typename MakeSigned::type, typename MakeUnsigned::type >::type type; }; - template struct UnderlyingType { - typedef typename __OctaUnderlyingType::type type; - }; + template + using UnderlyingType = typename __OctaUnderlyingType::type; } #endif \ No newline at end of file diff --git a/octa/utility.h b/octa/utility.h index d998bb9..28fe82b 100644 --- a/octa/utility.h +++ b/octa/utility.h @@ -12,24 +12,24 @@ namespace octa { template - static inline constexpr typename RemoveReference::type && + static inline constexpr RemoveReference && move(T &&v) noexcept { - return static_cast::type &&>(v); + return static_cast &&>(v); } template static inline constexpr T && - forward(typename RemoveReference::type &v) noexcept { + forward(RemoveReference &v) noexcept { return static_cast(v); } template static inline constexpr T && - forward(typename RemoveReference::type &&v) noexcept { + forward(RemoveReference &&v) noexcept { return static_cast(v); } - template typename AddRvalueReference::type declval(); + template AddRvalueReference declval(); template void swap(T &a, T &b) { T c(move(a)); diff --git a/octa/vector.h b/octa/vector.h index 44201cf..618ecc2 100644 --- a/octa/vector.h +++ b/octa/vector.h @@ -78,7 +78,7 @@ namespace octa { void clear() { if (p_cap > 0) { - if (!octa::IsPOD::value) { + if (!octa::IsPOD()) { T *cur = p_buf, *last = p_buf + p_len; while (cur != last) (*cur++).~T(); } @@ -92,7 +92,7 @@ namespace octa { if (this == &v) return *this; if (p_cap >= v.p_cap) { - if (!octa::IsPOD::value) { + if (!octa::IsPOD()) { T *cur = p_buf, *last = p_buf + p_len; while (cur != last) (*cur++).~T(); } @@ -104,7 +104,7 @@ namespace octa { p_buf = (T *)new uchar[p_cap * sizeof(T)]; } - if (octa::IsPOD::value) { + if (octa::IsPOD()) { memcpy(p_buf, v.p_buf, p_len * sizeof(T)); } else { T *cur = p_buf, *last = p_buf + p_len; @@ -129,7 +129,7 @@ namespace octa { size_t len = p_len; reserve(n); p_len = n; - if (octa::IsPOD::value) { + if (octa::IsPOD()) { for (size_t i = len; i < p_len; ++i) { p_buf[i] = T(v); } @@ -154,7 +154,7 @@ namespace octa { } T *tmp = (T *)new uchar[p_cap * sizeof(T)]; if (oc > 0) { - if (octa::IsPOD::value) { + if (octa::IsPOD()) { memcpy(tmp, p_buf, p_len * sizeof(T)); } else { T *cur = p_buf, *tcur = tmp, *last = tmp + p_len; @@ -195,7 +195,7 @@ namespace octa { } void pop() { - if (!octa::IsPOD::value) { + if (!octa::IsPOD()) { p_buf[--p_len].~T(); } else { --p_len;