C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Another reason why we should have simple operator for forward (and move)

From: Keenan Horrigan <friedkeenan_at_[hidden]>
Date: Sun, 08 Oct 2023 15:34:11 +0000
Others have put forth other perfectly clean solutions that work. But also if P2677 "Reconsidering concepts in-place syntax" were accepted, we'd also be able to write something like

[](auto:T &&param) { f(std::forward<T>(param)); }

Which I think to be a fairly clean solution as well.

------- Original Message -------
On Sunday, October 8th, 2023 at 10:25 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:


> For quite a while now, a few people have been saying that we should
> have simple shorthand for 'forward', for example the following:
>
> template<typename T>
>
> void Func(T &&arg)
> {
> SomeOtherFunc( forward<T>(arg) );
>
> }
>
> could be simplified to something like:
>
> template<typename T>
>
> void Func(T &&arg)
> {
> SomeOtherFunc( ^^arg );
> }
>
> Well today I thought of another reason why we should have this.
> Consider the following lambda:
>
> auto forwardingLambda = [](auto&& param) { f(std::forward<T>(param)); };
>
>
> It doesn't compile because we don't have 'T'. In order to keep the
> 'auto' in there, we would need to write:
>
> auto forwardingLambda = [](auto&& param) {
> f(std::forward<std::conditional<std::is_rvalue_reference<decltype(param)>::value,
>
> std::remove_reference<decltype(param)>::type,
>
> decltype(param)>::type>(param));
>
> };
>
> Ain't nobody got time for that. It would be better if we could just do:
>
> auto forwardingLambda = [](auto&& param) { f(^^param); };
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-10-08 15:34:28