Boost logo

Boost :

Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: James Armstrong (armstrhu_at_[hidden])
Date: 2015-05-04 23:54:08


So, as it is currently implemented, it doesn't actually make use of
boost::any or boost::variants. I used a deque<void*> to store addresses of
the data, and deque<boost::core::typeinfo> to store the data types.
Therefore, iterating through the container to get the data for datatype T
simply involves iterating through the deque<boost::core::typeinfo> until a
type match is found, then casting the void* to a T* for the corresponding
index.

There are definitely different ways to take the idea, and maybe there is
use for multiple types of heterogeneous containers. The way this container
is setup has the advantage (depending on your viewpoint) that you do not
have to explicit declare what data types the container will store up
front. This could be useful in some context where, for instance, you are
pulling information from a database where you don't quite know up front
whether certain fields will be numeric or character data until you've
queried the db. This container can allow you to pop in whatever data-type
the result is, without having to explicitly list out every possibility up
front.

-- 
James Armstrong

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk