#include <set>
#include <list>
#include <vector>
#include <algorithm>
#include <deque>

#include <iostream>

#include "misc.h"


using namespace std;


// insert(pos,const T&) is general inserter.
// Writen a general class where the container is variable

//
// C is the container eg list<T> vector<T> set<T> ...
// T is the type

template<class C, class T>
class display_container
{
   C c;
public:

   display_container(C c_=C()) : c(c_) {}

   // Apply general inserter
   void insert(const T& val) { inserter(c,c.end()) = val; }
   // Fill container
   void insert(vector<T>& v)
   {
      for (unsigned int i=0; i<v.size(); ++i)
         insert( v[i] );
   }

   ostream& print(ostream& os) const
   {
      copy(c.begin(),c.end(),ostream_iterator<T>(os," "));
      return os;
   }
   ostream& print2(ostream& os) { 
      copy(c.begin(),c.end(),ostream_iterator<T>(os," ")); return os; }
};


//
// Helper test function : places elements into
// generic container and prints them
//
template< typename C, class T>
void example( display_container< C, T> & container )
{
   int a[] = {83, 2, 100, 89, 20,   4, 02, 594, 93, 30,   29 };
   vector<int> v(a,a+sizeof(a)/sizeof(int));

   container.insert(v);
   container.print2(cout);
}


//
// General Insertion test
//
void test01()
{
   int a[] = {83, 2, 100, 89, 20,   4, 02, 594, 93, 30,   29 };
   vector<int> v(a,a+sizeof(a)/sizeof(int));

   //
   // Set
   //

   set< int, greater<int> > s;
   display_container< 
      set< int, greater<int> >&, 
      int> c1(s);

   c1.insert(v);
   c1.print2(cout);
   cout << endl << endl;

   //
   // Vector
   //

   vector<int> w;
   display_container<
      vector< int >&,
      int> c2(w);

   c2.insert(v);
   c2.print2(cout);
   cout << endl << endl;

   //
   // List
   //

   example( fconst( display_container<list< int>, int>() ) );
   cout << endl << endl;

   //
   // Deque
   //

   example( fconst( display_container<deque< int>, int>() ) );
   cout << endl << endl;

   //
   // Multi-set
   //

   example( fconst( display_container<multiset< int>, int>() ) );
   cout << endl << endl;
}


void main()
{
   test01();
}

