Boost logo

Boost :

Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: Boris Rasin (boris_at_[hidden])
Date: 2015-05-06 07:37:49

On 5/6/2015 7:25 AM, James Armstrong wrote:
> I've given this a little more thought...So, I am not sure that generic
> algorithms like you suggest would be very beneficial. Ultimately, the type
> erased object are effectively pointers to memory in the heap. I'd think
> that any tangible benefit of allowing the user to choose their own
> container would be wiped out by the fact that the actual data is stored
> discontiguously out in the heap and you still need to dereference pointers
> to get to it. In this case, I think that defining the container but
> allowing the user to insert any datatype into natively would be more user
> friendly than allowing the use of any container but requiring the use of a
> type erased datatype. Also, to me it just feels 'cleaner' to call a method
> on the container rather than pass the container to a function. My current
> 2 cents

boost::variant (unlike boost::any) stores data by value.

As to what "feels cleaner": a single algorithm function which accepts
any sequence container (std::vector, std::array, std::list,
std::forward_list, boost::circular_buffer, etc.) with any type erased or
discriminated union objects (boost::any, boost::type_erasure::any,
boost::variant, eggs::variant, etc.) or a single specialized container
type mimicking behavior of vector<any>?

Boost list run by bdawes at, gregod at, cpdaniel at, john at