执行控制的c++函数代理
c++ function proxy for execution control
我想创建一个"function proxy"
- 一个函数对象。
- 它的返回类型和参数类型是自动继承的从给定的"基"函数类型作为模板参数。"基地"函数类型可以是(function pointer/boost::function/boost::bind)
- 用给定类型的函数对象初始化。
- 当它被调用时(就像你可以调用原始函数一样),它能够将调用存储到boost::bind之类的东西中,并将其传递到其他地方(有意为之,一个线程安全的队列,以便以后可以在另一个队列中调用它),然后返回调用结果。
现在,我的问题是如何(甚至可能)创建这个(functor)类使用模板teq,并传递未知参数列表给绑定。
template<typename R, typename... ARGS>
class Proxy {
typedef std::function<R(ARGS...)> Function;
Function f;
public:
Proxy(Function _f) : f(_f) {}
R operator(ARGS... args) {
std::function<R> bound = std::bind(f, args...);
send_to_worker_thread(bound);
wait_for_worker_thread();
return worker_thread_result();
}
};
// Because we really want type deduction
template<typename R, typename... ARGS>
Proxy<R,ARGS...>* newProxy(R(*x)(ARGS...)) {
return new Proxy(std::function<R,ARGS...>(x);
}
我还没有测试过。
你可能想要异步的东西,但是我把它留给你。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- 具有所表示类的相同构造函数签名的代理类模板
- 使用函数指针作为成员函数的代理
- 为成员函数定义代理,该代理将成员函数指针作为模板参数
- 为什么即使对于 "copy on write" 的 const 成员函数也返回一个代理类?
- C++11 使用代理将成员函数传递给线程
- C++11 如何代理只有其名称和父类的类函数
- 使用提升的集合中的成员函数代理
- 如何在C#中实现C++风格的函数指针?,不使用代理
- 将 std::function 代理为需要参数数组的 C 函数
- 通过继承代理std::函数
- 如何为代理类实现相等操作符函数
- C++11类型列表展开器和静态函数的代理调用程序
- 执行控制的c++函数代理