C++ Logo

std-discussion

Advanced search

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

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Fri, 30 Apr 2021 01:32:29 +0200
On 29/04/2021 23:17, Jason McKesson via Std-Discussion wrote:
> And my point is that you don't need to*make* them invalid, precisely
> because nobody can*detect* that they became invalid. User code isn't
> allowed to use them, so you don't need to do anything. Neither do
> `vector` implementations. You will find exactly zero code in
> `std::vector` implementations that magically mark those pointers as
> "invalid".
>
> They're invalid by convention, not by actual execution of something.

<devil's advocate>

If it's not because the compiler may take advantage of it, and it
doesn't actually get checked by sanitizers, and what not: then why is
there such a convention?

Does it allow for some hypothetical extra leeway in `vector`
implementations? Is it purely an historical artefact, maybe due to how
`vector` was used to be implemented? Something else?

 From the sentence above, it seems to me that you agree with the fact
that the straightforward implementation of `vector` will incur in no
costs if it wanted to provide the guarantee that the pointers are valid.
So why not providing the guarantee?

</devil's advocate>

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 18:32:46