The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Интерактивная система просмотра системных руководств (man-ов)

 ТемаНаборКатегория 
 
 [Cписок руководств | Печать]

remove_copy (3)
  • >> remove_copy (3) ( Solaris man: Библиотечные вызовы )
  • 
                           Standard C++ Library
                 Copyright 1998, Rogue Wave Software, Inc.
    
    
    NAME
         remove_copy
    
          - 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 InputIterator,
                  class OutputIterator,
                  class T>
         OutputIterator remove_copy (InputIterator first,
                                     InputIterator last,
                                     OutputIterator result,
                                     const T& value);
    
    
    
    DESCRIPTION
         The remove_copy algorithm copies all the  elements  referred
         to  by  the  iterator i in the range [first, last) for which
         the following corresponding condition does  not  hold:    *i
         == value. remove_copy returns an iterator that points to the
         end of the resulting range.  remove_copy  is  stable,  which
         means that the relative order of the elements in the result-
         ing range is the same as their relative order in the  origi-
         nal  range.  The  elements  in the original sequence are not
         altered by remove_copy.
    
    
    
    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&) { return 1; }
          };
    
         int main ()
          {
           int arr[10] = {1,2,3,4,5,6,7,8,9,10};
           vector<int> v(arr+0, 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;
            //
            // Now remove all 3s on output.
            //
            remove_copy(v.begin(),           v.end(),            <br>
            ostream_iterator<int,char>(cout," "), 3);
           cout << endl << endl;
            //
            // Now remove everything satisfying predicate on output.
            // Should yield a NULL vector.
            //
           remove_copy_if(v.begin(),          v.end(),           <br>
           ostream_iterator<int,char>(cout," "),
                          all_true<int>());
    
           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  parame-
         ters, you always need to supply the Allocator template argu-
         ment. 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, remove_if, remove_copy_if
    
    
    
    


    Поиск по тексту MAN-ов: 




    Партнёры:
    PostgresPro
    Inferno Solutions
    Hosting by Hoster.ru
    Хостинг:

    Закладки на сайте
    Проследить за страницей
    Created 1996-2024 by Maxim Chirkov
    Добавить, Поддержать, Вебмастеру