/***************************************************************************
 * This program illustrates 'vector' basics.
 ***************************************************************************/
#include <iostream>
#include <vector>

using std::cin;           
using std::cout;            
using std::endl;            
using std::vector;

void show_vec(const vector<int>& vec);// A function declaration
/* This form is better than the one in the handout, because it doesn't 
 * have to make a copy of 'vec' before outputting its contents.
 */
int main()
{
	// Declare an empty vector of ints.
	vector<int> blank_slate;
	// Declare a vector of size 5. It will be initialized to 0's.
	vector<int> zeros(5);
	// Declare a vector of 5 17's.
	vector<int> just_seventeens(5,17);
	// Display the contents of each.
	cout<<"The vector 'blank_slate' contains\n";
	show_vec(blank_slate);
	cout<<"\nThe vector 'zeros' contains\n";
	show_vec(zeros);
	cout<<"\nThe vector 'just_seventeens' contains\n";
	show_vec(just_seventeens);
	int array[]={0,1,1,2,3,5,8,13};
	vector<int> fibonacci(array, array+8);//Initialize a vector
					      //from an array.
	cout<<"\nThe vector 'fibonacci' contains\n";
	show_vec(fibonacci);
	// Load a vector using push_back().
	vector<int> custom;
	int x;
	cout<<"\nPlease enter space-separated integers, and 's' to stop:";
	while(cin>>x)
		custom.push_back(x);//Load 'custom' from the keyboard.
	cout<<"The vector 'custom' contains\n";
	show_vec(custom);

	vector<int> copycat(custom);//Declare another vector with the values
				    //from 'custom'.
	cout<<"\nNow 'copycat' has the same values as 'custom':\n";
	show_vec(copycat);

	blank_slate=custom;//Make 'blank_slate' a copy of 'custom'
	cout<<"\nSo does 'blank_slate'.\n";
	show_vec(blank_slate);

	//Show that copies are independent of the original.
	blank_slate.push_back(2006);
	cout<<"\nThe new blank_slate: ";
	show_vec(blank_slate);
	cout<<"\nAs you would hope, 'custom' is unchanged: ";
	show_vec(custom);
	return 0;
}

void show_vec(const vector<int>& vec) // This is the definition of the function.
{
	/*typedef vector<int>::size_type vec_size;
	for(vec_size i=0; i!=vec.size();i++)
		cout<<vec[i]<<" ";*/
	for(int i=0; i!=vec.size();i++)
		cout<<vec[i]<<" ";
	
}

