Boost logo

Boost :

From: Jarl Lindrud (jlindrud_at_[hidden])
Date: 2006-08-19 13:35:13


Hi,

RCF, a C++ middleware framework, supports using Boost Serialization for
serialization of data structures. One of my user's reported a serialization bug
to me, which I finally boiled down into the following piece of code:

#include <sstream>
#include <string>
#include <vector>

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp>

template<typename Archive>
struct X
{
    template<typename T>
    void operator<<(const T &t)
    {
        Archive &archive = (*(Archive *) NULL);
        archive << t;
    }
};

void dummy()
{
    typedef boost::archive::text_oarchive Archive;
    X<Archive> &x = * (X<Archive> *) NULL;
    std::vector<char> *pt = NULL;

    // uncomment this line to cause the test to fail
    //x << pt;
}

int main(int argc, char* argv[])
{
    std::vector<char> v0(25, '%');
    std::vector<char> v1;

    std::ostringstream ostr;
    boost::archive::text_oarchive(ostr) & v0;

    std::istringstream istr(ostr.str());
    boost::archive::text_iarchive(istr) & v1;
    
    bool ok = (v0 == v1);
    return 0;
}

I find this odd, to say the least! I've tried it on Visual C++ 7.1, using boost
1.33.0 and 1.33.1.

Regards,
Jarl.

http://www.codeproject.com/threads/Rcf_Ipc_For_Cpp.asp


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