|
Boost : |
Subject: Re: [boost] [serialization] Passing literals to oarchive
From: Robert Ramey (ramey_at_[hidden])
Date: 2015-03-27 00:40:12
Bjorn Reese wrote
> Currently we cannot pass literals directly to an oarchive like this:
>
> oarchive << 42;
>
> since compilation fails in interface_oarchive.hpp, as the operator<<
> only takes parameters by reference.
Actually, all parameters are already const reference. I realize that it
doesn't look that way. That's because interface_oarchive::operator<<(T & t)
is never called from the application but rather from lower level. By
the time interface_oarchive::operator<<(T & t) gets called, the T already
has the "const" as part of the type. (Actually it has a & also so the
interface_oarchive::operator<<(T) would actually be the same. I
realize this is confusing, but that's the way C++ works.
> We can remedy this by changing operator<< to take the parameter
> by const-ref instead, as show below. Is there any reason not to do
> this?
so there's nothing to remedy
FWIW - there is a case to be made for replacing at the top level
text_oarchive::operator<<(const T & t) with
text_oarchive::operator<<(T && t) but that's another discussion.
Robert Ramey
-- View this message in context: http://boost.2283326.n4.nabble.com/serialization-Passing-literals-to-oarchive-tp4673832p4673842.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk