title: How to write test for C++ templates?
body: <p>Suppose I am writing a <em>template</em> library consisting of a function template</p>
  
  <pre><code>template&lt;T&gt; void f(T);
  </code></pre>
  
  <p>with the requirement that it works with a predefined set of classes A, B, C, and D, e.g., the following must compile:</p>
  
  <pre><code>template&lt;&gt; void f(A);
  template&lt;&gt; void f(B);
  template&lt;&gt; void f(C);
  template&lt;&gt; void f(D);
  </code></pre>
  
  <p>Which test framework can I use to write test cases that captures this requirement at runtime instead of failing at compilation of the test code?  In another word, I would like the framework to instantiate the templates at <em>runtime</em> and produce a nicely formatted error report if a subset of them fails.</p>
  
  <p>I know I can forego test frameworks altogether and simply write a simple cc file containing the 4 lines above.  But I was hoping I could incorporate this requirement into regular, standard test cases for generation of test status reports.  For example,</p>
  
  <pre><code>test f works with A: passed.
  test f works with B: passed.
  test f works with C: failed!  Cannot cast type C!
  test f works with D: passed.
  
  3 of 4 tests passed.
  1 of 4 tests failed.
  </code></pre>