C++ Logo

std-proposals

Advanced search

Re: [std-proposals] pass() replacement for: forward<>()

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 5 Jan 2023 20:35:20 -0500
On Thu, Jan 5, 2023 at 7:44 PM Phil Bouchard via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Greetings,
>
> Please find attached a small wrapper function that could be useful as a replacement for forward<>() which uses explicit type specification (for some reason),

There is a reason. The fact that you don't know what that reason is is
why `pass` can't actually do what you claim. The odd thing is, your
code doesn't even show you replacing `forward`; `::foo` still uses
`forward`.

`std::forward` is meant to be used in perfect forwarding scenarios.
This means you have a forwarding reference. Your example only uses
`pass` with a non-template function. So forwarding references aren't
around.

Really, your `pass` is no different than using `std::move`. If I make
a `foo_pass` template that's like `foo` except that you use `pass`
rather than `std::forward`, then it does the wrong thing:
https://gcc.godbolt.org/z/EMndz1xds

So this `pass` is absolutely not a replacement for `std::forward`. It
cannot be used for perfect forwarding.

> shorter to type and can be used as perfect forwarding for virtual functions as well,

Virtual functions cannot be templates and therefore cannot have
"perfect forwarding". I think you need to take some time to learn what
that term actually refers to.

> not only with template functions. You can use it for universal parameter types as well.

Received on 2023-01-06 01:35:29