Hi All!
I've got few questions concerning the date_time, optional and serialization libs (1.32) and how they work together.
I'm trying to serialize a
optional using a binary Archive.
Unfortunately the extraction code fails to compile. This is because the optional<T> requires T to have a default constructor, when extraction from an archive (see code take from optional.hpp below). I changed the code ( see blow) to work around this. I know that is neither efficient (heap usage) nor exception safe but it works for me. Also it requires operator=. But ptime has got this. Does any body have more advanced suggestions to solve this?
Another thing is that I'm unable to serialize not_a_date_time ptimes. The extractions fails here. I'm using the binary archive. Is that supported? The documentation of date time only states compatibility with text and XML archive...
Any hints are greatly appreciated and thanks in advance.
kind regards
Alex
template
void save(
Archive & ar,
const boost::optional<T> & t,
const unsigned int /*version*/
){
bool tflag = t;
ar << boost::serialization::make_nvp("initialized", tflag);
if (tflag)
//ar << boost::serialization::make_nvp("value", &(*t));
ar << &(*t);
}
template
void load(
Archive & ar,
boost::optional<T> & t,
const unsigned int /*version*/
){
bool tflag;
ar >> boost::serialization::make_nvp("initialized", tflag);
if (tflag){
T* p;
ar >> p;// boost::serialization::make_nvp("value", p);
t.reset(*p);
//T aux;
//ar >> boost::serialization::make_nvp("value", aux);
//t.reset(aux);
delete p;
}
else {
t.reset();
}
}