// vectorbasics.cpp

#include <vector>
#include <iostream>
using namespace std;

int main()
{
	const int len = 10;
	int a[len];
	vector<int> v(len);

	for (int i = 0; i < v.size(); ++i)
	{	a[i] = i;
		v[i] = i;
	}

	cout << "a" << '\t' << "v" << endl;
	cout << "=" << '\t' << "=" << endl;
	for (int j = 0; j < v.size(); ++j)
		cout << a[j] << '\t' << v.at(j) << endl;

	cout << "Elmt beyond end of a is " << a[len] << endl;

	v.push_back(10);
	cout << "Elmt beyond end of v is " << v.at(len) << endl;
	cout << "v's size is " << v.size() << endl;
	cout << "v's capacity is " << v.capacity() << endl;

	// demonstrate iterators
	vector<int>::iterator itr;
	itr = v.begin();			// itr is at the start of v
	cout << "itr points to " << *itr << endl;	// dereferences itr
	cout << "itr contains: " << itr << endl;
	++itr;
	cout << "itr now points to " << *itr << endl;	// dereferences itr

	// typical iterator loop
	for (itr = v.begin(); itr != v.end(); ++itr)
		cout << *itr << ", ";
	cout << endl;

	// let's use reverse iterators
	vector<int>::reverse_iterator ritr;
	ritr = v.rbegin();
	cout << "ritr points to " << *ritr << endl;
	++ritr;
	cout << "ritr now points to " << *ritr << endl;

	// let's loop backwards thru v
	for (ritr = v.rbegin(); ritr != v.rend(); ++ritr)
		cout << *ritr << ", ";
	cout << endl;

	// don't do this!
	++ritr;
	cout << "ritr now points to " << *ritr << endl;
	*ritr = 99;
	cout << "ritr now points to " << *ritr << endl;

	return 0;
}
