Search code examples
c++mnemonics

How do you remember the differences between rvalue, lvalue, etc?


This question is great because it has answers on what are the differences between rvalue, lvalue, xvalue, glvalue, and prvalue. The top answer has a decent explanation of each, and I understand their differences when I read them. However, I'm having a hard time keeping them straight in my head, and I have to google them every time someone uses these terms to remind myself which one is which.

Are there any common mnemonics or other ways people remember which one is which? I'd really like to be able to keep them all straight in my head without mixing them up as I currently do.


Solution

  • I make 2 associations:

    • you can only take the address of an lvalue
    • xvalues is what an std::move expression is

    If it's neither then it's probably a prvalue.

    Now, to remember glvalues and rvalues I simply imagine this graph:

    lvalues and xvalues are both glvalues, while xvalues and prvalues are both rvalues. That's really all you need to know in practice.

    Maybe a mnemonic to remember lvaluse, xvalues, and prvalues go at the bottom are the words Lower eXPRessions (it contains L, X, and PR). Maybe not.