iterators of a swapped std::list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux