1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <iostream>
#include <string>
#include <functional>
#include <boost\fusion\container\vector.hpp>
#include <boost\fusion\functional\invocation.hpp>
class AObject
{
public:
virtual ~AObject()=0;
};
AObject::~AObject(){}
class AConcrete : public AObject
{
public:
void do_something(std::string a, int b) const
{
std::cout<<"a = "<<a<<"\n";
std::cout<<"b = "<<b<<"\n";
}
virtual ~AConcrete(){}
};
template<class Callable>
class Action
{
public:
Action(std::string const& name_, std::string const& description_,Callable callable_)
:name(name_),description(description_),callable(callable_)
{
}
template<class Sequence>
void operator()(Sequence param_) const
{
boost::fusion::invoke_procedure(callable,param_);
}
private:
std::string name;
std::string description;
Callable callable;
};
template<class Callable>
Action<Callable> make_Action(std::string const& name_, std::string const& description_,Callable callable_)
{
return Action<Callable>(name_,description_,callable_);
}
template<class action_t>
void invoke(AConcrete const& obj,action_t act)
{
const int i = 0;
const std::string s = "Hello";
typedef boost::fusion::vector<AConcrete const&,std::string,int> param_t;
param_t param(obj,s,i);
act(param);
}
int main()
{
auto do_something = make_Action("do_something", "call do_something", &AConcrete::do_something);
AConcrete concrete;
invoke(concrete,do_something);
return 0;
} |
Partager