C++ Logo

std-discussion

Advanced search

Re: On "transparently replaceable" in std::vector operations

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 29 Apr 2021 10:30:15 +0200
Hello,

On 29/04/2021 07:33, Christopher Hallock via Std-Discussion wrote:
>
> I was adding my own concerns about these library clauses being
> underspecified and overly broad. Getting back to your original question,
> which is whether library invalidation "sticks", given [basic.life]/8: I
> believe it does. If the invalidating operation move-assigns or
> copy-assigns the elements, then [basic.life]/8 doesn't even apply
> because no new object was created. If the invalidating operation
> move-constructs or copy-constructs the elements, then there is room for
> ambiguity, but I think the intent is that even in this case, the
> invalidation "sticks". I believe things happen in this sequence: 1)
> element is destroyed, which automatically invalidates pointers to it; 2)
> new element is created in the same place, "resurrecting" the old
> pointers via [basic.life]/8; 3) the library clause kicks in and
> invalidates the resurrected pointers once more.

Well... "sure"? Does this now make std::vector unimplementable in the
C++ language, as it requires implementation "magic" to perform 3)?

Is it worth to keep such a thing in the light of the lifetime guarantees
now provided by the language?

And/or, can I have the "magic" as well for my own containers?

Thanks,

-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2021-04-29 03:30:24