Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between r-value references and l-value references? (CodeGen)

Tags:

c++

c++11

What does an r-value reference look like from a lower-level perspective. I just can't seem to wrap my head around it! Can I see an example of generated code (either equivalent C or x86/x64) from a r-value reference vs. a l-value reference?

For example, what would this construct look like? Let's assume no copy elision for now.

vector<SomethingHUUGE> myFunc();
void foo(vector<SomethingHUUGE>&&);

int main() { foo(myFunc()); return 0; }
like image 791
Clark Gaebel Avatar asked Oct 14 '25 14:10

Clark Gaebel


1 Answers

There is no difference for the purposes of code generation. The only semantic difference between the two is that you know an RValue reference is about to be destroyed, while an lvalue reference will not.

like image 66
Billy ONeal Avatar answered Oct 17 '25 02:10

Billy ONeal