Implement no-op functor using boost::bind

1.2k Views Asked by At

I have a function void get(boost::function<void(void)> callback) { callback(); }. I want to make a call like get(boost::bind(/* don't know what to put here*/)); without implementing any other functions, variables or structs, so that the callback does nothing. Is it possible to implement such "no-op" callback in C++03 ?

Usage of boost::bind() is prefered but not required - may be, there are some other tricks to achieve my goal.

1

There are 1 best solutions below

3
On BEST ANSWER

You could use something like boost::bind(std::plus<int>(), 0, 0), which should be optimised away to nothing.

It would make the code rather clearer if you relaxed your restriction and defined a no-op functor instead.