2015-04-13 21:25:31 +00:00
|
|
|
/* Type traits for OctaSTD.
|
|
|
|
*
|
|
|
|
* This file is part of OctaSTD. See COPYING.md for futher information.
|
|
|
|
*/
|
|
|
|
|
2015-06-28 15:04:49 +00:00
|
|
|
#ifndef OCTA_TYPE_TRAITS_HH
|
|
|
|
#define OCTA_TYPE_TRAITS_HH
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-04-13 22:04:25 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-06-28 14:39:04 +00:00
|
|
|
#include "octa/types.hh"
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-04-23 19:38:18 +00:00
|
|
|
namespace octa {
|
2015-06-06 17:22:10 +00:00
|
|
|
/* forward declarations */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 20:47:30 +00:00
|
|
|
template<typename> struct RemoveCvBase;
|
2015-06-04 20:08:56 +00:00
|
|
|
template<typename> struct AddLr;
|
|
|
|
template<typename> struct AddRr;
|
2015-06-04 20:47:30 +00:00
|
|
|
template<typename> struct AddConstBase;
|
|
|
|
template<typename> struct RemoveReferenceBase;
|
|
|
|
template<typename> struct RemoveAllExtentsBase;
|
2015-06-04 20:08:56 +00:00
|
|
|
|
|
|
|
template<typename ...> struct CommonTypeBase;
|
|
|
|
}
|
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
template<typename> struct IsReference;
|
|
|
|
template<typename> struct IsTriviallyDefaultConstructible;
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemoveCv = typename octa::detail::RemoveCvBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddLvalueReference = typename octa::detail::AddLr<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddRvalueReference = typename octa::detail::AddRr<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddConst = typename octa::detail::AddConstBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemoveReference = typename octa::detail::RemoveReferenceBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemoveAllExtents = typename octa::detail::RemoveAllExtentsBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> octa::AddRvalueReference<T> declval_in();
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-23 19:53:05 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* integral constant */
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, T val>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct IntegralConstant {
|
2015-06-04 21:57:06 +00:00
|
|
|
static constexpr T value = val;
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-07 23:55:08 +00:00
|
|
|
using Value = T;
|
|
|
|
using Type = IntegralConstant<T, val>;
|
2015-04-18 17:32:25 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
constexpr operator Value() const { return value; }
|
|
|
|
constexpr Value operator()() const { return value; }
|
|
|
|
};
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-07 23:55:08 +00:00
|
|
|
using True = IntegralConstant<bool, true>;
|
|
|
|
using False = IntegralConstant<bool, false>;
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, T val> constexpr T IntegralConstant<T, val>::value;
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is void */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsVoidBase : False {};
|
2015-06-05 22:45:07 +00:00
|
|
|
template< > struct IsVoidBase<void>: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsVoid: octa::detail::IsVoidBase<RemoveCv<T>> {};
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is null pointer */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename> struct IsNullPointerBase : False {};
|
|
|
|
template< > struct IsNullPointerBase<octa::Nullptr>: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsNullPointer:
|
|
|
|
octa::detail::IsNullPointerBase<RemoveCv<T>> {};
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is integer */
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsIntegralBase: False {};
|
2015-06-04 20:19:05 +00:00
|
|
|
|
|
|
|
template<> struct IsIntegralBase<bool >: True {};
|
|
|
|
template<> struct IsIntegralBase<char >: True {};
|
|
|
|
template<> struct IsIntegralBase<short >: True {};
|
|
|
|
template<> struct IsIntegralBase<int >: True {};
|
|
|
|
template<> struct IsIntegralBase<long >: True {};
|
|
|
|
|
2015-06-30 22:07:28 +00:00
|
|
|
template<> struct IsIntegralBase<octa::sbyte >: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::byte >: True {};
|
2015-06-08 20:20:12 +00:00
|
|
|
template<> struct IsIntegralBase<octa::ushort>: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::uint >: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::ulong >: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::llong >: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::ullong>: True {};
|
|
|
|
|
|
|
|
template<> struct IsIntegralBase<octa::Char16>: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::Char32>: True {};
|
|
|
|
template<> struct IsIntegralBase<octa::Wchar >: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-05-03 23:00:27 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsIntegral: octa::detail::IsIntegralBase<RemoveCv<T>> {};
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is floating point */
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsFloatingPointBase: False {};
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<> struct IsFloatingPointBase<float >: True {};
|
|
|
|
template<> struct IsFloatingPointBase<double>: True {};
|
|
|
|
|
|
|
|
template<> struct IsFloatingPointBase<octa::ldouble>: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsFloatingPoint: octa::detail::IsFloatingPointBase<RemoveCv<T>> {};
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is array */
|
2015-04-13 22:19:52 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename > struct IsArray : False {};
|
|
|
|
template<typename T > struct IsArray<T[] >: True {};
|
|
|
|
template<typename T, octa::Size N> struct IsArray<T[N]>: True {};
|
2015-04-13 22:19:52 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is pointer */
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-07 03:10:08 +00:00
|
|
|
template<typename > struct IsPointerBase : False {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsPointerBase<T *>: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsPointer: octa::detail::IsPointerBase<RemoveCv<T>> {};
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is lvalue reference */
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-07 03:10:08 +00:00
|
|
|
template<typename > struct IsLvalueReference : False {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsLvalueReference<T &>: True {};
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is rvalue reference */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-07 03:10:08 +00:00
|
|
|
template<typename > struct IsRvalueReference : False {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsRvalueReference<T &&>: True {};
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is enum */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsEnum: IntegralConstant<bool, __is_enum(T)> {};
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is union */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsUnion: IntegralConstant<bool, __is_union(T)> {};
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is class */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsClass: IntegralConstant<bool, __is_class(T)> {};
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is function */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
|
|
|
struct FunctionTestDummy {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> char function_test(T *);
|
|
|
|
template<typename T> char function_test(FunctionTestDummy);
|
|
|
|
template<typename T> int function_test(...);
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> T &function_source(int);
|
2015-06-07 03:10:08 +00:00
|
|
|
template<typename T> FunctionTestDummy function_source(...);
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool = octa::IsClass<T>::value ||
|
2015-06-07 03:10:08 +00:00
|
|
|
octa::IsUnion<T>::value ||
|
|
|
|
octa::IsVoid<T>::value ||
|
|
|
|
octa::IsReference<T>::value ||
|
|
|
|
octa::IsNullPointer<T>::value
|
2015-06-04 20:08:56 +00:00
|
|
|
> struct IsFunctionBase: IntegralConstant<bool,
|
2015-06-04 21:57:06 +00:00
|
|
|
sizeof(function_test<T>(function_source<T>(0))) == 1
|
2015-04-23 00:46:29 +00:00
|
|
|
> {};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsFunctionBase<T, true>: False {};
|
2015-06-04 20:08:56 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsFunction: octa::detail::IsFunctionBase<T> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is arithmetic */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsArithmetic: IntegralConstant<bool,
|
|
|
|
(IsIntegral<T>::value || IsFloatingPoint<T>::value)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is fundamental */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsFundamental: IntegralConstant<bool,
|
|
|
|
(IsArithmetic<T>::value || IsVoid<T>::value || IsNullPointer<T>::value)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is compound */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsCompound: IntegralConstant<bool,
|
|
|
|
!IsFundamental<T>::value
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is pointer to member */
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-04-23 19:38:18 +00:00
|
|
|
template<typename>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct IsMemberPointerBase: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsMemberPointerBase<T U::*>: True {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsMemberPointer: octa::detail::IsMemberPointerBase<RemoveCv<T>> {};
|
2015-04-14 00:12:00 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is pointer to member object */
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-04-23 19:38:18 +00:00
|
|
|
template<typename>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct IsMemberObjectPointerBase: False {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsMemberObjectPointerBase<T U::*>: IntegralConstant<bool,
|
|
|
|
!octa::IsFunction<T>::value
|
2015-04-23 01:16:48 +00:00
|
|
|
> {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsMemberObjectPointer:
|
|
|
|
octa::detail::IsMemberObjectPointerBase<RemoveCv<T>> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is pointer to member function */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-04-23 19:38:18 +00:00
|
|
|
template<typename>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct IsMemberFunctionPointerBase: False {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsMemberFunctionPointerBase<T U::*>: IntegralConstant<bool,
|
|
|
|
octa::IsFunction<T>::value
|
2015-04-23 17:47:33 +00:00
|
|
|
> {};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsMemberFunctionPointer:
|
|
|
|
octa::detail::IsMemberFunctionPointerBase<RemoveCv<T>> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is reference */
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsReference: IntegralConstant<bool,
|
|
|
|
(IsLvalueReference<T>::value || IsRvalueReference<T>::value)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-13 22:19:52 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is object */
|
2015-04-13 21:56:02 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsObject: IntegralConstant<bool,
|
|
|
|
(!IsFunction<T>::value && !IsVoid<T>::value && !IsReference<T>::value)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-13 21:25:31 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is scalar */
|
2015-04-13 22:04:25 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsScalar: IntegralConstant<bool,
|
|
|
|
(IsMemberPointer<T>::value || IsPointer<T>::value || IsEnum<T>::value
|
|
|
|
|| IsNullPointer <T>::value || IsArithmetic<T>::value)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-13 22:04:25 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is abstract */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsAbstract: IntegralConstant<bool, __is_abstract(T)> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is const */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-05 22:45:07 +00:00
|
|
|
template<typename > struct IsConst : False {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsConst<const T>: True {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is volatile */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-05 22:45:07 +00:00
|
|
|
template<typename > struct IsVolatile : False {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsVolatile<volatile T>: True {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is empty */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsEmpty: IntegralConstant<bool, __is_empty(T)> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is POD */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsPod: IntegralConstant<bool, __is_pod(T)> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is polymorphic */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsPolymorphic: IntegralConstant<bool, __is_polymorphic(T)> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is signed */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-07-01 17:51:39 +00:00
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
struct IsSignedBase: IntegralConstant<bool, T(-1) < T(0)> {};
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, bool = octa::IsArithmetic<T>::value>
|
|
|
|
struct IsSigned: False {};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-07-01 17:51:39 +00:00
|
|
|
struct IsSigned<T, true>: octa::detail::IsSignedBase<T> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is unsigned */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-07-01 17:51:39 +00:00
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
struct IsUnsignedBase: IntegralConstant<bool, T(0) < T(-1)> {};
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, bool = octa::IsArithmetic<T>::value>
|
|
|
|
struct IsUnsigned: False {};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-07-01 17:51:39 +00:00
|
|
|
struct IsUnsigned<T, true>: octa::detail::IsUnsignedBase<T> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is standard layout */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsStandardLayout: IntegralConstant<bool, __is_standard_layout(T)> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is literal type */
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsLiteralType: IntegralConstant<bool, __is_literal_type(T)> {};
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is trivially copyable */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct IsTriviallyCopyable: IntegralConstant<bool,
|
2015-06-04 21:57:06 +00:00
|
|
|
IsScalar<RemoveAllExtents<T>>::value
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is trivial */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTrivial: IntegralConstant<bool, __is_trivial(T)> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* has virtual destructor */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:19:05 +00:00
|
|
|
struct HasVirtualDestructor: IntegralConstant<bool,
|
2015-06-04 21:57:06 +00:00
|
|
|
__has_virtual_destructor(T)
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is constructible */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
|
|
|
#define OCTA_MOVE(v) static_cast<octa::RemoveReference<decltype(v)> &&>(v)
|
2015-04-23 19:53:05 +00:00
|
|
|
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename, typename T> struct Select2nd { using Type = T; };
|
2015-06-04 20:08:56 +00:00
|
|
|
struct Any { Any(...); };
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A> typename Select2nd<
|
|
|
|
decltype(OCTA_MOVE(T(declval_in<A>()...))), True
|
|
|
|
>::Type is_ctible_test(T &&, A &&...);
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
#undef OCTA_MOVE
|
2015-04-23 19:53:05 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename ...A> False is_ctible_test(Any, A &&...);
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool, typename T, typename ...A>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct CtibleCore: CommonTypeBase<
|
2015-06-04 21:57:06 +00:00
|
|
|
decltype(is_ctible_test(declval_in<T>(), declval_in<A>()...))
|
2015-05-03 22:50:09 +00:00
|
|
|
>::Type {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* function types are not constructible */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename R, typename ...A1, typename ...A2>
|
|
|
|
struct CtibleCore<false, R(A1...), A2...>: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* scalars are default constructible, refs are not */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct CtibleCore<true, T>: octa::IsScalar<T> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* scalars and references are constructible from one arg if
|
|
|
|
* implicitly convertible to scalar or reference */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct CtibleRef {
|
2015-06-04 21:57:06 +00:00
|
|
|
static True test(T);
|
2015-06-04 20:08:56 +00:00
|
|
|
static False test(...);
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct CtibleCore<true, T, U>: CommonTypeBase<
|
|
|
|
decltype(CtibleRef<T>::test(declval_in<U>()))
|
2015-05-03 22:50:09 +00:00
|
|
|
>::Type {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* scalars and references are not constructible from multiple args */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U, typename ...A>
|
|
|
|
struct CtibleCore<true, T, U, A...>: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* treat scalars and refs separately */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool, typename T, typename ...A>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct CtibleVoidCheck: CtibleCore<
|
2015-06-04 21:57:06 +00:00
|
|
|
(octa::IsScalar<T>::value || octa::IsReference<T>::value), T, A...
|
2015-04-23 19:38:18 +00:00
|
|
|
> {};
|
|
|
|
|
|
|
|
/* if any of T or A is void, IsConstructible should be false */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
|
|
|
struct CtibleVoidCheck<true, T, A...>: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename ...A> struct CtibleContainsVoid;
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
template<> struct CtibleContainsVoid<>: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
|
|
|
struct CtibleContainsVoid<T, A...> {
|
|
|
|
static constexpr bool value = octa::IsVoid<T>::value
|
|
|
|
|| CtibleContainsVoid<A...>::value;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* entry point */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct Ctible: CtibleVoidCheck<
|
2015-06-04 21:57:06 +00:00
|
|
|
CtibleContainsVoid<T, A...>::value || octa::IsAbstract<T>::value,
|
|
|
|
T, A...
|
2015-04-23 19:38:18 +00:00
|
|
|
> {};
|
|
|
|
|
|
|
|
/* array types are default constructible if their element type is */
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N>
|
2015-06-04 21:57:06 +00:00
|
|
|
struct CtibleCore<false, T[N]>: Ctible<octa::RemoveAllExtents<T>> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* otherwise array types are not constructible by this syntax */
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N, typename ...A>
|
2015-06-04 21:57:06 +00:00
|
|
|
struct CtibleCore<false, T[N], A...>: False {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
|
|
|
/* incomplete array types are not constructible */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
|
|
|
struct CtibleCore<false, T[], A...>: False {};
|
2015-06-04 20:08:56 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
|
|
|
struct IsConstructible: octa::detail::Ctible<T, A...> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is default constructible */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsDefaultConstructible: IsConstructible<T> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is copy constructible */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsCopyConstructible: IsConstructible<T,
|
|
|
|
AddLvalueReference<AddConst<T>>
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is move constructible */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsMoveConstructible: IsConstructible<T,
|
|
|
|
AddRvalueReference<T>
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is assignable */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U> typename octa::detail::Select2nd<
|
|
|
|
decltype((declval_in<T>() = declval_in<U>())), True
|
|
|
|
>::Type assign_test(T &&, U &&);
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> False assign_test(Any, T &&);
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U, bool = octa::IsVoid<T>::value ||
|
|
|
|
octa::IsVoid<U>::value
|
2015-06-04 20:08:56 +00:00
|
|
|
> struct IsAssignableBase: CommonTypeBase<
|
2015-06-04 21:57:06 +00:00
|
|
|
decltype(assign_test(declval_in<T>(), declval_in<U>()))
|
2015-05-03 22:50:09 +00:00
|
|
|
>::Type {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsAssignableBase<T, U, true>: False {};
|
2015-06-04 20:08:56 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct IsAssignable: octa::detail::IsAssignableBase<T, U> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is copy assignable */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsCopyAssignable: IsAssignable<
|
|
|
|
AddLvalueReference<T>,
|
|
|
|
AddLvalueReference<AddConst<T>>
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
/* is move assignable */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsMoveAssignable: IsAssignable<
|
|
|
|
AddLvalueReference<T>,
|
|
|
|
const AddRvalueReference<T>
|
2015-06-04 20:19:05 +00:00
|
|
|
> {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is destructible */
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename> struct IsDtibleApply { using Type = int; };
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsDestructorWellformed {
|
|
|
|
template<typename TT> static char test(typename IsDtibleApply<
|
|
|
|
decltype(octa::detail::declval_in<TT &>().~TT())
|
2015-05-03 22:50:09 +00:00
|
|
|
>::Type);
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename TT> static int test(...);
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
static constexpr bool value = (sizeof(test<T>(12)) == sizeof(char));
|
2015-04-23 18:26:26 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
template<typename, bool> struct DtibleImpl;
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct DtibleImpl<T, false>: octa::IntegralConstant<bool,
|
|
|
|
IsDestructorWellformed<octa::RemoveAllExtents<T>>::value
|
2015-04-23 18:26:26 +00:00
|
|
|
> {};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct DtibleImpl<T, true>: True {};
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool> struct DtibleFalse;
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct DtibleFalse<T, false>
|
|
|
|
: DtibleImpl<T, octa::IsReference<T>::value> {};
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct DtibleFalse<T, true>: False {};
|
2015-06-04 20:47:30 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsDestructible: octa::detail::DtibleFalse<T, IsFunction<T>::value> {};
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct IsDestructible<T[]>: False {};
|
2015-06-04 20:47:30 +00:00
|
|
|
template< > struct IsDestructible<void>: False {};
|
2015-04-23 18:26:26 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially constructible */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
2015-06-04 20:47:30 +00:00
|
|
|
struct IsTriviallyConstructible: False {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyConstructible<T>: IntegralConstant<bool,
|
|
|
|
__has_trivial_constructor(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyConstructible<T, T &>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyConstructible<T, const T &>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyConstructible<T, T &&>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially default constructible */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyDefaultConstructible: IsTriviallyConstructible<T> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially copy constructible */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyCopyConstructible: IsTriviallyConstructible<T,
|
|
|
|
AddLvalueReference<const T>
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially move constructible */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyMoveConstructible: IsTriviallyConstructible<T,
|
|
|
|
AddRvalueReference<T>
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially assignable */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename ...A>
|
2015-06-04 20:47:30 +00:00
|
|
|
struct IsTriviallyAssignable: False {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyAssignable<T>: IntegralConstant<bool,
|
|
|
|
__has_trivial_assign(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyAssignable<T, T &>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyAssignable<T, const T &>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyAssignable<T, T &&>: IntegralConstant<bool,
|
|
|
|
__has_trivial_copy(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially copy assignable */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyCopyAssignable: IsTriviallyAssignable<T,
|
|
|
|
AddLvalueReference<const T>
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially move assignable */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct IsTriviallyMoveAssignable: IsTriviallyAssignable<T,
|
|
|
|
AddRvalueReference<T>
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is trivially destructible */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:47:30 +00:00
|
|
|
struct IsTriviallyDestructible: IntegralConstant<bool,
|
2015-06-04 21:57:06 +00:00
|
|
|
__has_trivial_destructor(T)
|
2015-06-04 20:47:30 +00:00
|
|
|
> {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is base of */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename B, typename D>
|
|
|
|
struct IsBaseOf: IntegralConstant<bool, __is_base_of(B, D)> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* is convertible */
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename F, typename T, bool = octa::IsVoid<F>::value
|
|
|
|
|| octa::IsFunction<T>::value || octa::IsArray<T>::value
|
2015-06-04 20:47:30 +00:00
|
|
|
> struct IsConvertibleBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename octa::IsVoid<T>::Type;
|
2015-04-23 01:39:43 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename F, typename T>
|
|
|
|
struct IsConvertibleBase<F, T, false> {
|
|
|
|
template<typename TT> static void test_f(TT);
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename FF, typename TT,
|
|
|
|
typename = decltype(test_f<TT>(declval_in<FF>()))
|
2015-06-04 20:47:30 +00:00
|
|
|
> static octa::True test(int);
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
template<typename, typename> static octa::False test(...);
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = decltype(test<F, T>(0));
|
2015-04-23 01:39:43 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename F, typename T>
|
|
|
|
struct IsConvertible: octa::detail::IsConvertibleBase<F, T>::Type {};
|
2015-04-23 01:39:43 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* type equality */
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-05 22:45:07 +00:00
|
|
|
template<typename, typename> struct IsSame : False {};
|
|
|
|
template<typename T > struct IsSame<T, T>: True {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* extent */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::uint I = 0>
|
|
|
|
struct Extent: IntegralConstant<octa::Size, 0> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-08 20:20:12 +00:00
|
|
|
struct Extent<T[], 0>: IntegralConstant<octa::Size, 0> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::uint I>
|
|
|
|
struct Extent<T[], I>: IntegralConstant<octa::Size, Extent<T, I - 1>::value> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N>
|
|
|
|
struct Extent<T[N], 0>: IntegralConstant<octa::Size, N> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N, octa::uint I>
|
|
|
|
struct Extent<T[N], I>: IntegralConstant<octa::Size, Extent<T, I - 1>::value> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* rank */
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T> struct Rank: IntegralConstant<octa::Size, 0> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-08 20:20:12 +00:00
|
|
|
struct Rank<T[]>: IntegralConstant<octa::Size, Rank<T>::value + 1> {};
|
2015-04-23 00:46:29 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N>
|
|
|
|
struct Rank<T[N]>: IntegralConstant<octa::Size, Rank<T>::value + 1> {};
|
2015-04-23 00:26:03 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* remove const, volatile, cv */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveConstBase { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveConstBase<const T> { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveVolatileBase { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveVolatileBase<volatile T> { using Type = T; };
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemoveConst = typename octa::detail::RemoveConstBase<T>::Type;
|
|
|
|
template<typename T>
|
|
|
|
using RemoveVolatile = typename octa::detail::RemoveVolatileBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:47:30 +00:00
|
|
|
struct RemoveCvBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = octa::RemoveVolatile<octa::RemoveConst<T>>;
|
2015-05-06 18:52:07 +00:00
|
|
|
};
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* add const, volatile, cv */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool = octa::IsReference<T>::value
|
|
|
|
|| octa::IsFunction<T>::value || octa::IsConst<T>::value>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct AddConstCore { using Type = T; };
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct AddConstCore<T, false> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const T;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct AddConstBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename AddConstCore<T>::Type;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool = octa::IsReference<T>::value
|
|
|
|
|| octa::IsFunction<T>::value || octa::IsVolatile<T>::value>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct AddVolatileCore { using Type = T; };
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct AddVolatileCore<T, false> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = volatile T;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct AddVolatileBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename AddVolatileCore<T>::Type;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddVolatile = typename octa::detail::AddVolatileBase<T>::Type;
|
2015-05-06 18:52:07 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:47:30 +00:00
|
|
|
struct AddCvBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = octa::AddConst<octa::AddVolatile<T>>;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddCv = typename octa::detail::AddCvBase<T>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* remove reference */
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveReferenceBase { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveReferenceBase<T &> { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveReferenceBase<T &&> { using Type = T; };
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* remove pointer */
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemovePointerBase { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemovePointerBase<T * > { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemovePointerBase<T * const > { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemovePointerBase<T * volatile > { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemovePointerBase<T * const volatile> { using Type = T; };
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemovePointer = typename octa::detail::RemovePointerBase<T>::Type;
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* add pointer */
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct AddPointerBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = octa::RemoveReference<T> *;
|
2015-04-23 01:16:48 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 01:16:48 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using AddPointer = typename octa::detail::AddPointerBase<T>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* add lvalue reference */
|
2015-04-18 15:09:08 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename T> struct AddLr { using Type = T &; };
|
|
|
|
template<typename T> struct AddLr<T &> { using Type = T &; };
|
|
|
|
template<typename T> struct AddLr<T &&> { using Type = T &; };
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddLr<void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = void;
|
2015-04-18 15:09:08 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddLr<const void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const void;
|
2015-04-18 15:09:08 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddLr<volatile void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = volatile void;
|
2015-04-18 15:09:08 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddLr<const volatile void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const volatile void;
|
2015-04-18 15:09:08 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-18 15:09:08 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* add rvalue reference */
|
2015-04-18 15:09:08 +00:00
|
|
|
|
2015-06-04 20:19:05 +00:00
|
|
|
namespace detail {
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename T> struct AddRr { using Type = T &&; };
|
|
|
|
template<typename T> struct AddRr<T &> { using Type = T &&; };
|
|
|
|
template<typename T> struct AddRr<T &&> { using Type = T &&; };
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddRr<void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = void;
|
2015-04-23 19:53:05 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddRr<const void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const void;
|
2015-04-23 19:53:05 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddRr<volatile void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = volatile void;
|
2015-04-23 19:53:05 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
template<> struct AddRr<const volatile void> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const volatile void;
|
2015-04-23 19:53:05 +00:00
|
|
|
};
|
2015-06-04 20:19:05 +00:00
|
|
|
}
|
2015-04-18 15:09:08 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* remove extent */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveExtentBase { using Type = T; };
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveExtentBase<T[ ]> { using Type = T; };
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N>
|
2015-06-07 23:55:08 +00:00
|
|
|
struct RemoveExtentBase<T[N]> { using Type = T; };
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using RemoveExtent = typename octa::detail::RemoveExtentBase<T>::Type;
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* remove all extents */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename T> struct RemoveAllExtentsBase { using Type = T; };
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct RemoveAllExtentsBase<T[]> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = RemoveAllExtentsBase<T>;
|
2015-04-22 23:26:29 +00:00
|
|
|
};
|
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N> struct RemoveAllExtentsBase<T[N]> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = RemoveAllExtentsBase<T>;
|
2015-04-22 23:26:29 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* make (un)signed
|
|
|
|
*
|
|
|
|
* this is bad, but i don't see any better way
|
|
|
|
* shamelessly copied from graphitemaster @ neothyne
|
|
|
|
*/
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U> struct TypeList {
|
2015-06-07 23:55:08 +00:00
|
|
|
using First = T;
|
|
|
|
using Rest = U;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-04-23 19:38:18 +00:00
|
|
|
/* not a type */
|
2015-06-04 20:08:56 +00:00
|
|
|
struct TlNat {
|
|
|
|
TlNat() = delete;
|
|
|
|
TlNat(const TlNat &) = delete;
|
|
|
|
TlNat &operator=(const TlNat &) = delete;
|
|
|
|
~TlNat() = delete;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-30 22:07:28 +00:00
|
|
|
using Stypes = TypeList<octa::sbyte,
|
2015-06-07 23:55:08 +00:00
|
|
|
TypeList<short,
|
|
|
|
TypeList<int,
|
|
|
|
TypeList<long,
|
2015-06-08 20:20:12 +00:00
|
|
|
TypeList<octa::llong, TlNat>>>>>;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-30 22:07:28 +00:00
|
|
|
using Utypes = TypeList<octa::byte,
|
2015-06-08 20:20:12 +00:00
|
|
|
TypeList<octa::ushort,
|
|
|
|
TypeList<octa::uint,
|
|
|
|
TypeList<octa::ulong,
|
|
|
|
TypeList<octa::ullong, TlNat>>>>>;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, octa::Size N, bool = (N <= sizeof(typename T::First))>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct TypeFindFirst;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, typename U, octa::Size N>
|
2015-06-04 21:57:06 +00:00
|
|
|
struct TypeFindFirst<TypeList<T, U>, N, true> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = T;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<typename T, typename U, octa::Size N>
|
2015-06-04 21:57:06 +00:00
|
|
|
struct TypeFindFirst<TypeList<T, U>, N, false> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename TypeFindFirst<U, N>::Type;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U,
|
|
|
|
bool = octa::IsConst<octa::RemoveReference<T>>::value,
|
|
|
|
bool = octa::IsVolatile<octa::RemoveReference<T>>::value
|
2015-06-04 20:08:56 +00:00
|
|
|
> struct ApplyCv {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = U;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T, U, true, false> { /* const */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const U;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T, U, false, true> { /* volatile */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = volatile U;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T, U, true, true> { /* const volatile */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const volatile U;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T &, U, true, false> { /* const */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const U &;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T &, U, false, true> { /* volatile */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = volatile U &;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ApplyCv<T &, U, true, true> { /* const volatile */
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = const volatile U &;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool = octa::IsIntegral<T>::value ||
|
|
|
|
octa::IsEnum<T>::value>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct MakeSigned {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, bool = octa::IsIntegral<T>::value ||
|
|
|
|
octa::IsEnum<T>::value>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct MakeUnsigned {};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct MakeSigned<T, true> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename TypeFindFirst<Stypes, sizeof(T)>::Type;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
struct MakeUnsigned<T, true> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename TypeFindFirst<Utypes, sizeof(T)>::Type;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
template<> struct MakeSigned<bool , true> {};
|
2015-06-07 23:55:08 +00:00
|
|
|
template<> struct MakeSigned<short , true> { using Type = short; };
|
|
|
|
template<> struct MakeSigned<int , true> { using Type = int; };
|
|
|
|
template<> struct MakeSigned<long , true> { using Type = long; };
|
2015-06-08 20:20:12 +00:00
|
|
|
|
2015-06-30 22:07:28 +00:00
|
|
|
template<> struct MakeSigned<octa::sbyte , true> { using Type = octa::sbyte; };
|
|
|
|
template<> struct MakeSigned<octa::byte , true> { using Type = octa::sbyte; };
|
2015-06-08 20:20:12 +00:00
|
|
|
template<> struct MakeSigned<octa::ushort, true> { using Type = short; };
|
|
|
|
template<> struct MakeSigned<octa::uint , true> { using Type = int; };
|
|
|
|
template<> struct MakeSigned<octa::ulong , true> { using Type = long; };
|
|
|
|
template<> struct MakeSigned<octa::llong , true> { using Type = octa::llong; };
|
|
|
|
template<> struct MakeSigned<octa::ullong, true> { using Type = octa::llong; };
|
2015-06-04 20:08:56 +00:00
|
|
|
|
|
|
|
template<> struct MakeUnsigned<bool , true> {};
|
2015-06-08 20:20:12 +00:00
|
|
|
template<> struct MakeUnsigned<short , true> { using Type = octa::ushort; };
|
|
|
|
template<> struct MakeUnsigned<int , true> { using Type = octa::uint; };
|
|
|
|
template<> struct MakeUnsigned<long , true> { using Type = octa::ulong; };
|
|
|
|
|
2015-06-30 22:07:28 +00:00
|
|
|
template<> struct MakeUnsigned<octa::sbyte , true> { using Type = octa::byte; };
|
|
|
|
template<> struct MakeUnsigned<octa::byte , true> { using Type = octa::byte; };
|
2015-06-08 20:20:12 +00:00
|
|
|
template<> struct MakeUnsigned<octa::ushort, true> { using Type = octa::ushort; };
|
|
|
|
template<> struct MakeUnsigned<octa::uint , true> { using Type = octa::uint; };
|
|
|
|
template<> struct MakeUnsigned<octa::ulong , true> { using Type = octa::ulong; };
|
|
|
|
template<> struct MakeUnsigned<octa::llong , true> { using Type = octa::ullong; };
|
|
|
|
template<> struct MakeUnsigned<octa::ullong, true> { using Type = octa::ullong; };
|
2015-06-04 20:08:56 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct MakeSignedBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename ApplyCv<T,
|
2015-06-04 21:57:06 +00:00
|
|
|
typename MakeSigned<octa::RemoveCv<T>>::Type
|
2015-06-07 23:55:08 +00:00
|
|
|
>::Type;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct MakeUnsignedBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename ApplyCv<T,
|
2015-06-04 21:57:06 +00:00
|
|
|
typename MakeUnsigned<octa::RemoveCv<T>>::Type
|
2015-06-07 23:55:08 +00:00
|
|
|
>::Type;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
2015-06-04 20:08:56 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using MakeSigned = typename octa::detail::MakeSignedBase<T>::Type;
|
|
|
|
template<typename T>
|
|
|
|
using MakeUnsigned = typename octa::detail::MakeUnsignedBase<T>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* conditional */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool _cond, typename T, typename U>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct ConditionalBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = T;
|
2015-04-22 23:26:29 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
struct ConditionalBase<false, T, U> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = U;
|
2015-04-22 23:26:29 +00:00
|
|
|
};
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-18 15:46:44 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool _cond, typename T, typename U>
|
|
|
|
using Conditional = typename octa::detail::ConditionalBase<_cond, T, U>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* result of call at compile time */
|
2015-04-18 15:46:44 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
#define OCTA_FWD(T, _v) static_cast<T &&>(_v)
|
|
|
|
template<typename F, typename ...A>
|
|
|
|
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)...);
|
2015-04-23 19:38:18 +00:00
|
|
|
}
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename B, typename T, typename D>
|
|
|
|
inline auto rof_invoke(T B::*pmd, D &&ref) ->
|
|
|
|
decltype(OCTA_FWD(D, ref).*pmd) {
|
|
|
|
return OCTA_FWD(D, ref).*pmd;
|
2015-04-23 19:38:18 +00:00
|
|
|
}
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename PMD, typename P>
|
|
|
|
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);
|
2015-04-23 19:38:18 +00:00
|
|
|
}
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename B, typename T, typename D, typename ...A>
|
|
|
|
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)...);
|
2015-04-23 19:38:18 +00:00
|
|
|
}
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename PMF, typename P, typename ...A>
|
|
|
|
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)...);
|
2015-04-18 15:46:44 +00:00
|
|
|
}
|
2015-06-04 20:08:56 +00:00
|
|
|
#undef OCTA_FWD
|
2015-04-18 15:46:44 +00:00
|
|
|
|
2015-04-23 19:38:18 +00:00
|
|
|
template<typename, typename = void>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct ResultOfCore {};
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename F, typename ...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>()...));
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-21 22:54:09 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct ResultOfBase: ResultOfCore<T> {};
|
2015-06-04 20:08:56 +00:00
|
|
|
} /* namespace detail */
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using ResultOf = typename octa::detail::ResultOfBase<T>::Type;
|
2015-04-21 22:54:09 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* enable if */
|
2015-04-21 22:54:09 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool B, typename T = void> struct EnableIfBase {};
|
2015-04-23 19:38:18 +00:00
|
|
|
|
2015-06-07 23:55:08 +00:00
|
|
|
template<typename T> struct EnableIfBase<true, T> { using Type = T; };
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<bool B, typename T = void>
|
|
|
|
using EnableIf = typename octa::detail::EnableIfBase<B, T>::Type;
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* decay */
|
2015-04-22 23:26:29 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-04 20:08:56 +00:00
|
|
|
struct DecayBase {
|
2015-04-22 23:26:29 +00:00
|
|
|
private:
|
2015-06-07 23:55:08 +00:00
|
|
|
using U = octa::RemoveReference<T>;
|
2015-04-22 23:26:29 +00:00
|
|
|
public:
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = octa::Conditional<octa::IsArray<U>::value,
|
2015-06-04 21:57:06 +00:00
|
|
|
octa::RemoveExtent<U> *,
|
|
|
|
octa::Conditional<octa::IsFunction<U>::value,
|
|
|
|
octa::AddPointer<U>, octa::RemoveCv<U>>
|
2015-06-07 23:55:08 +00:00
|
|
|
>;
|
2015-04-22 23:26:29 +00:00
|
|
|
};
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using Decay = typename octa::detail::DecayBase<T>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
/* common type */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:08:56 +00:00
|
|
|
namespace detail {
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename ...T> struct CommonTypeBase;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct CommonTypeBase<T> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = Decay<T>;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U> struct CommonTypeBase<T, U> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = Decay<decltype(true ? octa::detail::declval_in<T>()
|
|
|
|
: octa::detail::declval_in<U>())>;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U, typename ...V>
|
|
|
|
struct CommonTypeBase<T, U, V...> {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = typename CommonTypeBase<
|
|
|
|
typename CommonTypeBase<T, U>::Type, V...
|
|
|
|
>::Type;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
2015-06-04 20:08:56 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T, typename U, typename ...V>
|
|
|
|
using CommonType = typename octa::detail::CommonTypeBase<T, U, V...>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* aligned storage */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N> struct AlignedTest {
|
2015-06-29 22:18:08 +00:00
|
|
|
union Type {
|
2015-06-30 22:07:28 +00:00
|
|
|
octa::byte data[N];
|
2015-06-08 00:38:44 +00:00
|
|
|
octa::MaxAlign align;
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N, octa::Size A> struct AlignedStorageBase {
|
2015-06-29 22:18:08 +00:00
|
|
|
struct Type {
|
2015-06-30 22:07:28 +00:00
|
|
|
alignas(A) octa::byte data[N];
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N, octa::Size A
|
2015-06-04 21:57:06 +00:00
|
|
|
= alignof(typename octa::detail::AlignedTest<N>::Type)
|
|
|
|
> using AlignedStorage = typename octa::detail::AlignedStorageBase<N, A>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* aligned union */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size ...N> struct AlignMax;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N> struct AlignMax<N> {
|
|
|
|
static constexpr octa::Size value = N;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N1, octa::Size N2> struct AlignMax<N1, N2> {
|
|
|
|
static constexpr octa::Size value = (N1 > N2) ? N1 : N2;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N1, octa::Size N2, octa::Size ...N>
|
2015-06-04 21:57:06 +00:00
|
|
|
struct AlignMax<N1, N2, N...> {
|
2015-06-08 20:20:12 +00:00
|
|
|
static constexpr octa::Size value
|
2015-06-04 21:57:06 +00:00
|
|
|
= AlignMax<AlignMax<N1, N2>::value, N...>::value;
|
2015-04-23 19:38:18 +00:00
|
|
|
};
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N, typename ...T> struct AlignedUnionBase {
|
|
|
|
static constexpr octa::Size alignment_value
|
2015-06-04 21:57:06 +00:00
|
|
|
= AlignMax<alignof(T)...>::value;
|
2015-04-23 17:47:33 +00:00
|
|
|
|
|
|
|
struct type {
|
2015-06-30 22:07:28 +00:00
|
|
|
alignas(alignment_value) octa::byte data[AlignMax<N,
|
2015-06-04 21:57:06 +00:00
|
|
|
sizeof(T)...>::value];
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
} /* namespace detail */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-08 20:20:12 +00:00
|
|
|
template<octa::Size N, typename ...T>
|
2015-06-04 21:57:06 +00:00
|
|
|
using AlignedUnion = typename octa::detail::AlignedUnionBase<N, T...>::Type;
|
2015-04-24 18:43:20 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
/* underlying type */
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 20:47:30 +00:00
|
|
|
namespace detail {
|
2015-05-05 18:29:47 +00:00
|
|
|
/* gotta wrap, in a struct otherwise clang ICEs... */
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> struct UnderlyingTypeBase {
|
2015-06-07 23:55:08 +00:00
|
|
|
using Type = __underlying_type(T);
|
2015-04-23 17:47:33 +00:00
|
|
|
};
|
2015-06-04 20:47:30 +00:00
|
|
|
}
|
2015-04-23 17:47:33 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
|
|
|
using UnderlyingType = typename octa::detail::UnderlyingTypeBase<T>::Type;
|
2015-06-06 17:22:10 +00:00
|
|
|
} /* namespace octa */
|
2015-04-13 21:25:31 +00:00
|
|
|
|
|
|
|
#endif
|