A number of posts I've read lately claim for(const auto &it : vec)
is the same as using the longer iterator syntax for(std::vector<Type*>::const_iterator it = vec.begin(); it != vec.end(); it++)
. But, I came upon this post that says they're not the same.
Currently, I'm trying to erase an element in a for loop, after it is used, and wondering if there is any way to convert const auto &it : nodes
to std::vector<txml::XMLElement*>::iterator
?
Code in question:
std::vector<txml2::XMLElement *> nodes;
//...
for (const auto &it : nodes)
{
//...
nodes.erase(it);
}
I pretty sure I could just rewrite std::vector<txml2::XMLElement*>
as a const pointer, but would prefer not to since this code is just for debugging in the moment.
Aucun commentaire:
Enregistrer un commentaire