Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to serialize boost::uuids::uuid

I'm currently using boost::uuids::uuid in a project and I want to serialize objects containin boost::uuids::uuid. I tried the simple example below but I get an error:

/usr/include/boost/archive/basic_text_oprimitive.hpp:92: error: no match for ‘operator<<’ in ‘((boost::archive::basic_text_oprimitive >*)this)->boost::archive::basic_text_oprimitive >::os << t’

I would really appriciate if someone could help me.

#include <fstream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

class classA {
public:
    classA() : id(boost::uuids::random_generator()()) {}
private:
    friend class boost::serialization::access;
    boost::uuids::uuid id;
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version) {
        ar & id;
    }
};

int main(void) {
    classA a;
    std::ofstream ofs("uuid.txt");
    boost::archive::text_oarchive oa(ofs);
    oa << a;
    ofs.close();
    return 0;
}
like image 345
Murat Yirci Avatar asked May 25 '12 14:05

Murat Yirci


1 Answers

Include <boost/uuid/uuid_serialize.hpp> to enable serialization for uuids. http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html#boost/uuid/uuid_serialize.hpp

like image 74
anh_ng8 Avatar answered Nov 19 '22 17:11

anh_ng8