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-05 18:08:14

Do you mean something that would work along the lines of...

std::vector<boost::any> my_vec;
// fill my_vec with various data types

//iterate through doubles
for (auto itr = itr_begin<double>(my_vec); itr != itr_end<double>(my_vec);
    // ...

//iterate through strings
for (auto itr = itr_begin<std::string>(my_vec); itr !=
itr_end<std::string>(my_vec); ++itr)
    // ...

where itr_begin and itr_end generate iterators for the templated type over
any container of type erased objects. I didn't quite get what you were
suggesting at first, but yeah I think I agree that would be more useful.

On Tue, May 5, 2015 at 3:37 PM, Boris Rasin <boris_at_[hidden]> wrote:

> On 5/5/2015 9:04 PM, James Armstrong wrote:
>> You're correct in that a vector<boost::any> can achieve the same thing,
>> and
>> that would probably be the better way to implement this internally. I
>> guess the proposal would be to provide the container interface to give
>> some
>> data modification functions and iterators which iterate over only a given
>> type and such. That way there would be a standardized container with
>> methods to deal with the data in a type specific way.
>> But why do you need special container type if all you want are
> algorithms and iterator adapters? Like I said before, this could be useful,
> but wouldn't it be better to write this as generic algorithms capable of
> working with any container of boost::any, not just vector? Better yet, any
> container of type erased or discriminated union objects (boost::any,
> boost::type_erasure::any, boost::variant, eggs::variant, etc.)?
> _______________________________________________
> Unsubscribe & other changes:

James Armstrong

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