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? :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…