std::array::rbegin
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
返回一个反向迭代器指array容器的最后一个元素。
rbegin指向end方法获得的元素的前一个元素。
Notice that unlike member array::back, which returns a reference to this same element, this function returns a reverse random access iterator.
注意和back不同,back是返回同一个元素的引用,这个方法返回的是一个随机访问迭代器 。
Parameters
noneReturn Value
A reverse iterator to the reverse beginning of the sequence.一个反向迭代器指向序列开头。
如果array对象是const,那么返回的是const迭代器。
迭代器类型属于随机访问迭代器。
Example
| |
Output:
myarray contains: 14 80 26 4
|
注意反向迭代器递增的时候是翻转着移动的。
例子:
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<int,5> ai{10,20,30,40,50};
auto it=ai.rbegin();
cout<<"ai=";
for(int i:ai)
cout<<i<<" ";
cout<<endl;
cout<<"ai.rbegin()="<<*ai.rbegin()<<endl;
cout<<"ai.rbegin()+1="<<*(ai.rbegin()+1)<<endl;
cout<<"ai.rbegin()+2="<<*(ai.rbegin()+2)<<endl;
cout<<"ai.rbegin()+3="<<*(ai.rbegin()+3)<<endl;
}
运行截图:
可以看到,当rbegin递增的时候,其遍历array的方向也是翻转的。
Complexity
Constant.Iterator validity
No changes.Data races
No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.容器元素不会被访问,但是返回的迭代器可以用来访问以及修改元素,同时访问以及修改他们都是安全的。
Exception safety
No-throw guarantee: this member function never throws exceptions.The copy construction or assignment of the returned iterator is also guaranteed to never throw.
该方法不会抛出异常。
通过复制或者赋值获得的该迭代器副本也不会抛出异常。
——————————————————————————————————————————————————————————————————
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-8-30
于GDUT
——————————————————————————————————————————————————————————————————