++


remove_copy()


template< class InputIterator, class OutputIterator,

class Type >

OutputIterator

remove_copy( InputIterator first, InputIterator last,

OutputIterator result, const Type &value );

remove_copy() , value, , result. . .

#include <algorithm>

#include <vector>

#include <assert.h>

#include <iostream.h>

/* :

:

0 1 0 2 0 3 0 4 0 5

remove erase():

1 2 3 4 5 3 0 4 0 5

erase():

1 2 3 4 5

remove_copy()

1 2 3 4 5

*/

 

int main()

{

int value = 0;

int ia[] = { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5 };

 

vector< int, allocator > vec( ia, ia+10 );

ostream_iterator< int > ofile( cout," ");

vector< int, allocator >::iterator vec_iter;

 

cout << " :\n";

copy( vec.begin(), vec.end(), ofile ); cout << '\n';

vec_iter = remove( vec.begin(), vec.end(), value );

 

cout << " remove erase():\n";

copy( vec.begin(), vec.end(), ofile ); cout << '\n';

//

vec.erase( vec_iter, vec.end() );

cout << " erase():\n";

copy( vec.begin(), vec.end(), ofile ); cout << '\n';

 

int ia2[5];

vector< int, allocator > vec2( ia, ia+10 );

remove_copy( vec2.begin(), vec2.end(), ia2, value );

 

cout << " remove_copy():\n";

copy( ia2, ia2+5, ofile ); cout << endl;

}




- -  - -  - -