.\" ident @(#)remove_copy_if.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH remove_copy_if 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2remove_copy_if\fP \ - Moves desired elements to the front of a container, and returns an iterator that describes where the sequence of desired elements ends. .SH SYNOPSIS .br #include .br template .RE .RS 0 OutputIterator remove_copy_if (InputIterator first, .RE .RS 31 InputIterator last, .br OutputIterator result, .br Predicate pred); .SH DESCRIPTION The remove_copy_if algorithm copies all the elements referred to by the iterator \f2i\fP in the range \f2[first, last)\fP for which the following condition does not hold: \f2pred(*i) == true\fP. remove_copy_if returns an iterator that points to the end of the resulting range. remove_copy_if is stable, which means that the relative order of the elements in the resulting range is the same as their relative order in the original range. .SH COMPLEXITY Exactly \f2last1 - first1 \fPapplications of the corresponding predicate are done. .SH EXAMPLE .RE .RS 0 // .br // remove.cpp .br // .RE .RS 1 #include .br #include .br #include .br #include .RE .RS 0 using namespace std; .br .br template .br struct all_true : public unary_function .RE .RS 1 { .RE .RS 2 bool operator() (const Arg&) { return 1; } .RE .RS 1 }; .RE .RS 0 .br int main () .RE .RS 1 { .RE .RS 2 int arr[10] = {1,2,3,4,5,6,7,8,9,10}; .br vector v(arr+0, arr+10); .RE .RS 0 .br .RE .RS 2 copy(v.begin(),v.end(), .RE .RS 7 ostream_iterator(cout," ")); .RE .RS 2 cout << endl << endl; .RE .RS 3 // .br // Remove the 7. .br // .RE .RS 2 vector::iterator result = remove(v.begin(), .RE .RS 33 v.end(), 7); .RE .RS 3 // .br // Delete dangling elements from the vector. .br // .RE .RS 2 v.erase(result, v.end()); .RE .RS 0 .RE .RS 2 copy(v.begin(),v.end(), .RE .RS 7 ostream_iterator(cout," ")); .RE .RS 2 cout << endl << endl; .RE .RS 3 // .br // Remove everything beyond the fourth element. .br // .RE .RS 2 result = remove_if(v.begin()+4, v.begin()+8, .RE .RS 11 all_true()); .RE .RS 3 // .br // Delete dangling elements. .br // .RE .RS 2 v.erase(result, v.end()); .RE .RS 0 .RE .RS 2 copy(v.begin(),v.end(), .RE .RS 7 ostream_iterator(cout," ")); .RE .RS 2 cout << endl << endl; .RE .RS 3 // .br // Now remove all 3s on output. .br // .RE .RS 2 remove_copy(v.begin(), v.end(),
ostream_iterator(cout," "), 3); .br cout << endl << endl; .RE .RS 3 // .br // Now remove everything satisfying predicate on output. .br // Should yield a NULL vector. .br // .br remove_copy_if(v.begin(), v.end(),
ostream_iterator(cout," "), .RE .RS 17 all_true()); .RE .RS 1 .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br 1 2 3 4 5 6 7 8 9 10 .br 1 2 3 4 5 6 8 9 10 .br 1 2 3 4 .br 1 2 4 .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Allocator\fP template argument. For instance, you need to write: \f2vector >\fP instead of: \f2vector\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO remove, remove_if, remove_copy