Skip to content

Commit

Permalink
Use invoke_result_t if building as c++17 except on android
Browse files Browse the repository at this point in the history
  • Loading branch information
edo9300 committed Nov 24, 2023
1 parent d579a50 commit ea60cce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include $(CLEAR_VARS)

LOCAL_MODULE := ocgcore
LOCAL_MODULE_FILENAME := libocgcore
LOCAL_SRC_FILES := card.cpp \
LOCAL_SRC_FILES := card.cpp \
duel.cpp \
effect.cpp \
field.cpp \
Expand All @@ -22,8 +22,8 @@ LOCAL_SRC_FILES := card.cpp \
processor.cpp \
scriptlib.cpp

LOCAL_CFLAGS := -pedantic -Wno-unused-parameter -Wextra -fno-rtti -fvisibility=hidden -DOCGCORE_EXPORT_FUNCTIONS
LOCAL_CPPFLAGS := -fexceptions
LOCAL_CFLAGS := -pedantic -Wno-unused-parameter -Wextra -fvisibility=hidden -DOCGCORE_EXPORT_FUNCTIONS
LOCAL_CPPFLAGS := -fexceptions -fno-rtti
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lua/include
LOCAL_STATIC_LIBRARIES += liblua5.3

Expand Down
12 changes: 10 additions & 2 deletions scriptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,16 @@ namespace scriptlib {
}
}

#if !defined(__ANDROID__) && ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
template<typename T, typename... Arg>
using FunctionResult = std::invoke_result_t<T, Arg...>;
#else
template<typename T, typename... Arg>
using FunctionResult = std::result_of_t<T(Arg...)>;
#endif

template<typename T, typename T2>
using EnableOnReturn = std::enable_if_t<std::is_same<std::result_of_t<T()>, T2>::value, int>;
using EnableOnReturn = std::enable_if_t<std::is_same<FunctionResult<T>, T2>::value, int>;

template<typename T, EnableOnReturn<T, void> = 0>
inline void lua_iterate_table_or_stack(lua_State* L, int idx, int max, T&& func) {
Expand Down Expand Up @@ -235,7 +243,7 @@ namespace scriptlib {

template<typename T>
inline bool lua_find_in_table_or_in_stack(lua_State* L, int idx, int max, T&& func) {
static_assert(std::is_same<std::result_of_t<T()>, bool>::value, "Callback function must return bool");
static_assert(std::is_same<FunctionResult<T>, bool>::value, "Callback function must return bool");
if(lua_istable(L, idx)) {
lua_pushnil(L);
while(lua_next(L, idx) != 0) {
Expand Down

0 comments on commit ea60cce

Please sign in to comment.