C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Floating an idea: Dereference operators for std::reference_wrapper

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 25 Sep 2024 12:29:28 +0100
On Wed, 25 Sept 2024 at 05:53, Jeremy Rifkin via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi,
> It'd be useful for me to have `std::reference_wrapper::operator->` and
> `std::reference_wrapper::operator*`.


Why? You didn't provide any rationale.

Isn't get() already sufficient for everything that operator* could do?
Do you really need operator->() when refwrap->foo() could be written as
refwrap.get().foo() instead?




> As far as I can tell this has not
> been proposed before. It would follow the precedent of std::optional as
> well as the forwarding comparison operators added in P2944. Has this
> been considered before or are there any glaring issues with such a
> functionality?
>
>
Apart from get() already existing, the main one is that it's a
**reference** wrapper, and you're proposing pointer-like semantics.

Received on 2024-09-25 11:30:47