Bruce Eckel's Thinking in C++, 2nd Ed | Contents | Prev | Next |
//: C21:copy_if.h // Roll 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 ///:~