Suppose you have a C++ empty list:
list<int> l;
and you insert three new elements from the beginning:
auto it = l.begin();
l.insert(it,10);
l.insert(it,20);
l.insert(it,30);
when trying to print the list elements from the beginning to the end:
for(int i: l){
cout << i << ' ';
}
the obtained result is: 10 20 30.
But it is supposed that insert function inserts elements before the element pointed by the iterator, so the obtained result should have been: 30 20 10.
Why does this happen?