The OpenNET Project / Index page

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

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

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

iter_swap (3)
  • >> iter_swap (3) ( Solaris man: Библиотечные вызовы )
  • 
                           Standard C++ Library
                 Copyright 1998, Rogue Wave Software, Inc.
    
    
    NAME
         iter_swap
    
          - Exchanges values in two locations.
    
    
    
    SYNOPSIS
         #include <algorithm>
         template <class ForwardIterator1, class ForwardIterator2>
         void iter_swap (ForwardIterator1, ForwardIterator2);
    
    
    
    DESCRIPTION
         The iter_swap algorithm exchanges the values pointed  to  by
         the two iterators a and b.
    
    
    
    EXAMPLE
         #include <vector>
         #include <algorithm>
         #include <iostream>
         using namespace std;
    
         int main ()
          {
           int d1[] = {6, 7, 8, 9, 10, 1, 2, 3, 4, 5};
            //
            // Set up a vector.
            //
           vector<int> v(d1+0, d1+10);
            //
            // Output original vector.
            //
           cout << "For the vector: ";
           copy(v.begin(), v.end(),
                ostream_iterator<int,char>(cout," "));
            //
            // Swap the first five elements with the
            // last five elements.
            //
           swap_ranges(v.begin(), v.begin()+5, v.begin()+5);
            //
            // Output result.
            //
           cout << endl << endl
           << "Swapping the first 5 elements with the last 5 gives: "
                 << endl << "     ";
           copy(v.begin(), v.end(),
                ostream_iterator<int,char>(cout," "));
            //
            // Now an example of iter_swap -- swap first and
            // last elements.
            //
            iter_swap(v.begin(), v.end()-1);
            //
            // Output result.
            //
           cout << endl << endl
                 << "Swapping the first and last elements gives: "
                 << endl << "     ";
           copy(v.begin(), v.end(),
                ostream_iterator<int,char>(cout," "));
           cout << endl;
    
           return 0;
          }
    
         Program Output
    
    
    
         For the vector: 6 7 8 9 10 1 2 3 4 5
         Swapping the first five elements with the last five gives:
             1 2 3 4 5 6 7 8 9 10
         Swapping the first and last elements gives:
             10 2 3 4 5 6 7 8 9 1
    
    
    
    WARNINGS
         If your compiler does not support default  template  parame-
         ters,  then you always need to supply the Allocator template
         argument. For instance, you have 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
         Iterators,_swap, swap_ranges
    
    
    
    


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




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

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