Bind, lambda and how to chain relative function calls
Hi, I would like to create a functor for calling functions in a chain like this : car.GetRigidBody().GetPosition().GetX() What is the best way to do that using bind (and lambda ?) The car.GetRigidBody() is easy : bind(&Car::GetRigidBody, &car) , but then I am a bit stuck. Note that I don't want to store the result of car.GetRigidBody(). I want the final functor to call all the functions everytime its operator() is called. So bind ( &Position::GetX, &bind ( &RigidBody::GetPosition, &bind ( &Car::GetRigidBody, &car )() )() ) would not be acceptable... Any help greatly appreciated Jacques Kerner
On 11/24/05, Kerner, Jacques
Hi,
I would like to create a functor for calling functions in a chain like this :
car.GetRigidBody().GetPosition().GetX()
What is the best way to do that using bind (and lambda ?)
The car.GetRigidBody() is easy : bind(&Car::GetRigidBody, &car) , but then I am a bit stuck. Note that I don't want to store the result of car.GetRigidBody(). I want the final functor to call all the functions everytime its operator() is called. So
bind ( &Position::GetX, &bind ( &RigidBody::GetPosition, &bind (
&Car::GetRigidBody,
&car )() )() )
would not be acceptable…
Any help greatly appreciated
Jacques Kerner
You're nearly there: bind(&Position::GetX, bind(&RigidBody::GetPosition, bind(&Car::GetRigidBody, &car))); should do the job - i.e. no '&' on the binds. Stuart Dootson
Kerner, Jacques wrote:
Hi,
I would like to create a functor for calling functions in a chain like this :
car.GetRigidBody().GetPosition().GetX()
What is the best way to do that using bind (and lambda ?)
The car.GetRigidBody() is easy : bind(&Car::GetRigidBody, &car) , but then I am a bit stuck. Note that I don't want to store the result of car.GetRigidBody(). I want the final functor to call all the functions everytime its operator() is called. So
bind ( &Position::GetX, &bind ( &RigidBody::GetPosition, &bind (
&Car::GetRigidBody, &car )() )() )
would not be acceptable...
Just drop the invocations: bind ( &Position::GetX, bind ( &RigidBody::GetPosition, bind( &Car::GetRigidBody, &car) ) )
participants (3)
-
Kerner, Jacques
-
Peter Dimov
-
Stuart Dootson