title: How could I print the contents of any container in a generic way?
body: <p>I am trying to write a piece of code for fun using C++ templates.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  template &lt;class Container&gt;
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; o, const Container&amp; container)
  {
      typename Container::const_iterator beg = container.begin();
  
      o &lt;&lt; "["; // 1
  
      while(beg != container.end())
      {
          o &lt;&lt; " " &lt;&lt; *beg++; // 2
      }
  
      o &lt;&lt; " ]"; // 3
  
      return o;
  }
  
  int main()
  {
      std::vector&lt;int&gt; list;
  
      list.push_back(0);
      list.push_back(0);
  
      std::cout &lt;&lt; list;
  
      return 0;
  }
  </code></pre>
  
  <p><strong><em>The above code doesn't compile :)</em></strong></p>
  
  <p>At 1, 2, 3 the same error is produced : <strong>error C2593: 'operator &lt;&lt;' is ambiguous</strong></p>
  
  <p>All what I am trying to do is overloading the &lt;&lt; operator to work with any container. Does that make sense ? How would that be done If possible, if not why ?</p>
  
  <p>EDIT :: Thanks for corrections :) 'sth' way is a good solution.</p>
  
  <p>I am just curious if this ambiguity -as Neil explained- would go away if we could use C++0x Concepts ?</p>