2

In Effective Modern C++

class Widget {
public:
 Widget(Widget&& rhs); // rhs is an lvalue, though it has
 …                    // an rvalue reference type
};

rhs is an lvalue

void f(Widget&& param); // rvalue reference

param is an rvalue reference

what is the difference between rhs and param?

rafix07
  • 20,001
  • 3
  • 20
  • 33
fizzbuzz
  • 159
  • 1
  • 1
  • 8
  • rhs is an rvalue inside of constructor. It means that you should use `std::move()` inside of function if you want to use rhs as rvalue reference, otherwise it will be interpreted as lvalue reference. – Ladence Jan 15 '20 at 12:16
  • @Ladence That's not accurate, though the consequence is correct – Lightness Races in Orbit Jan 15 '20 at 12:19
  • About the dup: the question is not the same _but_ the accepted answer provides an answer to this question: no difference. – YSC Jan 15 '20 at 12:20

1 Answers1

2

Type: The type of the argument, in both cases, is "rvalue reference to Widget".

Value category: The name of the argument, in both cases, is an lvalue expression.

There is no difference.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • If you were a type what would your `sizeof` return – Hatted Rooster Jan 15 '20 at 12:19
  • 3
    @SombreroChicken `sizeof(your mum)` – Lightness Races in Orbit Jan 15 '20 at 12:19
  • got it, they are rvalue reference to Widget. They can be assigned to, so they are also lvalue – fizzbuzz Jan 15 '20 at 12:57
  • @fizzbuzz I've heard that a few times "can be assigned to, so they are also lvalue" and it's not quite accurate. These are lvalues because they are lvalues. They are names that refer to an object, and that's pretty much always an lvalue, because the language rules say so. Rvalues generally have no names, e.g. the result of `std::move()`. lvalue/rvalue relates to the kind of _expression_ you have, not the kind of object you have. – Lightness Races in Orbit Jan 15 '20 at 13:00