Having trouble serializing a priority queue

101 views
Skip to first unread message

John Lagerquist

unread,
Feb 25, 2016, 6:54:01 PM2/25/16
to cereal serialization library
I am having trouble serializing a priority queue.  I get the "could not find any serialization functions..." error, although I have included types\queue.hpp.  Any advice on how to fix this is appreciated.


#include <cereal\types\queue.hpp>


...
namespace sys
{
class base
{
protected:
   
unsigned priority__power_distribution;

   
struct pless : public std::binary_function<std::shared_ptr<sys::base>, std::shared_ptr<sys::base>, bool>
   
{
 
bool operator()(std::shared_ptr<sys::base> x, std::shared_ptr<sys::base> y) const
 
{
 
return std::less<unsigned>()(x->priority__power_distribution, y->priority__power_distribution);
 
}
   
};

   std
::priority_queue<std::shared_ptr<sys::base>, std::vector<std::shared_ptr<sys::base>>, pless> sub_list;

   
friend class cereal::access;
   
template<class archive>

   
void serialize(archive &arch)
   
{
       arch
(CEREAL_NVP(sub_list));
   
}
};





w.shan...@gmail.com

unread,
Feb 25, 2016, 8:22:00 PM2/25/16
to cereal serialization library
Are you including support for vector and shared_ptr as well? Can you post the code where you perform the actual serialization?

John Lagerquist

unread,
Feb 25, 2016, 11:24:52 PM2/25/16
to cereal serialization library
I currently serialize some vectors and shared_ptr's and it all works fine, it's just the priority_queue that's giving me problems.

Here are my includes:

#include <string>
#include <queue>
#include <cereal\cereal.hpp>
#include <cereal\types\polymorphic.hpp>
#include <cereal\types\queue.hpp>
#include <cereal\archives\portable_binary.hpp>
#include <cereal\archives\json.hpp>

Here is the serialization code:
shared_ptr<sys::base> reactor = make_shared<sys::base>();
shared_ptr<sys::base> battery = make_shared<sys::base>);

 ofstream os
("cereal.json");
 
{
    cereal
::JSONOutputArchive oa(os);
    oa
(reactor, battery);
 
}
 os
.close();

John Lagerquist

unread,
Feb 26, 2016, 11:41:17 AM2/26/16
to cereal serialization library
Here's a simpler example that exhibits the problem:

#include <queue>
#include <fstream>
#include <cereal\types\queue.hpp>
#include <cereal\archives\json.hpp>
using namespace std;

struct
{
priority_queue<int> pq;

template<class archive>
void serialize(archive &arch)
{
arch(CEREAL_NVP(pq));
}
} test;

void main(void)
{
ofstream os("cereal.json");
{
cereal::JSONOutputArchive oa(os);
oa(test);
}
os.close();
}


--
You received this message because you are subscribed to a topic in the Google Groups "cereal serialization library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cerealcpp/D69x2HcgW-4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cerealcpp+...@googlegroups.com.
To post to this group, send email to cere...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerealcpp/6f37cd86-999e-4ed6-a46a-450c1679bc46%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
John Lagerquist
Chief Engineer
RallyTronics LLC


w.shan...@gmail.com

unread,
Feb 29, 2016, 1:16:08 PM2/29/16
to cereal serialization library
I'm able to reproduce this with a simple int priority queue. I'll open an issue on github for this: https://github.com/USCiLab/cereal/issues/264
To unsubscribe from this group and all its topics, send an email to cerealcpp+unsubscribe@googlegroups.com.

To post to this group, send email to cere...@googlegroups.com.

John Lagerquist

unread,
Feb 29, 2016, 1:34:21 PM2/29/16
to w.shan...@gmail.com, cereal serialization library
Thanks for your help.

To unsubscribe from this group and all its topics, send an email to cerealcpp+...@googlegroups.com.

To post to this group, send email to cere...@googlegroups.com.



--
John Lagerquist
Chief Engineer
RallyTronics LLC


--
You received this message because you are subscribed to a topic in the Google Groups "cereal serialization library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cerealcpp/D69x2HcgW-4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cerealcpp+...@googlegroups.com.

To post to this group, send email to cere...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages