diff --git a/developer-doc/plmdIntro.txt b/developer-doc/plmdIntro.txt index 7cbdc79e4e3ac7692a175e6d6bcca5b222023d83..e39f29aefb84fdfe55ab73e8df89f2917a076692 100644 --- a/developer-doc/plmdIntro.txt +++ b/developer-doc/plmdIntro.txt @@ -390,6 +390,47 @@ this does not work is when inline methods are used because of template expressio This trick is extensively used in plumed so as to avoid too many indirect dependencies among .h files. +\section cxx11features C++11 Features + +Since PLUMED 2.4 we systematically use C++11 features. Some of the most important ones are discussed here. + +\subsection cxx11features-auto Using auto + +Auto allows to implicitly declare the type of a variable. +This is particularly handy when using iterators from STL containers. +For instance, you can replace the following: +\verbatim + map<string,vector<AtomNumber> >::const_iterator m=atoms.groups.find(strings[i]); +\endverbatim +with: +\verbatim + const auto m=atoms.groups.find(strings[i]); +\endverbatim +Notice that the syntax is significantly simpler, especially if you do not +remember which exact type of map is the variable `groups`. + +Iterators are often used in loops. Thus, you can now replace +\verbatim + for(std::map<AtomNumber,Tensor>::const_iterator p=gradients.begin();p!=gradients.end();++p){ + a+=(*p).second; + } +\endverbatim +with +\verbatim + for(auto p=gradients.begin();p!=gradients.end();++p){ + a+=(*p).second; + } +\endverbatim +However, in cases where you do not need to explicitly use `p` as an iterator, you might find +even more convenient to use range-based loops: +\verbatim + for(const auto & p : gradients){ + a+=p.second; + } +\endverbatim +Notice that now `p` is a constant reference, so it is not anymore necessary to use the `*` operator. + + \section conc Conclusion The above is meant to give you some feel as to how plumed works. If there is stuff you do not diff --git a/src/analysis/LandmarkRegister.cpp b/src/analysis/LandmarkRegister.cpp index 0d7c6ff280ad0ca4fe69f8c45086649a2bec5e94..3e996393a863958e0c47dfdbdaa163111fa8caef 100644 --- a/src/analysis/LandmarkRegister.cpp +++ b/src/analysis/LandmarkRegister.cpp @@ -28,7 +28,7 @@ namespace analysis{ LandmarkRegister::~LandmarkRegister(){ if(m.size()>0){ std::string names=""; - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p) names+=p->first+" "; + for(const auto & p : m) names+=p.first+" "; std::cerr<<"WARNING: ReferenceConfiguration "+ names +" has not been properly unregistered. This might lead to memory leak!!\n"; } } @@ -39,7 +39,7 @@ LandmarkRegister& landmarkRegister(){ } void LandmarkRegister::remove(creator_pointer f){ - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p){ + for(auto p=m.begin();p!=m.end();++p){ if((*p).second==f){ m.erase(p); break; } diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index 2efeaf4a5bc2693954eb7788b5bbfed734e03a71..97c3392c6a8580586e15831122c1e20a2d08ef6b 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -903,7 +903,7 @@ last_step_warn_grid(0) bool concurrent=false; const ActionSet&actionSet(plumed.getActionSet()); - for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p) if(dynamic_cast<MetaD*>(*p)){ concurrent=true; break; } + for(const auto & p : actionSet) if(dynamic_cast<MetaD*>(p)){ concurrent=true; break; } if(concurrent) log<<" You are using concurrent metadynamics\n"; log<<" Bibliography "<<plumed.cite("Laio and Parrinello, PNAS 99, 12562 (2002)"); diff --git a/src/cltools/Driver.cpp b/src/cltools/Driver.cpp index 97a649ab86bdeb7c47593c75b40b4ff52c9e46e8..c47d6a2e1a7e8d80b7afd79eb8ffd7e5208ccc97 100644 --- a/src/cltools/Driver.cpp +++ b/src/cltools/Driver.cpp @@ -171,8 +171,7 @@ static vector<molfile_plugin_t *> plugins; static map <string, unsigned> pluginmap; static int register_cb(void *v, vmdplugin_t *p){ //const char *key = p->name; - std::pair<std::map<string,unsigned>::iterator,bool> ret; - ret = pluginmap.insert ( std::pair<string,unsigned>(string(p->name),plugins.size()) ); + const auto ret = pluginmap.insert ( std::pair<string,unsigned>(string(p->name),plugins.size()) ); if (ret.second==false) { //cerr<<"MOLFILE: found duplicate plugin for "<<key<<" : not inserted "<<endl; }else{ diff --git a/src/colvar/PathMSDBase.cpp b/src/colvar/PathMSDBase.cpp index 9b9ee99046b9ea8353625512a194d4b5af699676..69f1aecf41c20a03dd47cbdc6e5c9aa5843ad581 100644 --- a/src/colvar/PathMSDBase.cpp +++ b/src/colvar/PathMSDBase.cpp @@ -162,14 +162,13 @@ void PathMSDBase::calculate(){ // clean vector for(unsigned i=0;i< derivs_z.size();i++){derivs_z[i].zero();} - typedef vector< class ImagePath >::iterator imgiter; - for(imgiter it=imgVec.begin();it!=imgVec.end();++it){ - (*it).similarity=exp(-lambda*((*it).distance)); + for(auto & it : imgVec){ + it.similarity=exp(-lambda*(it.distance)); //log<<"DISTANCE "<<(*it).distance<<"\n"; for(unsigned i=0;i<s_path.size();i++){ - s_path[i]+=((*it).property[i])*(*it).similarity; + s_path[i]+=(it.property[i])*it.similarity; } - partition+=(*it).similarity; + partition+=it.similarity; } for(unsigned i=0;i<s_path.size();i++){ s_path[i]/=partition; val_s_path[i]->set(s_path[i]) ;} val_z_path->set(-(1./lambda)*std::log(partition)); @@ -177,11 +176,11 @@ void PathMSDBase::calculate(){ // clean up for(unsigned i=0;i< derivs_s.size();i++){derivs_s[i].zero();} // do the derivative - for(imgiter it=imgVec.begin();it!=imgVec.end();++it){ - double expval=(*it).similarity; - tmp=lambda*expval*(s_path[j]-(*it).property[j])/partition; - for(unsigned i=0;i< derivs_s.size();i++){ derivs_s[i]+=tmp*(*it).distder[i] ;} - if(j==0){for(unsigned i=0;i< derivs_z.size();i++){ derivs_z[i]+=(*it).distder[i]*expval/partition;}} + for(const auto & it : imgVec){ + double expval=it.similarity; + tmp=lambda*expval*(s_path[j]-it.property[j])/partition; + for(unsigned i=0;i< derivs_s.size();i++){ derivs_s[i]+=tmp*it.distder[i] ;} + if(j==0){for(unsigned i=0;i< derivs_z.size();i++){ derivs_z[i]+=it.distder[i]*expval/partition;}} } for(unsigned i=0;i< derivs_s.size();i++){ setAtomsDerivatives (val_s_path[j],i,derivs_s[i]); diff --git a/src/core/Action.cpp b/src/core/Action.cpp index ff1efdb714382bdc8e97ed0b27ab816806b2dd81..dfccecb172976e64aa279190e1fc9a2d89256ca4 100644 --- a/src/core/Action.cpp +++ b/src/core/Action.cpp @@ -115,8 +115,8 @@ int Action::fclose(FILE*fp){ } void Action::fflush(){ - for(files_iterator p=files.begin();p!=files.end();++p){ - std::fflush((*p)); + for(const auto & p : files){ + std::fflush(p); } } @@ -171,14 +171,14 @@ void Action::activate(){ prepare(); this->lockRequests(); } else return; - for(Dependencies::iterator p=after.begin();p!=after.end();++p) (*p)->activate(); + for(const auto & p : after) p->activate(); active=true; } void Action::setOption(const std::string &s){ // This overloads the action and activate some options options.insert(s); - for(Dependencies::iterator p=after.begin();p!=after.end();++p) (*p)->setOption(s); + for(const auto & p : after) p->setOption(s); } void Action::clearOptions(){ @@ -240,11 +240,11 @@ void Action::warning( const std::string & msg ){ void Action::calculateFromPDB( const PDB& pdb ){ activate(); - for(Dependencies::iterator p=after.begin();p!=after.end();++p){ - ActionWithValue*av=dynamic_cast<ActionWithValue*>(*p); + for(const auto & p : after){ + ActionWithValue*av=dynamic_cast<ActionWithValue*>(p); if(av){ av->clearInputForces(); av->clearDerivatives(); } - (*p)->readAtomsFromPDB( pdb ); - (*p)->calculate(); + p->readAtomsFromPDB( pdb ); + p->calculate(); } readAtomsFromPDB( pdb ); calculate(); diff --git a/src/core/Action.h b/src/core/Action.h index 360813e900c05ad2ed5d63adf0adf174b269c39f..21e0ea9716f05abcc9660cf4afed021d27e30bce 100644 --- a/src/core/Action.h +++ b/src/core/Action.h @@ -161,7 +161,6 @@ public: /// std::set<FILE*> files; - typedef std::set<FILE*>::iterator files_iterator; public: /// Standard constructor from ActionOptions diff --git a/src/core/ActionAtomistic.cpp b/src/core/ActionAtomistic.cpp index 9f8e900a8bcb08bd26f3e9ff0018f8e07f6e4701..662e4497b65fd613cd5786bd165c969c71d756fb 100644 --- a/src/core/ActionAtomistic.cpp +++ b/src/core/ActionAtomistic.cpp @@ -188,7 +188,7 @@ void ActionAtomistic::interpretAtomList( std::vector<std::string>& strings, std: // here we check if the atom name is the name of a group if(!ok){ if(atoms.groups.count(strings[i])){ - map<string,vector<AtomNumber> >::const_iterator m=atoms.groups.find(strings[i]); + const auto m=atoms.groups.find(strings[i]); t.insert(t.end(),m->second.begin(),m->second.end()); ok=true; } @@ -196,8 +196,8 @@ void ActionAtomistic::interpretAtomList( std::vector<std::string>& strings, std: // here we check if the atom name is the name of an added virtual atom if(!ok){ const ActionSet&actionSet(plumed.getActionSet()); - for(ActionSet::const_iterator a=actionSet.begin();a!=actionSet.end();++a){ - ActionWithVirtualAtom* c=dynamic_cast<ActionWithVirtualAtom*>(*a); + for(const auto & a : actionSet){ + ActionWithVirtualAtom* c=dynamic_cast<ActionWithVirtualAtom*>(a); if(c) if(c->getLabel()==strings[i]){ ok=true; t.push_back(c->getIndex()); diff --git a/src/core/ActionRegister.cpp b/src/core/ActionRegister.cpp index cac31b0b6f12a57e486a6bb1ae0446f1b1e06071..96fb73fb6b73c1b1ec6d8b60b5e7a869a3817947 100644 --- a/src/core/ActionRegister.cpp +++ b/src/core/ActionRegister.cpp @@ -32,7 +32,7 @@ namespace PLMD{ ActionRegister::~ActionRegister(){ if(m.size()>0){ string names=""; - for(mIterator p=m.begin();p!=m.end();++p)names+=p->first+" "; + for(const auto & p : m) names+=p.first+" "; std::cerr<<"WARNING: Directive "+ names +" has not been properly unregistered. This might lead to memory leak!!\n"; } } @@ -43,7 +43,7 @@ ActionRegister& actionRegister(){ } void ActionRegister::remove(creator_pointer f){ - for(mIterator p=m.begin();p!=m.end();++p){ + for(auto p=m.begin();p!=m.end();++p){ if((*p).second==f){ m.erase(p); break; } @@ -113,8 +113,7 @@ bool ActionRegister::printTemplate( const std::string& action, bool include_opti std::ostream & operator<<(std::ostream &log,const ActionRegister&ar){ vector<string> s; - for(ActionRegister::const_mIterator it=ar.m.begin();it!=ar.m.end();++it) - s.push_back((*it).first); + for(const auto & it : ar.m) s.push_back(it.first); sort(s.begin(),s.end()); for(unsigned i=0;i<s.size();i++) log<<" "<<s[i]<<"\n"; if(!ar.disabled.empty()){ diff --git a/src/core/ActionRegister.h b/src/core/ActionRegister.h index cf2cd35fe6b317d1de36aa83d5b5e06de891b042..6bf48530aea2c2d20fdee7ebb376854bbf5ce81e 100644 --- a/src/core/ActionRegister.h +++ b/src/core/ActionRegister.h @@ -51,16 +51,8 @@ class ActionRegister{ typedef void(*keywords_pointer)(Keywords&); /// Map action to a function which creates the related object std::map<std::string,creator_pointer> m; -/// Iterator over the map - typedef std::map<std::string,creator_pointer>::iterator mIterator; -/// Iterator over the map - typedef std::map<std::string,creator_pointer>::const_iterator const_mIterator; /// Map action to a function which documents the related object std::map<std::string,keywords_pointer> mk; -/// Iterator over the map - typedef std::map<std::string,Keywords>::iterator mIteratork; -/// Iterator over the map - typedef std::map<std::string,Keywords>::const_iterator const_mIteratork; /// Set of disabled actions (which were registered more than once) std::set<std::string> disabled; public: diff --git a/src/core/ActionSet.cpp b/src/core/ActionSet.cpp index 1c01ece37679132d6d2c8d7a1f1185db74207b70..cfbc63cc61d4230f088b319de5e36738626a38b3 100644 --- a/src/core/ActionSet.cpp +++ b/src/core/ActionSet.cpp @@ -42,16 +42,16 @@ void ActionSet::clearDelete(){ std::string ActionSet::getLabelList() const{ std::string outlist; - for(const_iterator p=begin();p!=end();++p){ - outlist+=dynamic_cast<Action*>(*p)->getLabel()+" "; + for(const auto & p : (*this)){ + outlist+=dynamic_cast<Action*>(p)->getLabel()+" "; }; return outlist; } std::vector<std::string> ActionSet::getLabelVector() const{ std::vector<std::string> outlist; - for(const_iterator p=begin();p!=end();++p){ - outlist.push_back(dynamic_cast<Action*>(*p)->getLabel()); + for(const auto & p : (*this)){ + outlist.push_back(dynamic_cast<Action*>(p)->getLabel()); }; return outlist; } diff --git a/src/core/ActionSet.h b/src/core/ActionSet.h index d0babf45a314fcb7f2d690631550dbf85264ccb5..2277f009b59d9282ae0df1039d8cd89902aa4c98 100644 --- a/src/core/ActionSet.h +++ b/src/core/ActionSet.h @@ -72,8 +72,8 @@ public: template <class T> std::vector<T> ActionSet::select()const{ std::vector<T> ret; - for(const_iterator p=begin();p!=end();++p){ - T t=dynamic_cast<T>(*p); + for(const auto & p : (*this)){ + T t=dynamic_cast<T>(p); if(t) ret.push_back(t); }; return ret; @@ -81,8 +81,8 @@ std::vector<T> ActionSet::select()const{ template <class T> T ActionSet::selectWithLabel(const std::string&s)const{ - for(const_iterator p=begin();p!=end();++p){ - T t=dynamic_cast<T>(*p); + for(const auto & p : (*this)){ + T t=dynamic_cast<T>(p); if(t && dynamic_cast<Action*>(t)->getLabel()==s) return t; }; return NULL; @@ -91,9 +91,9 @@ T ActionSet::selectWithLabel(const std::string&s)const{ template <class T> std::vector<Action*> ActionSet::selectNot()const{ std::vector<Action*> ret; - for(const_iterator p=begin();p!=end();++p){ - T t=dynamic_cast<T>(*p); - if(!t) ret.push_back(*p); + for(const auto & p : (*this)){ + T t=dynamic_cast<T>(p); + if(!t) ret.push_back(p); }; return ret; } diff --git a/src/core/ActionSetup.cpp b/src/core/ActionSetup.cpp index d0b7fd0ff88dd244c234ec53ee74612765adda6a..0a310d5654400624c89e377498e349495284ee88 100644 --- a/src/core/ActionSetup.cpp +++ b/src/core/ActionSetup.cpp @@ -30,9 +30,9 @@ ActionSetup::ActionSetup(const ActionOptions&ao): Action(ao) { const ActionSet& actionset(plumed.getActionSet()); - for(ActionSet::const_iterator p=actionset.begin();p!=actionset.end();++p){ + for(const auto & p : actionset){ // check that all the preceeding actions are ActionSetup - if( !dynamic_cast<ActionSetup*>(*p) ) error("Action " + getLabel() + " is a setup action, and should be only preceeded by other setup actions"); + if( !dynamic_cast<ActionSetup*>(p) ) error("Action " + getLabel() + " is a setup action, and should be only preceeded by other setup actions"); } } diff --git a/src/core/ActionWithVirtualAtom.cpp b/src/core/ActionWithVirtualAtom.cpp index 04febbf1ed44bddc5bd9cfc6e4777caedb543356..de6d0c6cb0395b2ca20c2e1d64ca1d0009b9ea21 100644 --- a/src/core/ActionWithVirtualAtom.cpp +++ b/src/core/ActionWithVirtualAtom.cpp @@ -67,8 +67,8 @@ void ActionWithVirtualAtom::setGradients(){ // this case if the atom is a virtual one if(atoms.isVirtualAtom(an)){ const ActionWithVirtualAtom* a=atoms.getVirtualAtomsAction(an); - for(std::map<AtomNumber,Tensor>::const_iterator p=a->gradients.begin();p!=a->gradients.end();++p){ - gradients[(*p).first]+=matmul(derivatives[i],(*p).second); + for(const auto & p : a->gradients){ + gradients[p.first]+=matmul(derivatives[i],p.second); } // this case if the atom is a normal one } else { diff --git a/src/core/Atoms.cpp b/src/core/Atoms.cpp index 2c3a5fbdcf1617ca1878d44dc137d21b1394f383..834f2e75ab3ef0f179b45fb553ba3d471ec23d90 100644 --- a/src/core/Atoms.cpp +++ b/src/core/Atoms.cpp @@ -202,15 +202,15 @@ void Atoms::share(const std::set<AtomNumber>& unique){ for(unsigned i=0;i<dd.mpi_request_index.size();i++) dd.mpi_request_index[i].wait(); } int count=0; - for(std::set<AtomNumber>::const_iterator p=unique.begin();p!=unique.end();++p){ - if(dd.g2l[p->index()]>=0){ - dd.indexToBeSent[count]=p->index(); - dd.positionsToBeSent[ndata*count+0]=positions[p->index()][0]; - dd.positionsToBeSent[ndata*count+1]=positions[p->index()][1]; - dd.positionsToBeSent[ndata*count+2]=positions[p->index()][2]; + for(const auto & p : unique){ + if(dd.g2l[p.index()]>=0){ + dd.indexToBeSent[count]=p.index(); + dd.positionsToBeSent[ndata*count+0]=positions[p.index()][0]; + dd.positionsToBeSent[ndata*count+1]=positions[p.index()][1]; + dd.positionsToBeSent[ndata*count+2]=positions[p.index()][2]; if(!massAndChargeOK){ - dd.positionsToBeSent[ndata*count+3]=masses[p->index()]; - dd.positionsToBeSent[ndata*count+4]=charges[p->index()]; + dd.positionsToBeSent[ndata*count+3]=masses[p.index()]; + dd.positionsToBeSent[ndata*count+4]=charges[p.index()]; } count++; } @@ -321,7 +321,7 @@ void Atoms::add(const ActionAtomistic*a){ } void Atoms::remove(const ActionAtomistic*a){ - vector<const ActionAtomistic*>::iterator f=find(actions.begin(),actions.end(),a); + auto f=find(actions.begin(),actions.end(),a); plumed_massert(f!=actions.end(),"cannot remove an action registered to atoms"); actions.erase(f); } diff --git a/src/core/CLToolRegister.cpp b/src/core/CLToolRegister.cpp index 5c62170e96b2848bd68421394fe6b0836825ade6..c300d30584ed46d1093a70f8155093d4f966bf6c 100644 --- a/src/core/CLToolRegister.cpp +++ b/src/core/CLToolRegister.cpp @@ -32,7 +32,7 @@ namespace PLMD{ CLToolRegister::~CLToolRegister(){ if(m.size()>0){ string names=""; - for(mIterator p=m.begin();p!=m.end();++p)names+=p->first+" "; + for(const auto & p : m) names+=p.first+" "; std::cerr<<"WARNING: CLTools "+ names +" has not been properly unregistered. This might lead to memory leak!!\n"; } } @@ -43,7 +43,7 @@ CLToolRegister& cltoolRegister(){ } void CLToolRegister::remove(creator_pointer f){ - for(mIterator p=m.begin();p!=m.end();++p){ + for(auto p=m.begin();p!=m.end();++p){ if((*p).second==f){ m.erase(p); break; } @@ -103,8 +103,7 @@ bool CLToolRegister::printManual( const std::string& cltool ){ vector<string> CLToolRegister::list()const{ vector<string> s; - for(const_mIterator it=m.begin();it!=m.end();++it) - s.push_back((*it).first); + for(const auto & it : m) s.push_back(it.first); sort(s.begin(),s.end()); return s; } diff --git a/src/core/CLToolRegister.h b/src/core/CLToolRegister.h index b4044ffae566c8bab10022ff724bcb1c398c8ee3..c99be9011c336f9e13d6db171e6705891865bc36 100644 --- a/src/core/CLToolRegister.h +++ b/src/core/CLToolRegister.h @@ -46,10 +46,6 @@ class CLToolRegister{ std::map<std::string,creator_pointer> m; /// Map cltool name to the keywords for this function std::map<std::string,Keywords> mk; -/// Iterator over the map - typedef std::map<std::string,creator_pointer>::iterator mIterator; -/// Iterator over the map - typedef std::map<std::string,creator_pointer>::const_iterator const_mIterator; /// Set of disabled cltools (which were registered more than once) std::set<std::string> disabled; public: diff --git a/src/core/GREX.cpp b/src/core/GREX.cpp index 001b0108f600389c80a990416d756b18123b77ec..b86ac57b849a9ef6ad59856365cca17aa928080e 100644 --- a/src/core/GREX.cpp +++ b/src/core/GREX.cpp @@ -74,7 +74,7 @@ void GREX::cmd(const string&key,void*val){ // do nothing } else { int iword=-1; - auto it=GREXWordMap().find(words[0]); + const auto it=GREXWordMap().find(words[0]); if(it!=GREXWordMap().end()) iword=it->second; switch(iword){ case cmd_initialized: diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index dadd5f31d7ea8831dfd644068577b2a45d056456..ff4e9b79f3c58ac3ee1768f5592f8ccd425e451d 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -128,7 +128,7 @@ void PlumedMain::cmd(const std::string & word,void*val){ } else { int iword=-1; double d; - auto it=plumedMainWordMap().find(words[0]); + const auto it=plumedMainWordMap().find(words[0]); if(it!=plumedMainWordMap().end()) iword=it->second; switch(iword) { case cmd_setBox: @@ -593,8 +593,8 @@ void PlumedMain::prepareDependencies(){ // which can be dynamically changed). // First switch off all actions - for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ - (*p)->deactivate(); + for(const auto & p : actionSet){ + p->deactivate(); //I think this is already done inside deactivate //(*p)->clearOptions(); } @@ -609,9 +609,9 @@ void PlumedMain::prepareDependencies(){ }; // also, if one of them is the total energy, tell to atoms that energy should be collected - for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ - if((*p)->isActive()){ - if((*p)->checkNeedsGradients()) (*p)->setOption("GRADIENTS"); + for(const auto & p : actionSet){ + if(p->isActive()){ + if(p->checkNeedsGradients()) p->setOption("GRADIENTS"); } } @@ -654,16 +654,16 @@ void PlumedMain::justCalculate(){ int iaction=0; // calculate the active actions in order (assuming *backward* dependence) - for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ - if((*p)->isActive()){ + for(const auto & p : actionSet){ + if(p->isActive()){ std::string actionNumberLabel; if(detailedTimers){ Tools::convert(iaction,actionNumberLabel); - actionNumberLabel="4A "+actionNumberLabel+" "+(*p)->getLabel(); + actionNumberLabel="4A "+actionNumberLabel+" "+p->getLabel(); stopwatch.start(actionNumberLabel); } - ActionWithValue*av=dynamic_cast<ActionWithValue*>(*p); - ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(*p); + ActionWithValue*av=dynamic_cast<ActionWithValue*>(p); + ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(p); { if(av) av->clearInputForces(); if(av) av->clearDerivatives(); @@ -672,13 +672,13 @@ void PlumedMain::justCalculate(){ if(aa) aa->clearOutputForces(); if(aa) if(aa->isActive()) aa->retrieveAtoms(); } - if((*p)->checkNumericalDerivatives()) (*p)->calculateNumericalDerivatives(); - else (*p)->calculate(); + if(p->checkNumericalDerivatives()) p->calculateNumericalDerivatives(); + else p->calculate(); // This retrieves components called bias if(av) bias+=av->getOutputQuantity("bias"); if(av) work+=av->getOutputQuantity("work"); if(av)av->setGradientsIfNeeded(); - ActionWithVirtualAtom*avv=dynamic_cast<ActionWithVirtualAtom*>(*p); + ActionWithVirtualAtom*avv=dynamic_cast<ActionWithVirtualAtom*>(p); if(avv)avv->setGradientsIfNeeded(); if(detailedTimers) stopwatch.stop(actionNumberLabel); } @@ -697,18 +697,19 @@ void PlumedMain::backwardPropagate(){ int iaction=0; stopwatch.start("5 Applying (backward loop)"); // apply them in reverse order - for(ActionSet::reverse_iterator p=actionSet.rbegin();p!=actionSet.rend();++p){ - if((*p)->isActive()){ + for(auto pp=actionSet.rbegin();pp!=actionSet.rend();++pp){ + const auto & p(*pp); + if(p->isActive()){ std::string actionNumberLabel; if(detailedTimers){ Tools::convert(iaction,actionNumberLabel); - actionNumberLabel="5A "+actionNumberLabel+" "+(*p)->getLabel(); + actionNumberLabel="5A "+actionNumberLabel+" "+p->getLabel(); stopwatch.start(actionNumberLabel); } - (*p)->apply(); - ActionAtomistic*a=dynamic_cast<ActionAtomistic*>(*p); + p->apply(); + ActionAtomistic*a=dynamic_cast<ActionAtomistic*>(p); // still ActionAtomistic has a special treatment, since they may need to add forces on atoms if(a) a->applyForces(); @@ -730,9 +731,9 @@ void PlumedMain::update(){ stopwatch.start("6 Update"); // update step (for statistics, etc) updateFlags.push(true); - for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ - (*p)->beforeUpdate(); - if((*p)->isActive() && (*p)->checkUpdate() && updateFlagsTop()) (*p)->update(); + for(const auto & p : actionSet){ + p->beforeUpdate(); + if(p->isActive() && p->checkUpdate() && updateFlagsTop()) p->update(); } while(!updateFlags.empty()) updateFlags.pop(); if(!updateFlags.empty()) plumed_merror("non matching changes in the update flags"); @@ -748,7 +749,7 @@ void PlumedMain::update(){ if(step%10000==0||doCheckPoint){ fflush(); log.flush(); - for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p) (*p)->fflush(); + for(const auto & p : actionSet) p->fflush(); } stopwatch.stop("6 Update"); } @@ -815,8 +816,8 @@ std::string PlumedMain::cite(const std::string&item){ } void PlumedMain::fflush(){ - for(files_iterator p=files.begin();p!=files.end();++p){ - (*p)->flush(); + for(const auto & p : files){ + p->flush(); } } @@ -833,8 +834,8 @@ void PlumedMain::stop(){ } void PlumedMain::runJobsAtEndOfCalculation(){ - for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ - (*p)->runFinalJobs(); + for(const auto & p : actionSet){ + p->runFinalJobs(); } } diff --git a/src/core/PlumedMain.h b/src/core/PlumedMain.h index 234296f84fd15305abcdc97340292788903658e1..ced8d15c9aa97358a3433acc2bc37c1e763d475e 100644 --- a/src/core/PlumedMain.h +++ b/src/core/PlumedMain.h @@ -137,7 +137,6 @@ private: bool doCheckPoint; std::set<FileBase*> files; - typedef std::set<FileBase*>::iterator files_iterator; /// Stuff to make plumed stop the MD code cleanly int* stopFlag; diff --git a/src/core/Value.cpp b/src/core/Value.cpp index db58db32891505218757c46db216eacfeaef5d5f..e344efb1ccf2376b7ba8e6c5bca690460a11879f 100644 --- a/src/core/Value.cpp +++ b/src/core/Value.cpp @@ -119,9 +119,9 @@ void Value::setGradients(){ AtomNumber an=aa->getAbsoluteIndex(j); if(atoms.isVirtualAtom(an)){ const ActionWithVirtualAtom* a=atoms.getVirtualAtomsAction(an); - for(std::map<AtomNumber,Tensor>::const_iterator p=a->getGradients().begin();p!=a->getGradients().end();++p){ + for(const auto & p : a->getGradients()){ // controllare l'ordine del matmul: - gradients[(*p).first]+=matmul(Vector(derivatives[3*j],derivatives[3*j+1],derivatives[3*j+2]),(*p).second); + gradients[p.first]+=matmul(Vector(derivatives[3*j],derivatives[3*j+1],derivatives[3*j+2]),p.second); } } else { for(unsigned i=0;i<3;i++) gradients[an][i]+=derivatives[3*j+i]; @@ -130,9 +130,9 @@ void Value::setGradients(){ } else if(aw){ std::vector<Value*> values=aw->getArguments(); for(unsigned j=0;j<derivatives.size();j++){ - for(std::map<AtomNumber,Vector>::const_iterator p=values[j]->gradients.begin();p!=values[j]->gradients.end();++p){ - AtomNumber iatom=(*p).first; - gradients[iatom]+=(*p).second*derivatives[j]; + for(const auto & p : values[j]->gradients){ + AtomNumber iatom=p.first; + gradients[iatom]+=p.second*derivatives[j]; } } } else plumed_error(); @@ -142,11 +142,11 @@ double Value::projection(const Value& v1,const Value&v2){ double proj=0.0; const std::map<AtomNumber,Vector> & grad1(v1.gradients); const std::map<AtomNumber,Vector> & grad2(v2.gradients); - for(std::map<AtomNumber,Vector>::const_iterator p1=grad1.begin();p1!=grad1.end();++p1){ - AtomNumber a=(*p1).first; - std::map<AtomNumber,Vector>::const_iterator p2=grad2.find(a); + for(const auto & p1 : grad1){ + AtomNumber a=p1.first; + const auto p2=grad2.find(a); if(p2!=grad2.end()){ - proj+=dotProduct((*p1).second,(*p2).second); + proj+=dotProduct(p1.second,(*p2).second); } } return proj; diff --git a/src/function/FuncPathMSD.cpp b/src/function/FuncPathMSD.cpp index 112cc46598116dbe4bcb3f8326705ccb699a5d2d..c1e32dcfeaf5d8d87767d54fa7859d17e6177d1a 100644 --- a/src/function/FuncPathMSD.cpp +++ b/src/function/FuncPathMSD.cpp @@ -124,10 +124,9 @@ vector<int> increasingOrder( vector<double> &v){ } // now sort according the second value sort(order.begin(), order.end(), ordering()); - typedef vector< pair<unsigned , myiter> >::const_iterator pairiter; vector<int> vv(v.size());n=0; - for ( pairiter it = order.begin(); it != order.end(); ++it ){ - vv[n]=(*it).first;n++; + for (const auto & it : order){ + vv[n]=it.first;n++; } return vv; } @@ -199,8 +198,8 @@ neigh_stride(-1.) // now backup the arguments for(unsigned i=0;i<getNumberOfArguments();i++)allArguments.push_back(getPntrToArgument(i)); double i=1.; - for(std::vector<Value*>:: const_iterator it=allArguments.begin();it!=allArguments.end() ;++it){ - indexmap[(*it)]=i;i+=1.; + for(const auto & it : allArguments){ + indexmap[it]=i;i+=1.; } } @@ -217,19 +216,18 @@ void FuncPathMSD::calculate(){ Value* val_s_path=getPntrToComponent("s"); Value* val_z_path=getPntrToComponent("z"); - typedef vector< pair< Value *,double> >::iterator pairiter; - for(pairiter it=neighpair.begin();it!=neighpair.end();++it){ - (*it).second=exp(-lambda*((*it).first->get())); - s_path+=(indexmap[(*it).first])*(*it).second; - partition+=(*it).second; + for(auto & it : neighpair){ + it.second=exp(-lambda*(it.first->get())); + s_path+=(indexmap[it.first])*it.second; + partition+=it.second; } s_path/=partition; val_s_path->set(s_path); val_z_path->set(-(1./lambda)*std::log(partition)); int n=0; - for(pairiter it=neighpair.begin();it!=neighpair.end();++it){ - double expval=(*it).second; - double tmp=lambda*expval*(s_path-(indexmap[(*it).first]))/partition; + for(const auto & it : neighpair){ + double expval=it.second; + double tmp=lambda*expval*(s_path-(indexmap[it.first]))/partition; setDerivative(val_s_path,n,tmp); setDerivative(val_z_path,n,expval/partition); n++; @@ -271,13 +269,12 @@ void FuncPathMSD::prepare(){ for(unsigned i=0;i<allArguments.size();i++)neighpair[i].first=allArguments[i]; } } - typedef vector< pair<Value*,double> >::iterator pairiter; vector<Value*> argstocall; //log.printf("PREPARING \n"); argstocall.clear(); if(!neighpair.empty()){ - for(pairiter it=neighpair.begin();it!=neighpair.end();++it){ - argstocall.push_back( (*it).first ); + for(const auto & it : neighpair){ + argstocall.push_back( it.first ); // log.printf("CALLING %p %f ",(*it).first ,indexmap[(*it).first] ); } }else{ diff --git a/src/generic/Debug.cpp b/src/generic/Debug.cpp index d1185816ac445e475ec82b135e80363e5b6af581..3f3786827d9763fe9effafd36b101941ee0bd9f9 100644 --- a/src/generic/Debug.cpp +++ b/src/generic/Debug.cpp @@ -108,15 +108,15 @@ void Debug::apply(){ if(logActivity){ const ActionSet&actionSet(plumed.getActionSet()); int a=0; - for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p){ - if(dynamic_cast<Debug*>(*p))continue; - if((*p)->isActive()) a++; + for(const auto & p : actionSet){ + if(dynamic_cast<Debug*>(p))continue; + if(p->isActive()) a++; }; if(a>0){ ofile.printf("activity at step %i: ",getStep()); - for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p){ - if(dynamic_cast<Debug*>(*p))continue; - if((*p)->isActive()) ofile.printf("+"); + for(const auto & p : actionSet){ + if(dynamic_cast<Debug*>(p))continue; + if(p->isActive()) ofile.printf("+"); else ofile.printf("-"); }; ofile.printf("\n"); diff --git a/src/generic/Flush.cpp b/src/generic/Flush.cpp index 1f1c7d65a11847d14e3db0dc3b3b9c15e10774de..b2248d0e3eae016f9bd3982ed2492047e23dc8e4 100644 --- a/src/generic/Flush.cpp +++ b/src/generic/Flush.cpp @@ -72,8 +72,8 @@ public: plumed.fflush(); log.flush(); const ActionSet & actionSet(plumed.getActionSet()); - for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p) - (*p)->fflush(); + for(const auto & p : actionSet) + p->fflush(); } }; diff --git a/src/generic/Group.cpp b/src/generic/Group.cpp index 36bd5788a9cdc9d5315ef84fb48bb1bde63f43be..5da037fdf1e2a7dcc209b211ffb8bd3f7d592d7e 100644 --- a/src/generic/Group.cpp +++ b/src/generic/Group.cpp @@ -177,7 +177,7 @@ Group::Group(const ActionOptions&ao): std::vector<AtomNumber> notfound; log<<" removing these atoms from the list:"; for(unsigned i=0;i<remove.size();i++){ - std::vector<AtomNumber>::iterator it = find(atoms.begin(),atoms.end(),remove[i]); + const auto it = find(atoms.begin(),atoms.end(),remove[i]); if(it!=atoms.end()){ log<<" "<<(*it).serial(); atoms.erase(it); diff --git a/src/reference/DRMSD.cpp b/src/reference/DRMSD.cpp index 405ec8c880d8ba99ed68a01bff936e155815ba67..1b681f4cd3653186e2007fe23fe4cdece0aadf4c 100644 --- a/src/reference/DRMSD.cpp +++ b/src/reference/DRMSD.cpp @@ -79,16 +79,16 @@ double DRMSD::calc( const std::vector<Vector>& pos, const Pbc& pbc, ReferenceVal Vector distance; myder.clear(); double drmsd=0.; - for(std::map< std::pair <unsigned,unsigned> , double>::const_iterator it=targets.begin();it!=targets.end();++it){ + for(const auto & it : targets){ - const unsigned i=getAtomIndex( it->first.first ); - const unsigned j=getAtomIndex( it->first.second ); + const unsigned i=getAtomIndex( it.first.first ); + const unsigned j=getAtomIndex( it.first.second ); if(nopbc) distance=delta( pos[i] , pos[j] ); else distance=pbc.distance( pos[i] , pos[j] ); const double len = distance.modulo(); - const double diff = len - it->second; + const double diff = len - it.second; const double der = diff / len; drmsd += diff * diff; diff --git a/src/reference/MetricRegister.cpp b/src/reference/MetricRegister.cpp index 1268da5f969059a1e7397c0bdc4e8748048b564d..b398dfa11e04c556fbed124b428d4890918c102a 100644 --- a/src/reference/MetricRegister.cpp +++ b/src/reference/MetricRegister.cpp @@ -27,7 +27,7 @@ namespace PLMD{ MetricRegister::~MetricRegister(){ if(m.size()>0){ std::string names=""; - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p) names+=p->first+" "; + for(const auto & p : m) names+=p.first+" "; std::cerr<<"WARNING: ReferenceConfiguration "+ names +" has not been properly unregistered. This might lead to memory leak!!\n"; } } @@ -38,7 +38,7 @@ MetricRegister& metricRegister(){ } void MetricRegister::remove(creator_pointer f){ - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p){ + for(auto p=m.begin();p!=m.end();++p){ if((*p).second==f){ m.erase(p); break; } diff --git a/src/tools/BiasRepresentation.cpp b/src/tools/BiasRepresentation.cpp index 3131bfdc4815ab1bfc3422b3cbabdd37e7998d5d..9aefeb3aba812f932ab60eeb34e83116b9b90881 100644 --- a/src/tools/BiasRepresentation.cpp +++ b/src/tools/BiasRepresentation.cpp @@ -261,9 +261,9 @@ void BiasRepresentation::getMinMaxBin(vector<double> &vmin, vector<double> &vmax } void BiasRepresentation::clear(){ // clear the hills - for(vector<KernelFunctions*>::const_iterator it = hills.begin(); it != hills.end(); ++it) + for(const auto & it : hills) { - delete *it; + delete it; } hills.clear(); // clear the grid diff --git a/src/tools/Grid.cpp b/src/tools/Grid.cpp index 4cf1ed520274595fe1bf7a5aa6ed5523e80a54dd..d66fee5eea5026b56d92735a3c1e94dd50c3ca06 100644 --- a/src/tools/Grid.cpp +++ b/src/tools/Grid.cpp @@ -731,7 +731,7 @@ void Grid::findSetOfPointsOnContour(const double& target, const std::vector<bool double SparseGrid::getValue(index_t index)const{ plumed_assert(index<maxsize_); double value=0.0; - iterator it=map_.find(index); + const auto it=map_.find(index); if(it!=map_.end()) value=it->second; return value; } @@ -741,9 +741,9 @@ double SparseGrid::getValueAndDerivatives plumed_assert(index<maxsize_ && usederiv_ && der.size()==dimension_); double value=0.0; for(unsigned int i=0;i<dimension_;++i) der[i]=0.0; - iterator it=map_.find(index); + const auto it=map_.find(index); if(it!=map_.end()) value=it->second; - iterator_der itder=der_.find(index); + const auto itder=der_.find(index); if(itder!=der_.end()) der=itder->second; return value; } @@ -779,8 +779,8 @@ void SparseGrid::writeToFile(OFile& ofile){ double f; writeHeader(ofile); ofile.fmtField(" "+fmt_); - for(iterator it=map_.begin();it!=map_.end();++it){ - index_t i=(*it).first; + for(const auto & it : map_){ + index_t i=it.first; xx=getPoint(i); if(usederiv_){f=getValueAndDerivatives(i,der);} else{f=getValue(i);} diff --git a/src/tools/Grid.h b/src/tools/Grid.h index e423e332ffe87147db93b3cc46f79ffd767ee221..060aa7f8dda12a68e8997a6abe23822e45ea0115 100644 --- a/src/tools/Grid.h +++ b/src/tools/Grid.h @@ -221,9 +221,7 @@ class SparseGrid : public Grid { std::map<index_t,double> map_; - typedef std::map<index_t,double>::const_iterator iterator; std::map< index_t,std::vector<double> > der_; - typedef std::map<index_t,std::vector<double> >::const_iterator iterator_der; protected: void clear(); diff --git a/src/tools/NeighborList.cpp b/src/tools/NeighborList.cpp index a07d8604d93db1f32507b52e13ca4790cac669a7..bb21353216956ab780c2939300816acd2c830656 100644 --- a/src/tools/NeighborList.cpp +++ b/src/tools/NeighborList.cpp @@ -128,8 +128,7 @@ vector<AtomNumber>& NeighborList::getReducedAtomList() { AtomNumber index0=fullatomlist_[neighbors_[i].first]; AtomNumber index1=fullatomlist_[neighbors_[i].second]; // I exploit the fact that requestlist_ is an ordered vector - vector<AtomNumber>::iterator p; - p = std::find(requestlist_.begin(), requestlist_.end(), index0); plumed_assert(p!=requestlist_.end()); newindex0=p-requestlist_.begin(); + auto p = std::find(requestlist_.begin(), requestlist_.end(), index0); plumed_assert(p!=requestlist_.end()); newindex0=p-requestlist_.begin(); p = std::find(requestlist_.begin(), requestlist_.end(), index1); plumed_assert(p!=requestlist_.end()); newindex1=p-requestlist_.begin(); neighbors_[i]=pair<unsigned,unsigned>(newindex0,newindex1); } diff --git a/src/tools/PDB.cpp b/src/tools/PDB.cpp index 3cd3de1761a8ca498143e67957b946923f652c5c..746e18212a600ace9446edb9a9f21a521c72a3b9 100644 --- a/src/tools/PDB.cpp +++ b/src/tools/PDB.cpp @@ -66,22 +66,19 @@ const std::vector<AtomNumber> & PDB::getAtomNumbers()const{ } std::string PDB::getAtomName(AtomNumber a)const{ - std::map<AtomNumber,unsigned>::const_iterator p; - p=number2index.find(a); + const auto p=number2index.find(a); if(p==number2index.end()) return ""; else return atomsymb[p->second]; } unsigned PDB::getResidueNumber(AtomNumber a)const{ - std::map<AtomNumber,unsigned>::const_iterator p; - p=number2index.find(a); + const auto p=number2index.find(a); if(p==number2index.end()) return 0; else return residue[p->second]; } std::string PDB::getResidueName(AtomNumber a) const{ - std::map<AtomNumber,unsigned>::const_iterator p; - p=number2index.find(a); + const auto p=number2index.find(a); if(p==number2index.end()) return ""; else return residuenames[p->second]; } @@ -297,8 +294,7 @@ Log& operator<<(Log& ostr, const PDB& pdb){ } Vector PDB::getPosition(AtomNumber a)const{ - std::map<AtomNumber,unsigned>::const_iterator p; - p=number2index.find(a); + const auto p=number2index.find(a); if(p==number2index.end()) plumed_merror("atom not available"); else return positions[p->second]; } diff --git a/src/tools/Tools.cpp b/src/tools/Tools.cpp index 8a3d1cf4fdf0a1f95e1aa0e676a682debc84aa73..2dac5e0332015674d3849760449e572d7254bb2f 100644 --- a/src/tools/Tools.cpp +++ b/src/tools/Tools.cpp @@ -212,7 +212,7 @@ void Tools::trimComments(string & s){ bool Tools::getKey(vector<string>& line,const string & key,string & s){ s.clear(); - for(vector<string>::iterator p=line.begin();p!=line.end();++p){ + for(auto p=line.begin();p!=line.end();++p){ if((*p).length()==0) continue; string x=(*p).substr(0,key.length()); if(x==key){ @@ -228,31 +228,31 @@ bool Tools::getKey(vector<string>& line,const string & key,string & s){ void Tools::interpretRanges(std::vector<std::string>&s){ vector<string> news; - for(vector<string>::iterator p=s.begin();p!=s.end();++p){ - news.push_back(*p); - size_t dash=p->find("-"); + for(const auto & p :s){ + news.push_back(p); + size_t dash=p.find("-"); if(dash==string::npos) continue; int first; - if(!Tools::convert(p->substr(0,dash),first)) continue; + if(!Tools::convert(p.substr(0,dash),first)) continue; int stride=1; int second; - size_t colon=p->substr(dash+1).find(":"); + size_t colon=p.substr(dash+1).find(":"); if(colon!=string::npos){ - if(!Tools::convert(p->substr(dash+1).substr(0,colon),second) || - !Tools::convert(p->substr(dash+1).substr(colon+1),stride)) continue; + if(!Tools::convert(p.substr(dash+1).substr(0,colon),second) || + !Tools::convert(p.substr(dash+1).substr(colon+1),stride)) continue; } else { - if(!Tools::convert(p->substr(dash+1),second)) continue; + if(!Tools::convert(p.substr(dash+1),second)) continue; } news.resize(news.size()-1); if(first<=second){ - plumed_massert(stride>0,"interpreting ranges "+ *p + ", stride should be positive"); + plumed_massert(stride>0,"interpreting ranges "+ p + ", stride should be positive"); for(int i=first;i<=second;i+=stride){ string ss; convert(i,ss); news.push_back(ss); } } else { - plumed_massert(stride<0,"interpreting ranges "+ *p + ", stride should be positive"); + plumed_massert(stride<0,"interpreting ranges "+ p + ", stride should be positive"); for(int i=first;i>=second;i+=stride){ string ss; convert(i,ss); @@ -326,8 +326,8 @@ bool Tools::startWith(const std::string & full,const std::string &start){ bool Tools::findKeyword(const std::vector<std::string>&line,const std::string&key){ const std::string search(key+"="); - for(vector<string>::const_iterator p=line.begin();p!=line.end();++p){ - if(startWith(*p,search)) return true; + for(const auto & p : line){ + if(startWith(p,search)) return true; } return false; } diff --git a/src/tools/Tools.h b/src/tools/Tools.h index bb9153adba7f84e9759497567f325076d723e885..b0e7c3ab231c5dfc1570f25c876f57a57de95bdc 100644 --- a/src/tools/Tools.h +++ b/src/tools/Tools.h @@ -169,7 +169,7 @@ void Tools::removeDuplicates(std::vector<T>& vec) inline bool Tools::parseFlag(std::vector<std::string>&line,const std::string&key,bool&val){ - for(std::vector<std::string>::iterator p=line.begin();p!=line.end();++p){ + for(auto p=line.begin();p!=line.end();++p){ if(key==*p){ val=true; line.erase(p); diff --git a/src/vesselbase/VesselRegister.cpp b/src/vesselbase/VesselRegister.cpp index d2e20b31bdb79c24cecb405c551ff2e3c4aff360..a249696539d8a13d5813e67d003e1b15429589b3 100644 --- a/src/vesselbase/VesselRegister.cpp +++ b/src/vesselbase/VesselRegister.cpp @@ -29,7 +29,7 @@ namespace vesselbase{ VesselRegister::~VesselRegister(){ if(m.size()>0){ std::string names=""; - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p) names+=p->first+" "; + for(const auto & p : m) names+=p.first+" "; std::cerr<<"WARNING: Vessel "+ names +" has not been properly unregistered. This might lead to memory leak!!\n"; } } @@ -40,7 +40,7 @@ VesselRegister& vesselRegister(){ } void VesselRegister::remove(creator_pointer f){ - for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p){ + for(auto p=m.begin();p!=m.end();++p){ if((*p).second==f){ m.erase(p); break; }