Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: Rob Stewart (rob.stewart_at_[hidden])
Date: 2015-05-10 14:11:20
On May 10, 2015 1:05:51 PM EDT, James Armstrong <armstrhu_at_[hidden]> wrote:
> I went ahead and modified the code to be templated over a sequence
> container. You can see the code here,
> poly_adaptor.h defined the class and main.cpp has some code with use
> So, one issue is that the type erased types do not have the same
> methods to
> access their data. For instance, boost::any requires that you use a
> boost::any_cast<T> in order for you to get the value, whereas a
> boost::variant uses the get<T> function or you can access it with a
> stream. Basically, it will be hard to have a nice templated class for
> these, others, and newly developed type erased types without a common
> method to access the data.
Create customization points. Implement the default access method and permit customization for other types. You could provide some common specializations in separate headers so users don't always have to reinvent the same wheel.
> The other thing, as you mentioned above, is that this will have to be
> limited to sequence containers. It would be nice to come up with
> fully general, but it again comes down to methods to access data. For
> example, the method for getting data from an std::map is very
> than from a sequence container.
There is no easy means to bridge that gap. Associative containers require a key.
(Sent from my portable computation engine)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk