|
Boost : |
Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: Thijs (M.A.) van den Berg (thijs_at_[hidden])
Date: 2015-05-05 06:03:07
> On 05 May 2015, at 11:21, Boris Rasin <boris_at_[hidden]> wrote:
>
> On 5/5/2015 9:31 AM, Thijs (M.A.) van den Berg wrote:
>>>> tuple_vector<Point, Line, Rectangle, Circle> shapes;
>>>> shapes.push_back(Point{1.0, 1.0} );
>>> This is neat, but it' not quite the same thing. Unlike std::vector<boost::any>, your tuple_vector does not organize objects into strictly linear arrangement. Using your example, there is no way to draw shapes in the order they were inserted into container.
>> Good point! So it loses overall ordering, only preservers it at the type level. The reason is that objects gets stored in linear memory per type.
>
> One could conceivably add another internal container to maintain overall index. But than again, is such tuple_vector<Point, Line, Rectangle, Circle> really better than std::vector<boost::variant<Point, Line, Rectangle, Circle>>? It would use less memory per object when some stored types are smaller than others, and in some circumstances these savings would exceed overhead of multiple internal containers and an additional index container. Any other advantages?
>
I think if you require preservation of ordering then you'll indeed need an extra index, but then you'll lose in speed and performance, and then I would just use a combination of std::vector and boost::variant / boost::any.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk