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:43:32


On 5/6/2015 2:24 PM, Alex Perry wrote:
> On 05 May 2015 23:24 Boris Rasin [mailto: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...
>>>
> Snip...
>>> //iterate through doubles
>>> for (auto itr = itr_begin<double>(my_vec); itr !=
>> itr_end<double>(my_vec);
>>> ++itr)
>>> {
>>> // ...
>>> }
> Snip
>> Yes. And this would work with std::vector<boost::any> and
>> std::list<boost::variant> alike.
> How would this differ from using boost.range filters?
>
> eg
> #include <boost/range/adaptors.hpp>
>
> for (auto & val : boost::adaptors::filter(my_vec, []( boost::any & i) { return !i.empty() && i.type() == typeid(int); } ) )
> {
> }

It wouldn't. Just a bit cleaner syntax, something like this:

for (auto& val : type_filter<int>(my_vec))
{
}


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