experiment: generate both the functor and the handling function
this pinpoints a compatibility problem: our lib::meta::Types<...> type sequence is not compatible with variadic template parameters, since it uses a fixed list of NullType default arguments to absorb the variable number of types. --> TODO: switch lib::meta::Types to variadic arguments!
This commit is contained in:
parent
6ae8ad5d0b
commit
9c346ca914
1 changed files with 51 additions and 23 deletions
|
|
@ -56,6 +56,8 @@ typedef unsigned int uint;
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//using lib::diff::GenNode;
|
//using lib::diff::GenNode;
|
||||||
|
using lib::meta::Types;
|
||||||
|
using lib::meta::NullType;
|
||||||
using proc::control::CommandSignature;
|
using proc::control::CommandSignature;
|
||||||
using proc::control::CommandDef;
|
using proc::control::CommandDef;
|
||||||
using lib::time::Time;
|
using lib::time::Time;
|
||||||
|
|
@ -68,30 +70,53 @@ using std::string;
|
||||||
|
|
||||||
using VecS = vector<string>;
|
using VecS = vector<string>;
|
||||||
|
|
||||||
|
template<typename...TYPES>
|
||||||
|
struct TyS
|
||||||
|
{
|
||||||
|
using Seq = TyS;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename X>
|
||||||
|
struct ArgSeq;
|
||||||
|
|
||||||
|
template<typename RET, typename...TYPES>
|
||||||
|
struct ArgSeq<RET(TYPES...)>
|
||||||
|
{
|
||||||
|
using Seq = TyS<TYPES...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename...ARGS>
|
template<typename...ARGS>
|
||||||
void
|
struct Funny
|
||||||
operate (ARGS const& ...args)
|
|
||||||
{
|
{
|
||||||
VecS strs = stringify<VecS> (args...);
|
static void
|
||||||
cout << join (strs);
|
operate (ARGS const& ...args)
|
||||||
}
|
{
|
||||||
|
VecS strs = stringify<VecS> (args...);
|
||||||
|
cout << join (strs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string
|
||||||
|
capture (ARGS const& ...args)
|
||||||
|
{
|
||||||
|
VecS strs = stringify<VecS> (args...);
|
||||||
|
return join (strs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
undo (ARGS const& ...args, string plonk)
|
||||||
|
{
|
||||||
|
VecS strs = stringify<VecS> (args...);
|
||||||
|
cout << "UNDO..." << plonk << "args=" << join (strs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename...ARGS>
|
template<typename...ARGS>
|
||||||
string
|
struct Funny<TyS<ARGS...>>
|
||||||
capture (ARGS const& ...args)
|
: Funny<ARGS...>
|
||||||
{
|
{ };
|
||||||
VecS strs = stringify<VecS> (args...);
|
|
||||||
return join (strs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename...ARGS>
|
|
||||||
void
|
|
||||||
undo (ARGS const& ...args)
|
|
||||||
{
|
|
||||||
VecS strs = stringify<VecS> (args...);
|
|
||||||
cout << "UNDO..." << join (strs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -104,10 +129,10 @@ undo (ARGS const& ...args)
|
||||||
int
|
int
|
||||||
main (int, char**)
|
main (int, char**)
|
||||||
{
|
{
|
||||||
cout << capture ("lalü", string("lala"), 12, 34L, 56.78) <<endl;
|
cout << Funny<const char*, string, int, long, double>::capture ("lalü", string("lala"), 12, 34L, 56.78) <<endl;
|
||||||
|
|
||||||
|
|
||||||
auto ops = operate<double,Time>;
|
auto ops = Funny<double,Time>::operate;
|
||||||
|
|
||||||
using FunnySIG = lib::meta::_Fun<typeof(ops)>::Sig;
|
using FunnySIG = lib::meta::_Fun<typeof(ops)>::Sig;
|
||||||
|
|
||||||
|
|
@ -119,15 +144,18 @@ main (int, char**)
|
||||||
SHOW_TYPE (SIG_Cap);
|
SHOW_TYPE (SIG_Cap);
|
||||||
SHOW_TYPE (SIG_Udo);
|
SHOW_TYPE (SIG_Udo);
|
||||||
|
|
||||||
|
using ArgS = ArgSeq<SIG_Opr>::Seq;
|
||||||
|
SHOW_TYPE (ArgS);
|
||||||
|
|
||||||
function<SIG_Opr> funny;
|
function<SIG_Opr> funny;
|
||||||
function<SIG_Cap> capy;
|
function<SIG_Cap> capy;
|
||||||
function<SIG_Udo> undy;
|
function<SIG_Udo> undy;
|
||||||
|
|
||||||
cout << "funny? " << bool(funny) <<endl;
|
cout << "funny? " << bool(funny) <<endl;
|
||||||
|
|
||||||
funny = operate<double,Time>;
|
funny = Funny<ArgS>::operate;
|
||||||
capy = capture<double,Time>;
|
capy = Funny<ArgS>::capture;
|
||||||
undy = undo<double,Time,string>;
|
undy = Funny<ArgS>::undo;
|
||||||
cout << "funny? " << bool(funny) <<endl;
|
cout << "funny? " << bool(funny) <<endl;
|
||||||
|
|
||||||
cout << capy (98.7654321987654321987654321, Time(1,2,3,4)) <<endl;
|
cout << capy (98.7654321987654321987654321, Time(1,2,3,4)) <<endl;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue