std::array::rbegin
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
Returns a reverse iterator pointing to the last element in the array container.
返回一个反向迭代器指array容器的最后一个元素。
rbegin points to the element right before the one that would be pointed to by member end.
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
none
Return Value
A reverse iterator to the reverse beginning of the sequence.
一个反向迭代器指向序列开头。
If the array object is const-qualified, the function returns a const_iterator. Otherwise, it
returns an iterator.
如果array对象是const,那么返回的是const迭代器。
Member types reverse_iterator and const_reverse_iterator are reverse random
access iterator types (pointing to an element and to a const element, respectively). See vector member types.
迭代器类型属于随机访问迭代器。
Example
|
|
Output:
myarray contains: 14 80 26 4
|
Notice how the reverse iterator iterates through the vector in a reverse way by increasing the iterator.
注意反向迭代器递增的时候是翻转着移动的。
例子:
#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
——————————————————————————————————————————————————————————————————