I found in a post how to delete elements from a container using an iterator. While iterating:
for(auto it = translationEvents.begin(); it != translationEvents.end();)
{
auto next = it;
++next; // get the next element
it->second(this); // process (and maybe delete) the current element
it = next; // skip to the next element
}
Why is auto used without the type in auto next = it;?
I use VS10,not C++11 !
autohas a different meaning in C++11 than it did before. In earlier standards,autowas a storage specifier for automatic storage duration – the typical storage an object has where it is destroyed at the end of its scope. In C++11, theautokeyword is used for type deduction of variables. The type of the variable is deduced from the expression being used to initialise it, much in the same way template parameters may be deduced from the types of a template function’s arguments.This type deduction is useful when typing out ugly long types has no benefit. Often, the type is obvious from the initialiser. It is also useful for variables whose type might depend on which instantiation of a template it appears in.
Many C++11 features are supported by default in VC10 and
autois one of them.