Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2000-11-18 21:14:05


I've uploaded some callback classes along the lines that William and I
were talking about (see the Callbacks2 folder). They include template
ctors for member functions that look like this:

template <typename OBJECT, typename METHOD>
callback1(OBJECT* object, METHOD method)
{
   typedef details::method_functor1<RETURN_TYPE, OBJECT, METHOD, ARG1>
MethodFunctor;

   MethodFunctor functor(object, method);
   mFunctor = new details::call_functor1<MethodFunctor, RETURN_TYPE,
ARG1>(functor);
}

where method_functor1 is:

template <typename RETURN_TYPE, typename OBJECT, typename METHOD,
typename ARG1>
class method_functor1 {
public:
                  method_functor1(OBJECT* object, METHOD method) :
mObject(object), mMethod(method) {assert(mObject != NULL); assert(mMethod
!= NULL);}
                  
         RETURN_TYPE operator()(ARG1 arg1) const {return
(mObject->*mMethod)(arg1);}
private:
   OBJECT* mObject;
   METHOD mMethod;
};

I experiemented with using the functional stuff in the standard library,
but I think they'll only be able to handle the one argument callback
case.

Note that the classes don't yet handle silently ignoring return values.

  -- Jesse


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk