On 30/03/2015 04:35, Robert Ramey wrote:
Bjorn Reese wrote
On 03/27/2015 05:49 PM, Robert Ramey wrote:
In this case the problem is different. A parameter value placed on the stack cannot be passed by "const T & t". This syntax assumes and enforces
Why not?
It generates a compile time error when you pass an rvalue.
It shouldn't. Literals are definitely compatible with "const T &". I'm not 100% certain but I believe rvalue references "T&&" should also be compatible, although they will probably collapse to basic references.
the reason I would think that it's not a common case is the following:
ar << 42; // put the value of 42 into the archive ...
ar >> ?; // what do we do with the result we're retrieving?
So I'm not seeing where this comes up.
Obviously >> must have an lvalue. That doesn't constrain << though. The OP was referring to unit tests, where presumably they were wanting to poke raw values into an archive in a particular order and verify that they deserialised the correct way into an actual object. As for why they wanted to do that, I don't know, but I can guess that one possibility is for testing backwards compatibility: given a known sequence of values written by some prior version of the object, verify that it deserialises correctly in the current version of the object. But there's lots of other possibilities too.