Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-04-03 11:55:30


hmm

The operator ar << takes a reference to a const argument.

It looks like the compiler is objecting to taking the reference
to an argument on the stack

ar << foo();

which seems like a good idea to me. In this case there would
be no problem, but in the case where the return of foo() would
be a "tracked" type, this would break the serialization system.

Robert Ramey

Drumheller, Michael wrote:
> The test program below (under boost 1_33, vc71) compiles fine, unless
> I change the "#if 1" to "#if 0", in which case it produces this:
> error C2679: binary '<<': no operator found which takes a right-hand
> operand of type 'double' (or there is no acceptable conversion)
>
> Can anyone explain why that should happen? A double is a double--why
> should '<<' care whether the rhs comes from funcall a variable?
>
> Note: The test program is clearly a nonsense program (in real life
> the role of foo() is played by some public (get-accessor) on klass--a
> very common pattern when doing a non-intrusive serialization). But I
> did not want to cloud the issue--I wanted to emphasize that the bug,
> if it is a bug, seems to have nothing to with klass.
>
> Thank you.
>
> Michael Drumheller
> -----------------------------------------------------------------begin--
> -------------------------------------------------------------
> #include <fstream>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/serialization/split_free.hpp>
> class klass {};
> double foo() { return 3.1416; }
> namespace boost { namespace serialization {
> template<class Archive>
> void save(Archive &ar, const klass & b, const unsigned int
> ver)
> {
> #if 1
> double x=foo();
> ar << x;
> #else
> ar << foo();
> #endif
> }
> template<class Archive>
> void load(Archive &ar, klass & b, const unsigned int
> ver){}//N/A for this demo
> }}
> BOOST_SERIALIZATION_SPLIT_FREE(klass);
> void out(const char *testfile, const klass & c)
> {
> std::ofstream ofs(testfile);
> boost::archive::text_oarchive oa(ofs);
> oa << c;
> }
> ----------------------------------------------------------------end-----
> -----------------------------------------------------------------
> Michael Drumheller
> Boeing Phantom Works
> Mathematics and Engineering Analysis
> 425.865.3520 michael.drumheller_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net