
14 Mar
2006
14 Mar
'06
1:10 p.m.
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?
IIRC, in previous discussions of this topic, the consensus was that it was an oversight. Josuttis mentions the lack of this algorithm, directing readers to use remove_copy_if. Jeff Flinn