deque::rbegin
反転 deque の最初の要素への反復子を返します。
const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );
戻り値
反転 deque の一つ目の要素を指定するか、deque、通常の最後の要素では、対応する逆のランダム アクセス反復子。
解説
rbegin は 反転 deque と 開始 が deque と併用するために使用されます。
rbegin の戻り値が const_reverse_iteratorに割り当てると、deque オブジェクトは変更できません。 rbegin の戻り値が reverse_iteratorに割り当てると、deque オブジェクトを変更できます。
rbegin が deque を逆方向に反復処理するために使用できます。
使用例
// deque_rbegin.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.rbegin( );
cout << "Last element in the deque is " << *c1_rIter << "." << endl;
cout << "The deque contains the elements: ";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << *c1_Iter << " ";
cout << "in that order.";
cout << endl;
// rbegin can be used to iterate through a deque in reverse order
cout << "The reversed deque is: ";
for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
cout << *c1_rIter << " ";
cout << endl;
c1_rIter = c1.rbegin( );
*c1_rIter = 40; // This would have caused an error if a
// const_reverse iterator had been declared as
// noted above
cout << "Last element in deque is now " << *c1_rIter << "." << endl;
}
必要条件
ヘッダー: <deque>
名前空間: std