remove man page on SunOS

Man page or keyword search:  
man Server   20652 pages
apropos Keyword Search (all sections)
Output format
SunOS logo
[printable version]

remove(3C++)			       -			  remove(3C++)

Standard C++ Library Copyright 1998, Rogue Wave Software, Inc.

NAME
       remove

	-  Moves  desired elements to the front of a container, and returns an
       iterator that describes where the sequence of desired elements ends.

SYNOPSIS
       #include <algorithm>
       template <class ForwardIterator, class T>
       ForwardIterator
       remove (ForwardIterator first,
       ForwardIterator last,
       const T& value);

DESCRIPTION
       The remove algorithm eliminates all the elements referred to by	itera‐
       tor  i  in  the	range  [first, last) for which the following condition
       holds:	  *i == value. remove returns an iterator that points  to  the
       end of the resulting range. remove is stable, which means that the rel‐
       ative order of the elements that are not removed is the same  as	 their
       relative order in the original range.

       remove  does not actually reduce the size of the sequence. It actually:
       1) copies the values that are to	 be  retained  to  the	front  of  the
       sequence,  and 2) returns an iterator that describes where the sequence
       of retained values ends. Elements that follow this iterator are	simply
       the original sequence values, left unchanged. Here's a simple example:

       Say we want to remove all values of "2" from the following sequence:

	     354621271

       Applying the remove algorithm results in the following sequence:

	     3546171|XX

       The  vertical  bar  represents the position of the iterator returned by
       remove. Note that the elements to the left of the vertical bar are  the
       original sequence with the "2s" removed.

       If  you	want to actually delete items from the container, use the fol‐
       lowing technique:

       container.erase(remove(first,last,value),container.end());

COMPLEXITY
       Exactly last1 - first1 applications of the corresponding predicate  are
       done.

EXAMPLE
//
// remove.cpp
//
 #include <algorithm>
 #include <vector>
 #include <iterator>
 #include <iostream>

using namespace std;

template<;class Arg>
struct all_true : public unary_function<;Arg, bool>
 {
  bool operator()(const Arg& x){ return 1; }
 };
int main ()
 {
  int arr[10] = {1,2,3,4,5,6,7,8,9,10};
  vector<int> v(arr, arr+10);
  copy(v.begin(),v.end(),
       ostream_iterator<int,char>(cout," "));
  cout << endl << endl;
   // remove the 7
  vector<int>::iterator result =
	   remove(v.begin(), v.end(), 7);
   // delete dangling elements from the vector
  v.erase(result, v.end());
  copy(v.begin(),v.end(),
       ostream_iterator<int,char>(cout," "));
  cout << endl << endl;
   // remove everything beyond the fourth element
  result = remove_if(v.begin()+4,
		     v.begin()+8, all_true<int>());
   // delete dangling elements
  v.erase(result, v.end());
  copy(v.begin(),v.end(),
       ostream_iterator<int,char>(cout," "));
  cout << endl << endl;
  return 0;
 }

Program Output

1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 8 9 10
1 2 3 4
1 2 4

WARNINGS
       If  your	 compiler  does	 not  support default template parameters, you
       always need to supply the Allocator template  argument.	For  instance,
       you need to write:

       vector<int, allocator<int> >

       instead of:

       vector<int>

       If  your compiler does not support namespaces, then you do not need the
       using declaration for std.

SEE ALSO
       remove_if, remove_copy, remove_copy_if

Rogue Wave Software		  02 Apr 1998			  remove(3C++)
[top]

List of man pages available for SunOS

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net