Function-Tools: simplify and modernise the main cases
...to not rely on the old-style signature templates anymore, i.e. get rid of typename FunctionSignature<function<RET(ARGS...)>> now, most cases just delegate to the "plain signature" case
This commit is contained in:
parent
f19fabfa3a
commit
f8f8cc02d1
1 changed files with 37 additions and 7 deletions
|
|
@ -51,7 +51,6 @@ typedef unsigned int uint;
|
|||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
using lib::meta::_Fun;
|
||||
|
||||
using std::function;
|
||||
using std::placeholders::_1;
|
||||
|
|
@ -62,21 +61,50 @@ using std::tuple;
|
|||
////////////////############# Investigation of implementation variants
|
||||
namespace lib {
|
||||
namespace meta {
|
||||
|
||||
template<class C, typename RET, typename...ARGS>
|
||||
struct _Fun<RET (C::*) (ARGS...)>
|
||||
|
||||
template<typename FUN>
|
||||
struct _FuZ
|
||||
: _FuZ<decltype(&FUN::operator())>
|
||||
{ };
|
||||
|
||||
/** Specialisation for a bare function signature */
|
||||
template<typename RET, typename...ARGS>
|
||||
struct _FuZ<RET(ARGS...)>
|
||||
{
|
||||
using Ret = RET;
|
||||
using Args = Types<ARGS...>;
|
||||
using Sig = RET(ARGS...);
|
||||
};
|
||||
/** Specialisation for using a function pointer */
|
||||
template<typename SIG>
|
||||
struct _FuZ<SIG*>
|
||||
: _FuZ<SIG>
|
||||
{ };
|
||||
|
||||
/** Specialisation when using a function reference */
|
||||
template<typename SIG>
|
||||
struct _FuZ<SIG&>
|
||||
: _FuZ<SIG>
|
||||
{ };
|
||||
|
||||
/** Specialisation to deal with member pointer to function */
|
||||
template<class C, typename RET, typename...ARGS>
|
||||
struct _Fun<RET (C::*) (ARGS...) const>
|
||||
: _Fun<RET (C::*) (ARGS...)>
|
||||
struct _FuZ<RET (C::*) (ARGS...)>
|
||||
: _FuZ<RET(ARGS...)>
|
||||
{ };
|
||||
|
||||
/** Specialisation to handle member pointer to const function;
|
||||
* indirectly this specialisation also handles lambdas,
|
||||
* as redirected by the main template (via `decltype`) */
|
||||
template<class C, typename RET, typename...ARGS>
|
||||
struct _FuZ<RET (C::*) (ARGS...) const>
|
||||
: _FuZ<RET(ARGS...)>
|
||||
{ };
|
||||
|
||||
}}//namespace lib::meta
|
||||
|
||||
using lib::meta::_FuZ;
|
||||
|
||||
////////////////############# Investigation of implementation variants
|
||||
|
||||
|
||||
|
|
@ -123,7 +151,7 @@ template<typename F>
|
|||
void
|
||||
showType (F)
|
||||
{
|
||||
using Sig = typename _Fun<F>::Sig;
|
||||
using Sig = typename _FuZ<F>::Sig;
|
||||
|
||||
SHOW_TYPE (F);
|
||||
SHOW_TYPE (Sig);
|
||||
|
|
@ -167,6 +195,8 @@ main (int, char**)
|
|||
SHOW_TYPE (decltype(&Funky::operator()));
|
||||
SHOW_TYPE (decltype(lambda));
|
||||
|
||||
SHOW_TYPE (_FuZ<int(uint)>::Sig);
|
||||
|
||||
cout << "\n.gulp.\n";
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue