|
Boost : |
Subject: [boost] Interest in a "Heterogenous Container" system?
From: Christian Schladetsch (christian.schladetsch_at_[hidden])
Date: 2009-06-28 17:10:19
Hello,
After a discussion on a different thread, I came up with an implementation
allowing containers to store and retrieve heterogenous instances, and
provide correct deep cloning of those containers.
A working motivational example is here http://tinyurl.com/larqyy. I have yet
to do a comparison with container<boost::any>.
This is just an initial proof-of-concept, and there remains a lot of work to
do if it were to be a complete proposal. Before I did that work (especially
since I have another proposal in the wings), I wanted to ask if there would
be any interest in a completed system?
The system is based on a modified ptr_container branch (also in the sandbox
- I've contacted Thorsten about this), and and allocator adaptor system to
deal with cloning. It allows one to place object pointers into a container
using syntax such as:
/// a vector of heterogenous objects
template <class Alloc = std::allocator<char>, class Base =
common_base >
struct vector;
heterogenous::vector<> v;
v.push_back<T0>(); // add a default-constructed
object of type T0
v.push_back<T1>(a0,a1,...,an); // add an object of type T1,
passig a0..an as ctor arguments
T1 &obj = v.ref_at<T1>(1); // get a reference of type
T1& to the object at index 1 or throw bad_cast
heterogenous::vector<> v2 = v; // copy the container; concrete
types are preserved
assert(v2.is_type_at<T1>(1));
There are many outstanding issues; it may not fly in the end, it may not
work for all container types and semantics, but I would like some early
opinion on whether it is even worth my pursuing further.
One initial issue that may break any interest is that instances put into the
container must be of a type T that derives from heterogenous::base<T>.
Regards,
Christian.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk