Am 27.06.19 um 10:13 schrieb degski:
On Thu, 27 Jun 2019 at 11:01, Alexander Grund via Boost
mailto:boost@lists.boost.org> wrote: 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
How does that gel with: "Some implementations of std::list throw from their move constructors" (David Sankel) ..." [because I would think the same as you]? Yes, swap head around, and if you really want safety, you can use a xor-swap of the [those] pointer[s], i.e. guaranteed no allocation (stack or heap).
He also wrote: "I understand that the implementation is easier if even an empty list has a dummy node, which requires allocation." So a move constructor must construct a dummy node for the moved-from list and that allocation might throw. I don't know WHY one would require this, but I'll just take his word that it MAY be required.