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


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

Re: R-value references and std::forward

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c++
Subject Re: R-value references and std::forward
Date 2022-12-15 16:39 +0100
Organization A noiseless patient Spider
Message-ID <tnff29$345p0$1@dont-email.me> (permalink)
References <6d19a662-76a1-4925-bd07-b259836f062bn@googlegroups.com>

Show all headers | View raw


Am 14.12.2022 um 09:44 schrieb Frederick Virchanza Gotham:
> The following code up on GodBolt:
> 
>      https://godbolt.org/z/bfs3qn5Gx
> 
> prints out:
> 
>      Dog takes l-value ref
>      Monkey takes r-value ref
>      Hello
> 
> I expected it to say "Monkey takes l-value ref".
> 
> Is the behaviour undefined because of my use of 'forward' on Line #22? Should 'forward' only be used with a so-called 'template parameter forwarding reference'?
> 

std::forward is for templated forwarding-references, not references you
know that they're r-value-references. With that you can use move() to
have a somewhat clearer code. And moving ints looks strange to me.

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