STLarray的rend方法(17)
原文地址:http://www.cplusplus.com/reference/array/array/rend/
public member function
std::array::rend
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
Return reverse iterator to reverse end
Returns a reverse iterator pointing to the theoretical element preceding the first element in the array (which is considered its reverse end).
返回一个反向迭代器指向理论上存在于array容器第一个元素之前的元素。(这个元素被认为是反向的结尾)
//今天突然发现用反向代替翻转更好0.0
The range between array::rbegin and array::rend contains all the elements of the array (in reverse order).
范围rbegin和rend包括了array里面的所有元素(逆序).
Parameters
none
Return Value
A reverse iterator to the reverse end 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
1 | 1 |
1 | // array::rbegin/rend |
Output:
14 80 26 4
Notice how the reverse iterator iterates through the array in a reverse way by increasing the iterator.
注意反向迭代器递增的时候是翻转着移动的。
例子:
#include
#include
using namespace std;
int main()
{
array<int,5> ai{10,20,30,40,50};
auto it=ai.end();
cout<<”ai=”;
for(int i:ai)
cout<<i<<” “;
cout<<endl;
cout<<”ai.rend()=”<<*ai.rend()<<endl;
cout<<”ai.rend()-1=”<<*(ai.rend()-1)<<endl;
cout<<”ai.rend()-2=”<<*(ai.rend()-2)<<endl;
cout<<”ai.rend()-3=”<<*(ai.rend()-3)<<endl;
}
运行结果:
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
——————————————————————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/stlarray的rend方法(17)/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!