Listing 5

struct simple_call
{
  virtual ~simple_call() {}
  virtual bool invoke() = 0;
  virtual bool is_completed() const = 0;
  virtual void wait_completion() = 0;
  virtual simple_call* make_clone() const = 0;
  template<typename T> static T* clone(T* from)
  {
    if(0 == from)
      return 0;
    T* to = static_cast<T*>(from->make_clone());
    assert(typeid(*to) == typeid(*from));
    return to;
  }
};
template<typename ret>
struct async_callback
{
  typedef typename call_traits<ret>::const_reference cr_ret;
  virtual ~async_callback() {}
  virtual void accept_result(cr_ret retval) = 0;
};
template<typename ret>
class dispatcher : public simple_call
{
public:
  dispatcher() : _ac(0) {}
  virtual ~dispatcher() {}
  typedef async_callback<ret>* ac_ptr;
  void deliver_to(ac_ptr ac) { _ac = ac; }
  virtual ret result() const = 0;
protected:
  ac_ptr _ac;
};
template<typename ret, typename params>
class callable;
template<typename ret>
class callable<ret, mpl::void_> 
  : public dispatcher<ret>
{
public:
  virtual void operator()() = 0;
};
template<typename ret, typename p1>
class callable<ret, mpl::vector<p1> > 
  : public dispatcher<ret>
{
public:
  virtual void operator()(p1) = 0;
};
// repeat for 2 or more parameters