Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rvalues and temporary objects in the FCD

It took me quite some time to understand the difference between an rvalue and a temporary object. But now the final committee draft states on page 75:

An rvalue [...] is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object.

I can't believe my eyes. This must be an error, right?


To clarify, here is how I understand the terms:

#include <string>

void foo(std::string&& str)
{
    std::cout << str << std::endl;
}

int main()
{
    foo(std::string("hello"));
}

In this program, there are two expressions that denote the same temporary object: the prvalue std::string("hello") and the lvalue str. Expressions are not objects, but their evaluation might yield one. Specifically, the evaluation of a prvalue yields a temporary object, but a prvalue IS NOT a temporary object. Does anyone agree with me or have I gone insane? :)

like image 726
fredoverflow Avatar asked Nov 05 '22 12:11

fredoverflow


1 Answers

Yes, i agree with you. This should be fixed in my opinion, and several people i deeply pay respect to have risen the exact same question about this.

like image 71
Johannes Schaub - litb Avatar answered Nov 12 '22 16:11

Johannes Schaub - litb