This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
iterators of a swapped std::list
- From: Mihai Vasilian <grayasm at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 1 May 2013 18:45:25 +0200
- Subject: iterators of a swapped std::list
Hi,
I have a question related to iterators of a swapped list.
#include <list>
#include <stdio.h>
int main()
{
int t[2]={-1,-2};
std::list<int> l1(t, t+2), l2;
std::list<int>::iterator beg=l1.begin(), end=l1.end();
l1.swap(l2);
for(; beg!=end; ++beg)
printf("\n%d", *beg);
return 0;
}
$ gcc --version
gcc (GCC) 4.8.0 20130411 (prerelease)
The program's output is:
-1
-2
4195008
-1
-2
4195008
-1
-2
4195008
and it doesn't stop.
I also tested GCC 4.7.3 with the same output.
Am I doing it wrong ?
Regards,
Mihai.