c++listiteratorswap

std::swap returns 0xBAADF00D


I'm trying to swap two std::list< dontcare* >::iterators under Visual 2005.

Iter it1 = ... ,it2 = ...; // it1 and it2 are ok, not end() or such
if(...){
    std::swap(it1,it2);
}

The swap works, but when I leave the if() scope, it1 points to 0xbaadfood. It2 is ok though.I tried several variations, including swap_iter and a hand-made swap.

Any help appreciated :)

EDIT

Ok, so shame time.

The swapped it1 was a local variable in the if's scope.

F**king cut'n pasting. Sorry for wasting your time :/


Solution

  • Are you omitting code inside your if? Most likely something else within your if check, but after the swap is actually invalidating the iterator (perhaps an erase).