I'm sure there's a good explanation for this effect, but I get rather
a strange output from this little test:
#include <iostream>
#include <list>
int main()
{
std::list<int> int_list;
int_list.push_b ack(1);
int_list.push_b ack(2);
int_list.push_b ack(3);
int_list.push_b ack(4);
std::list<int>: :reverse_iterat or rev = int_list.rbegin ();
while(rev != int_list.rend() )
{
std::cout << *rev++ << std::endl;
int_list.pop_ba ck(); // This line causes a problem.
}
return 0;
}
Output:
4
3
2
1
0
0
The inclusion of the int_list.pop_ba ck() call seems to cause the two
additional iterations through the loop that print the two extra zeros.
If I comment out the int_list.pop_ba ck() line the output is as
expected, and if i use a different conditional statement such as
while(! int_list.empty( )) the output is also as expected.
Does anyone know why this doesn't work? Are there member functions of
std::list that shouldn't be used with iterators, reverse-iterators or
something?
I'm using Red Hat 7 & g++.
a strange output from this little test:
#include <iostream>
#include <list>
int main()
{
std::list<int> int_list;
int_list.push_b ack(1);
int_list.push_b ack(2);
int_list.push_b ack(3);
int_list.push_b ack(4);
std::list<int>: :reverse_iterat or rev = int_list.rbegin ();
while(rev != int_list.rend() )
{
std::cout << *rev++ << std::endl;
int_list.pop_ba ck(); // This line causes a problem.
}
return 0;
}
Output:
4
3
2
1
0
0
The inclusion of the int_list.pop_ba ck() call seems to cause the two
additional iterations through the loop that print the two extra zeros.
If I comment out the int_list.pop_ba ck() line the output is as
expected, and if i use a different conditional statement such as
while(! int_list.empty( )) the output is also as expected.
Does anyone know why this doesn't work? Are there member functions of
std::list that shouldn't be used with iterators, reverse-iterators or
something?
I'm using Red Hat 7 & g++.
Comment