K
kalita
Hi All,
typedef std::list<int> Cont;
void f(Cont &c1, Cont &c2)
{
Cont::iterator it = c1.begin();
c1.swap(c2);
it == c2.begin(); // is this ill formed?
}
Visual C++ 2005 has fancy iterator debugging, and it asserts at the
last line saying that iterators are incompatible and cannot be
compared. Basically, when in debugging mode it stores pointer to
container with each iterator, and this pointer obviously still points
to c1 despite the swap, so comparison with iterator obtained from
c2.begin() fails.
Could somebody enlighten me if this is correct behaviour (i.e. the code
is ill formed), or if this is VC 2005 bug.
cheers,
Marcin
typedef std::list<int> Cont;
void f(Cont &c1, Cont &c2)
{
Cont::iterator it = c1.begin();
c1.swap(c2);
it == c2.begin(); // is this ill formed?
}
Visual C++ 2005 has fancy iterator debugging, and it asserts at the
last line saying that iterators are incompatible and cannot be
compared. Basically, when in debugging mode it stores pointer to
container with each iterator, and this pointer obviously still points
to c1 despite the swap, so comparison with iterator obtained from
c2.begin() fails.
Could somebody enlighten me if this is correct behaviour (i.e. the code
is ill formed), or if this is VC 2005 bug.
cheers,
Marcin