0

Well, I see that with C++11, there are 4 new functions in list (STL) that return iterators, which are cbegin, cend, crbegin, crend. As I was reading at cplusplus (webpage), I saw that they simply return const iterators of all 4 kinds(beginning, end, reverse beginning and reverse end iterators), but the question is:

The functions that existed before C++11 ALREADY returned const iterators if the list was const-qualified (I'm talking about begin, end, rbegin and rend), so what is the difference of these const iterators and the returned by the new C++11 functions? Or at least, what is the point of making 4 news functions when you already had 4 that returned the same const iterators?

Thanks and sorry for my english.

1 Answers1

2

cbegin always returns a const_iterator.

begin will return a const_iterator if you call it on a const container, but sometimes you have a mutable container, and for some reason you want a const_iterator. Before, you had to call begin, and then explicitly cast the iterator it returned to a const_iterator.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45