1. reverse预设capacity大小:效率上优势,正确性保证
2.swap 两个vector内容的交换,效率较高
3.base() 从reverse_iterator抽取出iterator
#include<vector>
#include<iostream>
using namespace std;
int main()
{
vector<int> testVector = { 1,2,3,4,5 };//c++11
testVector.clear();
testVector.reserve(2);
cout << testVector.capacity() << endl;//5
testVector = { 1,2,3,4,5 };
vector<int> testVector2;
testVector2.swap(testVector);
cout << testVector.size() << endl;//0
cout << testVector2.size() << endl;//5
for (vector<int>::reverse_iterator reiter = testVector2.rbegin(); reiter != testVector2.rend(); ++reiter)
{
cout << *reiter;
if (reiter.base() != testVector2.end())
cout << "-" << *reiter.base() << endl;//rebegin-->end; rend-->begin
}
getchar();
return 0;
}