title: restrict a template function, to only allow certain types
body: <p>Here say I have a simple template function that in principle can accept all kind of types:</p>
  
  <pre><code>template &lt;class Type&gt;
  std::ostream&amp; operator&lt;&lt; (std::ostream&amp; stream, const Type subject) {
  stream &lt;&lt; "whatever, derived from subject\n";
  return stream; }
  </code></pre>
  
  <p>I only want to use this template to cout a few types, say std::vector and boost::array objects. However whenever I use cout to other types even elementary types, e.g. std::cout &lt;&lt; int(5);, will be a compilation error, because there are two possible implementations of operator&lt;&lt;(std::ostream, int) now, one is in standard c++, the other specified by my template function.</p>
  
  <p>I would like to ask, is it possible to restrict my template function, so that it only accepts a few types specified by me? That is how to tell the compiler to ignore my template when i use cout &lt;&lt; int(5). Thanks in advance.</p>
  
  <p>To be more clear, this is what I want to do:</p>
  
  <pre><code>template &lt;class Type&gt;
  std::ostream&amp; operator&lt;&lt; (std::ostream&amp; stream, const Type subject) {
  if (Type == TypeA or TypeB or TypeC) //use this template and do these {...};
  else //ignore this template, and use operator&lt;&lt; provided in standard c++ library.
  }
  </code></pre>