Re: filtering items in a container
On 2007-10-27 10:19, Anonymous wrote:
I am trying to write a filtering algorithm without reinventing the
wheel. I basically want to select items in a container that have a
certain 'property' - i.e. satisfy a certain criteria - to be provided by
a predicate function.
In pseudocode, it would look something like this:
template <class T1 /*container type*/, typename T2/* type held in
container*/>
T1<T2> filter(const T1<T2>& source, PredicateFunctor func)
{
T1<T2> filtered_output ;
std::for_each(source.begin(), source.end(), func());
//somehow append those matching to variable filtered_output
return filtered_output ;
}
The idea is so that I could use such an algorithm to filter or 'select'
items that match certain criteria from an STL container - e.g. a vector
or map of objects.
if there is an existing STL algo that does that - or you can thing of a
better way of doing (implementing) this, please let me know
Sounds like remove_copy_if().
--
Erik Wikstr??m