title: SFINAE + sizeof = detect if expression compiles
body: <p>I just found out how to check if <code>operator&lt;&lt;</code> is provided for a type.</p>
  
  <pre><code>template&lt;class T&gt; T&amp; lvalue_of_type();
  template&lt;class T&gt; T  rvalue_of_type();
  
  template&lt;class T&gt;
  struct is_printable
  {
      template&lt;class U&gt; static char test(char(*)[sizeof(
          lvalue_of_type&lt;std::ostream&gt;() &lt;&lt; rvalue_of_type&lt;U&gt;()
      )]);
      template&lt;class U&gt; static long test(...);
  
      enum { value = 1 == sizeof test&lt;T&gt;(0) };
      typedef boost::integral_constant&lt;bool, value&gt; type;
  };
  </code></pre>
  
  <p>Is this trick well-known, or have I just won the metaprogramming Nobel prize? ;)</p>
  
  <p>EDIT: I made the code simpler to understand and easier to adapt with two global function template declarations <code>lvalue_of_type</code> and <code>rvalue_of_type</code>.</p>