From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2006-03-14 08:08:24
Caleb Epstein wrote:
> I've recently wondered why std::copy doesn't have an analogous std::copy_if:
> template<class InIt, class OutIt, class Pr>
> OutIt *copy_if*(InIt first, InIt last, OutIt dest, Pr pred);
> that would copy elements to dest where the predicate returns true. Not
> unlike "grep" in Perl and "filter" in Python.
> The same goal can be achieved with std::remove_copy_if and the use of a
> sense-reversed predicate, but this leads to confusing code IMHO.
> Why wouldn't this be part of the Standard Library, or am I missing something
> ridiculously obvious?
I guess it should have been part of C++98, but didn't make it due to
perhaps time contraints.
With the advent of ranges, we might make *all* the xxx_if versions of
algorithms redundant by replacing xxx_if( range, pred ) with
xxx( range | filtered( pred ) );
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk