Search code examples
c++boost-bindboost-function

Implement no-op functor using boost::bind


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.


Solution

  • 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.