From df1b9daeaf8cf7a37f5ae9cad30b80d77d7bdc51 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 14 Apr 2015 01:12:00 +0100 Subject: [PATCH] add move/forward and more traits --- octa/traits.h | 47 +++++++++++++++++++++++++++++++++++++++++++++-- octa/types.h | 2 ++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/octa/traits.h b/octa/traits.h index 8c541a4..3dd4cb6 100644 --- a/octa/traits.h +++ b/octa/traits.h @@ -44,7 +44,7 @@ namespace octa { template struct IntegralConstant { - static const T value = val; + static constexpr const T value = val; typedef T value_type; typedef IntegralConstant type; @@ -53,7 +53,7 @@ namespace octa { typedef IntegralConstant true_t; typedef IntegralConstant false_t; - template const T IntegralConstant::value; + template constexpr const T IntegralConstant::value; /* is integer */ @@ -100,6 +100,27 @@ namespace octa { template struct IsPointer: IsPointerBase::type> {}; + /* is pointer to member function */ + + template struct IsMemberPointerBase: false_t {}; + template + struct IsMemberPointerBase: true_t {}; + + template + struct IsMemberPointer: IsMemberPointerBase< + typename RemoveConstVolatile::type + > {}; + + /* is null pointer */ + + template struct IsNullPointerBase : false_t {}; + template< > struct IsNullPointerBase: true_t {}; + + template + struct IsNullPointer: IsNullPointerBase< + typename RemoveConstVolatile::type + > {}; + /* is POD: currently wrong */ template struct IsPOD: IntegralConstant struct IsArray : false_t {}; template struct IsArray: true_t {}; template struct IsArray: true_t {}; + + /* move */ + + template + static inline constexpr typename RemoveReference::type && + move(T &&v) noexcept { + return (typename RemoveReference::type &&)v; + } + + /* forward */ + + template + static inline constexpr T && + forward(typename RemoveReference::type &v) noexcept { + return (T &&)v; + } + + template + static inline constexpr T && + forward(typename RemoveReference::type &&v) noexcept { + return (T &&)v; + } } #endif \ No newline at end of file diff --git a/octa/types.h b/octa/types.h index f12acf9..4794b0d 100644 --- a/octa/types.h +++ b/octa/types.h @@ -18,6 +18,8 @@ namespace octa { typedef long long llong; typedef long double ldouble; + + typedef decltype(nullptr) nullptr_t; } #endif \ No newline at end of file