diff --git a/octa/memory.h b/octa/memory.h index 5218c27..d464493 100644 --- a/octa/memory.h +++ b/octa/memory.h @@ -522,11 +522,11 @@ private: namespace detail { template struct BoxIf { - typedef Box<_T> Box; + typedef octa::Box<_T> Box; }; template struct BoxIf<_T[]> { - typedef Box<_T[]> BoxUnknownSize; + typedef octa::Box<_T[]> BoxUnknownSize; }; template struct BoxIf<_T[_N]> { diff --git a/octa/type_traits.h b/octa/type_traits.h index 4c06c82..15589d1 100644 --- a/octa/type_traits.h +++ b/octa/type_traits.h @@ -13,7 +13,17 @@ namespace octa { /* forward declarations */ - template struct __OctaRemoveCv; +namespace detail { + template struct RemoveCv; + template struct AddLr; + template struct AddRr; + template struct AddConst; + template struct RemoveReference; + template struct RemoveAllExtents; + + template struct CommonTypeBase; +} + template struct __OctaAddLr; template struct __OctaAddRr; template struct __OctaAddConst; @@ -22,10 +32,8 @@ namespace octa { template struct __OctaRemoveAllExtents; template struct IsTriviallyDefaultConstructible; - template struct __OctaCommonType; - template - using RemoveCv = typename __OctaRemoveCv<_T>::Type; + using RemoveCv = typename octa::detail::RemoveCv<_T>::Type; template using AddLvalueReference = typename __OctaAddLr<_T>::Type; @@ -42,8 +50,9 @@ namespace octa { template using RemoveAllExtents = typename __OctaRemoveAllExtents<_T>::Type; - /* declval also defined here to avoid including utility.h */ - template AddRvalueReference<_T> __octa_declval(); +namespace detail { + template octa::AddRvalueReference<_T> declval_in(); +} /* integral constant */ @@ -152,25 +161,29 @@ namespace octa { /* is function */ - struct __OctaFunctionTestDummy {}; +namespace detail { + struct FunctionTestDummy {}; - template char __octa_function_test(_T *); - template char __octa_function_test(__OctaFunctionTestDummy); - template int __octa_function_test(...); + template char function_test(_T *); + template char function_test(FunctionTestDummy); + template int function_test(...); - template _T &__octa_function_source(int); - template __OctaFunctionTestDummy __octa_function_source(...); + template _T &function_source(int); + template FunctionTestDummy function_source(...); - template::value || IsUnion<_T>::value - || IsVoid<_T>::value || IsReference<_T>::value - || IsNullPointer<_T>::value - > struct __OctaIsFunction: IntegralConstant(__octa_function_source<_T>(0))) == 1 + template::value || + octa::IsUnion<_T>::value || + octa::IsVoid<_T>::value || + octa::IsReference<_T>::value || + octa::IsNullPointer<_T>::value + > struct IsFunctionBase: IntegralConstant(function_source<_T>(0))) == 1 > {}; - template struct __OctaIsFunction<_T, true>: False {}; + template struct IsFunctionBase<_T, true>: False {}; +} /* namespace detail */ - template struct IsFunction: __OctaIsFunction<_T> {}; +template struct IsFunction: octa::detail::IsFunctionBase<_T> {}; /* is arithmetic */ @@ -316,91 +329,92 @@ namespace octa { /* is constructible */ -#define __OCTA_MOVE(v) static_cast &&>(v) +namespace detail { +#define OCTA_MOVE(v) static_cast &&>(v) - template struct __OctaSelect2nd { typedef _T Type; }; - struct __OctaAny { __OctaAny(...); }; + template struct Select2nd { typedef _T Type; }; + struct Any { Any(...); }; - template typename __OctaSelect2nd< - decltype(__OCTA_MOVE(_T(__octa_declval<_A>()...))), True - >::Type __octa_is_ctible_test(_T &&, _A &&...); + template typename Select2nd< + decltype(OCTA_MOVE(_T(declval_in<_A>()...))), True + >::Type is_ctible_test(_T &&, _A &&...); -//#undef __OCTA_MOVE +#undef OCTA_MOVE - template False __octa_is_ctible_test(__OctaAny, _A &&...); + template False is_ctible_test(Any, _A &&...); template - struct __OctaCtibleCore: __OctaCommonType< - decltype(__octa_is_ctible_test(__octa_declval<_T>(), - __octa_declval<_A>()...)) + struct CtibleCore: CommonTypeBase< + decltype(is_ctible_test(declval_in<_T>(), declval_in<_A>()...)) >::Type {}; /* function types are not constructible */ template - struct __OctaCtibleCore: False {}; + struct CtibleCore: False {}; /* scalars are default constructible, refs are not */ template - struct __OctaCtibleCore: IsScalar<_T> {}; + struct CtibleCore: octa::IsScalar<_T> {}; /* scalars and references are constructible from one arg if * implicitly convertible to scalar or reference */ template - struct __OctaCtibleRef { - static True __test(_T); - static False __test(...); + struct CtibleRef { + static True test(_T); + static False test(...); }; template - struct __OctaCtibleCore: __OctaCommonType< - decltype(__OctaCtibleRef<_T>::__test(__octa_declval<_U>())) + struct CtibleCore: CommonTypeBase< + decltype(CtibleRef<_T>::test(declval_in<_U>())) >::Type {}; /* scalars and references are not constructible from multiple args */ template - struct __OctaCtibleCore: False {}; + struct CtibleCore: False {}; /* treat scalars and refs separately */ template - struct __OctaCtibleVoidCheck: __OctaCtibleCore< - (IsScalar<_T>::value || IsReference<_T>::value), _T, _A... + struct CtibleVoidCheck: CtibleCore< + (octa::IsScalar<_T>::value || octa::IsReference<_T>::value), _T, _A... > {}; /* if any of T or A is void, IsConstructible should be false */ template - struct __OctaCtibleVoidCheck: False {}; + struct CtibleVoidCheck: False {}; - template struct __OctaCtibleContainsVoid; + template struct CtibleContainsVoid; - template<> struct __OctaCtibleContainsVoid<>: False {}; + template<> struct CtibleContainsVoid<>: False {}; template - struct __OctaCtibleContainsVoid<_T, _A...> { - static constexpr bool value = IsVoid<_T>::value - || __OctaCtibleContainsVoid<_A...>::value; + struct CtibleContainsVoid<_T, _A...> { + static constexpr bool value = octa::IsVoid<_T>::value + || CtibleContainsVoid<_A...>::value; }; /* entry point */ template - struct __OctaCtible: __OctaCtibleVoidCheck< - __OctaCtibleContainsVoid<_T, _A...>::value || IsAbstract<_T>::value, + struct Ctible: CtibleVoidCheck< + CtibleContainsVoid<_T, _A...>::value || octa::IsAbstract<_T>::value, _T, _A... > {}; /* array types are default constructible if their element type is */ template - struct __OctaCtibleCore: __OctaCtible> {}; + struct CtibleCore: Ctible> {}; /* otherwise array types are not constructible by this syntax */ template - struct __OctaCtibleCore: False {}; + struct CtibleCore: False {}; /* incomplete array types are not constructible */ template - struct __OctaCtibleCore: False {}; + struct CtibleCore: False {}; +} /* namespace detail */ - template - struct IsConstructible: __OctaCtible<_T, _A...> {}; +template +struct IsConstructible: octa::detail::Ctible<_T, _A...> {}; /* is default constructible */ @@ -420,23 +434,25 @@ namespace octa { /* is assignable */ - template typename __OctaSelect2nd< - decltype((__octa_declval<_T>() = __octa_declval<_U>())), True - >::Type __octa_assign_test(_T &&, _U &&); +namespace detail { + template typename octa::detail::Select2nd< + decltype((declval_in<_T>() = declval_in<_U>())), True + >::Type assign_test(_T &&, _U &&); - template False __octa_assign_test(__OctaAny, _T &&); + template False assign_test(Any, _T &&); - template::value || - IsVoid<_U>::value - > struct __OctaIsAssignable: __OctaCommonType< - decltype(__octa_assign_test(__octa_declval<_T>(), __octa_declval<_U>())) + template::value || + octa::IsVoid<_U>::value + > struct IsAssignableBase: CommonTypeBase< + decltype(assign_test(declval_in<_T>(), declval_in<_U>())) >::Type {}; template - struct __OctaIsAssignable<_T, _U, true>: False {}; + struct IsAssignableBase<_T, _U, true>: False {}; +} /* namespace detail */ - template - struct IsAssignable: __OctaIsAssignable<_T, _U> {}; +template +struct IsAssignable: octa::detail::IsAssignableBase<_T, _U> {}; /* is copy assignable */ @@ -458,7 +474,7 @@ namespace octa { template struct IsDestructorWellformed { template static char __test(typename __OctaIsDtibleApply< - decltype(__octa_declval<_TT &>().~_TT()) + decltype(octa::detail::declval_in<_TT &>().~_TT()) >::Type); template static int __test(...); @@ -597,7 +613,7 @@ namespace octa { template static void __test_f(_TT); template(__octa_declval<_FF>())) + typename = decltype(__test_f<_TT>(octa::detail::declval_in<_FF>())) > static True __test(int); template static False __test(...); @@ -657,10 +673,12 @@ namespace octa { template using RemoveVolatile = typename __OctaRemoveVolatile<_T>::Type; +namespace detail { template - struct __OctaRemoveCv { - typedef RemoveVolatile> Type; + struct RemoveCv { + typedef octa::RemoveVolatile> Type; }; +} /* add const, volatile, cv */ @@ -793,251 +811,266 @@ namespace octa { typedef RemoveAllExtents<_T> Type; }; - /* make (un)signed - * - * this is bad, but i don't see any better way - * shamelessly copied from graphitemaster @ neothyne - */ +/* make (un)signed + * + * this is bad, but i don't see any better way + * shamelessly copied from graphitemaster @ neothyne + */ - template struct __OctaTl { - typedef _T __first; - typedef _U __rest; +namespace detail { + template struct TypeList { + typedef _T first; + typedef _U rest; }; /* not a type */ - struct __OctaNat { - __OctaNat() = delete; - __OctaNat(const __OctaNat &) = delete; - __OctaNat &operator=(const __OctaNat &) = delete; - ~__OctaNat() = delete; + struct TlNat { + TlNat() = delete; + TlNat(const TlNat &) = delete; + TlNat &operator=(const TlNat &) = delete; + ~TlNat() = delete; }; - typedef __OctaTl>>>> __octa_stypes; + typedef TypeList>>>> stypes; - typedef __OctaTl>>>> __octa_utypes; + typedef TypeList>>>> utypes; - template - struct __OctaTypeFindFirst; + template + struct TypeFindFirst; template - struct __OctaTypeFindFirst<__OctaTl<_T, _U>, _N, true> { + struct TypeFindFirst, _N, true> { typedef _T Type; }; template - struct __OctaTypeFindFirst<__OctaTl<_T, _U>, _N, false> { - typedef typename __OctaTypeFindFirst<_U, _N>::Type Type; + struct TypeFindFirst, _N, false> { + typedef typename TypeFindFirst<_U, _N>::Type Type; }; template>::value, - bool = IsVolatile>::value - > struct __OctaApplyCv { + bool = octa::IsConst>::value, + bool = octa::IsVolatile>::value + > struct ApplyCv { typedef _U Type; }; template - struct __OctaApplyCv<_T, _U, true, false> { /* const */ + struct ApplyCv<_T, _U, true, false> { /* const */ typedef const _U Type; }; template - struct __OctaApplyCv<_T, _U, false, true> { /* volatile */ + struct ApplyCv<_T, _U, false, true> { /* volatile */ typedef volatile _U Type; }; template - struct __OctaApplyCv<_T, _U, true, true> { /* const volatile */ + struct ApplyCv<_T, _U, true, true> { /* const volatile */ typedef const volatile _U Type; }; template - struct __OctaApplyCv<_T &, _U, true, false> { /* const */ + struct ApplyCv<_T &, _U, true, false> { /* const */ typedef const _U &Type; }; template - struct __OctaApplyCv<_T &, _U, false, true> { /* volatile */ + struct ApplyCv<_T &, _U, false, true> { /* volatile */ typedef volatile _U &Type; }; template - struct __OctaApplyCv<_T &, _U, true, true> { /* const volatile */ + struct ApplyCv<_T &, _U, true, true> { /* const volatile */ typedef const volatile _U &Type; }; - template::value || IsEnum<_T>::value> - struct __OctaMakeSigned {}; + template::value || + octa::IsEnum<_T>::value> + struct MakeSigned {}; - template::value || IsEnum<_T>::value> - struct __OctaMakeUnsigned {}; + template::value || + octa::IsEnum<_T>::value> + struct MakeUnsigned {}; template - struct __OctaMakeSigned<_T, true> { - typedef typename __OctaTypeFindFirst<__octa_stypes, sizeof(_T)>::Type Type; + struct MakeSigned<_T, true> { + typedef typename TypeFindFirst::Type Type; }; template - struct __OctaMakeUnsigned<_T, true> { - typedef typename __OctaTypeFindFirst<__octa_utypes, sizeof(_T)>::Type Type; + struct MakeUnsigned<_T, true> { + typedef typename TypeFindFirst::Type Type; }; - template<> struct __OctaMakeSigned {}; - template<> struct __OctaMakeSigned { typedef schar Type; }; - template<> struct __OctaMakeSigned { typedef schar Type; }; - template<> struct __OctaMakeSigned { typedef short Type; }; - template<> struct __OctaMakeSigned { typedef short Type; }; - template<> struct __OctaMakeSigned { typedef int Type; }; - template<> struct __OctaMakeSigned { typedef int Type; }; - template<> struct __OctaMakeSigned { typedef long Type; }; - template<> struct __OctaMakeSigned { typedef long Type; }; - template<> struct __OctaMakeSigned { typedef llong Type; }; - template<> struct __OctaMakeSigned { typedef llong Type; }; + template<> struct MakeSigned {}; + template<> struct MakeSigned { typedef schar Type; }; + template<> struct MakeSigned { typedef schar Type; }; + template<> struct MakeSigned { typedef short Type; }; + template<> struct MakeSigned { typedef short Type; }; + template<> struct MakeSigned { typedef int Type; }; + template<> struct MakeSigned { typedef int Type; }; + template<> struct MakeSigned { typedef long Type; }; + template<> struct MakeSigned { typedef long Type; }; + template<> struct MakeSigned { typedef llong Type; }; + template<> struct MakeSigned { typedef llong Type; }; - template<> struct __OctaMakeUnsigned {}; - template<> struct __OctaMakeUnsigned { typedef uchar Type; }; - template<> struct __OctaMakeUnsigned { typedef uchar Type; }; - template<> struct __OctaMakeUnsigned { typedef ushort Type; }; - template<> struct __OctaMakeUnsigned { typedef ushort Type; }; - template<> struct __OctaMakeUnsigned { typedef uint Type; }; - template<> struct __OctaMakeUnsigned { typedef uint Type; }; - template<> struct __OctaMakeUnsigned { typedef ulong Type; }; - template<> struct __OctaMakeUnsigned { typedef ulong Type; }; - template<> struct __OctaMakeUnsigned { typedef ullong Type; }; - template<> struct __OctaMakeUnsigned { typedef ullong Type; }; + template<> struct MakeUnsigned {}; + template<> struct MakeUnsigned { typedef uchar Type; }; + template<> struct MakeUnsigned { typedef uchar Type; }; + template<> struct MakeUnsigned { typedef ushort Type; }; + template<> struct MakeUnsigned { typedef ushort Type; }; + template<> struct MakeUnsigned { typedef uint Type; }; + template<> struct MakeUnsigned { typedef uint Type; }; + template<> struct MakeUnsigned { typedef ulong Type; }; + template<> struct MakeUnsigned { typedef ulong Type; }; + template<> struct MakeUnsigned { typedef ullong Type; }; + template<> struct MakeUnsigned { typedef ullong Type; }; - template struct __OctaMakeSignedBase { - typedef typename __OctaApplyCv<_T, - typename __OctaMakeSigned>::Type + template struct MakeSignedBase { + typedef typename ApplyCv<_T, + typename MakeSigned>::Type >::Type Type; }; - template struct __OctaMakeUnsignedBase { - typedef typename __OctaApplyCv<_T, - typename __OctaMakeUnsigned>::Type + template struct MakeUnsignedBase { + typedef typename ApplyCv<_T, + typename MakeUnsigned>::Type >::Type Type; }; +} /* namespace detail */ - template - using MakeSigned = typename __OctaMakeSignedBase<_T>::Type; - template - using MakeUnsigned = typename __OctaMakeUnsignedBase<_T>::Type; +template +using MakeSigned = typename octa::detail::MakeSignedBase<_T>::Type; +template +using MakeUnsigned = typename octa::detail::MakeUnsignedBase<_T>::Type; - /* conditional */ +/* conditional */ +namespace detail { template - struct __OctaConditional { + struct ConditionalBase { typedef _T Type; }; template - struct __OctaConditional { + struct ConditionalBase { typedef _U Type; }; +} - template - using Conditional = typename __OctaConditional<_cond, _T, _U>::Type; +template +using Conditional = typename octa::detail::ConditionalBase<_cond, _T, _U>::Type; - /* result of call at compile time */ +/* result of call at compile time */ -#define __OCTA_FWD(_T, _v) static_cast<_T &&>(_v) +namespace detail { +#define OCTA_FWD(_T, _v) static_cast<_T &&>(_v) template - inline auto __octa_rof_invoke(_F &&__f, _A &&...__args) -> - decltype(__OCTA_FWD(_F, __f)(__OCTA_FWD(_A, __args)...)) { - return __OCTA_FWD(_F, __f)(__OCTA_FWD(_A, __args)...); + inline auto rof_invoke(_F &&f, _A &&...args) -> + decltype(OCTA_FWD(_F, f)(OCTA_FWD(_A, args)...)) { + return OCTA_FWD(_F, f)(OCTA_FWD(_A, args)...); } template - inline auto __octa_rof_invoke(_T _B::*__pmd, _D &&__ref) -> - decltype(__OCTA_FWD(_D, __ref).*__pmd) { - return __OCTA_FWD(_D, __ref).*__pmd; + inline auto rof_invoke(_T _B::*pmd, _D &&ref) -> + decltype(OCTA_FWD(_D, ref).*pmd) { + return OCTA_FWD(_D, ref).*pmd; } template - inline auto __octa_rof_invoke(_PMD &&__pmd, _P &&__ptr) -> - decltype((*__OCTA_FWD(_P, __ptr)).*__OCTA_FWD(_PMD, __pmd)) { - return (*__OCTA_FWD(_P, __ptr)).*__OCTA_FWD(_PMD, __pmd); + inline auto rof_invoke(_PMD &&pmd, _P &&ptr) -> + decltype((*OCTA_FWD(_P, ptr)).*OCTA_FWD(_PMD, pmd)) { + return (*OCTA_FWD(_P, ptr)).*OCTA_FWD(_PMD, pmd); } template - inline auto __octa_rof_invoke(_T _B::*__pmf, _D &&__ref, _A &&...__args) -> - decltype((__OCTA_FWD(_D, __ref).*__pmf)(__OCTA_FWD(_A, __args)...)) { - return (__OCTA_FWD(_D, __ref).*__pmf)(__OCTA_FWD(_A, __args)...); + inline auto rof_invoke(_T _B::*pmf, _D &&ref, _A &&...args) -> + decltype((OCTA_FWD(_D, ref).*pmf)(OCTA_FWD(_A, args)...)) { + return (OCTA_FWD(_D, ref).*pmf)(OCTA_FWD(_A, args)...); } template - inline auto __octa_rof_invoke(_PMF &&__pmf, _P &&__ptr, _A &&...__args) -> - decltype(((*__OCTA_FWD(_P, __ptr)).*__OCTA_FWD(_PMF, __pmf)) - (__OCTA_FWD(_A, __args)...)) { - return ((*__OCTA_FWD(_P, __ptr)).*__OCTA_FWD(_PMF, __pmf)) - (__OCTA_FWD(_A, __args)...); + inline auto rof_invoke(_PMF &&pmf, _P &&ptr, _A &&...args) -> + decltype(((*OCTA_FWD(_P, ptr)).*OCTA_FWD(_PMF, pmf)) + (OCTA_FWD(_A, args)...)) { + return ((*OCTA_FWD(_P, ptr)).*OCTA_FWD(_PMF, pmf)) + (OCTA_FWD(_A, args)...); } -#undef __OCTA_FWD +#undef OCTA_FWD template - struct __OctaResultOf {}; + struct ResultOfCore {}; template - struct __OctaResultOf<_F(_A...), decltype(void(__octa_rof_invoke( - __octa_declval<_F>(), __octa_declval<_A>()...)))> { - using type = decltype(__octa_rof_invoke(__octa_declval<_F>(), - __octa_declval<_A>()...)); + struct ResultOfCore<_F(_A...), decltype(void(rof_invoke( + octa::detail::declval_in<_F>(), octa::detail::declval_in<_A>()...)))> { + using type = decltype(rof_invoke(octa::detail::declval_in<_F>(), + octa::detail::declval_in<_A>()...)); }; - template struct __OctaResultOfBase: __OctaResultOf<_T> {}; + template struct ResultOfBase: ResultOfCore<_T> {}; +} /* namespace detail */ +template +using ResultOf = typename octa::detail::ResultOfBase<_T>::Type; + +/* enable if */ + +namespace detail { + template struct EnableIfBase {}; + + template struct EnableIfBase { typedef _T Type; }; +} + +template +using EnableIf = typename octa::detail::EnableIfBase<_B, _T>::Type; + +/* decay */ + +namespace detail { template - using ResultOf = typename __OctaResultOfBase<_T>::Type; - - /* enable if */ - - template struct __OctaEnableIf {}; - - template struct __OctaEnableIf { typedef _T Type; }; - - template - using EnableIf = typename __OctaEnableIf<_B, _T>::Type; - - /* decay */ - - template - struct __OctaDecay { + struct DecayBase { private: - typedef RemoveReference<_T> _U; + typedef octa::RemoveReference<_T> _U; public: - typedef Conditional::value, - RemoveExtent<_U> *, - Conditional::value, AddPointer<_U>, RemoveCv<_U>> + typedef octa::Conditional::value, + octa::RemoveExtent<_U> *, + octa::Conditional::value, + octa::AddPointer<_U>, octa::RemoveCv<_U>> > Type; }; +} - template - using Decay = typename __OctaDecay<_T>::Type; +template +using Decay = typename octa::detail::DecayBase<_T>::Type; - /* common type */ +/* common type */ - template struct __OctaCommonType; +namespace detail { + template struct CommonTypeBase; - template struct __OctaCommonType<_T> { + template struct CommonTypeBase<_T> { typedef Decay<_T> Type; }; - template struct __OctaCommonType<_T, _U> { - typedef Decay() - : __octa_declval<_U>())> Type; + template struct CommonTypeBase<_T, _U> { + typedef Decay() + : octa::detail::declval_in<_U>())> Type; }; template - struct __OctaCommonType<_T, _U, _V...> { - typedef typename __OctaCommonType::Type, + struct CommonTypeBase<_T, _U, _V...> { + typedef typename CommonTypeBase::Type, _V...>::Type Type; }; +} - template - using CommonType = typename __OctaCommonType<_T, _U, _V...>::Type; +template +using CommonType = typename octa::detail::CommonTypeBase<_T, _U, _V...>::Type; /* aligned storage */