|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2005-09-29 10:35:31
Vladimir Prus wrote:
> So, my original question stands -- it is even possible to make
> boost::any serializable?
I've spent a few minutes looking at boost::any and don't see any obvious way
to do it in a general way. If it is possible, it would only be so by
depending on or expanding upon implementation of serialization.
So, what can I suggest? Here are some very preliminary thoughts.
The difficulty in serializing boost::any is that we only know which type is
being serialized at runtime. If we know the possible types that our
instance of boost::any might contain we might be able to use something like:
struct my_class {
boost::any m_any;
...
};
template<class Archive>
void my_class::save(Archive & ar, const unsigned int version){
// define which types we think we will be using
// (be prepared for bad_anycast exception);
boost::variant<int, char, bool> v = m_any;
ar << v;
}
template<class Archive>
void my_class::load(Archive & ar, const unsigned int version){
// define which types we think we will be = m_any;
boost::variant<int, char, bool> v;
ar >> v;
m_any = v;
}
This is merely speculative so i have no idea whether it would really work or
not.
Robert Ramey
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