On 06 May 2015 12:44 Boris Rasin [mailto:boris@pointx.org] wrote:-
snip...
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 [1]). 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>() ) ) { } Alex [1] http://bannalia.blogspot.co.uk/2014/05/fast-polymorphic-collections.html