C++ Logo

std-proposals

Advanced search

Re: [std-proposals] p3039r1 proxy temporary objects

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 21 Feb 2026 09:03:19 +0000
On Fri, 20 Feb 2026, 18:39 Marcin Jaczewski via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> Paper suggests rewriting `ptr->meber` by `(*ptr).member`.
>
> But this creates an interesting case, new `->` created this way will
> have capabilities impossible compared to manually written `->`.
>
> Consider example:
> ```
> const auto& foo = ptr->member;
> ```
> and `ptr` that has a `*` returning proxy value.
>

Is it common to return a proxy where you directly access its data member?

I can't think of a case where I'd want that, rather than having a proxy
where you use its member functions. But maybe I'm not imaginative enough.



With this rewrite, the lifetime of the proxy object will be expanded
> to the lifetime of the `foo` reference.
> Using user defined `->` you can't in anyway do this as this operator
> is required to return pointer and not value (as it will call nested of
> `->`).
>
> This is expected behavior? If yes then maybe we should
> discourage of further use of user defined `->` operator?
>

As I noted in another reply in the thread, you would probably still
want operator-> for std::to_address to work on an end iterator, which is a
requirement for iterators that model std::contiguous_iterator.

If the paper gets approved, I would want compilers to warn about a
contiguous iterator that doesn't define operator->.

Received on 2026-02-21 09:03:36