jeudi 28 février 2019

Cereal serialisation issue for std::chrono with dynamic library

I have a problem with cereal library (http://uscilab.github.io/cereal/).

I have a shared library, and I would like to serialize one of its classes using cereal library. It has a member of time_point from std::chrono

Here is a part of the code of my object in Event.h

    #include <cereal/types/chrono.hpp>
    #include <cereal/types/string.hpp>

    class EventBase
    {
    private:
         std::string m_Id;
         std::chrono::high_resolution_clock::time_point m_StartTime;
    public:
        template<class Archive> void serialize(Archive & archive)
        {
          archive(m_Id, m_StartTime);
        }

The library compiles without a problem. Then I would like to use my library in an executable where I try to serialize one of the object:

    #include <cereal/archives/json.hpp>
    cereal::JSONOutputArchive output(std::cout);
    output(API::Event());

This code does not compile and it is complaining about the missing serialize function for the time_point. If I intend to serialize only the string it compiles.

Aucun commentaire:

Enregistrer un commentaire