Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87898
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: R-value references and std::forward |
| Date | 2022-12-14 12:42 +0100 |
| 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> |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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