Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: James Armstrong (armstrhu_at_[hidden])
Date: 2015-05-05 18:53:14
I just took a look at boost::any and boost::variant (I haven't really
worked with these, so unfamiliar) and it looks like this idea definitely
do-able. I think that the restriction is that the container elements must
implement a type() method so that when requesting one specific data type,
we do not return another type which has been cast into the type requested.
I think this is a more generally applicable method than designing one
container which does this. I like the vector_tuple idea as well and think
there is definite merit to storing data of the same type together in order
to improve efficiency. In that scenario, I think there is no getting
around designing a container/adapter specifically for that (I could be
On Tue, May 5, 2015 at 4:23 PM, Boris Rasin <boris_at_[hidden]> wrote:
> On 5/6/2015 1:08 AM, James Armstrong wrote:
>> 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.
> Yes. And this would work with std::vector<boost::any> and
> std::list<boost::variant> alike.
> Unsubscribe & other changes:
-- James Armstrong
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk