From 2dcd9ee986274359a7d20026dd161818226b5ab0 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 29 Jul 2018 14:35:51 +0300 Subject: [PATCH] Use a standard implementation to check for type conversion. --- include/sqrat/sqratTypes.h | 53 +++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/include/sqrat/sqratTypes.h b/include/sqrat/sqratTypes.h index b9c6b5ad..f10ab5fa 100644 --- a/include/sqrat/sqratTypes.h +++ b/include/sqrat/sqratTypes.h @@ -46,27 +46,6 @@ namespace Sqrat { -/// @cond DEV - -// copied from http://www.experts-exchange.com/Programming/Languages/CPP/A_223-Determing-if-a-C-type-is-convertable-to-another-at-compile-time.html -template -struct is_convertible -{ -private: - struct True_ { char x[2]; }; - struct False_ { }; - - static True_ helper(T2 const &); - static False_ helper(...); - - static T1* dummy; - -public: - static bool const YES = ( - sizeof(True_) == sizeof(is_convertible::helper(*dummy)) - ); -}; - template struct popAsInt { @@ -171,20 +150,20 @@ struct Var { if (ptr != NULL) { value = *ptr; #if !defined (SCRAT_NO_ERROR_CHECKING) - } else if (is_convertible::YES) { /* value is likely of integral type like enums */ + } else if (std::is_convertible::value) { /* value is likely of integral type like enums */ SQCLEAR(vm); // clear the previous error - value = popAsInt::YES>(vm, idx).value; + value = popAsInt::value>(vm, idx).value; #endif } else { // initialize value to avoid warnings - value = popAsInt::YES>(vm, idx).value; + value = popAsInt::value>(vm, idx).value; } SQCATCH(vm) { #if defined (SCRAT_USE_EXCEPTIONS) SQUNUSED(e); // avoid "unreferenced local variable" warning #endif - if (is_convertible::YES) { /* value is likely of integral type like enums */ - value = popAsInt::YES>(vm, idx).value; + if (std::is_convertible::value) { /* value is likely of integral type like enums */ + value = popAsInt::value>(vm, idx).value; } else { SQRETHROW(vm); } @@ -202,7 +181,7 @@ struct Var { if (ClassType::hasClassData(vm)) ClassType::PushInstanceCopy(vm, value); else /* try integral type */ - pushAsInt::YES>().push(vm, value); + pushAsInt::value>().push(vm, value); } private: @@ -258,7 +237,7 @@ struct Var { if (ClassType::hasClassData(vm)) ClassType::PushInstance(vm, &value); else /* try integral type */ - pushAsInt::YES>().push(vm, value); + pushAsInt::value>().push(vm, value); } private: @@ -1092,7 +1071,6 @@ SCRAT_MAKE_NONREFERENCABLE(signed __int64) SCRAT_MAKE_NONREFERENCABLE(std::string) #endif - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Pushes a value on to a given VM's stack /// @@ -1112,7 +1090,6 @@ inline void PushVar(HSQUIRRELVM vm, T* value) { Var::push(vm, value); } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Pushes a value on to a given VM's stack /// @@ -1132,6 +1109,22 @@ inline void PushVar(HSQUIRRELVM vm, const T& value) { Var::push(vm, value); } +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Pushes a pack of values on to a given VM's stack +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +template +inline void PushVars(HSQUIRRELVM vm, T value) { + PushVar(vm, value); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Pushes a pack of values on to a given VM's stack +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +template +inline void PushVars(HSQUIRRELVM vm, T value, Ts &&... tail) { + PushVar(vm, value); + PushVars(vm, std::forward(tail)...); +} /// @cond DEV template