I am developing a program in which I do so much:
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 this in several objects that basically apply the property to all of its children. Coming from the world of Ruby, I am dying to do something like:
for_all_bodies{ body->SetCollideMode(m) }
In any case, to make this code more private, for example, or otherwise improve it?
I realize how C ++ works, that it is stack-based, and there is no contextual information to create the ideal closure function (does this require a virtual machine?), But at least it’s better compared to the current repetition of this code at 100 programming times.
Jordi source
share