I am developing a program where I find myself doing this like this a lot:
void Model::SetCollideMode( const std::string &m )
{
Body *body;
std::map<std::string, Body* >::iterator iter;
for (iter=this->bodies.begin(); iter!=this->bodies.end(); iter++)
{
body = iter->second;
body->SetCollideMode( m );
}
}
I have several methods like that in several object that basically apply a property to all its children. Coming from Ruby world I am dying to do something like:
for_all_bodies{ body->SetCollideMode(m) }
There is anyway to make this code more closures like or in other way improve it?
I am conscious of how C++ works, that it is stack based and there is no context information to create a perfect closure like functionality (this need a VM?) but at least improve over the current repeat this code 100 times kind of programming.