> Hi George, > > George A. Heintzelman writes: > ... > > TModule::Process() { > > StartProcessing(); > > for ( /* each track in a container */ ) { > > if ((*fPtrToCutFunction)(track)) { > > /* Process */ > > } > > } > > } > > But if we wanted to write these modules out, we would have to be able > > to stream somehow pointers-to-function. > ... > > Instead of pointers-to-function, what about using Functional Objects > (Functors) as described in Chapter 18 of Stroustrup's C++ P.L. Special > Ed.? Basically, instead of using a function you use a class with a > method like: > > bool operator()(TTrack*); > > Since it is just an object, it should be able to be sent through ROOT > I/O. Yes, this is a possible way of doing it. This has the unfortunate drawback of expanding CINT's dictionary rather dramatically, if this is used extensively. A second problem is that you require that the functor base class have a virtual operator(), since the whole point is to have dynamic dispatch. This amounts to the same overhead as ptr-to-function as that's all a virtual function is, so its not a big deal; but it does mean that much of the STL function library stuff no longer is so useful since they don't use virtual dispatch at all, preferring instead fairly heavy template machinery (which works well in a completely compiled code, but causes problems in CINT). Eg, not1(DynamicBinderFunctionObj) returns a class of type unary_negate<DynamicBinderFunctionObj>, which does not derive from DynamicBinderFunctionObj itself. > This would also gain you the ability to make use of the binder > functions (bind1st, bind2nd) which would allow people to pass closures > (function + parameters) to the module. Like I say, wouldn't be easy to integrate because of the above problems. Would be nice, though, if it were possible. One could write specializations of these elements of the standard lib for a dynamic-dispatch functor, I suppose. It would need a bit of thought. George Heintzelman gah@bnl.gov
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:36 MET