C++ Logo


Advanced search

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

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 30 Apr 2021 10:09:42 +0200
pt., 30 kwi 2021 o 07:51 Hyman Rosen via Std-Discussion
<std-discussion_at_[hidden]> napisaƂ(a):
> On Thu, Apr 29, 2021 at 7:56 PM Jason McKesson via Std-Discussion <std-discussion_at_[hidden]> wrote:
>> Put simply, a pointer/reference to an element in a container is not,
>> and should not be considered, a fancy index.
> Put simply, you're wrong. As is always the case with needless restrictions,
> the past harms the future with dumb caution, while the future finds itself
> hamstrung by decisions made in the absence of knowledge that the future has
> and the past did not.

And "future" harm who now? You have multiple problems because compilers change,
if you follow this "dumb caution" your code would work for years
without problems.

You simply do not know what the future will bring and you try to
reason about this now?
You have better knowledge than in the past but you still have zero
knowledge about the future.

This means if you restrict yourself more then all your versions, past,
current and future will agree.

Pointer invalidation is a great tool to recognize what code is broken
and what is not,
if any code accesses a pointer to invalided memory then we know he
wants the old value not new one (diffrent object).
image trying sort vector when someone else try shift all elements
(aside for concurrent access and multithreading problems).

> If a programmer has pointers to elements of a vector, and wants to use them
> with full knowledge of what they point to and what the contents mean, it is
> not the business of the library designer to impose arbitrary restrictions.
> Worse, as is usual with these undefined behavior parade of horribles, the
> code will work fine until it doesn't, when some optimizationalist finally
> figures out how to use the restriction to break the clear intent of the code.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2021-04-30 03:09:53