![]() |
VOOZH | about |
ForwardIterator next (ForwardIterator it, typename iterator_traits::difference_type n = 1); it: Iterator to the base position. difference_type: It is the numerical type that represents distances between iterators of the ForwardIterator type. n: Total no. of positions by which the iterator has to be advanced. In the syntax, n is assigned a default value 1 so it will atleast advance by 1 position. Returns: It returns an iterator to the element n positions away from it.Output:
v1 = 1 2 3 4 5 6 7 v2 = 8 9 10 1 2 3 4
How can it be helpful ?
v1 = 1 2 3 7 8 9 v2 = 4 5 6 1 2 3Explanation: Here, just look how if we want copy only a selected portion of the list, then we can make use of std::next, as otherwise we cannot use any +=, -= operators with bidirectional iterators supported by lists. So, we used std::next and directly advanced the iterator by three positions.