Monday, March 16, 2009

Generic Tree

Boost::ptr_container is the standard solution for containers of pointers of heap-allocated objects in an exception-safe manner and with minimal overhead.
The applications are very interesting. For instance, it is easy to write a Generic Tree code and use it as in:

Inner<std::string> root("root");
root.add_child(new Leaf<std::string>("test son of root"));
Inner<int> * n1 = new Inner<int>(1);
root.add_child(n1);
n1->add_child(new Leaf<std::string>("test son of integer"));
depth_first(root);


I'm working on a version of the Generic Tree which supports serialization, but this is hard to achieve according to this post

No comments:

Post a Comment