Given allocators a1 and a2, where a1 != a2,
and std::vectors v1(a1) and v2(a2)
then v1.swap(v2) invalidates all iterators.
Is this expected behavior?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general,
swapnever invalidates iterators. However, another rule comes into play when the allocators are different. In that case the behavior depends onallocator_traits<a1>::propagate_on_container_swap::valueandallocator_traits<a2>::propagate_on_container_swap::value. If both are true, the allocators are exchanged along with the data, all iterators remain valid. If either is false, behavior is undefined, so the particular behavior exhibited by VC++ 2010 is allowed.From
[container.requirements.general](wording from n3290):and
and
23.3.6.5 does not specify alternate rules for
vector::swap().