title: Call explicit constructor/destructor with traits in templatized function
body: <p>I'm trying to call explicit constructor/destructor with traits in templatized function.</p>
  
  <pre><code>template &lt;int i&gt;
  struct Traits
  {
  };
  template &lt;&gt;
  struct Traits&lt;1&gt;
  {
    typedef Foo type_t;
  };
  template &lt;&gt;
  struct Traits&lt;2&gt;
  {
    typedef Bar type_t;
  };
  
  template &lt;class Traits&gt;
  void DoSomething(void* p_in)
  {
    typename Traits::type_t* p = reinterpret_cast&lt;typename Traits::type_t*&gt;(p_in);
    // this works.
    new (p) typename Traits::type_t;
    // neither of following two does work.
    p-&gt;~typename Traits::type_t();
    p-&gt;typename ~Traits::type_t();
  }
  
  // call
  void* p_in = malloc(BIG_ENOUGH);
  DoSomething&lt;Traits&lt;1&gt; &gt;(p_in);
  free(p_in);
  </code></pre>
  
  <p>In GCC 4.4.3 with -ansi flag, calling explicit constructor works fine. However, calling explicit destructor does not work, giving following error:</p>
  
  <pre><code>error: expected identifier before 'typename'
  error: expected ';' before 'typename'
  </code></pre>
  
  <p>I suspect some parentheses or keyword is missing. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>People ask about why I am doing this... Yes, as expected, I want to use memory pool, and give two functions to clients. Internally it uses a static pointer to the memory pool for malloc/free.</p>
  
  <pre><code>template&lt;class Traits&gt;
  typename Traits::type_t* memory_pool_new();
  template&lt;class Traits&gt;
  void memory_pool_delete();
  </code></pre>
  
  <p>Of course this approach has limitations... like only default constructor can be used. I thought about overloading new, but it requires overloading new of all type_t's, and it will change the behavior of existing codes.</p>