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 17:21:26 +0200
Hi,

On 29/04/2021 15:56, Jason McKesson via Std-Discussion wrote:
>> Well... "sure"? Does this now make std::vector unimplementable in the
>> C++ language, as it requires implementation "magic" to perform 3)?
> Um, no. A pointer becoming invalid is not something you can detect.
> Being invalid means that UB will happen if you try to use it. And UB
> could include everything "working" as you would expect.

I didn't say I can detect it...

... I said that if I implement a conforming `vector` myself, I will lack
the "magic" to make pointers into my vector invalidated. My users still
can't use those pointers (because that's the specification), but for the
compiler, those pointers will be 100% valid and so it won't be able to
apply the same (theoretical) reasoning and optimizations that it can
apply for `std::vector` itself.

Since I clearly also want those optimizations, is there any reason for
C++ not providing such a thing to end-users, so that can I also have the
magic "invalidate these pointers" facility for my own containers?

If the reason is that no implementation has actually ever implemented
such a thing, and actually all implementations don't invalidate anything
(pointers simply point to other objects, depending on the operation, and
compilers don't take advantage of this, and sanitizers don't check for
this), is there any reason for keeping the invalidation wording?


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 10:21:41