Date: Thu, 25 Sep 2025 10:01:26 +0200
czw., 25 wrz 2025 o 08:55 Jan Schultke via Std-Proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> > Is this not easily fixable by converting the:
> >
> > constexpr T* operator->() {...}
> > constexpr T const* operator->() const {...}
> >
> > with just:
> >
> > constexpr T* operator->() & {...}
> > constexpr T const* operator->() const& {...}
>
> Making operator-> reference-qualified in general is a bad idea. It
> prevents valid use cases like:
>
> getAddress()->modify()
>
> or
>
> getOptionalBuilder()->set(1).build()
>
> Also I'm pretty sure that the const& overload works with rvalues.
Overall I think `->` is somewhat broken as it makes it hard to use
some proxy objects too.
One solution I had it create "final" operator `->` that return
refs/values instead of pointer, like:
```
T& operator->(int) { ... } //int is to inform compiler that is not
normal operator `->`
```
Compiler will stop chaining `->` on this overload (instead of stopping
on buildin `->`).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisaĆ(a):
>
> > Is this not easily fixable by converting the:
> >
> > constexpr T* operator->() {...}
> > constexpr T const* operator->() const {...}
> >
> > with just:
> >
> > constexpr T* operator->() & {...}
> > constexpr T const* operator->() const& {...}
>
> Making operator-> reference-qualified in general is a bad idea. It
> prevents valid use cases like:
>
> getAddress()->modify()
>
> or
>
> getOptionalBuilder()->set(1).build()
>
> Also I'm pretty sure that the const& overload works with rvalues.
Overall I think `->` is somewhat broken as it makes it hard to use
some proxy objects too.
One solution I had it create "final" operator `->` that return
refs/values instead of pointer, like:
```
T& operator->(int) { ... } //int is to inform compiler that is not
normal operator `->`
```
Compiler will stop chaining `->` on this overload (instead of stopping
on buildin `->`).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-09-25 08:01:42