I'd like to implement a directory object which stores different types of object. Need to be able access the objects by name, get the actual pointer type and serialize it. The object I have in mind looks like this:
struct Object {
std::string name;
SomeType ptr;
};
struct Dir {
std::string name;
std::set<Object> objects;
};
"SomeType" I was thinking of using Boost::variant. But then it seems like I'd need to add object types into variant list during run-time. Even if I know the object types in a dir ahead, It would become
template <typename Typelist>
struct Object<Typelist> {
std::string name;
boost::variant<Typelist> objects;
};
where Typelist
is different for different dirs. Then, having a dir of dirs would be the dynamic union of Typelist. It looks complicated. And it will soon hit the limit of 50 variant types. Alternative is Boost::Any to simplify semantics. But I'd like to iterate on the set of objects, and do stuff on it -- each object is a boost::fusion adapt_struct -- I want to fusion::for_each on each member of each object and display them, e.g.. Any alternatives or suggestions?