STL array的rend方法(17)
来源:互联网 发布:电子地图编辑软件 编辑:程序博客网 时间:2024/04/29 10:36
原文地址:http://www.cplusplus.com/reference/array/array/rend/
public member function
<array>
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
noneReturn Value
A reverse iterator to the reverse end of the sequence.返回值是一个反向迭代器指向序列的反向结尾。
如果array对象是const,那么返回的是const迭代器。
迭代器类型属于随机访问迭代器。
Example
12345678910111213141516
// array::rbegin/rend#include <iostream>#include <array>int main (){ std::array<int,4> myarray = {4, 26, 80, 14} ; std::cout << "myarray contains:"; for ( auto rit=myarray.rbegin() ; rit < myarray.rend(); ++rit ) std::cout << ' ' << *rit; std::cout << '\n'; return 0;}
Edit & Run
Output:
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.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
——————————————————————————————————————————————————————————————————
0 0
- STL array的rend方法(17)
- STL vector中的rend方法(10)
- STL 反向迭代器(rbegin,rend)
- STL array的at方法(2)
- STL array的back方法(3)
- STL array的begin方法(4)
- STL array的cend方法(6)
- STL array的crend方法(8)
- STL array的empty方法(10)
- STL array的fill方法(12)
- STL array的front方法(13)
- STL array的operator[]方法(15)
- STL array的rbegin方法(16)
- STL array的size方法(18)
- STL array的swap方法(19)
- 反向迭代器( rbegin, rend )[STL]
- STL array的crbegin方法(7)
- STL array的data方法(9)
- 退出MFC应用程序的方法集
- 八达岭动物园老虎咬死巡逻员
- 八达岭动物园老虎咬死巡逻员
- 八达岭动物园老虎咬死巡逻员
- 八达岭动物园老虎咬死巡逻员
- STL array的rend方法(17)
- BaseDB MongoDb dao数据库操作类
- Leetcode 细节实现 Rotate Image
- android双击灭屏
- Façade(外观模式)
- map 样例
- Linux分区、格式化、加载磁盘
- Cocos2d-x JNI使用--震动
- 门禁管理