#include #include #include int main() { std::vector vec { "Lewis Hamilton", "Lewis Hamilton", "Nico Roseberg", "Sebastain Vettel", "Lewis Hamilton", "Sebastain Vettel", "Sebastain Vettel", "Sebastain Vettel", "Fernando Alonso" }; auto it { vec.begin() }; // Constant time std::cout << "Latest winner is: " << *it << std::endl; it += 8; // Constant time std::cout << "Winner before 8 years was: " << *it << std::endl; std::advance(it, -3); // Contant time std::cout << "Winner before 3 years of that was: " << *it << std::endl; std::forward_list fwd { vec.begin(), vec.end() }; auto it1 { fwd.begin() }; std::cout << "Latest winner is: " << *it1 << std::endl; std::advance(it1, 5); // Time taken is proportional to the number of elements std::cout << "Winner before 5 years was: " << *it1 << std::endl; // Going back will result in compilr time error as forward_list only allows us to move towards the end. // std::advance(it1, -2); // Compiler error return 0; }