Date: Thu, 25 Sep 2025 08:16:48 -0500
On Thu, Sep 25, 2025, 7:55 AM Andre Kostur via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> I'd had a different thought overnight. What about allowing one to
> add `auto operator->() = default;`. If this is selected by overload
> resolution, then behave as in paragraph 2 of [expr.ref] (rewrite the
> code as `(*(E1)).E2`) instead of the behaviour in [over.ref] (the
> current "keep calling operator-> until you get a raw pointer, then
> rewrite to (*(E1)).E2") . The practical result is that instead of
> using the overloaded operator->() and calling operator-> on the result
> of that, use the overloaded operator*() and apply the dot operator on
> the result of that. This moves the type decisions over to operator*
> where the reference-qualifications are preserved.
>
See P3039.
Whether this needs explicit opt-in or not, simply rewriting lhs->rhs as
(*lhs).rhs seems like a nice win. That's what it already means for
pointers, so why not for class types.
Barry
>
std-proposals_at_[hidden]> wrote:
> I'd had a different thought overnight. What about allowing one to
> add `auto operator->() = default;`. If this is selected by overload
> resolution, then behave as in paragraph 2 of [expr.ref] (rewrite the
> code as `(*(E1)).E2`) instead of the behaviour in [over.ref] (the
> current "keep calling operator-> until you get a raw pointer, then
> rewrite to (*(E1)).E2") . The practical result is that instead of
> using the overloaded operator->() and calling operator-> on the result
> of that, use the overloaded operator*() and apply the dot operator on
> the result of that. This moves the type decisions over to operator*
> where the reference-qualifications are preserved.
>
See P3039.
Whether this needs explicit opt-in or not, simply rewriting lhs->rhs as
(*lhs).rhs seems like a nice win. That's what it already means for
pointers, so why not for class types.
Barry
>
Received on 2025-09-25 13:17:07