/* Lecture Code 4.0
 *
 * STL iterator basics.  This code shows off how to iterate
 * over a vector using iterators, as well as how to modify
 * specific elements using iterators.
 */

#include <iostream>
#include <vector>
using namespace std;

/* Constant: kNumValues
 * -------------------------------------------------
 * The number of elements to insert into the vector.
 */
const size_t kNumValues = 10;

int main() {
	/* Create a vector and fill it with the first kNumValues
	 * integers.
	 */
	vector<int> values;
	for (size_t i = 0; i < kNumValues; ++i)
		values.push_back(i);
	
	/* Use iterators to print out the contents of the vector.
	 * We iterate starting at begin(), ending when the iterator
	 * has hit end, and at each step access the stored value
	 * using the * operator.
	 */
	for (vector<int>::iterator itr = values.begin(); itr != values.end(); ++itr)
		cout << *itr << " ";
	cout << endl;
	
	/* Use iterators to set every element of the vector to 137. */
	for (vector<int>::iterator itr = values.begin(); itr != values.end(); ++itr)
		*itr = 137;
	
	/* Print everything back out. */
	for (vector<int>::iterator itr = values.begin(); itr != values.end(); ++itr)
		cout << *itr << " ";
	cout << endl;
}