Re: Heterogeneous container
AFAIR, variant's are serializable, but you will need to predefine the set of storable types. Do you really need a boost::any like level of heterogeneity ?
Re: Heterogeneous container
Quote:
Originally Posted by
superbonzo
AFAIR, variant's are serializable, but you will need to predefine the set of storable types. Do you really need a boost::any like level of heterogeneity ?
Actually, I've never used Boost::Variant before, and am not sure how it would be used to make a heterogeneous container.
EDIT: Ok, I just found the function boost::get which makes things a lot easier. This may work for my needs.
Re: Heterogeneous container
Actually, that may not be necessary.
There is Boost.PropertyTree that has basically that exact interface, and furthermore, it already works with the serializer!
Code:
boost::property_tree::ptree pt;
pt.put<std::string>("name", "Chris");
pt.put("age", 23);
std::ofstream ofs("out.xml");
boost::archive::xml_oarchive xml(ofs);
xml << BOOST_SERIALIZATION_NVP(pt);
Re: Heterogeneous container
beware that boost ptree will store everything as strings, using iostream operator, lexical cast and user defined translators to map types to strings and viceversa. So, it's a very different design from <any> or <variant> that store the real objects on the heap and on the stack, respectively ...
Re: Heterogeneous container
Quote:
Originally Posted by
superbonzo
beware that boost ptree will store everything as strings, using iostream operator, lexical cast and user defined translators to map types to strings and viceversa. So, it's a very different design from <any> or <variant> that store the real objects on the heap and on the stack, respectively ...
Well, I suppose I'll be using it for configuration structures of basic type values which need to be written to/from file. In other words, I think I'm using it for exactly what is was meant for. :)