There's probably no place in the language where you couldn't give something a different name; this is just a little act of kindness, a bit like size()
and length()
on std::string
.
Remembering to use cbegin
when working on a const
container is a PITA, so the const_iterator begin() const
is useful. At the same time, when I'm explicitly interested in obtaining a const
iterator, without cbegin
I'd have to do something convoluted like ((const std::vector<int> &)vec).begin()
, which is certainly less readable/writable than vec.cbegin()
.
Now, you could argue that there are places where little acts of kindness like this are more sorely needed (and which scale better — supporting all the combinations of regular/reverse/const iterators quickly makes the interface explode), and I would certainly agree with you.
Incidentally, having the const_iterator begin
avoids the need for other fiddling to make the range-based for loop work correctly on const
objects.