Boost logo

Boost :

From: degski (degski_at_[hidden])
Date: 2019-06-27 08:13:33


On Thu, 27 Jun 2019 at 11:01, Alexander Grund via Boost <
boost_at_[hidden]> wrote:

>
> 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
>

 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).

degski

-- 
@realdegski
https://edition.cnn.com/interactive/2019/06/middleeast/saudi-teen-death-penalty-intl/
"Anyone who believes that exponential growth can go on forever in a finite
world is either a madman or an economist" - Kenneth E. Boulding

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk