Boost logo

Boost Users :

Subject: [Boost-users] [serialization] how to serialize boost::function
From: Igor R (boost.lists_at_[hidden])
Date: 2009-09-15 07:09:28


Hello,

Is it possible to serialize the following class:

struct foo
{
        void f1(int a)
        {}
        void f2(const std::string& s)
        {}

                void init()
                {
                using boost::bind;
                functors_.push_back(bind(&foo::f1, this, 1));
                functors_.push_back(bind(&foo::f2, this, "test"));
                }

        std::vector<boost::function<void(void)> > functors_;
};

That is, I'd like save the functors, in order to run them later, when
the object is loaded from the archive.

A straightforward attempt fails:

struct foo
{
//......
        friend class boost::serialization::access;
        template<class Archive> void serialize(Archive &ar, const unsigned int version)
        {
                ar & BOOST_SERIALIZATION_NVP(functors_);
        }
};

1>d:\dev\servision\projects\windows\thirdparty\boost\boost\serialization\access.hpp(109)
: error C2039: 'serialize' : is not a member of
'boost::function<Signature>'


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