[bind / lambda] binding a factory funtion instead of an value

Lets say i need a functor of type typedef boost::function1<Ret, Arg1> Functor; and i have a function Ret Foo(Arg1 a, Arg2 b); Creating a Functor object is easy if i have a Arg2 object Arg2 arg2; Functor f(boost::bind<Ret>(&Foo, _1, arg2); But what if i want to create the Arg2 object in the functor when it is used? Like i have a function Arg2 CreateArg2(); and i don't want Functor f(boost::bind<Ret>(&Foo, _1, CreateArg2()); but something like Functor f(boost::bind<Ret>(&Foo, _1, &CreateArg2); so that f(arg1) = Foo(arg1, CreateArg2()); I have a vague feeling that lambda might have a solution to this, but i don't know how! Bertolt

Bertolt Mildner wrote:
Lets say i need a functor of type
typedef boost::function1<Ret, Arg1> Functor;
and i have a function
Ret Foo(Arg1 a, Arg2 b);
Creating a Functor object is easy if i have a Arg2 object
Arg2 arg2;
Functor f(boost::bind<Ret>(&Foo, _1, arg2);
But what if i want to create the Arg2 object in the functor when it is used?
Like i have a function
Arg2 CreateArg2();
and i don't want
Functor f(boost::bind<Ret>(&Foo, _1, CreateArg2());
but something like
Functor f(boost::bind<Ret>(&Foo, _1, &CreateArg2);
so that f(arg1) = Foo(arg1, CreateArg2());
bind( Foo, _1, bind( CreateArg2 ) ).

"Peter Dimov" <pdimov@mmltd.net> schrieb im Newsbeitrag news:000c01c57782$32d4ae20$6401a8c0@pdimov2...
but something like
Functor f(boost::bind<Ret>(&Foo, _1, &CreateArg2);
so that f(arg1) = Foo(arg1, CreateArg2());
bind( Foo, _1, bind( CreateArg2 ) ).
Ha, it is realy obvious! Now i'm also able to find it in the docu :)) Thanks a lot! Bertolt
participants (2)
-
Bertolt Mildner
-
Peter Dimov