Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a function with argument that would be result of boost::bind?

So I want to create a function like:

void proxy_do_stuff(boost::bind return_here)
{
  return_here(); // call stuff pased into boost::bind
}

And I could call it like :

proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument));

How to do such thing?

like image 290
Rella Avatar asked Aug 31 '11 05:08

Rella


2 Answers

The return type of boost::bind is of type boost::function. See below:

void proxy_do_stuff(boost::function<void()> return_here)
{
    return_here(); // call stuff pased into boost::bind
}
like image 148
Miguel Avatar answered Sep 23 '22 21:09

Miguel


#include <boost/bind.hpp>

template<typename T>
void proxy_do_stuff(T return_here)
{
    return_here(); // call stuff pased into boost::bind
}

struct myclass
{
    void myfunction(int, int)
    {
    }
    void foo()
    {
        int my_function_argument_value = 3;
        int etc_fun_argument= 5;
        proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument));
    }
};

int main()
{
    myclass c;
    c.foo();
    return 0;
}
like image 23
Eddy Pronk Avatar answered Sep 21 '22 21:09

Eddy Pronk