This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]