Does std::move() invalidate iterators?

This question already has an answer here:

  • Does moving a vector invalidate iterators? 4 answers

  • After http://en.cppreference.com notes (emphasis mine):

    After container move assignment (overload (2)), unless elementwise move assignment is forced by incompatible allocators, references, pointers, and iterators (other than the end iterator) to other remain valid , but refer to elements that are now in *this. The current standard makes this guarantee via the blanket statement in §23.2.1[container.requirements.general]/12, and a more direct guarantee is under consideration via LWG 2321

    Notes

    As hvd have rightly pointed out there is at least once case where the move assignent is forced to invalidate iterators - when the new container has incompatible allocator.

    As Ben Voigt noted there is a broader discussion in this topic over here and it actually already covers the c++11 aspects of the question...


    No, they should not get invalidated after a move operation.

    23.3.6.5/1

    all iterators and references before the point of insertion are unaffected, unless the new container size is greater than the previous capacity (in which case all iterators and references are invalidated)

    链接地址: http://www.djcxy.com/p/94462.html

    上一篇: 最大可能的尺寸图像和div展开以填充空间

    下一篇: std :: move()是否使迭代器失效?