Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2006-10-24 17:39:52


> Matt Davies wrote:
>
> <snip>
>
> I am not sure if I can store a functor with parameter
> values in a generic container only to invoke it at a later
> time.
>
> Any ideas would be very welcome.

You can use boost::bind to bind all the arguments and get a nullary functor
back, which you can store in a container as a boost::function. Something
like this (not tested):

void foo(int i, string s) { ... }

typedef boost::function<void (void)> func_t;
std::vector<func_t> v;
func_t a_function = boost:bind(&foo, 1, "fred");
v.push_back(a_function);

... then later ...

func_t a_function = v.front();
a_function(); // <- invoke foo(1, "fred");

-delfin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net