/*****************************************************************************
 * This program is intended as a scratch pad to test the template class
 * sumVec, based on Vec from the text.
 * We examine iterator access, index access, copy construction, 
 * and assignment.
 * **************************************************************************/
#include<iostream>
#include<iomanip>
#include "sumVec.h"
using std::cin; using std::cout;
using std::endl;

template<class T>
void Vec_out(const Vec<T>& v)
{
	 v.show();
	 return;
}

int main()
{
	sumVec<int> nums(3,7);
	nums.show();
	sumVec<int> nums2(nums);
	cout<<endl;
	nums2.show();
	cout<<endl;
	nums2[1]=77;
	nums[2]=-77;
	cout<<endl<<"'nums2' is constructed from 'nums', then altered: ";
	nums2.show();
	nums=nums;//harmless
	cout<<endl<<"''nums' remains unchanged: ";
	nums.show();
	sumVec<int> nums3=nums;
	nums3.show();
	nums3.push_back(67);
	cout<<endl<<"nums3: ";
	nums3.show();
	cout<<endl<<"nums: ";
	nums.show();
	nums.clear();
	cout<<endl<<"After clearing, nums: ";
	nums.show();
	for(int i=10; i!=60; i+=10)
	nums.push_back(i);
	cout<<endl;
	cout<<"\nIterator access to the elements of a sumVec works:\n";
	for(sumVec<int>::iterator it=nums.begin(); it!=nums.end(); it++)
		cout<<*it<<" ";
	cout<<endl<<"\nNote that the sum doesn't come up.\n";
	
	sumVec<int> second(nums);
	cout<<"\nThe copy constructor works:\n"; 
	for(sumVec<int>::size_type i=0; i!=second.size(); i++)
		cout<<second[i]<<" ";
	cout<<endl<<endl;
	Vec<int> base_nums(3,8);
	
	
	
	Vec<int>& p=nums;
	Vec<int>& q=base_nums;
	cout<<"Observe dynamic binding with a sumVec: ";
	p.show();
	cout<<"\nand with a Vec: ";
	q.show();
	cout<<endl;
	Vec<Vec<int>*> vecs;/* Make a vector of base class
				    pointers.*/
	Vec<int>* ptr=&nums;
	vecs.push_back(ptr);/*base class pointers can point to 
			      derived class objects.*/
	cout<<"'show' from a base pointer to a sumVec: ";
	ptr->show();
	ptr=&base_nums;
	vecs.push_back(ptr);
	cout<<"\n'show' from a base pointer to a Vec: ";
	ptr->show();
	ptr=&nums3;
	vecs.push_back(ptr);
	cout<<"\n\nWe can handle a mixed vector with uniform code:\n";
	for(Vec<Vec<int>*>::const_iterator i=vecs.begin();
		       	i!=vecs.end();i++)
	{
		(*i)->show();
		cout<<endl;
	}
	
	

	return 0;
}

	
