Talk:cpp/iterator/advance

Hi, in my first version of the example i avoided the use of the uniform initialization of the vector, since it is a c++11 feature.

What's the policy for the wiki? Should c++11 features be used in the examples without any further notice? Should such examples be marked?

--Michel 06:47, 8 September 2011 (PDT)


 * I've asked a similar question earlier, and the answer was any feature in C++11 can be used. --Cubbi 08:06, 8 September 2011 (PDT)

I noticed that, in libc++, std::advance only has one template argument (InputIt). The correct Distance type is determined using std::iterator_traits::difference_type. Is this part of the real c++11 standard? I would assume so, but I don't have access to the actual document, so I don't know for sure. If it is, I can go ahead and update the page.

--Ryan

192.150.10.200 15:50, 21 October 2013 (PDT)
 * no, it didn't change in C++11 or even in the latest draft C++14. As the comment in libc++'s says, it's that library's non-standard extension. --Cubbi (talk) 17:39, 21 October 2013 (PDT)

Out of range value for n
I don't see any comment about what happens if n, positive or negative, would take the iterator out of the iterable. If n is positive I would guess it will move to iterable.end, but that's all I can think of.

--83.36.4.48 00:59, 12 July 2016 (PDT)
 * Standard says that advance "Increments (or decrements for negative n) iterator reference i by n.", so you should defer to explanation of what happens when you try to increment/decrement particular iterator past valid range. Usually it means UB. MiiNiPaa (talk) 04:09, 12 July 2016 (PDT)
 * made it explicit as a note, since this comes up every now and then. --Cubbi (talk) 06:52, 12 July 2016 (PDT)