#include <iostream>
#include <algorithm>
#include <numeric>
#include <list>

#include "complex.h"

// Generic list printing routine: output is "{ <elem1>, <elem2>, ... ".
template <class T>
std::ostream & operator<<(std::ostream & o, const std::list<T> & l)
{
  o << "{";
  std::list<T>::iterator i = l.begin(); 
  bool comma_needed = false;
  while (i != l.end())
  {
    if (comma_needed)
      o << ",";
    else 
      comma_needed = true;
    o << " " << *i;
    ++i;
  }
  o << " }";

  return o;
}

void main()
{
  std::list<complex> a;

  a.push_back(3);
  a.push_back(2);
  a.push_back(1);

  a.sort();
  std::cout << "a = " << a << std::endl;

  std::cout << "sum of a is "
     << std::accumulate(a.begin(), a.end(), complex(0))
     << std::endl;
}
