title: gtest - testing template class
body: <p>I want to test a template class with gtest. I read about TYPED_TESTs in <a href="https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#typed-tests" rel="noreferrer">Google Test manual</a> and looked at <a href="https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc" rel="noreferrer">official example</a> they reference, but still can't wrap my head around getting an object of template class instantiated in my test.</p>
  
  <p>Suppose the following simple template class:</p>
  
  <pre><code>template &lt;typename T&gt;
  class Foo
  {
  public:
      T data ;
  };
  </code></pre>
  
  <p>In testing class we declare</p>
  
  <pre><code>typedef ::testing::Types&lt;int, float&gt; MyTypes ;
  </code></pre>
  
  <p>Now how can I instantiate an object of class Foo for Ts listed in MyTypes in a test?
  E.g.</p>
  
  <pre><code>TYPED_TEST(TestFoo, test1)
  {
      Foo&lt;T&gt; object ;
      object.data = 1.0 ;
  
      ASSERT_FLOAT_EQ(object.data, 1.0) ;
  }
  </code></pre>