Skip to content

Commit

Permalink
'FuncUtils' module: fixed bug when the redirector was NOT working cor…
Browse files Browse the repository at this point in the history
…rectly when some params should be pass to the targeted func.
  • Loading branch information
Eugen committed Feb 1, 2016
1 parent 32bf4c4 commit 5417189
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions FuncUtils.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#ifndef FuncUtilsH
#define FuncUtilsH

#include <utility> // for 'std::move', 'std::forward'
//// [!] Version 1.01 [!]

#include <utility> // for 'std::move', 'std::forward'
#include <type_traits> // for 'std::is_same'

//// A functor (Function Object) CAN also be possibly used as a 'ProcName' OR 'FuncName'
#define EXEC_MEMBER_PROC_IF_PRESENT(ProcName) namespace ProcName {\
void ExecIfPresent(...) throw() {}\
\
template <class C, typename... TArgs>\
void ExecIfPresent(C& obj, TArgs&... args) {\
obj.ProcName(std::forward<TArgs>(args)...);\
auto ExecIfPresent(C& obj, TArgs&&... args)\
/*Remove prototype from the overload resolution if such a callable (func./functor) is NOT exist*/\
-> decltype(obj.ProcName(std::forward<TArgs>(args)...))\
{\
static_assert(std::is_same<void,\
typename decltype(obj.ProcName(std::forward<TArgs>(args)...))>::value,\
"'EXEC_MEMBER_PROC_IF_PRESENT' SHOULD be used with the procedures,"\
" which returns nothing (void)");\
obj.ProcName(std::forward<TArgs>(args)...); /*MS VS is OK with the 'return void'*/\
}\
};

// If NOT exists - returns the 'DefaultValue', which SHOULD be the same type as a decltype(*.FuncName())
// If NOT exists - returns the 'DefaultValue',
// which SHOULD be the same type as a decltype(*.FuncName())
// Works with static/const/virtual funcs
#define EXEC_MEMBER_FUNC_IF_PRESENT(FuncName, DefaultValue) namespace FuncName {\
template <typename TReturnType = decltype(DefaultValue)>\
Expand All @@ -21,8 +33,9 @@
}\
\
template <class C, typename... TArgs>\
auto ExecIfPresent(C& obj, TArgs&... args)\
-> decltype(obj.FuncName(std::forward<TArgs>(args)...)) /* do NOT use 'const C& obj' NOR 'C::FuncName()'*/\
auto ExecIfPresent(C& obj, TArgs&&... args)\
/*Remove prototype from the overload resolution if such a callable (func./functor) is NOT exist*/\
-> decltype(obj.FuncName(std::forward<TArgs>(args)...)) /*NOT 'const C& obj' NOR 'C::FuncName()'*/\
{\
return std::move(obj.FuncName(std::forward<TArgs>(args)...));\
}\
Expand Down

0 comments on commit 5417189

Please sign in to comment.