Boost logo

Boost Users :

Subject: [Boost-users] [Serialization][Variant] serialization of variant containing boost::blank
From: dariomt_at_[hidden]
Date: 2011-01-14 08:55:09


Hi,

In the following code I show how a boost::variant that has a boost::blank
cannot be serialized, and a proposed fix. I argue that this should work out
of the box. This is with Boost 1.42.0.

Am I doing something wrong here, or is serialization of boost::blank
somewhere already?

Thanks

#include <boost/variant/variant.hpp>
#include <boost/serialization/variant.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <sstream>

#ifdef FIX
// suggested fix: non-intrusive serialize() for boost::blank
namespace boost { namespace serialization
{
    template<class Archive>
    void serialize(Archive &, boost::blank &, const unsigned int)
    {
        // Nothing to do here
    }
} }
#endif

int main()
{
    boost::variant<int, double> v1 = 666;
    boost::variant<boost::blank, int, double> v2 = 666;

    std::ostringstream os;
    boost::archive::text_oarchive oa(os);

    // works!
    oa << v1;

    // compile error about boost::blank not having a serialize method
    // #define FIX to compile
    oa << v2;

    return 0;
}



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