| | | | | |

Handling function objects (aka functors) - 2

template < class ParentFunctor , typename Fun >
class FunctorHandler : public FunctorImpl
  < typename ParentFunctor::ResultType , typename ParentFunctor::ParmList >
{
public:
  typedef ParentFunctor::ResultType ResultType;
  FunctorHandler (const Fun& fun) : fun_(fun) {}
  FunctorHandler* Clone() const { return new FunctorHandler(*this); }
  ResultType operator () ()  { return fun_(); }
  ResultType operator () (typename ParentFunctor::Parm1 p1)
  {
    return fun_(p1);
  }
  ResultType operator ()
    (typename ParentFunctor::Parm1 p1, typename ParentFunctor::Parm2 p2)
  {
    return fun_(p1, p2);
  }
  ...
private:
  Fun fun_; // stored by value
};

| | Top of Page | 8. Generalized Functors - 10 of 26