C++ Logo

std-discussion

Advanced search

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

From: Hyman Rosen <hyrosen_at_[hidden]>
Date: Fri, 30 Apr 2021 01:50:14 -0400
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.

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.

Received on 2021-04-30 00:50:32