
24 Oct
2006
24 Oct
'06
9:39 p.m.
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