In Qt there are similar classes to list an map. These classes provide a begin_const() method that returns a const_iterator. The documentation says that these const_iterators should be used whenever possible since they are faster.
The STL only gives you a const_iterator if the instance itself is const. Only one begin() method is implemented (overloaded for const).
Is there any difference when read-accessing elements with iterator and const_iterator? (I dont’w know why there’s a difference for them in Qt)
It sure does. From http://qt-project.org/doc/qt-4.8/containers.html#stl-style-iterators:
What a stupid thing to say.
Safer? Yes. Faster? Even if this were the case (it apparently isn’t with gcc and clang), it is rarely a reason to prefer const iterators over non-const ones. This is premature optimization. The reason to prefer const iterators over non-const ones is safety. If you don’t need the pointed-to contents to be modified, use a const iterator. Think of what some maintenance programmer will do to your code.
As far as
beginversuscbeginis concerned, that’s a C++11 addition. This allows theautokeyword to use a const iterator, even in a non-const setting.