diff --git a/octa/traits.h b/octa/traits.h index 35efdb6..2332766 100644 --- a/octa/traits.h +++ b/octa/traits.h @@ -11,6 +11,13 @@ #include "octa/types.h" #include "octa/utility.h" +/* libc++ and cppreference.com occasionally used for reference */ + +/* missing: + * + * UnderlyingType + */ + namespace octa { /* removers */ @@ -130,9 +137,31 @@ namespace octa { template struct IsClass: IntegralConstant {}; - /* is function TODO */ + /* is function */ - template struct IsFunction: false_t {}; + template struct IsReference; + + namespace internal { + struct FunctionTestDummy {}; + + template char function_test(T *); + template char function_test(FunctionTestDummy); + template int function_test(...); + + template T &function_source(int); + template FunctionTestDummy function_source(...); + } + + template::value || IsUnion::value + || IsVoid::value || IsReference::value + || IsNullPointer::value + > struct IsFunctionBase: IntegralConstant(internal::function_source(0))) == 1 + > {}; + + template struct IsFunctionBase: false_t {}; + + template struct IsFunction: IsFunctionBase {}; /* is arithmetic */ @@ -230,10 +259,42 @@ namespace octa { IsScalar::type>::value > {}; + /* is base of */ + + template + struct IsBaseOf: IntegralConstant {}; + /* type equality */ - template struct IsEqual : false_t {}; - template struct IsEqual: true_t {}; + template struct IsSame : false_t {}; + template struct IsSame: true_t {}; + + /* extent */ + + template + struct Extent: IntegralConstant {}; + + template + struct Extent: IntegralConstant {}; + + template + struct Extent: IntegralConstant::value> {}; + + template + struct Extent: IntegralConstant {}; + + template + struct Extent: IntegralConstant::value> {}; + + /* rank */ + + template struct Rank: IntegralConstant {}; + + template + struct Rank: IntegralConstant::value + 1> {}; + + template + struct Rank: IntegralConstant::value + 1> {}; /* add lvalue reference */ @@ -257,23 +318,6 @@ namespace octa { template using AddRvalueReference = internal::AddRvalueReference; - /* extent */ - - template - struct Extent: IntegralConstant {}; - - template - struct Extent: IntegralConstant {}; - - template - struct Extent: IntegralConstant::value> {}; - - template - struct Extent: IntegralConstant {}; - - template - struct Extent: IntegralConstant::value> {}; - /* remove extent */ template struct RemoveExtent { typedef T type; }; @@ -342,7 +386,6 @@ namespace octa { }; } - /* cppreference.com used for reference */ template struct ResultOf: internal::ResultOf {}; /* enable_if */