Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #87898

Re: R-value references and std::forward

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Bo Persson <bo@bo-persson.se>
Newsgroups comp.lang.c++
Subject Re: R-value references and std::forward
Date Wed, 14 Dec 2022 12:42:48 +0100
Lines 26
Message-ID <jvtr5nFrbl6U1@mid.individual.net> (permalink)
References <6d19a662-76a1-4925-bd07-b259836f062bn@googlegroups.com> <jvtj6mFq5jfU1@mid.individual.net> <a4ffe6c9-868a-4a12-9ab2-49094d7466c8n@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net K764hOihDUxXXq5gTCb8MAFy083WvuueYN2UBsf/boVim5qoaA
Cancel-Lock sha1:YKUrPs1Pd28y9QsevRy/nDfRWZo=
User-Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1
Content-Language sv
In-Reply-To <a4ffe6c9-868a-4a12-9ab2-49094d7466c8n@googlegroups.com>
Xref csiph.com comp.lang.c++:87898

Show key headers only | View raw


On 2022-12-14 at 10:48, Frederick Virchanza Gotham wrote:
> On Wednesday, December 14, 2022 at 9:27:06 AM UTC, Bo Persson wrote:
> 
>> You are using it wrong, anyway. When the value is an int&, you should
>> "forward" is using forward<int&>(arg).
>>
>> That's what happens with a forwarding reference.
> 
> 
> If I knew for certain that it was an "int&" then why would I bother using 'forward' on it?

Beats me, it was your example.

> 
> The question I'm asking is why 'forward' in this case is turning an L-value into an R-value?

Because that's how template argument deduction works. When you 
explicitly supply <int> to a function returning T&&, you get an int&&. 
No surprise here.

> Is it because it's UB to use 'forward' on something that isn't a "template parameter forwarding reference"?

No, but not very useful. The whole idea of std::forward is that it can 
adapt to the deduced template parameter. If there is no template, it is 
outside if the intended use pattern.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

R-value references and std::forward Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-12-14 00:44 -0800
  Re: R-value references and std::forward Bo Persson <bo@bo-persson.se> - 2022-12-14 10:26 +0100
    Re: R-value references and std::forward Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-12-14 01:48 -0800
      Re: R-value references and std::forward Bo Persson <bo@bo-persson.se> - 2022-12-14 12:42 +0100
        Re: R-value references and std::forward Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-12-14 06:46 -0800
          Re: R-value references and std::forward Öö Tiib <ootiib@hot.ee> - 2022-12-15 05:48 -0800
      Re: R-value references and std::forward Juha Nieminen <nospam@thanks.invalid> - 2022-12-14 12:41 +0000
        Re: R-value references and std::forward Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-15 19:03 +0100
  Re: R-value references and std::forward Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-15 16:39 +0100
  Re: R-value references and std::forward Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-12-17 10:55 -0800

csiph-web