Functors

I’ve been thinking about my C++ problem.

I initially expected the return type of the bind expression would be void (*)(void). Obviously (well, it’s obvious now, anyway), this is not what bind returns. Rather, bind returns a function object (aka, a functor). A functor is just an object that implements operator(), making itself a “callable entity”. In my case, bind is returning a functor which implements void operator()(void) — which is similar, but not quite the same as a “nullary” function pointer void (*)(void).

So, what’s the type of the functor? Turns out it’s:


class boost::_bi::bind_t<void,void (__cdecl*)(int),class boost::_bi::list1<class boost::_bi::value > >

Couldn’t be simpler than that, eh? How do I know this? The compiler tells me the type when it errors-out during compilation. And that is the most frustrating thing of all. The compiler knows the damn type, but there is no way for me to tell it, “Yes, yes! Just use one of those, thanks.”

At least, not until we get Dave Abraham’s new auto keyword.

Advertisements

2 Responses to “Functors”


  1. 1 Bheeshmar July 25, 2005 at 7:14 pm

    Crap! I couldn’t remember the name “auto” to put in my other response…


  1. 1 mark++ » Blog Archive » boost::function Trackback on July 26, 2005 at 11:59 am
Comments are currently closed.




%d bloggers like this: