共用方式為


reverse_iterator::base

從其 reverse_iterator 復原基本的迭代器。

RandomIterator base( ) const;

傳回值

基礎 reverse_iterator的 Iterator。

備註

與其基礎 Iterator 關聯性所有反向 Iterator 的識別為:

&* (reverse_iterator (i) == &) * ( i – 1)。

實際上,這表示此反向序列的 reverse_iterator 將參考 (右側) 項目以外的項目位置的 Iterator 原始序列參考了。 因此,如果 Iterator 解決了在序列 (2, 4, 6, 8),則為 reverse_iterator 的元素 6 會說明這個反向順序 (8, 6, 4, 2) 的項目 4。

範例

// reverse_iterator_base.cpp
// compile with: /EHsc
#include <iterator>
#include <algorithm>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;
   int i;

   vector<int> vec;
   for ( i = 1 ; i < 6 ; ++i )  
   {
      vec.push_back ( 2 * i );
   }
   
   vector <int>::iterator vIter;
   cout << "The vector vec is: ( ";
   for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++ )
      cout << *vIter << " ";
   cout << ")." << endl;

   vector <int>::reverse_iterator rvIter;
   cout << "The vector vec reversed is: ( ";
   for ( rvIter = vec.rbegin( ) ; rvIter != vec.rend( ); rvIter++)
      cout << *rvIter << " ";
   cout << ")." << endl;

   vector <int>::iterator pos, bpos;
   pos = find ( vec.begin ( ), vec.end ( ), 6 );
   cout << "The iterator pos points to: " << *pos << "." << endl;

   typedef reverse_iterator<vector<int>::iterator>::iterator_type it_vec_int_type;

   reverse_iterator<it_vec_int_type> rpos ( pos );
   cout << "The reverse_iterator rpos points to: " << *rpos 
        << "." << endl;

   bpos = rpos.base ( );
   cout << "The iterator underlying rpos is bpos & it points to: " 
        << *bpos << "." << endl;
}

Output

The vector vec is: ( 2 4 6 8 10 ).
The vector vec reversed is: ( 10 8 6 4 2 ).
The iterator pos points to: 6.
The reverse_iterator rpos points to: 4.
The iterator underlying rpos is bpos & it points to: 6.

需求

標頭:<迭代器>

命名空間: std

請參閱

參考

reverse_iterator 類別

標準樣板程式庫