C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 12 Apr 2025 12:51:39 -0400
On Sat, Apr 12, 2025 at 12:15 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>
>
> 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?

The difference is that `c_str` isn't implicit. It's not something you
mark on the variable's declaration. Whether `c_str` or `string_view`,
they are all things you have to actively do to the variable after it
is created as part of its usage. They aren't part of the declaration.

Received on 2025-04-12 16:51:51