Date: Fri, 15 Jan 2021 09:26:36 -0600
On Fri, Jan 15, 2021 at 7:49 AM Jean-Baptiste Vallon Hoarau via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> Hello everyone,
>
> I think you are all aware how verbose perfect forwarding is. I haven't
> seen any proposal that could tackle this (admittedly minor) issue so far,
> except the one on hygienic macros.
> So what if we had an operator for casting to a reference?
> For example, given a value x, than the following could be equivalent :
> x& -> static_cast<decltype(x)&>(x)
> x&& -> static_cast<decltype(x)&&>(x)
>
> This would make forwarding a lot less cumbersome to write/read (goodbye
> decltype(x)(x), hello x&&). However, I don't see many use cases for
> explicit lvalue cast, and this would be at odd with lambda capture syntax.
>
> Let me know what you think.
> -Jean-Baptiste
>
I'd written this a while ago (
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0644r1.html),
which would be a prefix operator >> for forwarding. This got rejected in
2017, >> is just a bad choice in the context of templates which are already
using a lot of angle brackets.
Prefix && is a gcc extension so isn't an option. Postfix && looks like it's
starting the beginning of a logical conjunction.
In discussion of my paper, the possibility of a good-but-nonconflicting
keyword was brought up and people suggested declfwd (vote was 0-10) and
fwdexpr (vote was 7-5). The best option here seems to be to add some kind
of hygienic macro language feature such that we can introduce std::fwd(x)
to actually be a function that does forwarding.
Barring that, I don't know if we can just by fiat say that std::fwd is a
magic thing that is not addressable (we do already say that in general for
standard library functions) that Just Works because of Compiler Magic.
Barry
Std-Proposals <std-proposals_at_[hidden]> wrote:
> Hello everyone,
>
> I think you are all aware how verbose perfect forwarding is. I haven't
> seen any proposal that could tackle this (admittedly minor) issue so far,
> except the one on hygienic macros.
> So what if we had an operator for casting to a reference?
> For example, given a value x, than the following could be equivalent :
> x& -> static_cast<decltype(x)&>(x)
> x&& -> static_cast<decltype(x)&&>(x)
>
> This would make forwarding a lot less cumbersome to write/read (goodbye
> decltype(x)(x), hello x&&). However, I don't see many use cases for
> explicit lvalue cast, and this would be at odd with lambda capture syntax.
>
> Let me know what you think.
> -Jean-Baptiste
>
I'd written this a while ago (
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0644r1.html),
which would be a prefix operator >> for forwarding. This got rejected in
2017, >> is just a bad choice in the context of templates which are already
using a lot of angle brackets.
Prefix && is a gcc extension so isn't an option. Postfix && looks like it's
starting the beginning of a logical conjunction.
In discussion of my paper, the possibility of a good-but-nonconflicting
keyword was brought up and people suggested declfwd (vote was 0-10) and
fwdexpr (vote was 7-5). The best option here seems to be to add some kind
of hygienic macro language feature such that we can introduce std::fwd(x)
to actually be a function that does forwarding.
Barring that, I don't know if we can just by fiat say that std::fwd is a
magic thing that is not addressable (we do already say that in general for
standard library functions) that Just Works because of Compiler Magic.
Barry
Received on 2021-01-15 09:26:51