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 12:10:41 +0200
On 29/04/2021 10:30, Giuseppe D'Angelo via Std-Discussion wrote:
>> 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?


To elaborate: is the "magic" here really something that was part of the
*design* (for the purpose of allowing optimizations, sanitizers checks,
etc.), or just something that was implied by an earlier storage/lifetime
model, and simply not adjusted to the lifetime model we have today?


Thank you,
-- 
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 05:10:48