// Assumes pred is the incoming condition replace_copy_if(begin, end, not1(pred));
//: C06:copy_if.h // Create your own STL-style algorithm. #ifndef COPY_IF_H #define COPY_IF_H template<typename ForwardIter, typename OutputIter, typename UnaryPred> OutputIter copy_if(ForwardIter begin, ForwardIter end, OutputIter dest, UnaryPred f) { while(begin != end) { if(f(*begin)) *dest++ = *begin; ++begin; } return dest; } #endif // COPY_IF_H ///:~
Listado 7.47. C06/copy_if.h