deque::rend
傳回處理成功最後一個項目的位置會反轉雙向佇列的 Iterator。
const_reverse_iterator rend( ) const;
reverse_iterator rend( );
傳回值
處理成功最後一個項目的位置會反轉雙向佇列的反向隨機存取 Iterator (在 unreversed 雙向佇列中的第一個項目之前) 的位置。
備註
如同 結束 使用雙向佇列,rend 以反轉雙向佇列。
如果傳回值 rend 給 const_reverse_iterator,無法修改雙向佇列物件。 如果傳回值 rend 給 reverse_iterator,可以修改雙向佇列物件。
rend 可用來測試反向 Iterator 是否已到達的雙向佇列的結尾。
不應該取值 rend 所傳回的值。
範例
// deque_rend.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
int main( )
{
using namespace std;
deque <int> c1;
deque <int>::iterator c1_Iter;
deque <int>::reverse_iterator c1_rIter;
// If the following line had replaced the line above, an error
// would have resulted in the line modifying an element
// (commented below) because the iterator would have been const
// deque <int>::const_reverse_iterator c1_rIter;
c1.push_back( 10 );
c1.push_back( 20 );
c1.push_back( 30 );
c1_rIter = c1.rend( );
c1_rIter --; // Decrementing a reverse iterator moves it forward
// in the deque (to point to the first element here)
cout << "The first element in the deque is: " << *c1_rIter << endl;
cout << "The deque is: ";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << *c1_Iter << " ";
cout << endl;
// rend can be used to test if an iteration is through all of
// the elements of a reversed deque
cout << "The reversed deque is: ";
for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
cout << *c1_rIter << " ";
cout << endl;
c1_rIter = c1.rend( );
c1_rIter--; // Decrementing the reverse iterator moves it backward
// in the reversed deque (to the last element here)
*c1_rIter = 40; // This modification of the last element would
// have caused an error if a const_reverse
// iterator had been declared (as noted above)
cout << "The modified reversed deque is: ";
for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
cout << *c1_rIter << " ";
cout << endl;
}
需求
標頭: <deque>
命名空間: std