C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Possible Flaw/Hole in the type system

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 25 Sep 2025 08:55:17 +0200
> 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.

Received on 2025-09-25 06:55:31