Am 27.06.19 um 09:33 schrieb Gavin Lambert via Boost:
On 27/06/2019 19:06, degski wrote:
Yes, but std::swap must also not invalidate any references, pointers, or iterators referring to the elements of the containers being swapped, which leaves the scope for throwing rather small [if at all possible].
Are you sure about that?
Perhaps it is a failure of my imagination (or I'm misunderstanding what you're saying), but that doesn't even seem possible.
On how this is possible: Imagine `std::list` as a simple linked list (pointer to (element, pointer-to-next)-tuples). On move, you simply move the HEAD pointer to the new list and a NULL to the old list. Result: Pointers/References to all elements are still valid. Same for e.g. vectors: Only pointers to array are swapped -> Unchanged element pointers obviously after `swap(foo, bar)` an old pointer `oldFoo = &foo[1]` set before the swap does now point into `bar`: `assert(oldFoo == &bar[1])`