I'd like to have something along the lines of a heterogeneous map class, eg:
Code:
heterogeneous_map map;
map.set<std::string>("name", "Chris");
map.set<int>("age", 23);
std::string name = map.get<std::string>("name");
int age = map.get<int>("age");
This isn't particularly hard to achieve with a std::map<std::string, boost::any>, the problem arises because I need to be able to serialize and de-serialize these heterogeneous maps. I'm using Boost::Serialization, which works very well for most things I've tried so far, but it has no support for serializing a boost::any object. What can I do?
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 ?
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.
Last edited by Chris_F; October 26th, 2011 at 05:24 AM.
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 ...
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.
Bookmarks