C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Automatic perfect forwarding is possible and not too complicated

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 12 Apr 2025 17:15:20 +0100
On Friday, April 11, 2025, Lénárd Szolnoki <cpp_at_[hidden]> wrote:

> Can't work safely in general. Just because an id is used last lexically
> within a function it does not mean that it is the last used reference to
> the object. A previous call could leak the reference and a later call can
> use it.
>
> Similarly, implicitly moved strings can silently invalidate string_views.
>


Yeah but isn't that kind of like saying that we shouldn't have
'std::string::c_str' because the pointers might become invalid if you do
something with the string?

If you're going to use a string_view to refer to the contents of an
std::string, then you already need to make sure that the string doesn't
change too much. So you wouldn't use a trigraph '&&&' reference to refer
to a string if either:
a) You've already stored the value of c_str()
b) You're going to plunder the string's resources

Received on 2025-04-12 16:15:25