diff --git a/octa/type_traits.h b/octa/type_traits.h index f122faa..7949035 100644 --- a/octa/type_traits.h +++ b/octa/type_traits.h @@ -14,24 +14,21 @@ namespace octa { /* forward declarations */ namespace detail { - template struct RemoveCv; + template struct RemoveCvBase; template struct AddLr; template struct AddRr; - template struct AddConst; - template struct RemoveReference; - template struct RemoveAllExtents; + template struct AddConstBase; + template struct RemoveReferenceBase; + template struct RemoveAllExtentsBase; template struct CommonTypeBase; } -template struct __OctaAddConst; template struct IsReference; -template struct __OctaRemoveReference; -template struct __OctaRemoveAllExtents; template struct IsTriviallyDefaultConstructible; template -using RemoveCv = typename octa::detail::RemoveCv<_T>::Type; +using RemoveCv = typename octa::detail::RemoveCvBase<_T>::Type; template using AddLvalueReference = typename octa::detail::AddLr<_T>::Type; @@ -40,13 +37,13 @@ template using AddRvalueReference = typename octa::detail::AddRr<_T>::Type; template -using AddConst = typename __OctaAddConst<_T>::Type; +using AddConst = typename octa::detail::AddConstBase<_T>::Type; template -using RemoveReference = typename __OctaRemoveReference<_T>::Type; +using RemoveReference = typename octa::detail::RemoveReferenceBase<_T>::Type; template -using RemoveAllExtents = typename __OctaRemoveAllExtents<_T>::Type; +using RemoveAllExtents = typename octa::detail::RemoveAllExtentsBase<_T>::Type; namespace detail { template octa::AddRvalueReference<_T> declval_in(); @@ -482,290 +479,306 @@ template struct IsMoveAssignable: IsAssignable< const AddRvalueReference<_T> > {}; - /* is destructible */ +/* is destructible */ - template struct __OctaIsDtibleApply { typedef int Type; }; +namespace detail { + template struct IsDtibleApply { typedef int Type; }; template struct IsDestructorWellformed { - template static char __test(typename __OctaIsDtibleApply< + template static char test(typename IsDtibleApply< decltype(octa::detail::declval_in<_TT &>().~_TT()) >::Type); - template static int __test(...); + template static int test(...); - static constexpr bool value = (sizeof(__test<_T>(12)) == sizeof(char)); + static constexpr bool value = (sizeof(test<_T>(12)) == sizeof(char)); }; - template struct __OctaDtibleImpl; + template struct DtibleImpl; template - struct __OctaDtibleImpl<_T, false>: IntegralConstant>::value + struct DtibleImpl<_T, false>: octa::IntegralConstant>::value > {}; template - struct __OctaDtibleImpl<_T, true>: True {}; + struct DtibleImpl<_T, true>: True {}; - template struct __OctaDtibleFalse; + template struct DtibleFalse; - template struct __OctaDtibleFalse<_T, false> - : __OctaDtibleImpl<_T, IsReference<_T>::value> {}; + template struct DtibleFalse<_T, false> + : DtibleImpl<_T, octa::IsReference<_T>::value> {}; - template struct __OctaDtibleFalse<_T, true>: False {}; + template struct DtibleFalse<_T, true>: False {}; +} /* namespace detail */ - template - struct IsDestructible: __OctaDtibleFalse<_T, IsFunction<_T>::value> {}; +template +struct IsDestructible: octa::detail::DtibleFalse<_T, IsFunction<_T>::value> {}; - template struct IsDestructible<_T[]>: False {}; - template< > struct IsDestructible: False {}; +template struct IsDestructible<_T[]>: False {}; +template< > struct IsDestructible: False {}; - /* is trivially constructible */ +/* is trivially constructible */ - template - struct IsTriviallyConstructible: False {}; +template +struct IsTriviallyConstructible: False {}; - template - struct IsTriviallyConstructible<_T>: IntegralConstant {}; +template +struct IsTriviallyConstructible<_T>: IntegralConstant {}; - template - struct IsTriviallyConstructible<_T, _T &>: IntegralConstant {}; +template +struct IsTriviallyConstructible<_T, _T &>: IntegralConstant {}; - template - struct IsTriviallyConstructible<_T, const _T &>: IntegralConstant {}; +template +struct IsTriviallyConstructible<_T, const _T &>: IntegralConstant {}; - template - struct IsTriviallyConstructible<_T, _T &&>: IntegralConstant {}; +template +struct IsTriviallyConstructible<_T, _T &&>: IntegralConstant {}; - /* is trivially default constructible */ +/* is trivially default constructible */ - template - struct IsTriviallyDefaultConstructible: IsTriviallyConstructible<_T> {}; +template +struct IsTriviallyDefaultConstructible: IsTriviallyConstructible<_T> {}; - /* is trivially copy constructible */ +/* is trivially copy constructible */ - template - struct IsTriviallyCopyConstructible: IsTriviallyConstructible<_T, - AddLvalueReference - > {}; +template +struct IsTriviallyCopyConstructible: IsTriviallyConstructible<_T, + AddLvalueReference +> {}; - /* is trivially move constructible */ +/* is trivially move constructible */ - template - struct IsTriviallyMoveConstructible: IsTriviallyConstructible<_T, - AddRvalueReference<_T> - > {}; +template +struct IsTriviallyMoveConstructible: IsTriviallyConstructible<_T, + AddRvalueReference<_T> +> {}; - /* is trivially assignable */ +/* is trivially assignable */ - template - struct IsTriviallyAssignable: False {}; +template +struct IsTriviallyAssignable: False {}; - template - struct IsTriviallyAssignable<_T>: IntegralConstant {}; +template +struct IsTriviallyAssignable<_T>: IntegralConstant {}; - template - struct IsTriviallyAssignable<_T, _T &>: IntegralConstant {}; +template +struct IsTriviallyAssignable<_T, _T &>: IntegralConstant {}; - template - struct IsTriviallyAssignable<_T, const _T &>: IntegralConstant {}; +template +struct IsTriviallyAssignable<_T, const _T &>: IntegralConstant {}; - template - struct IsTriviallyAssignable<_T, _T &&>: IntegralConstant {}; +template +struct IsTriviallyAssignable<_T, _T &&>: IntegralConstant {}; - /* is trivially copy assignable */ +/* is trivially copy assignable */ - template - struct IsTriviallyCopyAssignable: IsTriviallyAssignable<_T, - AddLvalueReference - > {}; +template +struct IsTriviallyCopyAssignable: IsTriviallyAssignable<_T, + AddLvalueReference +> {}; - /* is trivially move assignable */ +/* is trivially move assignable */ - template - struct IsTriviallyMoveAssignable: IsTriviallyAssignable<_T, - AddRvalueReference<_T> - > {}; +template +struct IsTriviallyMoveAssignable: IsTriviallyAssignable<_T, + AddRvalueReference<_T> +> {}; - /* is trivially destructible */ +/* is trivially destructible */ - template - struct IsTriviallyDestructible: IntegralConstant {}; +template +struct IsTriviallyDestructible: IntegralConstant {}; - /* is base of */ +/* is base of */ - template - struct IsBaseOf: IntegralConstant {}; +template +struct IsBaseOf: IntegralConstant {}; - /* is convertible */ +/* is convertible */ - template::value - || IsFunction<_T>::value || IsArray<_T>::value - > struct __OctaIsConvertible { - typedef typename IsVoid<_T>::Type Type; +namespace detail { + template::value + || octa::IsFunction<_T>::value || octa::IsArray<_T>::value + > struct IsConvertibleBase { + typedef typename octa::IsVoid<_T>::Type Type; }; template - struct __OctaIsConvertible<_F, _T, false> { - template static void __test_f(_TT); + struct IsConvertibleBase<_F, _T, false> { + template static void test_f(_TT); template(octa::detail::declval_in<_FF>())) - > static True __test(int); + typename = decltype(test_f<_TT>(declval_in<_FF>())) + > static octa::True test(int); - template static False __test(...); + template static octa::False test(...); - typedef decltype(__test<_F, _T>(0)) Type; + typedef decltype(test<_F, _T>(0)) Type; }; +} - template - struct IsConvertible: __OctaIsConvertible<_F, _T>::Type {}; +template +struct IsConvertible: octa::detail::IsConvertibleBase<_F, _T>::Type {}; - /* type equality */ +/* type equality */ - template struct IsSame : False {}; - template struct IsSame<_T, _T>: True {}; +template struct IsSame : False {}; +template struct IsSame<_T, _T>: True {}; - /* extent */ +/* extent */ - template - struct Extent: IntegralConstant {}; +template +struct Extent: IntegralConstant {}; - template - struct Extent<_T[], 0>: IntegralConstant {}; +template +struct Extent<_T[], 0>: IntegralConstant {}; - template - struct Extent<_T[], _I>: IntegralConstant::value> {}; +template +struct Extent<_T[], _I>: IntegralConstant::value> {}; - template - struct Extent<_T[_N], 0>: IntegralConstant {}; +template +struct Extent<_T[_N], 0>: IntegralConstant {}; - template - struct Extent<_T[_N], _I>: IntegralConstant::value> {}; +template +struct Extent<_T[_N], _I>: IntegralConstant::value> {}; - /* rank */ +/* rank */ - template struct Rank: IntegralConstant {}; +template struct Rank: IntegralConstant {}; - template - struct Rank<_T[]>: IntegralConstant::value + 1> {}; +template +struct Rank<_T[]>: IntegralConstant::value + 1> {}; - template - struct Rank<_T[_N]>: IntegralConstant::value + 1> {}; +template +struct Rank<_T[_N]>: IntegralConstant::value + 1> {}; - /* remove const, volatile, cv */ - - template - struct __OctaRemoveConst { typedef _T Type; }; - template - struct __OctaRemoveConst { typedef _T Type; }; - - template - struct __OctaRemoveVolatile { typedef _T Type; }; - template - struct __OctaRemoveVolatile { typedef _T Type; }; - - template - using RemoveConst = typename __OctaRemoveConst<_T>::Type; - template - using RemoveVolatile = typename __OctaRemoveVolatile<_T>::Type; +/* remove const, volatile, cv */ namespace detail { template - struct RemoveCv { + struct RemoveConstBase { typedef _T Type; }; + template + struct RemoveConstBase { typedef _T Type; }; + + template + struct RemoveVolatileBase { typedef _T Type; }; + template + struct RemoveVolatileBase { typedef _T Type; }; +} + +template +using RemoveConst = typename octa::detail::RemoveConstBase<_T>::Type; +template +using RemoveVolatile = typename octa::detail::RemoveVolatileBase<_T>::Type; + +namespace detail { + template + struct RemoveCvBase { typedef octa::RemoveVolatile> Type; }; } - /* add const, volatile, cv */ +/* add const, volatile, cv */ - template::value - || IsFunction<_T>::value || IsConst<_T>::value> - struct __OctaAddConstBase { typedef _T Type; }; +namespace detail { + template::value + || octa::IsFunction<_T>::value || octa::IsConst<_T>::value> + struct AddConstCore { typedef _T Type; }; - template struct __OctaAddConstBase<_T, false> { + template struct AddConstCore<_T, false> { typedef const _T Type; }; - template struct __OctaAddConst { - typedef typename __OctaAddConstBase<_T>::Type Type; + template struct AddConstBase { + typedef typename AddConstCore<_T>::Type Type; }; - template::value - || IsFunction<_T>::value || IsVolatile<_T>::value> - struct __OctaAddVolatileBase { typedef _T Type; }; + template::value + || octa::IsFunction<_T>::value || octa::IsVolatile<_T>::value> + struct AddVolatileCore { typedef _T Type; }; - template struct __OctaAddVolatileBase<_T, false> { + template struct AddVolatileCore<_T, false> { typedef volatile _T Type; }; - template struct __OctaAddVolatile { - typedef typename __OctaAddVolatileBase<_T>::Type Type; + template struct AddVolatileBase { + typedef typename AddVolatileCore<_T>::Type Type; }; +} - template - using AddVolatile = typename __OctaAddVolatile<_T>::Type; +template +using AddVolatile = typename octa::detail::AddVolatileBase<_T>::Type; +namespace detail { template - struct __OctaAddCv { - typedef AddConst> Type; + struct AddCvBase { + typedef octa::AddConst> Type; }; +} - template - using AddCv = typename __OctaAddCv<_T>::Type; +template +using AddCv = typename octa::detail::AddCvBase<_T>::Type; - /* remove reference */ +/* remove reference */ +namespace detail { template - struct __OctaRemoveReference { typedef _T Type; }; + struct RemoveReferenceBase { typedef _T Type; }; template - struct __OctaRemoveReference<_T &> { typedef _T Type; }; + struct RemoveReferenceBase<_T &> { typedef _T Type; }; template - struct __OctaRemoveReference<_T &&> { typedef _T Type; }; + struct RemoveReferenceBase<_T &&> { typedef _T Type; }; +} - /* remove pointer */ +/* remove pointer */ +namespace detail { template - struct __OctaRemovePointer { typedef _T Type; }; + struct RemovePointerBase { typedef _T Type; }; template - struct __OctaRemovePointer<_T * > { typedef _T Type; }; + struct RemovePointerBase<_T * > { typedef _T Type; }; template - struct __OctaRemovePointer<_T * const > { typedef _T Type; }; + struct RemovePointerBase<_T * const > { typedef _T Type; }; template - struct __OctaRemovePointer<_T * volatile > { typedef _T Type; }; + struct RemovePointerBase<_T * volatile > { typedef _T Type; }; template - struct __OctaRemovePointer<_T * const volatile> { typedef _T Type; }; + struct RemovePointerBase<_T * const volatile> { typedef _T Type; }; +} - template - using RemovePointer = typename __OctaRemovePointer<_T>::Type; +template +using RemovePointer = typename octa::detail::RemovePointerBase<_T>::Type; - /* add pointer */ +/* add pointer */ - template struct __OctaAddPointer { - typedef RemoveReference<_T> *Type; +namespace detail { + template struct AddPointerBase { + typedef octa::RemoveReference<_T> *Type; }; +} - template - using AddPointer = typename __OctaAddPointer<_T>::Type; +template +using AddPointer = typename octa::detail::AddPointerBase<_T>::Type; - /* add lvalue reference */ +/* add lvalue reference */ namespace detail { template struct AddLr { typedef _T &Type; }; @@ -785,7 +798,7 @@ namespace detail { }; } - /* add rvalue reference */ +/* add rvalue reference */ namespace detail { template struct AddRr { typedef _T &&Type; }; @@ -805,29 +818,33 @@ namespace detail { }; } - /* remove extent */ +/* remove extent */ +namespace detail { template - struct __OctaRemoveExtent { typedef _T Type; }; + struct RemoveExtentBase { typedef _T Type; }; template - struct __OctaRemoveExtent<_T[ ] > { typedef _T Type; }; + struct RemoveExtentBase<_T[ ] > { typedef _T Type; }; template - struct __OctaRemoveExtent<_T[_N]> { typedef _T Type; }; + struct RemoveExtentBase<_T[_N]> { typedef _T Type; }; +} - template - using RemoveExtent = typename __OctaRemoveExtent<_T>::Type; +template +using RemoveExtent = typename octa::detail::RemoveExtentBase<_T>::Type; - /* remove all extents */ +/* remove all extents */ - template struct __OctaRemoveAllExtents { typedef _T Type; }; +namespace detail { + template struct RemoveAllExtentsBase { typedef _T Type; }; - template struct __OctaRemoveAllExtents<_T[]> { - typedef RemoveAllExtents<_T> Type; + template struct RemoveAllExtentsBase<_T[]> { + typedef RemoveAllExtentsBase<_T> Type; }; - template struct __OctaRemoveAllExtents<_T[_N]> { - typedef RemoveAllExtents<_T> Type; + template struct RemoveAllExtentsBase<_T[_N]> { + typedef RemoveAllExtentsBase<_T> Type; }; +} /* make (un)signed * @@ -1090,65 +1107,71 @@ namespace detail { template using CommonType = typename octa::detail::CommonTypeBase<_T, _U, _V...>::Type; - /* aligned storage */ +/* aligned storage */ - template struct __OctaAlignedTest { +namespace detail { + template struct AlignedTest { union type { - uchar __data[_N]; - octa::max_align_t __align; + uchar data[_N]; + octa::max_align_t align; }; }; - template struct __OctaAlignedStorage { + template struct AlignedStorageBase { struct type { - alignas(_A) uchar __data[_N]; + alignas(_A) uchar data[_N]; }; }; +} - template::Type) - > using AlignedStorage = typename __OctaAlignedStorage<_N, _A>::Type; +template::Type) +> using AlignedStorage = typename octa::detail::AlignedStorageBase<_N, _A>::Type; - /* aligned union */ +/* aligned union */ - template struct __OctaAlignMax; +namespace detail { + template struct AlignMax; - template struct __OctaAlignMax<_N> { + template struct AlignMax<_N> { static constexpr size_t value = _N; }; - template struct __OctaAlignMax<_N1, _N2> { + template struct AlignMax<_N1, _N2> { static constexpr size_t value = (_N1 > _N2) ? _N1 : _N2; }; template - struct __OctaAlignMax<_N1, _N2, _N...> { + struct AlignMax<_N1, _N2, _N...> { static constexpr size_t value - = __OctaAlignMax<__OctaAlignMax<_N1, _N2>::value, _N...>::value; + = AlignMax::value, _N...>::value; }; - template struct __OctaAlignedUnion { - static constexpr size_t __alignment_value - = __OctaAlignMax::value; + template struct AlignedUnionBase { + static constexpr size_t alignment_value + = AlignMax::value; struct type { - alignas(__alignment_value) uchar __data[__OctaAlignMax<_N, + alignas(alignment_value) uchar data[AlignMax<_N, sizeof(_T)...>::value]; }; }; +} /* namespace detail */ - template - using AlignedUnion = typename __OctaAlignedUnion<_N, _T...>::Type; +template +using AlignedUnion = typename octa::detail::AlignedUnionBase<_N, _T...>::Type; - /* underlying type */ +/* underlying type */ +namespace detail { /* gotta wrap, in a struct otherwise clang ICEs... */ - template struct __OctaUnderlyingType { + template struct UnderlyingTypeBase { typedef __underlying_type(_T) Type; }; +} - template - using UnderlyingType = typename __OctaUnderlyingType<_T>::Type; +template +using UnderlyingType = typename octa::detail::UnderlyingTypeBase<_T>::Type; } #endif \ No newline at end of file