C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Automatic perfect forwarding is possible and not too complicated

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 13 Apr 2025 22:56:18 +0100
On Sunday, April 13, 2025, Jonathan Wakely wrote:

>
> template<typename T> void f(T&&);
>
> Or simply:
>
> auto&& r = x;
>



I wonder if it really is too late to change this. I means let's say in
C++29, if the syntax were to change to:

    template<typename T> void f(T&?);
    auto &?r = x;

Then maybe in C++32, the old way could become deprecated, and removed in
C++35.

Then eventually we would be able to do the following:

    template<typename T>
    void f(T &?first_argument, T &&second_argument);

The first argument is a forwarding reference. The second argument is an
Rvalue reference.

It wouldn't be the first time that the meaning of a piece of pre-existing
code changed. For example I recently took some modern C++ code and tried to
compile it for a Texas Instruments microcontroller. It compiled fine but it
didn't work. It turned out that the problem was a line of code like:

        auto n = SomeFunction();

The compiler was interpreting it as:

        int auto n = SomeFunction();

(Remember when 'auto' just meant it was a variable local to the current
invocation of a function, i.e. not 'static')

After I die I'm going to come back to haunt the person who proposed '&&'
for forwarding references. It never should have happened. Has anyone got a
name I can give to God at the pearly gates when he asks me who I want to
haunt? Who is responsible for the monstrosity of '&&' for forwarding
references? And how did you all let that happen . . . . (shaking my head)

Received on 2025-04-13 21:56:21