Boost logo

Boost :

Subject: Re: [boost] [serialization] Passing literals to oarchive
From: Bjorn Reese (breese_at_[hidden])
Date: 2015-03-27 08:02:50


On 03/27/2015 05:40 AM, Robert Ramey wrote:

> 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

That is not what my compiler says:

hasher.cpp:126:13: error: invalid operands to binary expression
('hasher::oarchive<hasher::fnv1a>' and 'int')
     archive << 42 << x;
     ~~~~~~~ ^ ~~
/home/breese/src/boost/boost/boost/archive/detail/interface_oarchive.hpp:62:15:
note: candidate function [with T = int] not viable: expects an l-value
for 1st argument
     Archive & operator<<(T & t){
               ^
1 error generated.

> 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.

I am not using text_oarchive, but rather my own archive which inherits
from detail::common_oarchive.

I have attach a full working example (notice the comments in main().)




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk