Yes and no (It depends on the container in use):
- The range based for is a loop like for(iterator pos = range.begin(); pos !=
range.end(); ++pos) { /* with a range variable = *pos */ ... }
- An operator [] might do something different (eg. a std::map operator does a lookup on the key and create a new entry, if the key does not exist)
Example:
#include
#include
The result is:
0 2 4
0 0 2 0 4
(The second result might be a good shot in the own foot or even intended)