Subject: Re: [boost] Interest in a container which can hold multiple data types?
From: Alex Perry (Alex.Perry_at_[hidden])
Date: 2015-05-06 11:24:53
On 06 May 2015 12:44 Boris Rasin [mailto:boris_at_[hidden]] wrote:-
> It wouldn't. Just a bit cleaner syntax, something like this:
> for (auto& val : type_filter<int>(my_vec))
Ok thanks - though I was hoping for something which was designed for performance here.
Something along the lines of a boost.multiindex with the "primary" index being some sort of segmented collection with objects of the same size being stored together (so allowing faster access as per Joaquin's blog post referenced earlier ).
That way heterogeneous objects could be pushed into the container as they arrive (and the order of arrival traversed via the 2ndary index) but faster traversal of all objects of the same type achieved (I'm hitting severe cache misses in a particular system and was looking for some solution other than pooling / bucket allocators etc)
If itâs a cleaner syntax wanted though I agree my example using lambda's in a filter predicate is ugly - but templating the predicate up gives something very close to your syntax already
template<typename T> bool IsType(boost::any & val)
return !val.empty() && val.type() == typeid(T);
for ( auto & val : boost::adaptors::filter( my_vec, IsType<int>() ) )
Or even cleaner using the | range operator (though possibly will need to wrap my_vec here - for some reason I rarely use the | syntax even though I like it in principle so have to play every time):
for ( auto & val : my_vec | boost::adaptors::filtered( IsType<int>() ) )
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk