|
|
Hi !
Currently, I'am coding a nice C++ library, and I want a nice code, easy to read. Since I discovered the 'for_each' template, I use it, on the non critical parts. But is it really nice for everybody ? Just a real life example (from my library ;) )
struct PutOperatorsFunctor {
set<Operator*>* operators;
const set<Operator*>* builtInOperators;
PutOperatorsFunctor(set<Operator*>& operators, const set<Operator*>& builtInOperators) {
this->operators= &operators;
this->builtInOperators = &builtInOperators;
}
void operator() (map<string, Operator*>::value_type mapEntry) {
set<Operator*>::iterator it = builtInOperators->find(mapEntry.second);
if (it == builtInOperators ->end())
operators->insert(mapEntry.second);
}
}; // PutOperatorsFunctor
for_each(session.operatorsMap.begin(),
session .operatorsMap .end(),
PutOperatorsFunctor(operatorsToDisplay, session.builtInOperators));
|
This is easier to read rather than the classical 'for' way ?
|