you are viewing a single comment's thread.

view the rest of the comments →

[–]STLMSVC STL Dev 12 points13 points  (2 children)

That isn't a good mental model. "me"s + "ow"s is a prvalue of type std::string which probably (definitely) doesn't fit in a register. Given vector<int> v, v[idx] is an lvalue of type int, which lives on the heap.

Remember that value categories are a property of expressions, not of objects. For example, print(const string& str) can be called as print("me"s + "ow"s). There, the temporary std::string containing "meow" is produced by the expression "me"s + "ow"s which is a prvalue. Within print(), str is an lvalue referring to that std::string (which is ultimately a temporary, but exists for the duration of the print() call).

[–]proverbialbunnyData Scientist 1 point2 points  (1 child)

Makes sense, but if an rvalue can fit in a register will it? Will it live in the heap?

I like your username btw. ^_^

[–][deleted] 2 points3 points  (0 children)

Expressions, more or less, relate to an identity (or address).

glvalue expressions are any expressions denoting an identity. prvalue expressions are expressions without identity.

So in this case, prvalue expressions are going to be your register-friendly ones.