C++ Logo

std-proposals

Advanced search

Re: Operator for reference casting

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sun, 17 Jan 2021 16:27:53 -0500
On Sun, Jan 17, 2021 at 12:21 PM Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Sun, Jan 17, 2021 at 4:27 AM Drew Gross via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Some examples of when you don't want to forward a forwarding reference,
> might be easy to create bugs if it forwarded automatically:
> >
> > 1) A generic logging wrapper function
> > ```
> > auto LoggedCall(auto >&& f, auto >&& v) {
> > LogValue(v);
> > return f(v); // Oops, v was moved from! (Maybe, depending on
> signature of LogValue)
> > }
> > ```
>
> Why would a logging function move from its parameter? It should take
> it as a `const&`.
>

I could totally imagine a logging function with the signature
    void LogValue(std::string msg);
Your proposal would break that. That's bad.

–Arthur

Received on 2021-01-17 15:28:06