How get next (previous) element in std::list without incrementing (decrementing) iterator?

Yes, since C++11 there are the two methods you are looking for called std::prev and std::next. You can find them in the iterator library.

Example from cppreference.com

#include <iostream>
#include <iterator>
#include <list>
 
int main() 
{
    std::list<int> v{ 3, 1, 4 };
 
    auto it = v.begin();
 
    auto nx = std::next(it, 2);
 
    std::cout << *it << ' ' << *nx << '\n';
}

Output:

3 4

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)